Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to never resolve parent path when vhd-util query is called #378

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/libvhd.h
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ int vhd_initialize_header_parent_name(vhd_context_t *, const char *);
int vhd_write_parent_locators(vhd_context_t *, const char *);
int vhd_parent_locator_count(vhd_context_t *);
int vhd_parent_locator_get(vhd_context_t *, char **);
int vhd_parent_locator_unresolved_get(vhd_context_t *, char **);
int vhd_custom_parent_set(vhd_context_t *vhd, const char *parent);

int vhd_parent_locator_read(vhd_context_t *, vhd_parent_locator_t *, char **);
Expand Down
21 changes: 19 additions & 2 deletions vhd/lib/libvhd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1812,8 +1812,8 @@ vhd_parent_locator_read(vhd_context_t *ctx,
return err;
}

int
vhd_parent_locator_get(vhd_context_t *ctx, char **parent)
static int
vhd_parent_locator_get_impl(vhd_context_t *ctx, char **parent, bool resolve_parent)
{
int i, n, err;
char *name, *location;
Expand All @@ -1837,6 +1837,11 @@ vhd_parent_locator_get(vhd_context_t *ctx, char **parent)
if (_err)
continue;

if (!resolve_parent) {
*parent = name;
return 0;
}

err = vhd_find_parent(ctx, name, &location);
if (err)
VHDLOG("%s: couldn't find parent %s (%d)\n",
Expand All @@ -1852,6 +1857,18 @@ vhd_parent_locator_get(vhd_context_t *ctx, char **parent)
return err;
}

int
vhd_parent_locator_get(vhd_context_t *ctx, char **parent)
{
return vhd_parent_locator_get_impl(ctx, parent, true);
}

int
vhd_parent_locator_unresolved_get(vhd_context_t *ctx, char **parent)
{
return vhd_parent_locator_get_impl(ctx, parent, false);
}

/**
* Overrides the parent with the supplied one.
*
Expand Down
36 changes: 21 additions & 15 deletions vhd/lib/vhd-util-query.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,26 @@ vhd_util_query(int argc, char **argv)
char *name;
vhd_context_t vhd;
off64_t currsize;
int ret, err, c, size, physize, parent, fields, depth, fastresize, marker, allocated;

name = NULL;
size = 0;
physize = 0;
parent = 0;
fields = 0;
depth = 0;
fastresize = 0;
marker = 0;
allocated = 0;

int ret, err, c, size, physize, parent, fields, depth, fastresize, marker, allocated, resolve_parent;

name = NULL;
size = 0;
physize = 0;
parent = 0;
fields = 0;
depth = 0;
fastresize = 0;
marker = 0;
allocated = 0;
resolve_parent = 1;

if (!argc || !argv) {
err = -EINVAL;
goto usage;
}

optind = 0;
while ((c = getopt(argc, argv, "n:vspfdSmah")) != -1) {
while ((c = getopt(argc, argv, "n:vspfdSmauh")) != -1) {
switch (c) {
case 'n':
name = optarg;
Expand Down Expand Up @@ -93,6 +94,9 @@ vhd_util_query(int argc, char **argv)
case 'a':
allocated = 1;
break;
case 'u':
resolve_parent = 0;
break;
case 'h':
err = 0;
goto usage;
Expand Down Expand Up @@ -132,7 +136,7 @@ vhd_util_query(int argc, char **argv)
else {
char *pname;

ret = vhd_parent_locator_get(&vhd, &pname);
ret = resolve_parent ? vhd_parent_locator_get(&vhd, &pname) : vhd_parent_locator_unresolved_get(&vhd, &pname);
if (ret)
printf("query failed\n");
else {
Expand Down Expand Up @@ -212,6 +216,8 @@ vhd_util_query(int argc, char **argv)
"[-s print physical utilization (bytes)] [-p print parent] "
"[-f print fields] [-m print marker] [-d print chain depth] "
"[-S print max virtual size (MB) for fast resize] "
"[-a print allocated block count] [-h help]\n");
"[-a print allocated block count] "
"[-u don't resolve parent path] "
"[-h help]\n");
return err;
}