Skip to contentSkip to conversation

blktap2-vhd-util | add disk image convert functions, RAW <-> fixed VHD, and fixed <-> dynamic VHD for xen4.0.0

PATCH New Alfred Song 1 participant 1 message Jul 14, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 blktap2-vhd-util | add disk image convert functions, RAW <-> fixed VHD, and fixed <-> dynamic VHD for xen4.0.0

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

include/libvhd.h +105 -5
diff -Naur blktap2/include/libvhd.h blktap2-new/include/libvhd.h
@@ -24,6 +24,19 @@
  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
+/*++
+
+History:   Alfred Song			06/24/2010
+			add globle debug flag declare: 		vhd_globle_dbg
+			add macro: 							VHD_GLOBLE_LOG
+		   Alfred Song			06/25/2010
+			add function:						vhd_raw_to_fixed
+												vhd_fiexed_to_raw
+			Alfred Song			07/12/2010
+			add function:						vhd_fiexed_to_dynamic
+												vhd_dynamic_to_fixed
+
+--*/
 #ifndef _VHD_LIB_H_
 #define _VHD_LIB_H_
 
@@ -36,6 +49,7 @@
 #include <sys/bswap.h>
 #endif
 
+#include <syslog.h>
 #include "blk_uuid.h"
 #include "vhd.h"
 
@@ -68,6 +82,17 @@
   #define BE64_OUT(foo)
 #endif
 
+
+extern int vhd_globle_dbg; /* system log switch */
+
+#define VHD_GLOBLE_LOG(_f, _a...)						\
+	do {												\
+		if (vhd_globle_dbg)								\
+			syslog(LOG_INFO, "%s\\%s, %d\\"_f,	\
+			       __FILE__, __func__, __LINE__, ##_a);						\
+	} while (0)
+
+
 #define MIN(a, b)                  (((a) < (b)) ? (a) : (b))
 #define MAX(a, b)                  (((a) > (b)) ? (a) : (b))
 
@@ -75,6 +100,7 @@
 
 #define VHD_BLOCK_SHIFT            21
 #define VHD_BLOCK_SIZE             (1ULL << VHD_BLOCK_SHIFT)
+#define VHD_SECTORS_PER_BLOCK		(VHD_BLOCK_SIZE >> VHD_SECTOR_SHIFT)
 
 #define UTF_16                     "UTF-16"
 #define UTF_16LE                   "UTF-16LE"
@@ -128,9 +154,9 @@
 typedef uint32_t                   vhd_flag_creat_t;
 
 struct vhd_bat {
-	uint32_t                   spb;
-	uint32_t                   entries;
-	uint32_t                  *bat;
+	uint32_t                   spb;          /* sector number per block */
+	uint32_t                   entries;    /* total entry number */
+	uint32_t                  *bat;         /* entry table */
 };
 
 struct vhd_batmap {
@@ -144,8 +170,8 @@
 	int                        oflags;
 	int                        is_block;
 
-	uint32_t                   spb;
-	uint32_t                   bm_secs;
+	uint32_t                   spb;            /* sectors per block */
+	uint32_t                   bm_secs;        /* sectors of bitmap */
 
 	vhd_header_t               header;
 	vhd_footer_t               footer;
@@ -323,4 +349,78 @@
 int vhd_io_read(vhd_context_t *, char *, uint64_t, uint32_t);
 int vhd_io_write(vhd_context_t *, char *, uint64_t, uint32_t);
 
+off_t get_file_size_rev(const char * name);
+
+/*++
+
+  Function Name:	vhd_raw_to_fixed
+
+  Description:      convert raw disk image to fixed type vhd disk image
+
+  Creator:          Alfred Song        06/25/2010
+
+  Input:			src_name		- source file name
+  					tag_name		- target file name
+
+  Output:			0				- success
+  					others			- fail
+
+--*/
+int vhd_raw_to_fixed(char * src_name, char * tag_name);
+
+/*++
+
+  Function Name:	vhd_fixed_to_raw
+
+  Description:      convert fixed type vhd disk image to raw disk image
+
+  Creator:          Alfred Song        06/25/2010
+
+  Input:			src_name		- source file name
+  					tag_name		- target file name
+
+  Output:			0				- success
+  					others			- fail
+
+--*/
+int vhd_fixed_to_raw(char * src_name, char * tag_name);
+
+/*++
+
+  Function Name:	vhd_fixed_to_dynamic
+
+  Description:      convert fixed type vhd disk image to dynamic type vhd disk image
+
+  Creator:          Alfred Song        07/07/2010
+
+  Input:			src_name		- source file name
+  					tag_name		- target file name
+
+  Output:			0				- success
+  					others			- fail
+
+--*/
+int
+vhd_fixed_to_dynamic(char * src_name, char * tag_name);
+
+/*++
+
+  Function Name:	vhd_dynamic_to_fixed
+
+  Description:      convert dynamic type vhd disk image to fixed type vhd disk image
+
+  Creator:          Alfred Song        07/07/2010
+
+  Input:			src_name		- source file name
+  					tag_name		- target file name
+
+  Output:			0				- success
+  					others			- fail
+
+--*/
+int
+vhd_dynamic_to_fixed(char * src_name, char * tag_name);
+
+//int get_file_size(char *, off_t *);
+
 #endif
include/vhd-util.h +8 -0
diff -Naur blktap2/include/vhd-util.h blktap2-new/include/vhd-util.h
@@ -24,6 +24,13 @@
  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
+
+/*++
+
+History:   Alfred Song			06/24/2010
+			add function vhd_util_convert
+
+--*/
 #ifndef _VHD_UTIL_H_
 #define _VHD_UTIL_H_
 
@@ -40,5 +47,6 @@
 int vhd_util_scan(int argc, char **argv);
 int vhd_util_check(int argc, char **argv);
 int vhd_util_revert(int argc, char **argv);
+int vhd_util_convert(int argc, char ** argv);
 
 #endif
vhd/lib/Makefile +1 -0
diff -Naur blktap2/vhd/lib/Makefile blktap2-new/vhd/lib/Makefile
@@ -42,6 +42,7 @@
 LIB-SRCS        += vhd-util-snapshot.c
 LIB-SRCS        += vhd-util-scan.c
 LIB-SRCS        += vhd-util-check.c
+LIB-SRCS        += vhd-util-convert.c
 LIB-SRCS        += relative-path.c
 LIB-SRCS        += atomicio.c
 
vhd/lib/libvhd.c +555 -13

729 lines not on this page · raw message

vhd/lib/vhd-util-check.c +1 -1
diff -Naur blktap2/vhd/lib/vhd-util-check.c blktap2-new/vhd/lib/vhd-util-check.c
@@ -89,7 +89,7 @@
 		     footer->crtr_ver == VHD_VERSION(1, 1))) {
 			char tmp = footer->hidden;
 			footer->hidden = 0;
-			checksum = vhd_checksum_footer(footer);
+			checksum = vhd_checksum_footer(footer); /* ignore 'hidden' */
 			footer->hidden = tmp;
 
 			if (checksum == footer->checksum)
vhd/lib/vhd-util-convert.c +136 -0

136 lines not on this page · raw message

vhd/vhd-util.c +10 -0
diff -Naur blktap2/vhd/vhd-util.c blktap2-new/vhd/vhd-util.c
@@ -24,6 +24,13 @@
  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
+/*++
+
+History:   Alfred Song			06/24/2010
+			add process function: 		vhd_util_convert
+			add globle debug set: 		vhd_globle_dbg
+
+--*/
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -59,6 +66,7 @@
 	{ .name = "scan",        .func = vhd_util_scan          },
 	{ .name = "check",       .func = vhd_util_check         },
 	{ .name = "revert",      .func = vhd_util_revert        },
+	{ .name = "convert",     .func = vhd_util_convert       },
 };
 
 #define print_commands()					\
@@ -136,8 +144,10 @@
 	for (i = 1; i < cargc; i++) {
 		char *arg = argv[i + (argc - cargc)];
 
+		/* system log for debug, and ignore this option */
 		if (!strcmp(arg, "--debug")) {
 			libvhd_set_log_level(1);
+			vhd_globle_dbg = 1;
 			continue;
 		}
 

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel