public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* how to map "/dev/root" to "/proc/partitions" entry in user prog?
@ 2002-05-14 21:12 Jeff Meininger
  2002-05-14 21:26 ` Miquel van Smoorenburg
  2002-05-15 15:33 ` Martin Schewe
  0 siblings, 2 replies; 4+ messages in thread
From: Jeff Meininger @ 2002-05-14 21:12 UTC (permalink / raw)
  To: linux-kernel


In a user program, you can read /proc/partitions to determine what disks 
and partitions are available, and you can read /proc/mounts to see which 
of them are mounted, and where.

However, on many configurations, /proc/mounts will list "/dev/root" 
instead of the corresponding entry in /proc/partitions (such as /dev/hda1 
or /dev/ide/host0/...).

How can I reliably map /dev/root to the corresponding entry in 
/proc/partitions?  Is there some /proc thing I'm missing, or is there an 
ioctl that can give me the information I'm looking for?

The only way I've been able to do this so far is to read in the output of
the "mount" command, or read fstab or mtab.  Reading fstab or mtab is
unreliable, because they don't necessarily contain accurate information.  
Parsing the output of "mount" seems kludgy, and introduces a lot of
complexity because it might list /dev/hda1 instead of
/dev/ide/host0/.../part1, thus requiring an additional layer of mapping.  
Plus, the "mount" command might not be available at all.

Whether devfs is running or not, I just want to be able to figure out
which device in /proc/partitions corresponds to /dev/root.

Thanks very much for your help!!
Please Cc me in your response.

-Jeff Meininger


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: how to map "/dev/root" to "/proc/partitions" entry in user prog?
  2002-05-14 21:12 how to map "/dev/root" to "/proc/partitions" entry in user prog? Jeff Meininger
@ 2002-05-14 21:26 ` Miquel van Smoorenburg
  2002-05-15 15:39   ` Denis Vlasenko
  2002-05-15 15:33 ` Martin Schewe
  1 sibling, 1 reply; 4+ messages in thread
From: Miquel van Smoorenburg @ 2002-05-14 21:26 UTC (permalink / raw)
  To: linux-kernel

In article <Pine.LNX.4.44.0205141554240.2160-100000@spaz.localdomain>,
Jeff Meininger  <jeffm@boxybutgood.com> wrote:
>How can I reliably map /dev/root to the corresponding entry in 
>/proc/partitions?

The first two lines in /proc/partitions are major/minor of the
device. Simply stat("/", &st) and use st.st_dev (and the major/minor
macros in glibc)

>Please Cc me in your response.

I'm reading and posting this on a mail2news gateway, sorry.

Mike.
-- 
"Insanity -- a perfectly rational adjustment to an insane world."
  - R.D. Lang


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: how to map "/dev/root" to "/proc/partitions" entry in user prog?
  2002-05-14 21:12 how to map "/dev/root" to "/proc/partitions" entry in user prog? Jeff Meininger
  2002-05-14 21:26 ` Miquel van Smoorenburg
@ 2002-05-15 15:33 ` Martin Schewe
  1 sibling, 0 replies; 4+ messages in thread
From: Martin Schewe @ 2002-05-15 15:33 UTC (permalink / raw)
  To: Jeff Meininger; +Cc: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 503 bytes --]

Hi,

On Tue, May 14, 2002 at 04:12:18PM -0500, Jeff Meininger wrote:
> How can I reliably map /dev/root to the corresponding entry in 
> /proc/partitions?  Is there some /proc thing I'm missing, or is there an 
> ioctl that can give me the information I'm looking for?

If you use devfs, you can check /dev/root, which is a symlink to your
root device:

	readlink("/dev/root", rootdev, PATH_MAX);

Otherwise you should take a look at busybox/libbb/find_root_device.c.

Regards,
		Martin

[-- Attachment #2: Type: application/pgp-signature, Size: 240 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: how to map "/dev/root" to "/proc/partitions" entry in user prog?
  2002-05-14 21:26 ` Miquel van Smoorenburg
@ 2002-05-15 15:39   ` Denis Vlasenko
  0 siblings, 0 replies; 4+ messages in thread
From: Denis Vlasenko @ 2002-05-15 15:39 UTC (permalink / raw)
  To: Miquel van Smoorenburg, linux-kernel; +Cc: Richard Gooch

On 14 May 2002 19:26, Miquel van Smoorenburg wrote:
> Jeff Meininger  <jeffm@boxybutgood.com> wrote:
> >How can I reliably map /dev/root to the corresponding entry in
> >/proc/partitions?
>
> The first two lines in /proc/partitions are major/minor of the
> device. Simply stat("/", &st) and use st.st_dev (and the major/minor
> macros in glibc)

Try to do it on NFS root and it will get confused.

Also it gets confused on:

# mount -o remount,ro /
mount: directory to mount not in host:dir format

Summary: /dev/root is nifty but has some rough edges.
--
vda

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2002-05-15 15:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-05-14 21:12 how to map "/dev/root" to "/proc/partitions" entry in user prog? Jeff Meininger
2002-05-14 21:26 ` Miquel van Smoorenburg
2002-05-15 15:39   ` Denis Vlasenko
2002-05-15 15:33 ` Martin Schewe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox