using os.major

J

John Doe

Does anyone understand what a 'raw device number' is with respect
os.major() and os.minor()

Found in os-file-dir.html, section 6.1.4, os.major() description is:

major(device)
Extracts a device major number from a raw device number. New in
version 2.3.

The problem is, after searching I can only find two references to 'raw
device number'. Naturally they are in os.major() and os.minor().

There seems to be something related to fileno, but that never returns the
value I know is true. In particular, Linux /dev/fd0 is (2/0).

Example:
--------------------------------
fd = open('/dev/fd0')
from os import major,minor
fd.fileno() 3
major(fd.fileno()) 0
minor(fd.fileno()) 3
from os import popen3 [instd,outstd,errstd] = popen3( 'file /dev/fd0' )
outstd.read()
'/dev/fd0: block special (2/0)\n'

As you can see, Major is 2, minor is 0. Which is also what ls -l /dev/fd0
reports.
--------------------------------

I've written a function to parse up the 'file /dev/fd0' results, but I'd
rather us the correct built in, or included modules, before writing my
own.

(e-mail address removed)
 
D

Dima Dorfman

John Doe said:
Does anyone understand what a 'raw device number' is with respect
os.major() and os.minor()
[...]
There seems to be something related to fileno, but that never returns the
value I know is true. In particular, Linux /dev/fd0 is (2/0).

The raw device number isn't the file descriptor number; it's the
device ID, such as those returned by stat in the st_dev and st_rdev
fields:
0

The documentation for os.stat mentions st_rdev, but it doesn't call it
the "raw" device number. The FreeBSD documentation is about evenly
split on calling it the "raw device number" or the "device ID", but
Posix uses the latter, and I think that makes more sense. There's
nothing raw about this value; I think it's only "raw" compared to
internal kernel structures, where a device could be a pointer to
struct instead of an integer (it's certainly not more raw than st_dev,
which has the same type).

Dima.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,297
Messages
2,571,525
Members
48,248
Latest member
LouveniaUc

Latest Threads

Top