diff --git a/fs/hfsplus/inode.c b/fs/hfsplus/inode.c index 1c57c873f05d..2ce6de574fa6 100644 --- a/fs/hfsplus/inode.c +++ b/fs/hfsplus/inode.c @@ -43,11 +43,19 @@ int hfsplus_write_begin(const struct kiocb *iocb, unsigned len, struct folio **foliop, void **fsdata) { + struct inode *inode = mapping->host; + struct hfsplus_sb_info *sbi = HFSPLUS_SB(inode->i_sb); + loff_t total_capacity; int ret; + total_capacity = (loff_t)sbi->total_blocks << sbi->alloc_blksz_shift; + + if (pos >= total_capacity) + return -EFBIG; + ret = cont_write_begin(iocb, mapping, pos, len, foliop, fsdata, hfsplus_get_block, - &HFSPLUS_I(mapping->host)->phys_size); + &HFSPLUS_I(inode)->phys_size); if (unlikely(ret)) hfsplus_write_failed(mapping, pos + len);