Skip to content

Commit babef37

Browse files
author
Al Viro
committed
excessive checks in ufs_write_failed() and ufs_evict_inode()
As it is, short copy in write() to append-only file will fail to truncate the excessive allocated blocks. As the matter of fact, all checks in ufs_truncate_blocks() are either redundant or wrong for that caller. As for the only other caller (ufs_evict_inode()), we only need the file type checks there. Cc: [email protected] Signed-off-by: Al Viro <[email protected]>
1 parent 006351a commit babef37

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

fs/ufs/inode.c

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,9 @@ void ufs_evict_inode(struct inode * inode)
844844
truncate_inode_pages_final(&inode->i_data);
845845
if (want_delete) {
846846
inode->i_size = 0;
847-
if (inode->i_blocks)
847+
if (inode->i_blocks &&
848+
(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
849+
S_ISLNK(inode->i_mode)))
848850
ufs_truncate_blocks(inode);
849851
}
850852

@@ -1103,7 +1105,7 @@ static int ufs_alloc_lastblock(struct inode *inode, loff_t size)
11031105
return err;
11041106
}
11051107

1106-
static void __ufs_truncate_blocks(struct inode *inode)
1108+
static void ufs_truncate_blocks(struct inode *inode)
11071109
{
11081110
struct ufs_inode_info *ufsi = UFS_I(inode);
11091111
struct super_block *sb = inode->i_sb;
@@ -1186,24 +1188,14 @@ static int ufs_truncate(struct inode *inode, loff_t size)
11861188

11871189
truncate_setsize(inode, size);
11881190

1189-
__ufs_truncate_blocks(inode);
1191+
ufs_truncate_blocks(inode);
11901192
inode->i_mtime = inode->i_ctime = current_time(inode);
11911193
mark_inode_dirty(inode);
11921194
out:
11931195
UFSD("EXIT: err %d\n", err);
11941196
return err;
11951197
}
11961198

1197-
static void ufs_truncate_blocks(struct inode *inode)
1198-
{
1199-
if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
1200-
S_ISLNK(inode->i_mode)))
1201-
return;
1202-
if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
1203-
return;
1204-
__ufs_truncate_blocks(inode);
1205-
}
1206-
12071199
int ufs_setattr(struct dentry *dentry, struct iattr *attr)
12081200
{
12091201
struct inode *inode = d_inode(dentry);

0 commit comments

Comments
 (0)