From a5fd85e7392b589d9d90ab515ad3e4bd1befd874 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Sat, 13 Nov 2010 14:41:01 +0000 Subject: [PATCH] inspect: Optimize root filesystem check. Avoid duplicate checks for things like /etc and /bin. --- src/inspect.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/inspect.c b/src/inspect.c index f5e4490..2f543b5 100644 --- a/src/inspect.c +++ b/src/inspect.c @@ -257,13 +257,18 @@ check_filesystem (guestfs_h *g, const char *device) fs->device = safe_strdup (g, device); fs->is_mountable = 1; + /* Optimize some of the tests by avoiding multiple tests of the same thing. */ + int is_dir_etc = guestfs_is_dir (g, "/etc") > 0; + int is_dir_bin = guestfs_is_dir (g, "/bin") > 0; + int is_dir_share = guestfs_is_dir (g, "/share") > 0; + /* Grub /boot? */ if (guestfs_is_file (g, "/grub/menu.lst") > 0 || guestfs_is_file (g, "/grub/grub.conf") > 0) fs->content = FS_CONTENT_LINUX_BOOT; /* Linux root? */ - else if (guestfs_is_dir (g, "/etc") > 0 && - guestfs_is_dir (g, "/bin") > 0 && + else if (is_dir_etc && + is_dir_bin && guestfs_is_file (g, "/etc/fstab") > 0) { fs->is_root = 1; fs->content = FS_CONTENT_LINUX_ROOT; @@ -271,16 +276,16 @@ check_filesystem (guestfs_h *g, const char *device) return -1; } /* Linux /usr/local? */ - else if (guestfs_is_dir (g, "/etc") > 0 && - guestfs_is_dir (g, "/bin") > 0 && - guestfs_is_dir (g, "/share") > 0 && + else if (is_dir_etc && + is_dir_bin && + is_dir_share && guestfs_exists (g, "/local") == 0 && guestfs_is_file (g, "/etc/fstab") == 0) fs->content = FS_CONTENT_LINUX_USR_LOCAL; /* Linux /usr? */ - else if (guestfs_is_dir (g, "/etc") > 0 && - guestfs_is_dir (g, "/bin") > 0 && - guestfs_is_dir (g, "/share") > 0 && + else if (is_dir_etc && + is_dir_bin && + is_dir_share && guestfs_exists (g, "/local") > 0 && guestfs_is_file (g, "/etc/fstab") == 0) fs->content = FS_CONTENT_LINUX_USR; -- 1.8.3.1