Richard W.M. Jones
2011-Mar-22 11:22 UTC
[Libguestfs] [PATCH] inspect: Simplify Windows root heuristic code.
-- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming blog: http://rwmj.wordpress.com Fedora now supports 80 OCaml packages (the OPEN alternative to F#) http://cocan.org/getting_started_with_ocaml_on_red_hat_and_fedora -------------- next part -------------->From 5776c145d411e5ae00072ecf422055f3d0bd29e2 Mon Sep 17 00:00:00 2001From: Richard W.M. Jones <rjones at redhat.com> Date: Tue, 22 Mar 2011 11:05:21 +0000 Subject: [PATCH 2/3] inspect: Simplify Windows root heuristic code. Add special is_file_nocase and is_dir_nocase functions and remove the duplicate checks for files and directories with different cases. --- src/inspect.c | 50 ++++++++++++++++++++++++++++++++++++++------------ 1 files changed, 38 insertions(+), 12 deletions(-) diff --git a/src/inspect.c b/src/inspect.c index 7cf18c3..20e8806 100644 --- a/src/inspect.c +++ b/src/inspect.c @@ -1,5 +1,5 @@ /* libguestfs - * Copyright (C) 2010 Red Hat Inc. + * Copyright (C) 2010-2011 Red Hat Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -230,6 +230,8 @@ static int check_windows_arch (guestfs_h *g, struct inspect_fs *fs); static int check_windows_software_registry (guestfs_h *g, struct inspect_fs *fs); static int check_windows_system_registry (guestfs_h *g, struct inspect_fs *fs); static char *resolve_windows_path_silently (guestfs_h *g, const char *); +static int is_file_nocase (guestfs_h *g, const char *); +static int is_dir_nocase (guestfs_h *g, const char *); static int extend_fses (guestfs_h *g); static int parse_unsigned_int (guestfs_h *g, const char *str); static int parse_unsigned_int_ignore_trailing (guestfs_h *g, const char *str); @@ -365,17 +367,13 @@ check_filesystem (guestfs_h *g, const char *device, guestfs_is_dir (g, "/spool") > 0) fs->content = FS_CONTENT_LINUX_VAR; /* Windows root? */ - else if (guestfs_is_file (g, "/AUTOEXEC.BAT") > 0 || - guestfs_is_file (g, "/autoexec.bat") > 0 || - guestfs_is_dir (g, "/Program Files") > 0 || - guestfs_is_dir (g, "/WINDOWS") > 0 || - guestfs_is_dir (g, "/Windows") > 0 || - guestfs_is_dir (g, "/windows") > 0 || - guestfs_is_dir (g, "/WIN32") > 0 || - guestfs_is_dir (g, "/Win32") > 0 || - guestfs_is_dir (g, "/WINNT") > 0 || - guestfs_is_file (g, "/boot.ini") > 0 || - guestfs_is_file (g, "/ntldr") > 0) { + else if (is_file_nocase (g, "/AUTOEXEC.BAT") > 0 || + is_dir_nocase (g, "/Program Files") > 0 || + is_dir_nocase (g, "/WINDOWS") > 0 || + is_dir_nocase (g, "/WIN32") > 0 || + is_dir_nocase (g, "/WINNT") > 0 || + is_file_nocase (g, "/boot.ini") > 0 || + is_file_nocase (g, "/ntldr") > 0) { fs->is_root = 1; fs->content = FS_CONTENT_WINDOWS_ROOT; fs->format = OS_FORMAT_INSTALLED; @@ -1662,6 +1660,34 @@ resolve_windows_path_silently (guestfs_h *g, const char *path) } static int +is_file_nocase (guestfs_h *g, const char *path) +{ + char *p; + int r; + + p = resolve_windows_path_silently (g, path); + if (!p) + return 0; + r = guestfs_is_file (g, p); + free (p); + return r > 0; +} + +static int +is_dir_nocase (guestfs_h *g, const char *path) +{ + char *p; + int r; + + p = resolve_windows_path_silently (g, path); + if (!p) + return 0; + r = guestfs_is_dir (g, p); + free (p); + return r > 0; +} + +static int extend_fses (guestfs_h *g) { size_t n = g->nr_fses + 1; -- 1.7.4.1
Matthew Booth
2011-Mar-22 16:12 UTC
[Libguestfs] [PATCH] inspect: Simplify Windows root heuristic code.
On 22/03/11 11:22, Richard W.M. Jones wrote:>> From 5776c145d411e5ae00072ecf422055f3d0bd29e2 Mon Sep 17 00:00:00 2001 > From: Richard W.M. Jones<rjones at redhat.com> > Date: Tue, 22 Mar 2011 11:05:21 +0000 > Subject: [PATCH 2/3] inspect: Simplify Windows root heuristic code. > > Add special is_file_nocase and is_dir_nocase functions and > remove the duplicate checks for files and directories with > different cases. > --- > src/inspect.c | 50 ++++++++++++++++++++++++++++++++++++++------------ > 1 files changed, 38 insertions(+), 12 deletions(-) > > diff --git a/src/inspect.c b/src/inspect.c > index 7cf18c3..20e8806 100644 > --- a/src/inspect.c > +++ b/src/inspect.c > @@ -365,17 +367,13 @@ check_filesystem (guestfs_h *g, const char *device, > guestfs_is_dir (g, "/spool")> 0) > fs->content = FS_CONTENT_LINUX_VAR; > /* Windows root? */ > - else if (guestfs_is_file (g, "/AUTOEXEC.BAT")> 0 || > - guestfs_is_file (g, "/autoexec.bat")> 0 || > - guestfs_is_dir (g, "/Program Files")> 0 || > - guestfs_is_dir (g, "/WINDOWS")> 0 || > - guestfs_is_dir (g, "/Windows")> 0 || > - guestfs_is_dir (g, "/windows")> 0 || > - guestfs_is_dir (g, "/WIN32")> 0 || > - guestfs_is_dir (g, "/Win32")> 0 || > - guestfs_is_dir (g, "/WINNT")> 0 || > - guestfs_is_file (g, "/boot.ini")> 0 || > - guestfs_is_file (g, "/ntldr")> 0) { > + else if (is_file_nocase (g, "/AUTOEXEC.BAT")> 0 || > + is_dir_nocase (g, "/Program Files")> 0 || > + is_dir_nocase (g, "/WINDOWS")> 0 || > + is_dir_nocase (g, "/WIN32")> 0 || > + is_dir_nocase (g, "/WINNT")> 0 || > + is_file_nocase (g, "/boot.ini")> 0 || > + is_file_nocase (g, "/ntldr")> 0) {Why not limit this list to /windows, /win32 and winnt? One of these directories must exist for it to be a windows root. Including the others risks erroneous identification. Matt -- Matthew Booth, RHCA, RHCSS Red Hat Engineering, Virtualisation Team GPG ID: D33C3490 GPG FPR: 3733 612D 2D05 5458 8A8A 1600 3441 EA19 D33C 3490