From 515053b74f98f508aafee0b9482e076c352686cb Mon Sep 17 00:00:00 2001 From: Sisyphus Date: Thu, 22 Aug 2013 17:27:41 +0300 Subject: [PATCH] init: fix trying mount devtmpfs into /dev --- init.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/init.c b/init.c index 754598f..2000643 100644 --- a/init.c +++ b/init.c @@ -79,7 +79,7 @@ static void fatal(const char *) __attribute__((noreturn)); static void fatal(const char *msg) { - printf("FATAL ERROR IN INIT: %s\nI can't recover from this," + printf("FATAL ERROR IN INIT: %s\nI can't recover from this, " "please reboot manually and send bugreport.\n", msg); while (1); } @@ -371,22 +371,21 @@ int main(int argc, char **argv) if (mount("sysfs", "/sys", "sysfs", 0, NULL)) fatal("failed to mount sysfs filesystem"); - if (statfs("/dev", &sfs)) - fatal("statfs /dev"); - /* Don't mount /dev if it is already mounted as tmpfs */ - if (sfs.f_type != TMPFS_MAGIC) { + if (stat("/", &rst)) + fatal("stat /"); + + /* Don't mount /dev if it is already mounted */ + if (stat("/dev", &cst)) + fatal("stat /dev"); + if (rst.st_dev == cst.st_dev && rst.st_ino != cst.st_ino) /* Try mount devtmpfs into /dev */ - if (mount("udevfs", "/dev", "devtmpfs", 0, "size=10M,mode=0755")) { - if (errno == ENODEV) { - /* There is no devtmpfs for current kernel, - * try mount tmpfs */ - if (mount("udev", "/dev", "tmpfs", 0, "size=10M,mode=0755")) - fatal("failed to mount tmpfs filesystem"); - } - else + if (mount("udevfs", "/dev", "devtmpfs", 0, "size=8M,mode=0755")) { + if (errno != ENODEV) fatal("failed to mount devtmpfs filesystem"); + /* There is no devtmpfs for current kernel, try mount tmpfs */ + if (mount("udev", "/dev", "tmpfs", 0, "size=8M,mode=0755")) + fatal("failed to mount tmpfs filesystem"); } - } /* ignore Control-C and keyboard stop signals */ sigemptyset(&sig); @@ -551,7 +550,7 @@ int main(int argc, char **argv) /* Make sure the current directory is not on the same filesystem as the root directory */ - if ( stat("/", &rst) || stat(".", &cst) ) + if (stat(".", &cst)) fatal("stat"); if ( rst.st_dev == cst.st_dev )