Maros Zatko
2015-Mar-17 14:33 UTC
[Libguestfs] [PATCH] RFE: support Windows drive letters in virt-ls
It is modelled after virt-cat. Fixes RHBZ#845234 Maros Zatko (1): virt-ls: support drive letters on Windows cat/ls.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) -- 1.9.3
Maros Zatko
2015-Mar-17 14:33 UTC
[Libguestfs] [PATCH] virt-ls: support drive letters on Windows
--- cat/ls.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/cat/ls.c b/cat/ls.c index 9161fb6..151c11d 100644 --- a/cat/ls.c +++ b/cat/ls.c @@ -37,6 +37,7 @@ #include "options.h" #include "visit.h" +#include "windows.h" /* Currently open libguestfs handle. */ guestfs_h *g; @@ -76,6 +77,8 @@ static void output_int64_uid (int64_t); static void output_string (const char *); static void output_string_link (const char *); +static char *from_maybe_windows_path (const char *); + static void __attribute__((noreturn)) usage (int status) { @@ -374,7 +377,7 @@ main (int argc, char *argv[]) unsigned errors = 0; while (optind < argc) { - const char *dir = argv[optind]; + const char *dir = from_maybe_windows_path(argv[optind]); switch (mode) { case 0: /* no -l or -R option */ @@ -401,6 +404,7 @@ main (int argc, char *argv[]) abort (); /* can't happen */ } + free (dir); optind++; } @@ -409,6 +413,31 @@ main (int argc, char *argv[]) exit (errors == 0 ? EXIT_SUCCESS : EXIT_FAILURE); } +static char * +from_maybe_windows_path (const char *dir) +{ + CLEANUP_FREE_STRING_LIST char **roots = NULL; + char *path = NULL; + char *root; + + roots = guestfs_inspect_get_roots (g); + assert (roots); + assert (roots[0] != NULL); + assert (roots[1] == NULL); + root = roots[0]; + + if (is_windows (g, root)) { + path = windows_path (g, root, dir, 1 /* readonly */ ); + if (path == NULL) { + guestfs_close (g); + exit (EXIT_FAILURE); + } + return path; + } + + return safe_strdup (g, dir); +} + static int do_ls (const char *dir) { -- 1.9.3
Richard W.M. Jones
2015-Mar-23 13:36 UTC
Re: [Libguestfs] [PATCH] virt-ls: support drive letters on Windows
On Tue, Mar 17, 2015 at 03:33:09PM +0100, Maros Zatko wrote:> --- > cat/ls.c | 31 ++++++++++++++++++++++++++++++- > 1 file changed, 30 insertions(+), 1 deletion(-) > > diff --git a/cat/ls.c b/cat/ls.c > index 9161fb6..151c11d 100644 > --- a/cat/ls.c > +++ b/cat/ls.c > @@ -37,6 +37,7 @@ > > #include "options.h" > #include "visit.h" > +#include "windows.h" > > /* Currently open libguestfs handle. */ > guestfs_h *g; > @@ -76,6 +77,8 @@ static void output_int64_uid (int64_t); > static void output_string (const char *); > static void output_string_link (const char *); > > +static char *from_maybe_windows_path (const char *); > + > static void __attribute__((noreturn)) > usage (int status) > { > @@ -374,7 +377,7 @@ main (int argc, char *argv[]) > unsigned errors = 0; > > while (optind < argc) { > - const char *dir = argv[optind]; > + const char *dir = from_maybe_windows_path(argv[optind]); > > switch (mode) { > case 0: /* no -l or -R option */ > @@ -401,6 +404,7 @@ main (int argc, char *argv[]) > abort (); /* can't happen */ > } > > + free (dir);Use CLEANUP_FREE instead?> optind++; > } > > @@ -409,6 +413,31 @@ main (int argc, char *argv[]) > exit (errors == 0 ? EXIT_SUCCESS : EXIT_FAILURE); > } > > +static char * > +from_maybe_windows_path (const char *dir) > +{ > + CLEANUP_FREE_STRING_LIST char **roots = NULL; > + char *path = NULL; > + char *root; > + > + roots = guestfs_inspect_get_roots (g); > + assert (roots); > + assert (roots[0] != NULL); > + assert (roots[1] == NULL); > + root = roots[0]; > + > + if (is_windows (g, root)) { > + path = windows_path (g, root, dir, 1 /* readonly */ ); > + if (path == NULL) { > + guestfs_close (g); > + exit (EXIT_FAILURE); > + } > + return path; > + } > + > + return safe_strdup (g, dir); > +}Hmmm. This isn't very similar to what cat/cat.c does. In cat/cat.c we do the inspection once only (inspection is expensive), and then we call windows_path conditionally based on that result. See: https://github.com/libguestfs/libguestfs/blob/master/cat/cat.c#L283-L301 Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://people.redhat.com/~rjones/virt-df/
Maybe Matching Threads
- [PATCH] RFE: support Windows drive letters in virt-ls
- [PATCH v2] virt-ls: support drive letters on Windows
- [PATCH v2] RFE: support Windows drive letters in virt-ls
- Re: [PATCH v3 1/3] virt-ls: support drive letters on Windows
- [PATCH v3 0/3] RFE: support Windows drive letter in virt-ls