diff options
Diffstat (limited to 'fs/omfs/file.c')
| -rw-r--r-- | fs/omfs/file.c | 46 |
1 files changed, 38 insertions, 8 deletions
diff --git a/fs/omfs/file.c b/fs/omfs/file.c index 6e7a3291bbe8..8a6d34fa668a 100644 --- a/fs/omfs/file.c +++ b/fs/omfs/file.c | |||
| @@ -50,7 +50,7 @@ int omfs_shrink_inode(struct inode *inode) | |||
| 50 | if (inode->i_size != 0) | 50 | if (inode->i_size != 0) |
| 51 | goto out; | 51 | goto out; |
| 52 | 52 | ||
| 53 | bh = sb_bread(inode->i_sb, clus_to_blk(sbi, next)); | 53 | bh = omfs_bread(inode->i_sb, next); |
| 54 | if (!bh) | 54 | if (!bh) |
| 55 | goto out; | 55 | goto out; |
| 56 | 56 | ||
| @@ -90,7 +90,7 @@ int omfs_shrink_inode(struct inode *inode) | |||
| 90 | if (next == ~0) | 90 | if (next == ~0) |
| 91 | break; | 91 | break; |
| 92 | 92 | ||
| 93 | bh = sb_bread(inode->i_sb, clus_to_blk(sbi, next)); | 93 | bh = omfs_bread(inode->i_sb, next); |
| 94 | if (!bh) | 94 | if (!bh) |
| 95 | goto out; | 95 | goto out; |
| 96 | oe = (struct omfs_extent *) (&bh->b_data[OMFS_EXTENT_CONT]); | 96 | oe = (struct omfs_extent *) (&bh->b_data[OMFS_EXTENT_CONT]); |
| @@ -222,7 +222,7 @@ static int omfs_get_block(struct inode *inode, sector_t block, | |||
| 222 | struct buffer_head *bh; | 222 | struct buffer_head *bh; |
| 223 | sector_t next, offset; | 223 | sector_t next, offset; |
| 224 | int ret; | 224 | int ret; |
| 225 | u64 new_block; | 225 | u64 uninitialized_var(new_block); |
| 226 | u32 max_extents; | 226 | u32 max_extents; |
| 227 | int extent_count; | 227 | int extent_count; |
| 228 | struct omfs_extent *oe; | 228 | struct omfs_extent *oe; |
| @@ -232,7 +232,7 @@ static int omfs_get_block(struct inode *inode, sector_t block, | |||
| 232 | int remain; | 232 | int remain; |
| 233 | 233 | ||
| 234 | ret = -EIO; | 234 | ret = -EIO; |
| 235 | bh = sb_bread(inode->i_sb, clus_to_blk(sbi, inode->i_ino)); | 235 | bh = omfs_bread(inode->i_sb, inode->i_ino); |
| 236 | if (!bh) | 236 | if (!bh) |
| 237 | goto out; | 237 | goto out; |
| 238 | 238 | ||
| @@ -265,7 +265,7 @@ static int omfs_get_block(struct inode *inode, sector_t block, | |||
| 265 | break; | 265 | break; |
| 266 | 266 | ||
| 267 | brelse(bh); | 267 | brelse(bh); |
| 268 | bh = sb_bread(inode->i_sb, clus_to_blk(sbi, next)); | 268 | bh = omfs_bread(inode->i_sb, next); |
| 269 | if (!bh) | 269 | if (!bh) |
| 270 | goto out; | 270 | goto out; |
| 271 | oe = (struct omfs_extent *) (&bh->b_data[OMFS_EXTENT_CONT]); | 271 | oe = (struct omfs_extent *) (&bh->b_data[OMFS_EXTENT_CONT]); |
| @@ -312,9 +312,17 @@ static int omfs_write_begin(struct file *file, struct address_space *mapping, | |||
| 312 | loff_t pos, unsigned len, unsigned flags, | 312 | loff_t pos, unsigned len, unsigned flags, |
| 313 | struct page **pagep, void **fsdata) | 313 | struct page **pagep, void **fsdata) |
| 314 | { | 314 | { |
| 315 | *pagep = NULL; | 315 | int ret; |
| 316 | return block_write_begin(file, mapping, pos, len, flags, | 316 | |
| 317 | pagep, fsdata, omfs_get_block); | 317 | ret = block_write_begin(mapping, pos, len, flags, pagep, |
| 318 | omfs_get_block); | ||
| 319 | if (unlikely(ret)) { | ||
| 320 | loff_t isize = mapping->host->i_size; | ||
| 321 | if (pos + len > isize) | ||
| 322 | vmtruncate(mapping->host, isize); | ||
| 323 | } | ||
| 324 | |||
| 325 | return ret; | ||
| 318 | } | 326 | } |
| 319 | 327 | ||
| 320 | static sector_t omfs_bmap(struct address_space *mapping, sector_t block) | 328 | static sector_t omfs_bmap(struct address_space *mapping, sector_t block) |
| @@ -333,7 +341,29 @@ const struct file_operations omfs_file_operations = { | |||
| 333 | .splice_read = generic_file_splice_read, | 341 | .splice_read = generic_file_splice_read, |
| 334 | }; | 342 | }; |
| 335 | 343 | ||
| 344 | static int omfs_setattr(struct dentry *dentry, struct iattr *attr) | ||
| 345 | { | ||
| 346 | struct inode *inode = dentry->d_inode; | ||
| 347 | int error; | ||
| 348 | |||
| 349 | error = inode_change_ok(inode, attr); | ||
| 350 | if (error) | ||
| 351 | return error; | ||
| 352 | |||
| 353 | if ((attr->ia_valid & ATTR_SIZE) && | ||
| 354 | attr->ia_size != i_size_read(inode)) { | ||
| 355 | error = vmtruncate(inode, attr->ia_size); | ||
| 356 | if (error) | ||
| 357 | return error; | ||
| 358 | } | ||
| 359 | |||
| 360 | setattr_copy(inode, attr); | ||
| 361 | mark_inode_dirty(inode); | ||
| 362 | return 0; | ||
| 363 | } | ||
| 364 | |||
| 336 | const struct inode_operations omfs_file_inops = { | 365 | const struct inode_operations omfs_file_inops = { |
| 366 | .setattr = omfs_setattr, | ||
| 337 | .truncate = omfs_truncate | 367 | .truncate = omfs_truncate |
| 338 | }; | 368 | }; |
| 339 | 369 | ||
