From: "Alfred Song" Subject: [PATCH] blktap2-vhd-util | add disk image convert functions, RAW <-> fixed VHD, and fixed <-> dynamic VHD for xen4.0.0 Date: Wed, 14 Jul 2010 09:44:40 +0800 Message-ID: <12321.2434621111$1279071908@news.gmane.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0062_01CB2339.2E281D40" Return-path: References: In-Reply-To: Content-Language: zh-cn List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org This is a multi-part message in MIME format. ------=_NextPart_000_0062_01CB2339.2E281D40 Content-Type: multipart/related; boundary="----=_NextPart_001_0063_01CB2339.2E281D40" ------=_NextPart_001_0063_01CB2339.2E281D40 Content-Type: multipart/alternative; boundary="----=_NextPart_002_0064_01CB2339.2E281D40" ------=_NextPart_002_0064_01CB2339.2E281D40 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Hi, + global system log macro for debug + vhd_dynamic_to_fixed + vhd_fixed_to_dynamic + vhd_fixed_to_raw + vhd_raw_to_fixed Patch for vhd_io_read & vhd_read & vhd_write return error when real data size less than the required data size, typically, the real data size less than a sector(512B) See Usage: xxx:~ # vhd-util convert Best Regards face ------=_NextPart_002_0064_01CB2339.2E281D40 Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

Hi,

 

+ global = system log macro for debug

+ vhd_dynamic_to_fixed

+ vhd_fixed_to_dynamic

+ = vhd_fixed_to_raw

+ = vhd_raw_to_fixed

Patch = for vhd_io_read & vhd_read = & vhd_write return error when real data size less than the required data = size,

typically, the real data size less than a sector(512B)

 

See = Usage:

xxx:~ = # vhd-util convert

 

Best Regards

3Dface

 

------=_NextPart_002_0064_01CB2339.2E281D40-- ------=_NextPart_001_0063_01CB2339.2E281D40 Content-Type: image/jpeg; name="image001.jpg" Content-Transfer-Encoding: base64 Content-ID: /9j/4AAQSkZJRgABAQEAYABgAAD/4QAWRXhpZgAASUkqAAgAAAAAAAAAAAD/2wBDAAgGBgcGBQgH BwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/ 2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIy MjIyMjIyMjIyMjL/wAARCAAfACIDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQF BgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS 0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4 eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi 4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREA AgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl 8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImK kpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP0 9fb3+Pn6/9oADAMBAAIRAxEAPwD3+oLy6jsrSW5l+5GuSB1PoB7k8VBquq22j2YubneVLhFVBksT /wDWBP4V574j8UXuphoYx5FnuyqD7zjtuP64H64zXTh8NKq0+hxYvGww8Wvtdj0XTNQg1XTbe/tz mKdA45BI9Qcdwcg+4q3Xj/hnxnJoDi2uGaXTyxYxgZdDg/cyRgE4yDx1xyTn07Q9ds/EOn/bLLzA gcxssi4ZWGD7joQeD3qa9CVKXkVhcXCvFNbmlRRRWB1nFfEa3uv7Otb+Eg29qzecN2CNxUKcd+eP Xn6157aeMLTTzIt7pwuyGV487SHwCCjbg2F+bdlQDlQDkdPd65+98EeGtQdWn0iAEf8APEtFn67C M11wxNqXs3/X5fmcM8GnX9stb7r/ACdn+KZ4RqHiG0v9ItrG2sCl3GyNPcFUGNqbdqlQCwbG87iS Cx6jGPUPhBaXcejXt5NkW88irCCTyVzuYdscgZHdSO1dFa/D/wAK2c/nRaPEzYIxM7yr/wB8uSP0 rpFVUUKqhVAwABgAVM66cORdf68/zLp4a1RT2tsv83ZfkhaKKK5jrP/Z ------=_NextPart_001_0063_01CB2339.2E281D40-- ------=_NextPart_000_0062_01CB2339.2E281D40 Content-Type: application/octet-stream; name="blktap2.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="blktap2.patch" diff -Naur blktap2/include/libvhd.h blktap2-new/include/libvhd.h=0A= --- blktap2/include/libvhd.h 2010-04-08 00:12:04.000000000 +0800=0A= +++ blktap2-new/include/libvhd.h 2010-07-12 15:41:40.000000000 +0800=0A= @@ -24,6 +24,19 @@=0A= * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS=0A= * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.=0A= */=0A= +/*++=0A= +=0A= +History: Alfred Song 06/24/2010=0A= + add globle debug flag declare: vhd_globle_dbg=0A= + add macro: VHD_GLOBLE_LOG=0A= + Alfred Song 06/25/2010=0A= + add function: vhd_raw_to_fixed=0A= + vhd_fiexed_to_raw=0A= + Alfred Song 07/12/2010=0A= + add function: vhd_fiexed_to_dynamic=0A= + vhd_dynamic_to_fixed=0A= +=0A= +--*/=0A= #ifndef _VHD_LIB_H_=0A= #define _VHD_LIB_H_=0A= =0A= @@ -36,6 +49,7 @@=0A= #include =0A= #endif=0A= =0A= +#include =0A= #include "blk_uuid.h"=0A= #include "vhd.h"=0A= =0A= @@ -68,6 +82,17 @@=0A= #define BE64_OUT(foo)=0A= #endif=0A= =0A= +=0A= +extern int vhd_globle_dbg; /* system log switch */=0A= +=0A= +#define VHD_GLOBLE_LOG(_f, _a...) \=0A= + do { \=0A= + if (vhd_globle_dbg) \=0A= + syslog(LOG_INFO, "%s\\%s, %d\\"_f, \=0A= + __FILE__, __func__, __LINE__, ##_a); \=0A= + } while (0)=0A= +=0A= +=0A= #define MIN(a, b) (((a) < (b)) ? (a) : (b))=0A= #define MAX(a, b) (((a) > (b)) ? (a) : (b))=0A= =0A= @@ -75,6 +100,7 @@=0A= =0A= #define VHD_BLOCK_SHIFT 21=0A= #define VHD_BLOCK_SIZE (1ULL << VHD_BLOCK_SHIFT)=0A= +#define VHD_SECTORS_PER_BLOCK (VHD_BLOCK_SIZE >> VHD_SECTOR_SHIFT)=0A= =0A= #define UTF_16 "UTF-16"=0A= #define UTF_16LE "UTF-16LE"=0A= @@ -128,9 +154,9 @@=0A= typedef uint32_t vhd_flag_creat_t;=0A= =0A= struct vhd_bat {=0A= - uint32_t spb;=0A= - uint32_t entries;=0A= - uint32_t *bat;=0A= + uint32_t spb; /* sector number per block */=0A= + uint32_t entries; /* total entry number */=0A= + uint32_t *bat; /* entry table */=0A= };=0A= =0A= struct vhd_batmap {=0A= @@ -144,8 +170,8 @@=0A= int oflags;=0A= int is_block;=0A= =0A= - uint32_t spb;=0A= - uint32_t bm_secs;=0A= + uint32_t spb; /* sectors per block */=0A= + uint32_t bm_secs; /* sectors of bitmap */=0A= =0A= vhd_header_t header;=0A= vhd_footer_t footer;=0A= @@ -323,4 +349,78 @@=0A= int vhd_io_read(vhd_context_t *, char *, uint64_t, uint32_t);=0A= int vhd_io_write(vhd_context_t *, char *, uint64_t, uint32_t);=0A= =0A= +off_t get_file_size_rev(const char * name);=0A= +=0A= +/*++=0A= +=0A= + Function Name: vhd_raw_to_fixed=0A= +=0A= + Description: convert raw disk image to fixed type vhd disk image=0A= +=0A= + Creator: Alfred Song 06/25/2010=0A= +=0A= + Input: src_name - source file name=0A= + tag_name - target file name=0A= +=0A= + Output: 0 - success=0A= + others - fail=0A= +=0A= +--*/=0A= +int vhd_raw_to_fixed(char * src_name, char * tag_name);=0A= +=0A= +/*++=0A= +=0A= + Function Name: vhd_fixed_to_raw=0A= +=0A= + Description: convert fixed type vhd disk image to raw disk image=0A= +=0A= + Creator: Alfred Song 06/25/2010=0A= +=0A= + Input: src_name - source file name=0A= + tag_name - target file name=0A= +=0A= + Output: 0 - success=0A= + others - fail=0A= +=0A= +--*/=0A= +int vhd_fixed_to_raw(char * src_name, char * tag_name);=0A= +=0A= +/*++=0A= +=0A= + Function Name: vhd_fixed_to_dynamic=0A= +=0A= + Description: convert fixed type vhd disk image to dynamic type = vhd disk image=0A= +=0A= + Creator: Alfred Song 07/07/2010=0A= +=0A= + Input: src_name - source file name=0A= + tag_name - target file name=0A= +=0A= + Output: 0 - success=0A= + others - fail=0A= +=0A= +--*/=0A= +int=0A= +vhd_fixed_to_dynamic(char * src_name, char * tag_name);=0A= +=0A= +/*++=0A= +=0A= + Function Name: vhd_dynamic_to_fixed=0A= +=0A= + Description: convert dynamic type vhd disk image to fixed type = vhd disk image=0A= +=0A= + Creator: Alfred Song 07/07/2010=0A= +=0A= + Input: src_name - source file name=0A= + tag_name - target file name=0A= +=0A= + Output: 0 - success=0A= + others - fail=0A= +=0A= +--*/=0A= +int=0A= +vhd_dynamic_to_fixed(char * src_name, char * tag_name);=0A= +=0A= +//int get_file_size(char *, off_t *);=0A= +=0A= #endif=0A= diff -Naur blktap2/include/vhd-util.h blktap2-new/include/vhd-util.h=0A= --- blktap2/include/vhd-util.h 2010-04-08 00:12:04.000000000 +0800=0A= +++ blktap2-new/include/vhd-util.h 2010-07-12 15:41:20.000000000 +0800=0A= @@ -24,6 +24,13 @@=0A= * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS=0A= * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.=0A= */=0A= +=0A= +/*++=0A= +=0A= +History: Alfred Song 06/24/2010=0A= + add function vhd_util_convert=0A= +=0A= +--*/=0A= #ifndef _VHD_UTIL_H_=0A= #define _VHD_UTIL_H_=0A= =0A= @@ -40,5 +47,6 @@=0A= int vhd_util_scan(int argc, char **argv);=0A= int vhd_util_check(int argc, char **argv);=0A= int vhd_util_revert(int argc, char **argv);=0A= +int vhd_util_convert(int argc, char ** argv);=0A= =0A= #endif=0A= diff -Naur blktap2/vhd/lib/Makefile blktap2-new/vhd/lib/Makefile=0A= --- blktap2/vhd/lib/Makefile 2010-04-08 00:12:04.000000000 +0800=0A= +++ blktap2-new/vhd/lib/Makefile 2010-06-24 13:03:21.000000000 +0800=0A= @@ -42,6 +42,7 @@=0A= LIB-SRCS +=3D vhd-util-snapshot.c=0A= LIB-SRCS +=3D vhd-util-scan.c=0A= LIB-SRCS +=3D vhd-util-check.c=0A= +LIB-SRCS +=3D vhd-util-convert.c=0A= LIB-SRCS +=3D relative-path.c=0A= LIB-SRCS +=3D atomicio.c=0A= =0A= diff -Naur blktap2/vhd/lib/libvhd.c blktap2-new/vhd/lib/libvhd.c=0A= --- blktap2/vhd/lib/libvhd.c 2010-04-08 00:12:04.000000000 +0800=0A= +++ blktap2-new/vhd/lib/libvhd.c 2010-07-12 15:40:20.000000000 +0800=0A= @@ -24,6 +24,20 @@=0A= * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS=0A= * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.=0A= */=0A= +/*++=0A= +=0A= +History: Alfred Song 06/24/2010=0A= + add globle debug flag define: vhd_globle_dbg=0A= + Alfred Song 06/25/2010=0A= + add function: vhd_raw_to_fixed=0A= + vhd_fiexed_to_raw=0A= + Alfred Song 07/12/2010=0A= + add function: vhd_fiexed_to_dynamic=0A= + vhd_dynamic_to_fixed=0A= + modify the vhd_raw_to_fixed and vhd_fiexed_to_raw to process =0A= + different target name.=0A= + =0A= +--*/=0A= #ifndef _GNU_SOURCE=0A= #define _GNU_SOURCE=0A= #endif=0A= @@ -42,6 +56,7 @@=0A= #include "relative-path.h"=0A= =0A= static int libvhd_dbg =3D 0;=0A= +int vhd_globle_dbg =3D 0;=0A= =0A= void=0A= libvhd_set_log_level(int level)=0A= @@ -51,12 +66,12 @@=0A= }=0A= =0A= #define VHDLOG(_f, _a...) \=0A= - do { \=0A= - if (libvhd_dbg) \=0A= - syslog(LOG_INFO, "libvhd::%s: "_f, \=0A= + do { \=0A= + if (libvhd_dbg) \=0A= + syslog(LOG_INFO, "libvhd::%s: "_f, \=0A= __func__, ##_a); \=0A= } while (0)=0A= -=0A= + =0A= #define BIT_MASK 0x80=0A= =0A= #ifdef ENABLE_FAILURE_TESTING=0A= @@ -413,7 +428,7 @@=0A= =0A= off =3D ctx->header.table_offset;=0A= bat =3D ctx->header.max_bat_size * sizeof(uint32_t);=0A= - off +=3D vhd_bytes_padded(bat);=0A= + off +=3D vhd_bytes_padded(bat); /* sector align for bat entry */=0A= =0A= *_off =3D off;=0A= return 0;=0A= @@ -945,6 +960,7 @@=0A= memcpy(footer, buf, sizeof(vhd_footer_t));=0A= =0A= vhd_footer_in(footer);=0A= +=0A= err =3D vhd_validate_footer(footer);=0A= =0A= out:=0A= @@ -970,6 +986,7 @@=0A= return -errno;=0A= =0A= err =3D vhd_read_footer_at(ctx, footer, off - 512);=0A= + =0A= if (err !=3D -EINVAL)=0A= return err;=0A= =0A= @@ -1817,7 +1834,7 @@=0A= return -EINVAL;=0A= =0A= off =3D vhd_sectors_to_bytes(blk);=0A= - size =3D vhd_bytes_padded(ctx->spb >> 3);=0A= + size =3D vhd_bytes_padded(ctx->spb >> 3); /* byte-size of bitmap */=0A= =0A= err =3D vhd_seek(ctx, off, SEEK_SET);=0A= if (err)=0A= @@ -1839,6 +1856,18 @@=0A= return err;=0A= }=0A= =0A= +/*=0A= +* Description: =0A= +* Read a block data from a VHD file.=0A= +* =0A= +* Input:=0A= +* ctx - pointer to VHD operation structure=0A= +* block - which block to read=0A= +*=0A= +* Output:=0A= +* bufp - output buffer saving block data read=0A= +*=0A= +*/=0A= int=0A= vhd_read_block(vhd_context_t *ctx, uint32_t block, char **bufp)=0A= {=0A= @@ -1878,6 +1907,7 @@=0A= goto fail;=0A= }=0A= =0A= + /* padded by 0 */=0A= if (end < off + ctx->header.block_size) {=0A= size =3D end - off;=0A= memset(buf + size, 0, ctx->header.block_size - size);=0A= @@ -1926,7 +1956,7 @@=0A= if (err)=0A= goto out;=0A= =0A= - vhd_footer_out(f);=0A= + vhd_footer_out(f); /* switch to big-endian before output to disk */=0A= =0A= err =3D vhd_write(ctx, f, sizeof(vhd_footer_t));=0A= =0A= @@ -2262,6 +2292,11 @@=0A= if (ret =3D=3D size)=0A= return 0;=0A= =0A= + /* when real data size less than the required data size, =0A= + return real data size. we consider it valid/invalid, decided by = errno. */=0A= + if (ret > 0 && ret < size)=0A= + return errno;=0A= +=0A= VHDLOG("%s: read of %zu returned %zd, errno: %d\n",=0A= ctx->file, size, ret, -errno);=0A= =0A= @@ -2279,6 +2314,11 @@=0A= if (ret =3D=3D size)=0A= return 0;=0A= =0A= + /* when real data size less than the required data size, =0A= + return real data size. we consider it valid/invalid, decided by = errno. */=0A= + if (ret > 0 && ret < size)=0A= + return errno;=0A= +=0A= VHDLOG("%s: write of %zu returned %zd, errno: %d\n",=0A= ctx->file, size, ret, -errno);=0A= =0A= @@ -2361,7 +2401,7 @@=0A= vhd_open(vhd_context_t *ctx, const char *file, int flags)=0A= {=0A= int err, oflags;=0A= -=0A= + =0A= if (flags & VHD_OPEN_STRICT)=0A= vhd_flag_clear(flags, VHD_OPEN_FAST);=0A= =0A= @@ -2387,6 +2427,7 @@=0A= }=0A= =0A= err =3D vhd_test_file_fixed(ctx->file, &ctx->is_block);=0A= + =0A= if (err)=0A= goto fail;=0A= =0A= @@ -2399,6 +2440,7 @@=0A= }=0A= =0A= err =3D vhd_read_footer(ctx, &ctx->footer);=0A= + =0A= if (err)=0A= goto fail;=0A= =0A= @@ -2475,7 +2517,7 @@=0A= * big endian unicode here =0A= */=0A= cd =3D iconv_open(UTF_16BE, "ASCII");=0A= - if (cd =3D=3D (iconv_t)-1) {=0A= + if (cd =3D=3D (iconv_t)-1) { /* (iconv_t)(-1) */=0A= err =3D -errno;=0A= goto out;=0A= }=0A= @@ -2527,6 +2569,22 @@=0A= return end;=0A= }=0A= =0A= +off_t=0A= +get_file_size_rev(const char *name)=0A= +{=0A= + int fd;=0A= + off_t end;=0A= +=0A= + fd =3D open(name, O_LARGEFILE | O_RDONLY);=0A= + if (fd =3D=3D -1) {=0A= + VHDLOG("unable to open '%s': %d\n", name, errno);=0A= + return -errno;=0A= + }=0A= + end =3D lseek(fd, 0, SEEK_END);=0A= + close(fd); =0A= + return end;=0A= +}=0A= +=0A= static int=0A= vhd_initialize_header(vhd_context_t *ctx, const char *parent_path, =0A= uint64_t size, int raw)=0A= @@ -2597,7 +2655,9 @@=0A= =0A= off =3D ctx->batmap.header.batmap_offset + =0A= vhd_sectors_to_bytes(ctx->batmap.header.batmap_size);=0A= - if (off & (VHD_SECTOR_SIZE - 1))=0A= + =0A= + /* 512 bytes align */=0A= + if (off & (VHD_SECTOR_SIZE - 1)) =0A= off =3D vhd_bytes_padded(off);=0A= =0A= for (i =3D 0; i < 3; i++) {=0A= @@ -2714,7 +2774,7 @@=0A= if (!vhd_type_dynamic(ctx))=0A= return -EINVAL;=0A= =0A= - map_bytes =3D (ctx->header.max_bat_size + 7) >> 3;=0A= + map_bytes =3D (ctx->header.max_bat_size + 7) >> 3; /* byte align for = map-table of batmap */=0A= header =3D &ctx->batmap.header;=0A= =0A= memset(header, 0, sizeof(vhd_batmap_header_t));=0A= @@ -2726,9 +2786,12 @@=0A= =0A= header->batmap_offset =3D off +=0A= vhd_bytes_padded(sizeof(vhd_batmap_header_t));=0A= - header->batmap_size =3D secs_round_up_no_zero(map_bytes);=0A= + =0A= + /* size in sector(round up) for map-table of batmap, not including = header of batmap */=0A= + header->batmap_size =3D secs_round_up_no_zero(map_bytes); =0A= header->batmap_version =3D VHD_BATMAP_CURRENT_VERSION;=0A= =0A= + /* size in byte(512 bytes round up) for map-table of batmap, not = including header of batmap */=0A= map_bytes =3D vhd_sectors_to_bytes(header->batmap_size);=0A= =0A= err =3D posix_memalign((void **)&ctx->batmap.map,=0A= @@ -2761,7 +2824,7 @@=0A= =0A= memset(ctx->bat.bat, 0, size);=0A= for (i =3D 0; i < ctx->header.max_bat_size; i++)=0A= - ctx->bat.bat[i] =3D DD_BLK_UNUSED;=0A= + ctx->bat.bat[i] =3D DD_BLK_UNUSED; /* initially, unused for each = entry */=0A= =0A= err =3D vhd_seek(ctx, ctx->header.table_offset, SEEK_SET);=0A= if (err)=0A= @@ -2862,6 +2925,8 @@=0A= memset(&ctx, 0, sizeof(vhd_context_t));=0A= footer =3D &ctx.footer;=0A= header =3D &ctx.header;=0A= + =0A= + /* size allocating by block align */=0A= blks =3D (bytes + VHD_BLOCK_SIZE - 1) >> VHD_BLOCK_SHIFT;=0A= size =3D blks << VHD_BLOCK_SHIFT;=0A= =0A= @@ -2984,6 +3049,10 @@=0A= if (test_bit(map, map_off + i))=0A= goto next;=0A= =0A= + /* =0A= + * consider the data sector are all-zero when the =0A= + * corresponding bit in bitmap is zero for better performance=0A= + */=0A= if (ctx && !vhd_bitmap_test(ctx, bitmap, bitmap_off + i))=0A= goto next;=0A= =0A= @@ -3175,8 +3244,10 @@=0A= int=0A= vhd_io_read(vhd_context_t *ctx, char *buf, uint64_t sec, uint32_t secs)=0A= {=0A= +/*=0A= if (vhd_sectors_to_bytes(sec + secs) > ctx->footer.curr_size)=0A= return -ERANGE;=0A= +*/=0A= =0A= if (!vhd_type_dynamic(ctx))=0A= return __vhd_io_fixed_read(ctx, buf, sec, secs);=0A= @@ -3342,11 +3413,482 @@=0A= int=0A= vhd_io_write(vhd_context_t *ctx, char *buf, uint64_t sec, uint32_t secs)=0A= {=0A= +/*=0A= if (vhd_sectors_to_bytes(sec + secs) > ctx->footer.curr_size)=0A= return -ERANGE;=0A= +*/=0A= =0A= if (!vhd_type_dynamic(ctx))=0A= return __vhd_io_fixed_write(ctx, buf, sec, secs);=0A= =0A= return __vhd_io_dynamic_write(ctx, buf, sec, secs);=0A= }=0A= +=0A= +/*=0A= +int =0A= +get_file_size(char * file_path, off_t * out_file_size)=0A= +{=0A= + int err;=0A= + struct stat stats;=0A= +=0A= + err =3D stat(file_path, &stats);=0A= + if (err =3D=3D -1)=0A= + return -errno;=0A= +=0A= + *out_file_size =3D stats.st_size;=0A= + return err; =0A= +}=0A= +*/=0A= +=0A= +/*++=0A= +=0A= + Function Name: vhd_raw_to_fixed=0A= +=0A= + Description: convert raw disk image to fixed type vhd disk image=0A= +=0A= + Creator: Alfred Song 06/25/2010=0A= +=0A= + Input: src_name - source file name=0A= + tag_name - target file name=0A= +=0A= + Output: 0 - success=0A= + others - fail=0A= +=0A= + NOTE: For better performance, we will do the overwritten convert!=0A= +=0A= +--*/=0A= +int=0A= +vhd_raw_to_fixed(char * src_name, char * tag_name)=0A= +{=0A= + uint64_t file_size;=0A= + vhd_context_t ctx;=0A= + int err;=0A= + =0A= + file_size =3D 0;=0A= + err =3D 0;=0A= + memset(&ctx, 0, sizeof(vhd_context_t));=0A= +=0A= + if (!src_name && !tag_name) {=0A= + VHD_GLOBLE_LOG("error, invalid input, src_name=3D%s, = tag_name=3D%s\n", \=0A= + src_name, tag_name);=0A= + goto out;=0A= + }=0A= +=0A= + VHD_GLOBLE_LOG("src_name=3D%s, tag_name=3D%s\n", src_name, tag_name);=0A= + =0A= + file_size =3D get_file_size_rev(src_name);=0A= + if (file_size =3D=3D 0) {=0A= + printf("Source file size is zero.\n");=0A= + VHD_GLOBLE_LOG("file_size(%"PRIu64").\n", file_size);=0A= + return -EINVAL;=0A= + }=0A= +=0A= + if (errno){=0A= + printf("Fail to get source file size.\n");=0A= + VHD_GLOBLE_LOG("errno(%d).\n", errno);=0A= + return -EINVAL;=0A= + } =0A= + VHD_GLOBLE_LOG("file_size=3D%"PRIu64"\n", file_size);=0A= +=0A= + vhd_initialize_footer(&ctx, HD_TYPE_FIXED, file_size);=0A= +=0A= + ctx.fd =3D open(src_name, O_WRONLY | O_LARGEFILE | O_DIRECT, 0644);=0A= + if (ctx.fd =3D=3D -1)=0A= + return -errno;=0A= +=0A= + ctx.file =3D strdup(src_name);=0A= + if (!ctx.file) {=0A= + err =3D -ENOMEM;=0A= + goto out;=0A= + }=0A= +=0A= + err =3D vhd_test_file_fixed(ctx.file, &ctx.is_block);=0A= + if (err)=0A= + goto out;=0A= +=0A= + err =3D vhd_write_footer_at(&ctx, &ctx.footer, file_size);=0A= + if (err)=0A= + goto out;=0A= +=0A= + /* no error, change name */=0A= + vhd_close(&ctx);=0A= + if (strcmp(src_name, tag_name) !=3D 0) {=0A= + err =3D rename(src_name, tag_name);=0A= + if (err) {=0A= + VHD_GLOBLE_LOG("error, src_name=3D%s, tag_name=3D%s, %d\n", \=0A= + src_name, tag_name, err);=0A= + goto out;=0A= + }=0A= + }=0A= + printf("NOTE: For better performance, we will do the overwritten = convert!\n");=0A= + printf("Done! Convert to %s.\n", tag_name);=0A= +=0A= +out:=0A= + vhd_close(&ctx);=0A= + if (err && !ctx.is_block)=0A= + unlink(src_name);=0A= + return err;=0A= +}=0A= +=0A= +/*++=0A= +=0A= + Function Name: vhd_fixed_to_raw=0A= +=0A= + Description: convert fixed type vhd disk image to raw disk image=0A= +=0A= + Creator: Alfred Song 06/25/2010=0A= +=0A= + Input: src_name - source file name=0A= + tag_name - target file name=0A= +=0A= + Output: 0 - success=0A= + others - fail=0A= +=0A= + NOTE: For better performance, we will do the overwritten convert!=0A= +=0A= +--*/=0A= +int=0A= +vhd_fixed_to_raw(char * src_name, char * tag_name)=0A= +{=0A= + uint64_t file_size;=0A= + vhd_context_t ctx;=0A= + int err;=0A= + =0A= + file_size =3D 0;=0A= + err =3D 0;=0A= + memset(&ctx, 0, sizeof(vhd_context_t));=0A= +=0A= + if (!src_name && !tag_name) {=0A= + VHD_GLOBLE_LOG("error, invalid input, src_name=3D%s, = tag_name=3D%s\n", \=0A= + src_name, tag_name);=0A= + goto out;=0A= + }=0A= +=0A= + VHD_GLOBLE_LOG("src_name=3D%s, tag_name=3D%s\n", src_name, tag_name);=0A= + =0A= + file_size =3D get_file_size_rev(src_name);=0A= + if (file_size =3D=3D 0) {=0A= + printf("Source file size is zero.\n");=0A= + VHD_GLOBLE_LOG("file_size(%"PRIu64").\n", file_size);=0A= + goto out;=0A= + }=0A= +=0A= + if (errno){=0A= + printf("Fail to get source file size.\n");=0A= + VHD_GLOBLE_LOG("errno(%d).\n", errno);=0A= + goto out;=0A= + } =0A= + VHD_GLOBLE_LOG("file_size=3D%"PRIu64"\n", file_size);=0A= +=0A= + err =3D truncate(src_name, file_size - 512);=0A= + if (err) {=0A= + VHD_GLOBLE_LOG("err(%d).\n", err);=0A= + goto out;=0A= + }=0A= +=0A= + /* no error, change name */=0A= + vhd_close(&ctx);=0A= + if (strcmp(src_name, tag_name) !=3D 0) {=0A= + err =3D rename(src_name, tag_name);=0A= + if (err) {=0A= + VHD_GLOBLE_LOG("error, src_name=3D%s, tag_name=3D%s, %d\n", \=0A= + src_name, tag_name, err);=0A= + goto out;=0A= + }=0A= + }=0A= + printf("NOTE: For better performance, we will do the overwritten = convert!\n");=0A= + printf("Done! Convert to %s.\n", tag_name);=0A= +=0A= +out:=0A= + vhd_close(&ctx);=0A= + if (err && !ctx.is_block)=0A= + unlink(src_name);=0A= + return err;=0A= +}=0A= +=0A= +/*++=0A= +=0A= + Function Name: vhd_fixed_to_dynamic=0A= +=0A= + Description: convert fixed type vhd disk image to dynamic type = vhd disk image=0A= +=0A= + Creator: Alfred Song 07/07/2010=0A= +=0A= + Input: src_name - source file name=0A= + tag_name - target file name=0A= +=0A= + Output: 0 - success=0A= + others - fail=0A= +=0A= +--*/=0A= +int=0A= +vhd_fixed_to_dynamic(char * src_name, char * tag_name)=0A= +{=0A= + vhd_context_t ctx_src;=0A= + vhd_context_t ctx_tag;=0A= + int err;=0A= + uint64_t current_block, sec, secs, total_block;=0A= + char * buf;=0A= + char * new_name;=0A= + =0A= + memset(&ctx_src, 0, sizeof(vhd_context_t));=0A= + memset(&ctx_tag, 0, sizeof(vhd_context_t));=0A= + err =3D 0;=0A= + buf =3D NULL;=0A= + new_name =3D NULL;=0A= + =0A= + if (!src_name && !tag_name) {=0A= + VHD_GLOBLE_LOG("error, invalid input, src_name=3D%s, = tag_name=3D%s\n", \=0A= + src_name, tag_name);=0A= + goto out;=0A= + }=0A= +=0A= + VHD_GLOBLE_LOG("src_name=3D%s, tag_name=3D%s\n", src_name, tag_name);=0A= +=0A= + /* size allocate to keep no overflow happen */=0A= + err =3D posix_memalign((void **)&new_name, 4096, strlen(src_name) + = 10);=0A= + if (err) {=0A= + err =3D -err;=0A= + goto out;=0A= + }=0A= +=0A= + strcpy(new_name, src_name);=0A= + strcat(new_name, ".bak");=0A= +=0A= + err =3D rename(src_name, new_name);=0A= + if (err) {=0A= + VHD_GLOBLE_LOG("error, src_name=3D%s, new_name=3D%s, %d\n", \=0A= + src_name, new_name, err);=0A= + goto out;=0A= + }=0A= +=0A= + VHD_GLOBLE_LOG("after renaming, src_name=3D%s, new_name=3D%s\n", \=0A= + src_name, new_name);=0A= +=0A= +/*=0A= + if (strcmp(src_name, tag_name) =3D=3D 0) {=0A= + printf("error, source file %s equals target file %s.\nPlease specify \=0A= +different name.\n", src_name, tag_name);=0A= + err =3D -EINVAL;=0A= + goto out;=0A= + //TODO=0A= + }=0A= +*/=0A= + printf("Back up source to %s.\n", new_name);=0A= + err =3D vhd_open(&ctx_src, new_name, VHD_OPEN_RDWR);=0A= + if (err) {=0A= + printf("error, opening %s: %d\n", new_name, err);=0A= + VHD_GLOBLE_LOG("error, opening new_name=3D%s, %d\n", new_name, err);=0A= + goto out;=0A= + }=0A= +=0A= + if (ctx_src.footer.type !=3D HD_TYPE_FIXED) {=0A= + err =3D -EINVAL;=0A= + printf("error, source file %s is not fixed type VHD, %d\n", new_name, = err);=0A= + VHD_GLOBLE_LOG("error, source file %s is not fixed type VHD, %d\n", = new_name, err);=0A= + goto out;=0A= + }=0A= +=0A= + if (ctx_src.footer.curr_size % VHD_BLOCK_SIZE) {=0A= + total_block =3D ctx_src.footer.curr_size / VHD_BLOCK_SIZE + 1;=0A= + } else {=0A= + total_block =3D ctx_src.footer.curr_size / VHD_BLOCK_SIZE;=0A= + }=0A= +=0A= + VHD_GLOBLE_LOG("curr_size=3D%"PRIu64", total_block=3D%"PRIu64"\n", = ctx_src.footer.curr_size, total_block);=0A= + =0A= + err =3D vhd_create(tag_name, total_block * VHD_BLOCK_SIZE, = HD_TYPE_DYNAMIC, 0);=0A= + if (err) {=0A= + printf("error, creating %s: %d\n", tag_name, err);=0A= + VHD_GLOBLE_LOG("error, creating tag_name=3D%s, %d\n", tag_name, err);=0A= + goto out;=0A= + }=0A= +=0A= + err =3D vhd_open(&ctx_tag, tag_name, VHD_OPEN_RDWR);=0A= + if (err) {=0A= + printf("error, opening %s: %d\n", tag_name, err);=0A= + VHD_GLOBLE_LOG("error, opening tag_name=3D%s, %d\n", tag_name, err);=0A= + goto out;=0A= + }=0A= +=0A= + sec =3D 0;=0A= + secs =3D VHD_SECTORS_PER_BLOCK;=0A= +=0A= + err =3D posix_memalign((void **)&buf, 4096, VHD_BLOCK_SIZE);=0A= + if (err) {=0A= + err =3D -err;=0A= + goto out;=0A= + }=0A= +=0A= + printf("Converting to %s.\n", tag_name);=0A= + for (current_block =3D 0; current_block < total_block; = current_block++) {=0A= + err =3D vhd_io_read(&ctx_src, buf, sec, secs);=0A= + if (err) { =0A= + VHD_GLOBLE_LOG("vhd_io_read error, sec=3D%"PRIu64", = current_block=3D%"PRIu64"\n", sec, current_block);=0A= + goto out;=0A= + }=0A= +=0A= + err =3D vhd_io_write(&ctx_tag, buf, sec, secs);=0A= + if (err) {=0A= + VHD_GLOBLE_LOG("vhd_io_write error, sec=3D%"PRIu64", = current_block=3D%"PRIu64"\n", sec, current_block);=0A= + goto out;=0A= + }=0A= +=0A= + sec +=3D secs;=0A= + if ((current_block % 10) =3D=3D 0) =0A= + printf(">"); /* progress show */=0A= + }=0A= + =0A= + VHD_GLOBLE_LOG("sec=3D%"PRIu64", current_block=3D%"PRIu64"\n", sec, = current_block);=0A= + printf("Done!\n");=0A= +out:=0A= + free(buf);=0A= + free(new_name);=0A= + vhd_close(&ctx_src);=0A= + vhd_close(&ctx_tag);=0A= + return err;=0A= +}=0A= +=0A= +/*++=0A= +=0A= + Function Name: vhd_dynamic_to_fixed=0A= +=0A= + Description: convert dynamic type vhd disk image to fixed type = vhd disk image=0A= +=0A= + Creator: Alfred Song 07/07/2010=0A= +=0A= + Input: src_name - source file name=0A= + tag_name - target file name=0A= +=0A= + Output: 0 - success=0A= + others - fail=0A= +=0A= +--*/=0A= +int=0A= +vhd_dynamic_to_fixed(char * src_name, char * tag_name)=0A= +{=0A= + vhd_context_t ctx_src;=0A= + vhd_context_t ctx_tag;=0A= + int err;=0A= + uint64_t current_block, sec, secs, total_block;=0A= + char * buf;=0A= + char * new_name;=0A= + =0A= + memset(&ctx_src, 0, sizeof(vhd_context_t));=0A= + memset(&ctx_tag, 0, sizeof(vhd_context_t));=0A= + err =3D 0;=0A= + buf =3D NULL;=0A= + new_name =3D NULL;=0A= +=0A= + if (!src_name && !tag_name) {=0A= + VHD_GLOBLE_LOG("error, invalid input, src_name=3D%s, = tag_name=3D%s\n", \=0A= + src_name, tag_name);=0A= + goto out;=0A= + }=0A= +=0A= + VHD_GLOBLE_LOG("src_name=3D%s, tag_name=3D%s\n", src_name, tag_name);=0A= +=0A= + /* size allocate to keep no overflow happen */=0A= + err =3D posix_memalign((void **)&new_name, 4096, strlen(src_name) + = 10);=0A= + if (err) {=0A= + err =3D -err;=0A= + goto out;=0A= + }=0A= +=0A= + strcpy(new_name, src_name);=0A= + strcat(new_name, ".bak");=0A= +=0A= + err =3D rename(src_name, new_name);=0A= + if (err) {=0A= + VHD_GLOBLE_LOG("error, src_name=3D%s, new_name=3D%s, %d\n", \=0A= + src_name, new_name, err);=0A= + goto out;=0A= + }=0A= +=0A= + VHD_GLOBLE_LOG("after renaming, src_name=3D%s, new_name=3D%s\n", \=0A= + src_name, new_name);=0A= +/*=0A= + if (strcmp(src_name, tag_name) =3D=3D 0) {=0A= + printf("error, source file %s equals target file %s.\nPlease specify \=0A= +different name.\n", src_name, tag_name);=0A= + err =3D -EINVAL;=0A= + goto out;=0A= + //TODO=0A= + }=0A= +*/=0A= +=0A= + printf("Back up source to %s.\n", new_name);=0A= + err =3D vhd_open(&ctx_src, new_name, VHD_OPEN_RDWR);=0A= + if (err) {=0A= + printf("error, opening %s: %d\n", new_name, err);=0A= + VHD_GLOBLE_LOG("error, opening new_name=3D%s, %d\n", new_name, err);=0A= + goto out;=0A= + }=0A= +=0A= + if (ctx_src.footer.type !=3D HD_TYPE_DYNAMIC) {=0A= + err =3D -EINVAL;=0A= + printf("error, source file %s is not dynamic type VHD, %d\n", = new_name, err);=0A= + VHD_GLOBLE_LOG("error, source file %s is not dynamic type VHD, %d\n", = new_name, err);=0A= + goto out;=0A= + }=0A= +=0A= + if (ctx_src.footer.curr_size % VHD_BLOCK_SIZE) {=0A= + total_block =3D ctx_src.footer.curr_size / VHD_BLOCK_SIZE + 1;=0A= + } else {=0A= + total_block =3D ctx_src.footer.curr_size / VHD_BLOCK_SIZE;=0A= + }=0A= +=0A= + VHD_GLOBLE_LOG("curr_size=3D%"PRIu64", total_block=3D%"PRIu64"\n", = ctx_src.footer.curr_size, total_block);=0A= + =0A= + err =3D vhd_create(tag_name, total_block * VHD_BLOCK_SIZE, = HD_TYPE_FIXED, 0);=0A= + if (err) {=0A= + printf("error, creating %s: %d\n", tag_name, err);=0A= + VHD_GLOBLE_LOG("error, creating tag_name=3D%s, %d\n", tag_name, err);=0A= + goto out;=0A= + }=0A= +=0A= + err =3D vhd_open(&ctx_tag, tag_name, VHD_OPEN_RDWR);=0A= + if (err) {=0A= + printf("error, opening %s: %d\n", tag_name, err);=0A= + VHD_GLOBLE_LOG("error, opening tag_name=3D%s, %d\n", tag_name, err);=0A= + goto out;=0A= + }=0A= +=0A= + sec =3D 0;=0A= + secs =3D VHD_SECTORS_PER_BLOCK;=0A= +=0A= + err =3D posix_memalign((void **)&buf, 4096, VHD_BLOCK_SIZE);=0A= + if (err) {=0A= + err =3D -err;=0A= + goto out;=0A= + }=0A= +=0A= + printf("Converting to %s.\n", tag_name);=0A= + for (current_block =3D 0; current_block < total_block; = current_block++) {=0A= + err =3D vhd_io_read(&ctx_src, buf, sec, secs);=0A= + if (err) { =0A= + VHD_GLOBLE_LOG("vhd_io_read error, sec=3D%"PRIu64", = current_block=3D%"PRIu64"\n", sec, current_block);=0A= + goto out;=0A= + }=0A= +=0A= + err =3D vhd_io_write(&ctx_tag, buf, sec, secs);=0A= + if (err) {=0A= + VHD_GLOBLE_LOG("vhd_io_write error, sec=3D%"PRIu64", = current_block=3D%"PRIu64"\n", sec, current_block);=0A= + goto out;=0A= + }=0A= +=0A= + sec +=3D secs;=0A= + if ((current_block % 10) =3D=3D 0) =0A= + printf(">"); /* progress show */=0A= + }=0A= + =0A= + VHD_GLOBLE_LOG("sec=3D%"PRIu64", current_block=3D%"PRIu64"\n", sec, = current_block);=0A= + printf("Done!\n");=0A= +out:=0A= + free(buf);=0A= + free(new_name);=0A= + vhd_close(&ctx_src);=0A= + vhd_close(&ctx_tag);=0A= + return err;=0A= +}=0A= +=0A= diff -Naur blktap2/vhd/lib/vhd-util-check.c = blktap2-new/vhd/lib/vhd-util-check.c=0A= --- blktap2/vhd/lib/vhd-util-check.c 2010-04-08 00:12:04.000000000 +0800=0A= +++ blktap2-new/vhd/lib/vhd-util-check.c 2010-06-29 11:38:41.000000000 = +0800=0A= @@ -89,7 +89,7 @@=0A= footer->crtr_ver =3D=3D VHD_VERSION(1, 1))) {=0A= char tmp =3D footer->hidden;=0A= footer->hidden =3D 0;=0A= - checksum =3D vhd_checksum_footer(footer);=0A= + checksum =3D vhd_checksum_footer(footer); /* ignore 'hidden' */=0A= footer->hidden =3D tmp;=0A= =0A= if (checksum =3D=3D footer->checksum)=0A= diff -Naur blktap2/vhd/lib/vhd-util-convert.c = blktap2-new/vhd/lib/vhd-util-convert.c=0A= --- blktap2/vhd/lib/vhd-util-convert.c 1970-01-01 08:00:00.000000000 = +0800=0A= +++ blktap2-new/vhd/lib/vhd-util-convert.c 2010-07-12 15:39:47.000000000 = +0800=0A= @@ -0,0 +1,136 @@=0A= +/*++=0A= +=0A= +File Name: vhd-util-convert.c=0A= +=0A= +Description: This function could be used to finish converting RAW = <-> Fixed VHD,=0A= + Fixed VHD <-> Dynamic VHD.=0A= +=0A= +Creator: Alfred Song 06/24/2010=0A= +=0A= +History: Alfred Song 07/12/2010=0A= + add function: vhd_fiexed_to_dynamic=0A= + vhd_dynamic_to_fixed =0A= +=0A= +--*/=0A= +#include =0A= +#include =0A= +#include =0A= +#include =0A= +#include =0A= +#include =0A= +#include =0A= +#include =0A= +#include =0A= +=0A= +#include "libvhd.h"=0A= +#include "vhd-util.h"=0A= +=0A= +#define DISK_TYPE_RAW 0=0A= +#define DISK_TYPE_VHD_FIXED 1=0A= +#define DISK_TYPE_VHD_DYNAMIC 2=0A= +#define DISK_TYPE_VHD_DIFF 3=0A= +=0A= +int=0A= +vhd_util_convert(int argc, char **argv)=0A= +{=0A= + char *input_file_name;=0A= + char *output_file_name;=0A= + long int source_type; /* -1 - invalid,=0A= + 0 - raw=0A= + 1 - fixed=0A= + 2 - dynamic=0A= + 3 - parent */=0A= + long int target_type; /* -1 - invalid,=0A= + 0 - raw=0A= + 1 - fixed=0A= + 2 - dynamic=0A= + 3 - parent */=0A= + int c, err;=0A= + vhd_flag_creat_t flags;=0A= +=0A= + input_file_name =3D NULL;=0A= + output_file_name =3D NULL;=0A= + source_type =3D -1;=0A= + target_type =3D -1;=0A= + err =3D -EINVAL;=0A= + flags =3D 0;=0A= + =0A= +=0A= + if (!argc || !argv)=0A= + goto usage;=0A= +=0A= + optind =3D 0;=0A= + while ((c =3D getopt(argc, argv, "i:o:s:t:h")) !=3D -1) {=0A= + switch (c) {=0A= + case 'i':=0A= + input_file_name =3D optarg;=0A= + break;=0A= + case 'o':=0A= + output_file_name =3D optarg;=0A= + break;=0A= + case 's':=0A= + source_type =3D strtol(optarg, NULL, 10);=0A= + break;=0A= + case 't':=0A= + target_type =3D strtol(optarg, NULL, 10);=0A= + break;=0A= + case 'h':=0A= + default:=0A= + goto usage;=0A= + }=0A= + }=0A= +=0A= + VHD_GLOBLE_LOG("cmd parameters: "=0A= + "input_file_name=3D%s, output_file_name=3D%s, "=0A= + "source_type=3D%ld, target_type=3D%ld\n",=0A= + input_file_name, output_file_name, source_type, target_type);=0A= +=0A= + if (!input_file_name || !output_file_name \=0A= + || source_type > 3 || source_type < 0 \=0A= + || target_type > 3 || target_type < 0 || optind !=3D argc)=0A= + goto usage;=0A= +=0A= + if (source_type =3D=3D DISK_TYPE_RAW && target_type =3D=3D = DISK_TYPE_VHD_FIXED) {=0A= + err =3D vhd_raw_to_fixed(input_file_name, output_file_name);=0A= + if(err) {=0A= + printf("Fail to convert RAW disk to VHD fixed disk.\n");=0A= + VHD_GLOBLE_LOG("Fail to convert RAW disk to VHD fixed disk.\n");=0A= + exit(1);=0A= + }=0A= + } else if (source_type =3D=3D DISK_TYPE_VHD_FIXED && target_type = =3D=3D DISK_TYPE_RAW) {=0A= + err =3D vhd_fixed_to_raw(input_file_name, output_file_name);=0A= + if(err) {=0A= + printf("Fail to convert VHD fixed disk to RAW disk.\n");=0A= + VHD_GLOBLE_LOG("Fail to convert VHD fixed disk to RAW disk.\n");=0A= + exit(1);=0A= + }=0A= + } else if (source_type =3D=3D DISK_TYPE_VHD_FIXED && target_type = =3D=3D DISK_TYPE_VHD_DYNAMIC) {=0A= + err =3D vhd_fixed_to_dynamic(input_file_name, output_file_name);=0A= + if(err) {=0A= + printf("Fail to convert VHD fixed disk to VHD dynamic disk. %d\n", = err);=0A= + VHD_GLOBLE_LOG("Fail to convert VHD fixed disk to VHD dynamic disk. = %d\n", err);=0A= + exit(1);=0A= + }=0A= + } else if (source_type =3D=3D DISK_TYPE_VHD_DYNAMIC && target_type = =3D=3D DISK_TYPE_VHD_FIXED) {=0A= + err =3D vhd_dynamic_to_fixed(input_file_name, output_file_name);=0A= + if(err) {=0A= + printf("Fail to convert VHD dynamic disk to VHD fixed disk. %d\n", = err);=0A= + VHD_GLOBLE_LOG("Fail to convert VHD dynamic disk to VHD fixed disk. = %d\n", err);=0A= + exit(1);=0A= + }=0A= + } else {=0A= + printf("Currently, only RAW <-> FIXED, FIXED <-> DYNAMIC convert is = supported.\n");=0A= + }=0A= +=0A= + return 0; //TODO=0A= +=0A= +usage:=0A= + printf("\=0A= +options: <-i input file name> \=0A= +<-o output file name> \=0A= +<-s source type(0 - raw, 1 - fixed, 2 - dynamic, 3 - differencing)> \=0A= +<-t target type(0 - raw, 1 - fixed, 2 - dynamic, 3 - differencing)> \=0A= +[-h help]\n");=0A= + return -EINVAL;=0A= +}=0A= +=0A= diff -Naur blktap2/vhd/vhd-util.c blktap2-new/vhd/vhd-util.c=0A= --- blktap2/vhd/vhd-util.c 2010-04-08 00:12:04.000000000 +0800=0A= +++ blktap2-new/vhd/vhd-util.c 2010-07-12 15:39:08.000000000 +0800=0A= @@ -24,6 +24,13 @@=0A= * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS=0A= * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.=0A= */=0A= +/*++=0A= +=0A= +History: Alfred Song 06/24/2010=0A= + add process function: vhd_util_convert=0A= + add globle debug set: vhd_globle_dbg=0A= +=0A= +--*/=0A= #include =0A= #include =0A= #include =0A= @@ -59,6 +66,7 @@=0A= { .name =3D "scan", .func =3D vhd_util_scan },=0A= { .name =3D "check", .func =3D vhd_util_check },=0A= { .name =3D "revert", .func =3D vhd_util_revert },=0A= + { .name =3D "convert", .func =3D vhd_util_convert },=0A= };=0A= =0A= #define print_commands() \=0A= @@ -136,8 +144,10 @@=0A= for (i =3D 1; i < cargc; i++) {=0A= char *arg =3D argv[i + (argc - cargc)];=0A= =0A= + /* system log for debug, and ignore this option */=0A= if (!strcmp(arg, "--debug")) {=0A= libvhd_set_log_level(1);=0A= + vhd_globle_dbg =3D 1;=0A= continue;=0A= }=0A= =0A= ------=_NextPart_000_0062_01CB2339.2E281D40 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel ------=_NextPart_000_0062_01CB2339.2E281D40--