Skip to content

Commit 92300ac

Browse files
aalexandrovichgregkh
authored andcommitted
fs/ntfs3: handle attr_set_size() errors when truncating files
[ Upstream commit 576248a ] 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> Stable-dep-of: d7ea849 ("fs/ntfs3: fix missing run load for vcn0 in attr_data_get_block_locked()") Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent caa36a9 commit 92300ac

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
@@ -371,8 +371,8 @@ static int ntfs_truncate(struct inode *inode, loff_t new_size)
371371
{
372372
struct super_block *sb = inode->i_sb;
373373
struct ntfs_inode *ni = ntfs_i(inode);
374-
int err, dirty = 0;
375374
u64 new_valid;
375+
int err;
376376

377377
if (!S_ISREG(inode->i_mode))
378378
return 0;
@@ -388,7 +388,6 @@ static int ntfs_truncate(struct inode *inode, loff_t new_size)
388388
}
389389

390390
new_valid = ntfs_up_block(sb, min_t(u64, ni->i_valid, new_size));
391-
392391
truncate_setsize(inode, new_size);
393392

394393
ni_lock(ni);
@@ -402,20 +401,19 @@ static int ntfs_truncate(struct inode *inode, loff_t new_size)
402401
ni->i_valid = new_valid;
403402

404403
ni_unlock(ni);
404+
if (unlikely(err))
405+
return err;
405406

406407
ni->std_fa |= FILE_ATTRIBUTE_ARCHIVE;
407408
inode->i_mtime = inode_set_ctime_current(inode);
408409
if (!IS_DIRSYNC(inode)) {
409-
dirty = 1;
410+
mark_inode_dirty(inode);
410411
} else {
411412
err = ntfs_sync_inode(inode);
412413
if (err)
413414
return err;
414415
}
415416

416-
if (dirty)
417-
mark_inode_dirty(inode);
418-
419417
/*ntfs_flush_inodes(inode->i_sb, inode, NULL);*/
420418

421419
return 0;

0 commit comments

Comments
 (0)