summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2011-03-22 11:05:21 +0000
committerRichard W.M. Jones <rjones@redhat.com>2011-03-29 20:22:51 +0100
commite3bb27af94641d1bed26574724ce46df73d2340e (patch)
treecf2463cd0811e028a5b01c54c96d8af49f3746f9 /src
parent7b367b4d927f5526925743a1bd9e57a94a48ea74 (diff)
downloadlibguestfs-e3bb27af94641d1bed26574724ce46df73d2340e.tar.gz
libguestfs-e3bb27af94641d1bed26574724ce46df73d2340e.tar.xz
libguestfs-e3bb27af94641d1bed26574724ce46df73d2340e.zip
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. (cherry picked from commit 5776c145d411e5ae00072ecf422055f3d0bd29e2)
Diffstat (limited to 'src')
-rw-r--r--src/inspect.c50
1 files changed, 38 insertions, 12 deletions
diff --git a/src/inspect.c b/src/inspect.c
index 8ab41bfd..09ef2b14 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
@@ -229,6 +229,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 add_fstab_entry (guestfs_h *g, struct inspect_fs *fs,
@@ -352,17 +354,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;
if (check_windows_root (g, fs) == -1)
@@ -1284,6 +1282,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;