static int hfsplus_free_extents(struct super_block *sb, struct hfsplus_extent *extent, u32 offset, u32 block_nr) { u32 count, start; int i; int err = 0; hfsplus_dump_extent(extent); for (i = 0; i < 8; extent++, i++) { count = be32_to_cpu(extent->block_count); if (offset == count) goto found; else if (offset < count) break; offset -= count; } /* panic? */ return -EIO; found: for (;;) { start = be32_to_cpu(extent->start_block); if (count <= block_nr) { err = hfsplus_block_free(sb, start, count); if (err) { pr_err("can't free extent\n"); hfs_dbg(EXTENT, " start: %u count: %u\n", start, count); } extent->block_count = 0; extent->start_block = 0; block_nr -= count; } else { count -= block_nr; err = hfsplus_block_free(sb, start + count, block_nr); if (err) { pr_err("can't free extent\n"); hfs_dbg(EXTENT, " start: %u count: %u\n", start, count); } extent->block_count = cpu_to_be32(count); block_nr = 0; } if (!block_nr || !i) { /* * Try to free all extents and * return only last error */ return err; } i--; extent--; count = be32_to_cpu(extent->block_count); } }
static int hfsplus_free_extents(hfsplus_handle_t *hfsplus_handle, struct super_block *sb, struct hfsplus_extent *extent, u32 offset, u32 block_nr) { u32 count, start; int i; hfsplus_dump_extent(extent); for (i = 0; i < 8; extent++, i++) { count = be32_to_cpu(extent->block_count); if (offset == count) goto found; else if (offset < count) break; offset -= count; } /* panic? */ printk("#### Return EIO from %s()\n", __FUNCTION__); return -EIO; found: for (;;) { start = be32_to_cpu(extent->start_block); if (count <= block_nr) { hfsplus_block_free(hfsplus_handle, sb, start, count); extent->block_count = 0; extent->start_block = 0; block_nr -= count; } else { count -= block_nr; hfsplus_block_free(hfsplus_handle, sb, start + count, block_nr); extent->block_count = cpu_to_be32(count); block_nr = 0; } if (!block_nr || !i) return 0; i--; extent--; count = be32_to_cpu(extent->block_count); } }