diff options
author | Dave Reisner <dreisner@archlinux.org> | 2014-04-02 10:41:30 -0400 |
---|---|---|
committer | Karel Zak <kzak@redhat.com> | 2014-04-23 11:55:08 +0200 |
commit | e0a487090cc5ffb2e3931433db585c9dd3b795b5 (patch) | |
tree | ba14b5752d95049522700cf9a646b94dcd7f490d | |
parent | 6b356f5d2cf51766c2304a75cfd2680c4fdf0cd1 (diff) | |
download | util-linux-e0a487090cc5ffb2e3931433db585c9dd3b795b5.tar.gz |
switch_root: verify initramfs by f_type, not devno
As of linux 3.14, the initramfs device will have both major and
minor 0, causing our paranoia check to fail. Make this version agnostic
by checking the filesystem type, rather than a device number.
Signed-off-by: Dave Reisner <dreisner@archlinux.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
-rw-r--r-- | sys-utils/switch_root.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/sys-utils/switch_root.c b/sys-utils/switch_root.c index 1222fb1b4..975360f01 100644 --- a/sys-utils/switch_root.c +++ b/sys-utils/switch_root.c @@ -23,6 +23,7 @@ #include <sys/mount.h> #include <sys/types.h> #include <sys/stat.h> +#include <sys/statfs.h> #include <sys/param.h> #include <fcntl.h> #include <stdio.h> @@ -45,6 +46,10 @@ #define MNT_DETACH 0x00000002 /* Just detach from the tree */ #endif +#define STATFS_RAMFS_MAGIC 0x858458f6 +#define STATFS_TMPFS_MAGIC 0x01021994 + + /* remove all files/directories below dirName -- don't cross mountpoints */ static int recursiveRemove(int fd) { @@ -177,12 +182,13 @@ static int switchroot(const char *newroot) if (cfd >= 0) { pid = fork(); if (pid <= 0) { - if (fstat(cfd, &sb) == 0) { - if (sb.st_dev == makedev(0, 1)) - recursiveRemove(cfd); - else - warn(_("old root filesystem is not an initramfs")); - } + struct statfs stfs; + if (fstatfs(cfd, &stfs) == 0 && + (stfs.f_type == STATFS_RAMFS_MAGIC || + stfs.f_type == STATFS_TMPFS_MAGIC)) + recursiveRemove(cfd); + else + warn(_("old root filesystem is not an initramfs")); if (pid == 0) exit(EXIT_SUCCESS); |