int vhd_io_allocate_blocks_fast(vhd_context_t *ctx, const uint32_t from_extent, const uint32_t to_extent, const bool ignore_2tb_limit) { off64_t max; int err, gap; int i = 0; int spp = getpagesize() >> VHD_SECTOR_SHIFT; assert(ctx); assert(from_extent <= to_extent); err = vhd_end_of_data(ctx, &max); if (err) return err; gap = 0; max >>= VHD_SECTOR_SHIFT; /* data region of segment should begin on page boundary */ if ((max + ctx->bm_secs) % spp) { gap = (spp - ((max + ctx->bm_secs) % spp)); max += gap; } for (i = from_extent; i <= to_extent; i++) { if (max > UINT_MAX && !ignore_2tb_limit) { printf("sector offset for extent %u exceeds the 2 TB limit\n", i); err = -EOVERFLOW; goto out; } ctx->bat.bat[i] = max; max += ctx->bm_secs + ctx->bat.spb; if ((max + ctx->bm_secs) % spp) { gap = (spp - ((max + ctx->bm_secs) % spp)); max += gap; } } err = vhd_write_bat(ctx, &ctx->bat); if (err) goto out; err = vhd_init_bitmaps(ctx, from_extent, to_extent); if (err) printf("failed to initialise bitmaps: %s\n", strerror(-err)); out: return err; }
static int vhd_journal_restore_bat(vhd_journal_t *j, vhd_bat_t *bat) { return vhd_write_bat(&j->vhd, bat); }