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>
#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>
#include "c.h"
#include "nls.h"
#include "closestream.h"
+#include "statfs_magic.h"
#ifndef MS_MOVE
#define MS_MOVE 8192
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);