[Libguestfs] [PATCH] inspect: Simplify Windows root heuristic code.

Matthew Booth mbooth at redhat.com
Tue Mar 22 16:12:58 UTC 2011


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




More information about the Libguestfs mailing list