ia64/xen-unstable

changeset 17152:36529ef3ef23

blktap: Fix unused warnings in block-qcow2.c with -D_FORTIFY_SOURCE=2.
Signed-off-by: Kevin Wolf <kwolf@suse.de>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Feb 28 13:19:38 2008 +0000 (2008-02-28)
parents 8612d3d9578a
children 0e22182446fa
files tools/blktap/drivers/block-qcow2.c
line diff
     1.1 --- a/tools/blktap/drivers/block-qcow2.c	Thu Feb 28 13:18:29 2008 +0000
     1.2 +++ b/tools/blktap/drivers/block-qcow2.c	Thu Feb 28 13:19:38 2008 +0000
     1.3 @@ -1243,167 +1243,6 @@ static void create_refcount_update(QCowC
     1.4  	}
     1.5  }
     1.6  
     1.7 -static int qcow2_create(const char *filename, int64_t total_size,
     1.8 -		const char *backing_file, int flags)
     1.9 -{
    1.10 -	int fd, header_size, backing_filename_len, l1_size, i, shift, l2_bits;
    1.11 -	QCowHeader header;
    1.12 -	uint64_t tmp, offset;
    1.13 -	QCowCreateState s1, *s = &s1;
    1.14 -
    1.15 -	memset(s, 0, sizeof(*s));
    1.16 -
    1.17 -	fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644);
    1.18 -	if (fd < 0)
    1.19 -		return -1;
    1.20 -	memset(&header, 0, sizeof(header));
    1.21 -	header.magic = cpu_to_be32(QCOW_MAGIC);
    1.22 -	header.version = cpu_to_be32(QCOW_VERSION);
    1.23 -	header.size = cpu_to_be64(total_size * 512);
    1.24 -	header_size = sizeof(header);
    1.25 -	backing_filename_len = 0;
    1.26 -	if (backing_file) {
    1.27 -		header.backing_file_offset = cpu_to_be64(header_size);
    1.28 -		backing_filename_len = strlen(backing_file);
    1.29 -		header.backing_file_size = cpu_to_be32(backing_filename_len);
    1.30 -		header_size += backing_filename_len;
    1.31 -	}
    1.32 -	s->cluster_bits = 12;  /* 4 KB clusters */
    1.33 -	s->cluster_size = 1 << s->cluster_bits;
    1.34 -	header.cluster_bits = cpu_to_be32(s->cluster_bits);
    1.35 -	header_size = (header_size + 7) & ~7;
    1.36 -	if (flags & BLOCK_FLAG_ENCRYPT) {
    1.37 -		header.crypt_method = cpu_to_be32(QCOW_CRYPT_AES);
    1.38 -	} else {
    1.39 -		header.crypt_method = cpu_to_be32(QCOW_CRYPT_NONE);
    1.40 -	}
    1.41 -	l2_bits = s->cluster_bits - 3;
    1.42 -	shift = s->cluster_bits + l2_bits;
    1.43 -	l1_size = (((total_size * 512) + (1LL << shift) - 1) >> shift);
    1.44 -	offset = align_offset(header_size, s->cluster_size);
    1.45 -	s->l1_table_offset = offset;
    1.46 -	header.l1_table_offset = cpu_to_be64(s->l1_table_offset);
    1.47 -	header.l1_size = cpu_to_be32(l1_size);
    1.48 -	offset += align_offset(l1_size * sizeof(uint64_t), s->cluster_size);
    1.49 -
    1.50 -	s->refcount_table = qemu_mallocz(s->cluster_size);
    1.51 -	if (!s->refcount_table)
    1.52 -		goto fail;
    1.53 -	s->refcount_block = qemu_mallocz(s->cluster_size);
    1.54 -	if (!s->refcount_block)
    1.55 -		goto fail;
    1.56 -
    1.57 -	s->refcount_table_offset = offset;
    1.58 -	header.refcount_table_offset = cpu_to_be64(offset);
    1.59 -	header.refcount_table_clusters = cpu_to_be32(1);
    1.60 -	offset += s->cluster_size;
    1.61 -
    1.62 -	s->refcount_table[0] = cpu_to_be64(offset);
    1.63 -	s->refcount_block_offset = offset;
    1.64 -	offset += s->cluster_size;
    1.65 -
    1.66 -	/* update refcounts */
    1.67 -	create_refcount_update(s, 0, header_size);
    1.68 -	create_refcount_update(s, s->l1_table_offset, l1_size * sizeof(uint64_t));
    1.69 -	create_refcount_update(s, s->refcount_table_offset, s->cluster_size);
    1.70 -	create_refcount_update(s, s->refcount_block_offset, s->cluster_size);
    1.71 -
    1.72 -	/* write all the data */
    1.73 -	write(fd, &header, sizeof(header));
    1.74 -	if (backing_file) {
    1.75 -		write(fd, backing_file, backing_filename_len);
    1.76 -	}
    1.77 -	lseek(fd, s->l1_table_offset, SEEK_SET);
    1.78 -	tmp = 0;
    1.79 -	for(i = 0;i < l1_size; i++) {
    1.80 -		write(fd, &tmp, sizeof(tmp));
    1.81 -	}
    1.82 -	lseek(fd, s->refcount_table_offset, SEEK_SET);
    1.83 -	write(fd, s->refcount_table, s->cluster_size);
    1.84 -
    1.85 -	lseek(fd, s->refcount_block_offset, SEEK_SET);
    1.86 -	write(fd, s->refcount_block, s->cluster_size);
    1.87 -
    1.88 -	qemu_free(s->refcount_table);
    1.89 -	qemu_free(s->refcount_block);
    1.90 -	close(fd);
    1.91 -	return 0;
    1.92 -fail:
    1.93 -	qemu_free(s->refcount_table);
    1.94 -	qemu_free(s->refcount_block);
    1.95 -	close(fd);
    1.96 -	return -ENOMEM;
    1.97 -}
    1.98 -
    1.99 -/* XXX: put compressed sectors first, then all the cluster aligned
   1.100 -   tables to avoid losing bytes in alignment */
   1.101 -static int qcow_write_compressed(struct disk_driver *bs, int64_t sector_num,
   1.102 -		const uint8_t *buf, int nb_sectors)
   1.103 -{
   1.104 -	BDRVQcowState *s = bs->private;
   1.105 -	z_stream strm;
   1.106 -	int ret, out_len;
   1.107 -	uint8_t *out_buf;
   1.108 -	uint64_t cluster_offset;
   1.109 -
   1.110 -	if (nb_sectors == 0) {
   1.111 -		/* align end of file to a sector boundary to ease reading with
   1.112 -		   sector based I/Os */
   1.113 -		cluster_offset = 512 * s->total_sectors;
   1.114 -		cluster_offset = (cluster_offset + 511) & ~511;
   1.115 -		ftruncate(s->fd, cluster_offset);
   1.116 -		return 0;
   1.117 -	}
   1.118 -
   1.119 -	if (nb_sectors != s->cluster_sectors)
   1.120 -		return -EINVAL;
   1.121 -
   1.122 -	out_buf = qemu_malloc(s->cluster_size + (s->cluster_size / 1000) + 128);
   1.123 -	if (!out_buf)
   1.124 -		return -ENOMEM;
   1.125 -
   1.126 -	/* best compression, small window, no zlib header */
   1.127 -	memset(&strm, 0, sizeof(strm));
   1.128 -	ret = deflateInit2(&strm, Z_DEFAULT_COMPRESSION,
   1.129 -			Z_DEFLATED, -12,
   1.130 -			9, Z_DEFAULT_STRATEGY);
   1.131 -	if (ret != 0) {
   1.132 -		qemu_free(out_buf);
   1.133 -		return -1;
   1.134 -	}
   1.135 -
   1.136 -	strm.avail_in = s->cluster_size;
   1.137 -	strm.next_in = (uint8_t *)buf;
   1.138 -	strm.avail_out = s->cluster_size;
   1.139 -	strm.next_out = out_buf;
   1.140 -
   1.141 -	ret = deflate(&strm, Z_FINISH);
   1.142 -	if (ret != Z_STREAM_END && ret != Z_OK) {
   1.143 -		qemu_free(out_buf);
   1.144 -		deflateEnd(&strm);
   1.145 -		return -1;
   1.146 -	}
   1.147 -	out_len = strm.next_out - out_buf;
   1.148 -
   1.149 -	deflateEnd(&strm);
   1.150 -
   1.151 -	if (ret != Z_STREAM_END || out_len >= s->cluster_size) {
   1.152 -		/* could not compress: write normal cluster */
   1.153 -		qcow_write(bs, sector_num, buf, s->cluster_sectors);
   1.154 -	} else {
   1.155 -		cluster_offset = get_cluster_offset(bs, sector_num << 9, 2,
   1.156 -											out_len, 0, 0);
   1.157 -		cluster_offset &= s->cluster_offset_mask;
   1.158 -		if (bdrv_pwrite(s->fd, cluster_offset, out_buf, out_len) != out_len) {
   1.159 -			qemu_free(out_buf);
   1.160 -			return -1;
   1.161 -		}
   1.162 -	}
   1.163 -
   1.164 -	qemu_free(out_buf);
   1.165 -	return 0;
   1.166 -}
   1.167 -
   1.168  static int qcow_submit(struct disk_driver *bs)
   1.169  {
   1.170  	struct BDRVQcowState *s = (struct BDRVQcowState*) bs->private;