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/