diff --git a/fs/hfs/inode.c b/fs/hfs/inode.c index c9e75c2e576a..2aef3c36a150 100644 --- a/fs/hfs/inode.c +++ b/fs/hfs/inode.c @@ -49,11 +49,19 @@ int hfs_write_begin(const struct kiocb *iocb, struct address_space *mapping, loff_t pos, unsigned int len, struct folio **foliop, void **fsdata) { + struct inode *inode = mapping->host; + struct hfs_sb_info *sbi = HFS_SB(inode->i_sb); + loff_t total_capacity; int ret; + total_capacity = (loff_t)sbi->fs_ablocks * sbi->alloc_blksz; + + if (pos >= total_capacity) + return -EFBIG; + ret = cont_write_begin(iocb, mapping, pos, len, foliop, fsdata, hfs_get_block, - &HFS_I(mapping->host)->phys_size); + &HFS_I(inode)->phys_size); if (unlikely(ret)) hfs_write_failed(mapping, pos + len);