hfsplus: fix return value of hfsplus_get_block()
[linux] / fs / hfsplus / extents.c
index 8e0f597..a930ddd 100644 (file)
@@ -100,6 +100,10 @@ static int __hfsplus_ext_write_extent(struct inode *inode,
        if (hip->extent_state & HFSPLUS_EXT_NEW) {
                if (res != -ENOENT)
                        return res;
+               /* Fail early and avoid ENOSPC during the btree operation */
+               res = hfs_bmap_reserve(fd->tree, fd->tree->depth + 1);
+               if (res)
+                       return res;
                hfs_brec_insert(fd, hip->cached_extents,
                                sizeof(hfsplus_extent_rec));
                hip->extent_state &= ~(HFSPLUS_EXT_DIRTY | HFSPLUS_EXT_NEW);
@@ -233,7 +237,9 @@ int hfsplus_get_block(struct inode *inode, sector_t iblock,
        ablock = iblock >> sbi->fs_shift;
 
        if (iblock >= hip->fs_blocks) {
-               if (iblock > hip->fs_blocks || !create)
+               if (!create)
+                       return 0;
+               if (iblock > hip->fs_blocks)
                        return -EIO;
                if (ablock >= hip->alloc_blocks) {
                        res = hfsplus_file_extend(inode, false);