how to get partition information of a hard disk with python

H

Hellmut Weber

Hi list,
I'm looking for a possibility to access the partiton inforamtion of a
hard disk of my computer from within a python program.

Googling I found the module 'parted' but didn't see any possibility to
get the desired information.
Is there any reasonable documentation for the parted module?

Any idea is appreciated ;-)

TIA

Hellmut
 
N

Nobody

I'm looking for a possibility to access the partiton inforamtion of a
hard disk of my computer from within a python program.

Have you considered parsing /proc/partitions?
 
A

Anssi Saari

Nobody said:
Have you considered parsing /proc/partitions?

One could also just read the partition table directly, it's on the
first sector usually. (Assuming a PC without a GUID partition
table...) The partition table is just 64 bytes at offset 446 into the
sector. In unixlikes you can just open the disk with file.open()...
Then again, unixlikes other than Linux have somewhat different ideas
about partitioning...
 
N

Nobody

One could also just read the partition table directly, it's on the
first sector usually. (Assuming a PC without a GUID partition
table...) The partition table is just 64 bytes at offset 446 into the
sector. In unixlikes you can just open the disk with file.open()...
Then again, unixlikes other than Linux have somewhat different ideas
about partitioning...

Apart from the portability issues, you usually need elevated privileges
to read the disk directly, while /proc/partitions is normally readable by
anyone.

OTOH, many of the tasks for which partition information is necessary would
require root privilege anyhow.
 
L

Lawrence D'Oliveiro

One could also just read the partition table directly, it's on the
first sector usually.

The Linux kernel includes built-in support for something close to two dozen
different partition formats, from the common ones like MS-DOS, Solaris, SGI,
Ultrix, EFI and BSD on down. Why reinvent parts of that when you can get it
all for free?
 
A

Anssi Saari

Lawrence D'Oliveiro said:
The Linux kernel includes built-in support for something close to two dozen
different partition formats, from the common ones like MS-DOS, Solaris, SGI,
Ultrix, EFI and BSD on down. Why reinvent parts of that when you can get it
all for free?

Because for the common case it's simple and easy and one might learn
something interesting?

But can you really get all that for free, in python? in other words,
is there a python API for all that? The stuff in /proc/partitions
seems rather limited to me, although I have only vanilla partitions on
my computers.
 
T

Tim Chase

But can you really get all that for free, in python? in other words,
is there a python API for all that? The stuff in /proc/partitions
seems rather limited to me, although I have only vanilla partitions on
my computers.

A similar question regarding reading partition-tables came up a
while back, so you (or the OP) might be interested in the thread:

http://www.mail-archive.com/[email protected]/msg267375.html

where I threw together a little partition-reading code that
should be fairly easy to modify.

-tkc
 
L

Lawrence D'Oliveiro

Because for the common case it's simple and easy and one might learn
something interesting?

You consider it “interesting†to reinvent stuff that others have already
done?
But can you really get all that for free, in python? in other words,
is there a python API for all that? The stuff in /proc/partitions
seems rather limited to me, although I have only vanilla partitions on
my computers.

What more do you want?
 
S

Seebs

You consider it ???interesting??? to reinvent stuff that others have already
done?

That isn't what the other poster said. The claim was that you might learn
something interesting.

When I reinvent stuff others have already done, I usually do indeed learn
something interesting. It may not be a good use of my time, but...

Here's the thing. As a learning exercise, "reinvent something others have
already done" is excellent. It means you have working code to study and
think about. Once you already know everything, of course, it stops being
useful, and then there's no reason to ever duplicate existing code.

But I learned more from writing a roguelike game which was pretty much in
no way superior to existing roguelikes than I would have from trying to
invent a new kind of game when I didn't understand how to program in the
first place, I suspect.

-s
 

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

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top