]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - fs/hfs/extent.c
Merge remote-tracking branch 'drm/drm-next' into drm-misc-next
[linux.git] / fs / hfs / extent.c
index 5d01826545809de7de454e2615553fc6a637ce70..263d5028d9d18e8c2db8426a5e12c82635160673 100644 (file)
@@ -117,6 +117,10 @@ static int __hfs_ext_write_extent(struct inode *inode, struct hfs_find_data *fd)
        if (HFS_I(inode)->flags & HFS_FLG_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, HFS_I(inode)->cached_extents, sizeof(hfs_extent_rec));
                HFS_I(inode)->flags &= ~(HFS_FLG_EXT_DIRTY|HFS_FLG_EXT_NEW);
        } else {
@@ -300,7 +304,7 @@ int hfs_free_fork(struct super_block *sb, struct hfs_cat_file *file, int type)
                return 0;
 
        blocks = 0;
-       for (i = 0; i < 3; extent++, i++)
+       for (i = 0; i < 3; i++)
                blocks += be16_to_cpu(extent[i].count);
 
        res = hfs_free_extents(sb, extent, blocks, blocks);
@@ -341,7 +345,9 @@ int hfs_get_block(struct inode *inode, sector_t block,
        ablock = (u32)block / HFS_SB(sb)->fs_div;
 
        if (block >= HFS_I(inode)->fs_blocks) {
-               if (block > HFS_I(inode)->fs_blocks || !create)
+               if (!create)
+                       return 0;
+               if (block > HFS_I(inode)->fs_blocks)
                        return -EIO;
                if (ablock >= HFS_I(inode)->alloc_blocks) {
                        res = hfs_extend_file(inode);