]>
git.ipfire.org Git - thirdparty/util-linux.git/blob - mount/mount_guess_rootdev.c
2 * Having the wrong rootdevice listed in mtab is slightly inconvenient.
3 * Try to guess what it could be...
4 * In case /proc/cmdline exists, and has the format
5 * stuff root=R more stuff...
6 * and we think we understand the number R, decode it as a root device.
9 * Erik Andersen writes:
10 * I did a similar find_real_root_device_name() in busybox some time back.
11 * Basically, do a stat("/", &rootstat) then walk /dev stat'ing each file
12 * and if (statbuf.st_rdev == rootstat.st_rdev) then you have a match.
17 #include "mount_guess_rootdev.h"
19 #define PROC_CMDLINE "/proc/cmdline"
30 devno
= strtoul(p
, &ep
, 16);
31 if ((ep
== p
+3 || ep
== p
+4) && (*ep
== ' ' || *ep
== 0)) {
60 sprintf(devname
, "/dev/%s%c", type
, let
);
62 sprintf(devname
, "/dev/%s%c%d", type
, let
, mi
);
63 return strdup(devname
);
69 mount_guess_rootdev() {
74 cf
= fopen(PROC_CMDLINE
, "r");
75 if (cf
&& fgets(line
, sizeof(line
), cf
)) {
76 for (p
= line
; *p
; p
++)
77 if (!strncmp(p
, " root=", 6))
85 char *p
= mount_guess_rootdev();