Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > How to get the minor and major device numbers with os.stat ?

Reply
Thread Tools

How to get the minor and major device numbers with os.stat ?

 
 
Alain Tesio
Guest
Posts: n/a
 
      08-24-2003
Hi, I can't manage to get the major or minor device numbers
with os.stat :

~ $ll /dev/xda7 /dev/xda8
brw-rw---- 1 root disk 13, 7 Nov 30 2000 /dev/xda7
brw-rw---- 1 root disk 13, 8 Nov 30 2000 /dev/xda8

~ $python
Python 2.2.2 (#4, Oct 15 2002, 04:21:2
[GCC 2.95.4 20011002 (Debian prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.stat("/dev/xda7")

(25008, 17383L, 5643L, 1, 0, 6, 0L, 1007270448, 975597764, 100727044
>>> os.stat("/dev/xda8")

(25008, 17384L, 5643L, 1, 0, 6, 0L, 1007270448, 975597764, 100727044
>>> 17384 / 256 , 17384 % 256

(67, 232)


I expected major*256+minor, I've tried a lot of combinations at random
and couldn't manage to get 17383 from (13,7)

Any idea ?

Thanks
Alain

 
Reply With Quote
 
 
 
 
Erik Max Francis
Guest
Posts: n/a
 
      08-24-2003
Alain Tesio wrote:

> I expected major*256+minor, I've tried a lot of combinations at random
> and couldn't manage to get 17383 from (13,7)


For the answer to this, you should really be looking at man stat. The
values here are implementation defined; Python's just mimicking whatever
the underlying OS is doing. What you want is st_rdev:

>>> import os
>>> os.system('ls -l /dev/ttyS0')

crw-rw---- 1 root uucp 4, 64 Jul 17 1994 /dev/ttyS0
0
>>> s = os.stat('/dev/ttyS0')
>>> tuple(s)

(8624, 9064L, 769L, 1, 0, 14, 0L, 1058628788, 774488935, 1058628789)
>>> s.st_rdev

1088
>>> divmod(1088, 256)

(4, 64)

--
Erik Max Francis && && http://www.alcyone.com/max/
__ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/ \ Get married, but never to a man who is home all day.
\__/ George Bernard Shaw
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
[Q] get device major/minor number Thomas Portmann Python 1 11-30-2010 08:35 PM
Publish and specify Major, Minor Version numbers using asp.net 2.0 =?Utf-8?B?dGhlV2l6YXJkMQ==?= ASP .Net 1 04-26-2006 08:38 AM
Confusion about row-major and column-major Jef Driesen C++ 2 01-12-2006 03:02 PM
Major Major Problem With ASP.NET kokwooi ASP .Net 6 09-19-2003 08:52 AM



Advertisments