summaryrefslogtreecommitdiffstats
path: root/sys-utils/switch_root.c
diff options
context:
space:
mode:
authorDave Reisner2014-04-02 16:41:30 +0200
committerKarel Zak2014-04-04 14:55:13 +0200
commitc7832fb8f122f08b10bc6712f1062295a239bd06 (patch)
treec2158e49db227662bf4a176a0c65e9edd8894d1e /sys-utils/switch_root.c
parentlibsmartcols: add missing COPYING file (diff)
downloadkernel-qcow2-util-linux-c7832fb8f122f08b10bc6712f1062295a239bd06.tar.gz
kernel-qcow2-util-linux-c7832fb8f122f08b10bc6712f1062295a239bd06.tar.xz
kernel-qcow2-util-linux-c7832fb8f122f08b10bc6712f1062295a239bd06.zip
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>
Diffstat (limited to 'sys-utils/switch_root.c')
-rw-r--r--sys-utils/switch_root.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/sys-utils/switch_root.c b/sys-utils/switch_root.c
index 1222fb1b4..dac946f8c 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>
@@ -36,6 +37,7 @@
#include "c.h"
#include "nls.h"
#include "closestream.h"
+#include "statfs_magic.h"
#ifndef MS_MOVE
#define MS_MOVE 8192
@@ -177,12 +179,12 @@ 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);