[Q] get device major/minor number

Thomas Portmann portoms at gmail.com
Tue Nov 30 15:35:43 EST 2010


On Tue, Nov 30, 2010 at 9:18 PM, Dan M <dan at catfolks.net> wrote:
> On Tue, 30 Nov 2010 21:09:14 +0100, Thomas Portmann wrote:

>> In the example below, I would like to get the major (8) and minor (0, 1,
>> 2) numbers of /dev/sda{,1,2}. How can I get them?
>
> I think the os.major() and os.minor() calls ought to do what you want.
>
>>>> import os
>>>> s = os.stat('/dev/sda1')
>>>> os.major(s.st_rdev)
> 8
>>>> os.minor(s.st_rdev)
> 1

Thank you very much Dan, this is exactly what I was looking for.


Tom



More information about the Python-list mailing list