vhd-util coalesce to a specified file

This commit is contained in:
anthony 2011-03-01 19:58:12 -08:00
parent 53eb46dc2a
commit 95d39161cc

View File

@ -134,17 +134,23 @@ vhd_util_coalesce(int argc, char **argv)
name = NULL; name = NULL;
pname = NULL; pname = NULL;
int pflag = 0;
parent.file = NULL; parent.file = NULL;
if (!argc || !argv) if (!argc || !argv)
goto usage; goto usage;
optind = 0; optind = 0;
while ((c = getopt(argc, argv, "n:h")) != -1) { while ((c = getopt(argc, argv, "n:p:h")) != -1) {
switch (c) { switch (c) {
case 'n': case 'n':
name = optarg; name = optarg;
break; break;
case 'p':
pflag = 1;
pname = optarg;
break;
case 'h': case 'h':
default: default:
goto usage; goto usage;
@ -160,12 +166,14 @@ vhd_util_coalesce(int argc, char **argv)
return err; return err;
} }
if (pname == NULL) {
err = vhd_parent_locator_get(&vhd, &pname); err = vhd_parent_locator_get(&vhd, &pname);
if (err) { if (err) {
printf("error finding %s parent: %d\n", name, err); printf("error finding %s parent: %d\n", name, err);
vhd_close(&vhd); vhd_close(&vhd);
return err; return err;
} }
}
if (vhd_parent_raw(&vhd)) { if (vhd_parent_raw(&vhd)) {
parent_fd = open(pname, O_RDWR | O_DIRECT | O_LARGEFILE, 0644); parent_fd = open(pname, O_RDWR | O_DIRECT | O_LARGEFILE, 0644);
@ -204,7 +212,9 @@ vhd_util_coalesce(int argc, char **argv)
err = 0; err = 0;
done: done:
if (pflag==0) {
free(pname); free(pname);
}
vhd_close(&vhd); vhd_close(&vhd);
if (parent.file) if (parent.file)
vhd_close(&parent); vhd_close(&parent);
@ -213,6 +223,6 @@ vhd_util_coalesce(int argc, char **argv)
return err; return err;
usage: usage:
printf("options: <-n name> [-h help]\n"); printf("options: <-n name> [ -p parent name] [-h help]\n");
return -EINVAL; return -EINVAL;
} }