Maros Zatko
2015-Mar-23 16:44 UTC
[Libguestfs] [PATCH v2] RFE: support Windows drive letters in virt-ls
It is modelled after virt-cat. Fixes RHBZ#845234 Ammended so it doesn't do inspection for every dir to list. Maros Zatko (1): virt-ls: support drive letters on Windows cat/ls.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) -- 1.9.3
Maros Zatko
2015-Mar-23 16:44 UTC
[Libguestfs] [PATCH v2] virt-ls: support drive letters on Windows
---
cat/ls.c | 32 +++++++++++++++++++++++++++++++-
1 file changed, 31 insertions(+), 1 deletion(-)
diff --git a/cat/ls.c b/cat/ls.c
index 9161fb6..b7a99b2 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 const char *get_windows_root ();
+
static void __attribute__((noreturn))
usage (int status)
{
@@ -176,6 +179,7 @@ main (int argc, char *argv[])
#define MODE_LS_R 2
#define MODE_LS_LR (MODE_LS_L|MODE_LS_R)
int mode = 0;
+ CLEANUP_FREE const char * win_root;
g = guestfs_create ();
if (g == NULL) {
@@ -371,10 +375,18 @@ main (int argc, char *argv[])
free_drives (drvs);
free_mps (mps);
+ win_root = get_windows_root ();
+
unsigned errors = 0;
while (optind < argc) {
- const char *dir = argv[optind];
+ CLEANUP_FREE const char *dir;
+
+ if (win_root != NULL) {
+ dir = windows_path (g, win_root, argv[optind], 1 /* readonly */ );
+ } else {
+ dir = safe_strdup (g, argv[optind]);
+ }
switch (mode) {
case 0: /* no -l or -R option */
@@ -409,6 +421,24 @@ main (int argc, char *argv[])
exit (errors == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
}
+static const char *
+get_windows_root (void)
+{
+ CLEANUP_FREE_STRING_LIST char **roots = NULL;
+ const char *root;
+
+ roots = guestfs_inspect_get_roots (g);
+ assert (roots);
+ assert (roots[0] != NULL);
+ assert (roots[1] == NULL);
+ root = safe_strdup(g, roots[0]);
+
+ if (is_windows (g, root))
+ return root;
+ else
+ return NULL;
+}
+
static int
do_ls (const char *dir)
{
--
1.9.3
Richard W.M. Jones
2015-Mar-24 13:26 UTC
Re: [Libguestfs] [PATCH v2] virt-ls: support drive letters on Windows
On Mon, Mar 23, 2015 at 05:44:35PM +0100, Maros Zatko wrote:> --- > cat/ls.c | 32 +++++++++++++++++++++++++++++++- > 1 file changed, 31 insertions(+), 1 deletion(-) > > diff --git a/cat/ls.c b/cat/ls.c > index 9161fb6..b7a99b2 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 const char *get_windows_root (); > + > static void __attribute__((noreturn)) > usage (int status) > { > @@ -176,6 +179,7 @@ main (int argc, char *argv[]) > #define MODE_LS_R 2 > #define MODE_LS_LR (MODE_LS_L|MODE_LS_R) > int mode = 0; > + CLEANUP_FREE const char * win_root; > > g = guestfs_create (); > if (g == NULL) { > @@ -371,10 +375,18 @@ main (int argc, char *argv[]) > free_drives (drvs); > free_mps (mps); > > + win_root = get_windows_root (); > + > unsigned errors = 0; > > while (optind < argc) { > - const char *dir = argv[optind]; > + CLEANUP_FREE const char *dir; > + > + if (win_root != NULL) { > + dir = windows_path (g, win_root, argv[optind], 1 /* readonly */ ); > + } else { > + dir = safe_strdup (g, argv[optind]); > + } > > switch (mode) { > case 0: /* no -l or -R option */ > @@ -409,6 +421,24 @@ main (int argc, char *argv[]) > exit (errors == 0 ? EXIT_SUCCESS : EXIT_FAILURE); > } > > +static const char * > +get_windows_root (void) > +{ > + CLEANUP_FREE_STRING_LIST char **roots = NULL; > + const char *root; > + > + roots = guestfs_inspect_get_roots (g);This breaks if inspector == 0 (eg. if the -m option is given). It will actually assert-fail on the next line. I strongly suggest you look at cat/cat.c and just copy what that program does. Also you need to update the documentation. Rich.> + assert (roots); > + assert (roots[0] != NULL); > + assert (roots[1] == NULL); > + root = safe_strdup(g, roots[0]); > + > + if (is_windows (g, root)) > + return root; > + else > + return NULL; > +} > + > static int > do_ls (const char *dir) > { > -- > 1.9.3 > > _______________________________________________ > Libguestfs mailing list > Libguestfs@redhat.com > https://www.redhat.com/mailman/listinfo/libguestfs-- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 100 libraries supported. http://fedoraproject.org/wiki/MinGW
Seemingly Similar Threads
- [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
- [PATCH v3 1/3] virt-ls: support drive letters on Windows
- [PATCH] virt-ls: support drive letters on Windows