lkml.org 
[lkml]   [1999]   [Oct]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [patch] replacing "/dev/root" in /proc/mounts
> > [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:

You're right!

> #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);
> }

Basically, yes. (see attached)

> 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.

Recompile, and make sure /dev is correct. I don't really see a problem with
that.

> 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

Actually, it does come from somewhere. From /etc/init.d/checkroot.sh

#
# Remount rootfs rw (default), but do not try to change mtab because it
# is on a ro fs until the remount succeeded. Then clean up old mtabs and
# finally write the new mtab.
#
mount -n -o remount,rw /
rm -f /etc/mtab~ /etc/nologin
: > /etc/mtab
mount -o remount,rw /
mount /proc

mount adds the mtab entry from /etc/fstab for / Seen it many times before.
Especially when the root dev was say, /dev/sdb1 instead of /dev/sda1 (and
/etc/mtab was incorrect)

> from somewhere. I couldn't believe they would abuse stat, and I was right;

What do you mean, abuse stat?

> 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.

Where does getfsfile get it's information from? The kernel? I don't have a
manpage for it.

> > > 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.

Actually, we could just put the contents of root= in /proc/mounts, couldn't
we?

> > 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.

Actually, it would probably be correct in saying /dev/nfs. I'm not sure
what the point of having the / listed in /proc/mounts as being correct
anyway. The kernel always knows how to do -o remounts with it (and any
other file system), and is never unmountable so you couldn't unmount then
mount back.

Maybe I'm confused as to what you wanted in the first message. How is it
helpful? (of course, it could be annoying) I thought about making a script
that would actually create /dev/root and it be a symlink to the real device.

--
Lab tests show that use of micro$oft causes cancer in lab animals
[unhandled content-type:application/x-gzip]
\
 
 \ /
  Last update: 2005-03-22 13:54    [W:0.079 / U:0.288 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site