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.
Unified · Split
| @@ -844,7 +844,9 @@ void ufs_evict_inode(struct inode * inode) · 843 unmodified lines | ||
| 844 | 844 | truncate_inode_pages_final(&inode->i_data); |
| 845 | 845 | if (want_delete) { |
| 846 | 846 | 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))) | |
| 848 | 850 | ufs_truncate_blocks(inode); |
| 849 | 851 | } |
| 850 | 852 | |
| @@ -1103,7 +1105,7 @@ out: · 252 unmodified lines | ||
| 1103 | 1105 | return err; |
| 1104 | 1106 | } |
| 1105 | 1107 | |
| 1106 | −static void __ufs_truncate_blocks(struct inode *inode) | |
| 1108 | +static void ufs_truncate_blocks(struct inode *inode) | |
| 1107 | 1109 | { |
| 1108 | 1110 | struct ufs_inode_info *ufsi = UFS_I(inode); |
| 1109 | 1111 | struct super_block *sb = inode->i_sb; |
| @@ -1186,7 +1188,7 @@ static int ufs_truncate(struct inode *inode, loff_t size) · 76 unmodified lines | ||
| 1186 | 1188 | |
| 1187 | 1189 | truncate_setsize(inode, size); |
| 1188 | 1190 | |
| 1189 | − __ufs_truncate_blocks(inode); | |
| 1191 | + ufs_truncate_blocks(inode); | |
| 1190 | 1192 | inode->i_mtime = inode->i_ctime = current_time(inode); |
| 1191 | 1193 | mark_inode_dirty(inode); |
| 1192 | 1194 | out: |
| @@ -1194,16 +1196,6 @@ out: · 1 unmodified line | ||
| 1194 | 1196 | return err; |
| 1195 | 1197 | } |
| 1196 | 1198 | |
| 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 | − | |
| 1207 | 1199 | int ufs_setattr(struct dentry *dentry, struct iattr *attr) |
| 1208 | 1200 | { |
| 1209 | 1201 | struct inode *inode = d_inode(dentry); |