Revision db89119d block/qcow2.c
b/block/qcow2.c | ||
---|---|---|
844 | 844 |
uint64_t tmp, offset; |
845 | 845 |
QCowCreateState s1, *s = &s1; |
846 | 846 |
QCowExtension ext_bf = {0, 0}; |
847 |
|
|
847 |
int ret; |
|
848 | 848 |
|
849 | 849 |
memset(s, 0, sizeof(*s)); |
850 | 850 |
|
... | ... | |
927 | 927 |
ref_clusters * s->cluster_size); |
928 | 928 |
|
929 | 929 |
/* write all the data */ |
930 |
write(fd, &header, sizeof(header)); |
|
930 |
ret = qemu_write_full(fd, &header, sizeof(header)); |
|
931 |
if (ret != sizeof(header)) { |
|
932 |
ret = -1; |
|
933 |
goto exit; |
|
934 |
} |
|
931 | 935 |
if (backing_file) { |
932 | 936 |
if (backing_format_len) { |
933 | 937 |
char zero[16]; |
... | ... | |
936 | 940 |
memset(zero, 0, sizeof(zero)); |
937 | 941 |
cpu_to_be32s(&ext_bf.magic); |
938 | 942 |
cpu_to_be32s(&ext_bf.len); |
939 |
write(fd, &ext_bf, sizeof(ext_bf)); |
|
940 |
write(fd, backing_format, backing_format_len); |
|
943 |
ret = qemu_write_full(fd, &ext_bf, sizeof(ext_bf)); |
|
944 |
if (ret != sizeof(ext_bf)) { |
|
945 |
ret = -1; |
|
946 |
goto exit; |
|
947 |
} |
|
948 |
ret = qemu_write_full(fd, backing_format, backing_format_len); |
|
949 |
if (ret != backing_format_len) { |
|
950 |
ret = -1; |
|
951 |
goto exit; |
|
952 |
} |
|
941 | 953 |
if (padding > 0) { |
942 |
write(fd, zero, padding); |
|
954 |
ret = qemu_write_full(fd, zero, padding); |
|
955 |
if (ret != padding) { |
|
956 |
ret = -1; |
|
957 |
goto exit; |
|
958 |
} |
|
943 | 959 |
} |
944 | 960 |
} |
945 |
write(fd, backing_file, backing_filename_len); |
|
961 |
ret = qemu_write_full(fd, backing_file, backing_filename_len); |
|
962 |
if (ret != backing_filename_len) { |
|
963 |
ret = -1; |
|
964 |
goto exit; |
|
965 |
} |
|
946 | 966 |
} |
947 | 967 |
lseek(fd, s->l1_table_offset, SEEK_SET); |
948 | 968 |
tmp = 0; |
949 | 969 |
for(i = 0;i < l1_size; i++) { |
950 |
write(fd, &tmp, sizeof(tmp)); |
|
970 |
ret = qemu_write_full(fd, &tmp, sizeof(tmp)); |
|
971 |
if (ret != sizeof(tmp)) { |
|
972 |
ret = -1; |
|
973 |
goto exit; |
|
974 |
} |
|
951 | 975 |
} |
952 | 976 |
lseek(fd, s->refcount_table_offset, SEEK_SET); |
953 |
write(fd, s->refcount_table, s->cluster_size); |
|
977 |
ret = qemu_write_full(fd, s->refcount_table, s->cluster_size); |
|
978 |
if (ret != s->cluster_size) { |
|
979 |
ret = -1; |
|
980 |
goto exit; |
|
981 |
} |
|
954 | 982 |
|
955 | 983 |
lseek(fd, s->refcount_block_offset, SEEK_SET); |
956 |
write(fd, s->refcount_block, ref_clusters * s->cluster_size); |
|
984 |
ret = qemu_write_full(fd, s->refcount_block, |
|
985 |
ref_clusters * s->cluster_size); |
|
986 |
if (ret != s->cluster_size) { |
|
987 |
ret = -1; |
|
988 |
goto exit; |
|
989 |
} |
|
957 | 990 |
|
991 |
ret = 0; |
|
992 |
exit: |
|
958 | 993 |
qemu_free(s->refcount_table); |
959 | 994 |
qemu_free(s->refcount_block); |
960 | 995 |
close(fd); |
... | ... | |
968 | 1003 |
bdrv_close(bs); |
969 | 1004 |
} |
970 | 1005 |
|
971 |
return 0;
|
|
1006 |
return ret;
|
|
972 | 1007 |
} |
973 | 1008 |
|
974 | 1009 |
static int qcow_create(const char *filename, QEMUOptionParameter *options) |
Also available in: Unified diff