Lines Matching defs:img

824 static int init_refcount(struct ext2_qcow2_image *img, blk64_t table_offset)
830 ref = &(img->refcount);
839 img->cluster_bits);
840 table_clusters >>= (img->cluster_bits + 6 - 1);
850 img->cluster_size, &ref->refcount_table);
855 ret = ext2fs_get_arrayzero(1, img->cluster_size, &ref->refcount_block);
930 static void free_qcow2_image(struct ext2_qcow2_image *img)
932 if (!img)
935 if (img->hdr)
936 ext2fs_free_mem(&img->hdr);
938 if (img->l1_table)
939 ext2fs_free_mem(&img->l1_table);
941 if (img->refcount.refcount_table)
942 ext2fs_free_mem(&img->refcount.refcount_table);
943 if (img->refcount.refcount_block)
944 ext2fs_free_mem(&img->refcount.refcount_block);
946 put_l2_cache(img);
948 ext2fs_free_mem(&img);
955 static void put_used_table(struct ext2_qcow2_image *img,
958 struct ext2_qcow2_l2_cache *cache = img->l2_cache;
969 memset(table->data, 0, img->cluster_size);
1037 static int add_l2_item(struct ext2_qcow2_image *img, blk64_t blk,
1040 struct ext2_qcow2_l2_cache *cache = img->l2_cache;
1042 blk64_t l1_index = blk / img->l2_size;
1043 blk64_t l2_index = blk & (img->l2_size - 1);
1051 get_free_table(img, &table);
1055 img->l1_table[l1_index] =
1064 static int update_refcount(int fd, struct ext2_qcow2_image *img,
1071 ref = &(img->refcount);
1072 table_index = offset >> (2 * img->cluster_bits - 1);
1083 img->cluster_size, NO_BLK);
1084 memset(ref->refcount_block, 0, img->cluster_size);
1104 static int sync_refcount(int fd, struct ext2_qcow2_image *img)
1108 ref = &(img->refcount);
1114 ref->refcount_table_clusters << img->cluster_bits, NO_BLK);
1117 generic_write(fd, (char *)ref->refcount_block, img->cluster_size,
1127 struct ext2_qcow2_image *img;
1131 retval = ext2fs_get_mem(sizeof(struct ext2_qcow2_image), &img);
1138 retval = initialize_qcow2_image(fd, fs, img);
1145 img->cluster_size);
1146 write_header(fd, img->hdr, sizeof(struct ext2_qcow2_hdr), header_size);
1149 end = img->refcount.refcount_block_offset;
1151 blk = end + img->cluster_size;
1152 for (offset = 0; offset <= end; offset += img->cluster_size) {
1153 if (update_refcount(fd, img, offset, blk)) {
1154 blk += img->cluster_size;
1159 end += img->cluster_size;
1185 if (update_refcount(fd, img, offset, offset)) {
1187 offset += img->cluster_size;
1197 if (update_refcount(fd, img, offset, offset)) {
1207 if (add_l2_item(img, blk, offset,
1208 offset + img->cluster_size)) {
1209 offset += img->cluster_size;
1210 if (update_refcount(fd, img, offset,
1211 offset + img->cluster_size)) {
1212 offset += img->cluster_size;
1213 if (update_refcount(fd, img, offset,
1221 offset += img->cluster_size;
1226 offset += img->cluster_size;
1229 update_refcount(fd, img, offset, offset);
1230 flush_l2_cache(img);
1231 sync_refcount(fd, img);
1234 seek_set(fd, img->l1_offset);
1235 size = img->l1_size * sizeof(__u64);
1236 generic_write(fd, (char *)img->l1_table, size, NO_BLK);
1239 free_qcow2_image(img);