diff --git a/src/inspect-fs.c b/src/inspect-fs.c index 02fdb2a9a4..0714ae1500 100644 --- a/src/inspect-fs.c +++ b/src/inspect-fs.c @@ -43,6 +43,7 @@ static int check_filesystem (guestfs_h *g, const char *mountable, int whole_device); static void extend_fses (guestfs_h *g); static int get_partition_context (guestfs_h *g, const char *partition, int *partnum_ret, int *nr_partitions_ret); +static int is_symlink_to (guestfs_h *g, const char *file, const char *wanted_target); /* Find out if 'device' contains a filesystem. If it does, add * another entry in g->fses. @@ -215,8 +216,7 @@ check_filesystem (guestfs_h *g, const char *mountable, /* Linux root? */ else if (is_dir_etc && (is_dir_bin || - (guestfs_is_symlink (g, "/bin") > 0 && - guestfs_is_dir (g, "/usr/bin") > 0)) && + is_symlink_to (g, "/bin", "usr/bin") > 0) && guestfs_is_file (g, "/etc/fstab") > 0) { fs->is_root = 1; fs->format = OS_FORMAT_INSTALLED; @@ -366,6 +366,22 @@ get_partition_context (guestfs_h *g, const char *partition, return 0; } +static int +is_symlink_to (guestfs_h *g, const char *file, const char *wanted_target) +{ + CLEANUP_FREE char *target = NULL; + + if (guestfs_is_symlink (g, file) == 0) + return 0; + + target = guestfs_readlink (g, file); + /* This should not fail, but play safe. */ + if (target == NULL) + return 0; + + return STREQ (target, wanted_target); +} + int guestfs_int_is_file_nocase (guestfs_h *g, const char *path) {