Skip to content

Commit 576248a

Browse files
fs/ntfs3: handle attr_set_size() errors when truncating files
If attr_set_size() fails while truncating down, the error is silently ignored and the inode may be left in an inconsistent state. Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
1 parent 3a6aba7 commit 576248a

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

fs/ntfs3/file.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -505,8 +505,8 @@ static int ntfs_truncate(struct inode *inode, loff_t new_size)
505505
{
506506
struct super_block *sb = inode->i_sb;
507507
struct ntfs_inode *ni = ntfs_i(inode);
508-
int err, dirty = 0;
509508
u64 new_valid;
509+
int err;
510510

511511
if (!S_ISREG(inode->i_mode))
512512
return 0;
@@ -522,7 +522,6 @@ static int ntfs_truncate(struct inode *inode, loff_t new_size)
522522
}
523523

524524
new_valid = ntfs_up_block(sb, min_t(u64, ni->i_valid, new_size));
525-
526525
truncate_setsize(inode, new_size);
527526

528527
ni_lock(ni);
@@ -536,20 +535,19 @@ static int ntfs_truncate(struct inode *inode, loff_t new_size)
536535
ni->i_valid = new_valid;
537536

538537
ni_unlock(ni);
538+
if (unlikely(err))
539+
return err;
539540

540541
ni->std_fa |= FILE_ATTRIBUTE_ARCHIVE;
541542
inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode));
542543
if (!IS_DIRSYNC(inode)) {
543-
dirty = 1;
544+
mark_inode_dirty(inode);
544545
} else {
545546
err = ntfs_sync_inode(inode);
546547
if (err)
547548
return err;
548549
}
549550

550-
if (dirty)
551-
mark_inode_dirty(inode);
552-
553551
return 0;
554552
}
555553

0 commit comments

Comments
 (0)