-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0001-Add-an-option-to-never-resolve-parent-path-when-vhd-.patch
More file actions
144 lines (136 loc) · 4.12 KB
/
Copy path0001-Add-an-option-to-never-resolve-parent-path-when-vhd-.patch
File metadata and controls
144 lines (136 loc) · 4.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
From e371dd87ad668e156309992bc83b96ad34fb4d38 Mon Sep 17 00:00:00 2001
From: Ronan Abhamon <ronan.abhamon@vates.fr>
Date: Thu, 16 Mar 2023 15:55:07 +0100
Subject: [PATCH 1/2] Add an option to never resolve parent path when vhd-util
query is called
Signed-off-by: Ronan Abhamon <ronan.abhamon@vates.fr>
---
include/libvhd.h | 1 +
vhd/lib/libvhd.c | 21 +++++++++++++++++++--
vhd/lib/vhd-util-query.c | 36 +++++++++++++++++++++---------------
3 files changed, 41 insertions(+), 17 deletions(-)
diff --git a/include/libvhd.h b/include/libvhd.h
index 7365918..3932547 100644
--- a/include/libvhd.h
+++ b/include/libvhd.h
@@ -341,6 +341,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 **);
diff --git a/vhd/lib/libvhd.c b/vhd/lib/libvhd.c
index 73be3ee..830e95a 100644
--- a/vhd/lib/libvhd.c
+++ b/vhd/lib/libvhd.c
@@ -1782,8 +1782,8 @@ out:
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;
@@ -1807,6 +1807,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",
@@ -1822,6 +1827,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.
*
diff --git a/vhd/lib/vhd-util-query.c b/vhd/lib/vhd-util-query.c
index 9aa131e..0cd0416 100644
--- a/vhd/lib/vhd-util-query.c
+++ b/vhd/lib/vhd-util-query.c
@@ -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;
@@ -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;
@@ -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 {
@@ -212,6 +216,8 @@ usage:
"[-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;
}