mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-22 07:03:38 +00:00
New API: inspect-get-roots to return roots from last inspection.
Return the roots found by the last call to inspect-os, but without redoing the whole inspection.
This commit is contained in:
@@ -1036,6 +1036,19 @@ This call assumes that the guest is Windows and that the
|
||||
systemroot could be determined by inspection. If this is not
|
||||
the case then an error is returned.
|
||||
|
||||
Please read L<guestfs(3)/INSPECTION> for more details.");
|
||||
|
||||
("inspect_get_roots", (RStringList "roots", [], []), -1, [],
|
||||
[],
|
||||
"return list of operating systems found by last inspection",
|
||||
"\
|
||||
This function is a convenient way to get the list of root
|
||||
devices, as returned from a previous call to C<guestfs_inspect_os>,
|
||||
but without redoing the whole inspection process.
|
||||
|
||||
This returns an empty list if either no root devices were
|
||||
found or the caller has not called C<guestfs_inspect_os>.
|
||||
|
||||
Please read L<guestfs(3)/INSPECTION> for more details.");
|
||||
|
||||
]
|
||||
|
||||
@@ -423,28 +423,11 @@ guestfs__inspect_os (guestfs_h *g)
|
||||
/* At this point we have, in the handle, a list of all filesystems
|
||||
* found and data about each one. Now we assemble the list of
|
||||
* filesystems which are root devices and return that to the user.
|
||||
* Fall through to guestfs__inspect_get_roots to do that.
|
||||
*/
|
||||
size_t count = 0;
|
||||
for (i = 0; i < g->nr_fses; ++i)
|
||||
if (g->fses[i].is_root)
|
||||
count++;
|
||||
|
||||
char **ret = calloc (count+1, sizeof (char *));
|
||||
if (ret == NULL) {
|
||||
perrorf (g, "calloc");
|
||||
char **ret = guestfs__inspect_get_roots (g);
|
||||
if (ret == NULL)
|
||||
guestfs___free_inspect_info (g);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
count = 0;
|
||||
for (i = 0; i < g->nr_fses; ++i) {
|
||||
if (g->fses[i].is_root) {
|
||||
ret[count] = safe_strdup (g, g->fses[i].device);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
ret[count] = NULL;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1307,6 +1290,37 @@ search_for_root (guestfs_h *g, const char *root)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char **
|
||||
guestfs__inspect_get_roots (guestfs_h *g)
|
||||
{
|
||||
/* NB. Doesn't matter if g->nr_fses == 0. We just return an empty
|
||||
* list in this case.
|
||||
*/
|
||||
|
||||
size_t i;
|
||||
size_t count = 0;
|
||||
for (i = 0; i < g->nr_fses; ++i)
|
||||
if (g->fses[i].is_root)
|
||||
count++;
|
||||
|
||||
char **ret = calloc (count+1, sizeof (char *));
|
||||
if (ret == NULL) {
|
||||
perrorf (g, "calloc");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
count = 0;
|
||||
for (i = 0; i < g->nr_fses; ++i) {
|
||||
if (g->fses[i].is_root) {
|
||||
ret[count] = safe_strdup (g, g->fses[i].device);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
ret[count] = NULL;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
char *
|
||||
guestfs__inspect_get_type (guestfs_h *g, const char *root)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user