lkml.org 
[lkml]   [1999]   [Oct]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [patch] replacing "/dev/root" in /proc/mounts
On Wed Oct 06, 1999 at 09:50:55PM -0400, Wakko Warner wrote:
> > There seems to currently be no mechanism (at least none I am aware of)
> > from user space to determine what the root device name _really_ is. The
> > kernel knows what the kdev_t for the root filesystem's device is, but
> > it apparently has no method of sharing that knowledge with userspace.
> > This patch lets /proc/mounts tell userspace the major/minor number of
> > the root filesystem. The patch applies to both 2.3.18 and 2.2.12.
>
> [wakko@ani:/backup/ani] stat / -FD
> FSDevice: /dev/sda1 (8:01)
> [wakko@ani:/backup/ani]
>
> stat is a program I wrote that uses struct stat and gives the info that you
> requested (-F looks in /dev to find the device, -D shows only the device
> that the file system is on)

hmm, stat based... So presumably it does something like:

#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
int main(int argc, char **argv)
{
struct stat statBuf;
unsigned int major, minor;
stat("/", &statBuf);
major=minor=statBuf.st_dev;
printf("/ is on device major %d, minor %d\n",
major>>8, minor&0xff);
return( 0);
}
while that does work, the problem with this approach is you have to look
under the kernel's hood to discover how the kernel _currently_ defines
a dev_t. Suppose somebody next week decides we don't have enough minor
numbers for the new XP-37 5000-slot DVD changer... boom.


Having just read the util-linux mount source more carefully, I realised
that the /etc/mtab entry mount writes is correct and that has to come
from somewhere. I couldn't believe they would abuse stat, and I was right;
I have found a better solution:

#include <stdio.h>
#include <fstab.h>
int main(int argc, char **argv)
{
struct fstab* fstabBuf;
printf("/ is on device %s\n",
(getfsfile ("/"))->fs_spec);
return( 0);
}
which works and won't be as fragile.

of course, /proc/mounts is still wrong, but I can special case "/"
pretty easily now without needing the kernel to be fixed.


> > can't remount /dev/root ro (since there isn't really a /dev/root),
> > so you can't get a clean reboot.
>
> Ever tried: [wakko@ani:/backup/ani] grep remount /etc/init.d/umountfs
> mount -n -o remount,ro / [wakko@ani:/backup/ani]

Ok, bad example, sorry. however, my point was that the kernel is lying.

> So, what happens when / is an nfs mount? [wakko@gohan:/home/wakko]
> cat /proc/mounts /dev/root / nfs rw,addr=192.168.2.3 0 0
> [wakko@gohan:/home/wakko]

same thing as always. I didn't mess with NFS (which is a special case in
the kernel mount code), I just touched the non-NFS cases. I don't know
what can be done to make the NFS case in /proc/mounts more correct.

-Erik

--
Erik B. Andersen Web: http://www.xmission.com/~andersen/
email: andersee@debian.org
--This message was written using 73% post-consumer electrons--

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:54    [from the cache]
©2003-2011 Jasper Spaans