Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > how to get partition information of a hard disk with python

Reply
Thread Tools

how to get partition information of a hard disk with python

 
 
Hellmut Weber
Guest
Posts: n/a
 
      09-21-2010
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

--
Dr. Hellmut Weber http://www.velocityreviews.com/forums/(E-Mail Removed)
Degenfeldstraße 2 tel +49-89-3081172
D-80803 München-Schwabing mobil +49-172-8450321
please: No DOCs, no PPTs. why: tinyurl.com/cbgq
 
Reply With Quote
 
 
 
 
Nobody
Guest
Posts: n/a
 
      09-22-2010
On Wed, 22 Sep 2010 00:31:04 +0200, Hellmut Weber wrote:

> 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?

 
Reply With Quote
 
 
 
 
Anssi Saari
Guest
Posts: n/a
 
      09-30-2010
Nobody <(E-Mail Removed)> writes:

> On Wed, 22 Sep 2010 00:31:04 +0200, Hellmut Weber wrote:
>
>> 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?


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...
 
Reply With Quote
 
Nobody
Guest
Posts: n/a
 
      09-30-2010
On Thu, 30 Sep 2010 11:41:48 +0300, Anssi Saari wrote:

>>> 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?

>
> 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.

 
Reply With Quote
 
Lawrence D'Oliveiro
Guest
Posts: n/a
 
      10-03-2010
In message <(E-Mail Removed)>, Anssi Saari wrote:

> Nobody <(E-Mail Removed)> writes:
>
>> Have you considered parsing /proc/partitions?

>
> 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?
 
Reply With Quote
 
Anssi Saari
Guest
Posts: n/a
 
      10-04-2010
Lawrence D'Oliveiro <(E-Mail Removed)_zealand> writes:

> 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.
 
Reply With Quote
 
Tim Chase
Guest
Posts: n/a
 
      10-04-2010
On 10/04/10 09:33, Anssi Saari wrote:
> 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/python-l...msg267375.html

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

-tkc


 
Reply With Quote
 
Lawrence D'Oliveiro
Guest
Posts: n/a
 
      10-05-2010
In message <(E-Mail Removed)>, Anssi Saari wrote:

> Lawrence D'Oliveiro <(E-Mail Removed)_zealand> writes:
>
>> 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?


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?
 
Reply With Quote
 
Seebs
Guest
Posts: n/a
 
      10-05-2010
On 2010-10-05, Lawrence D'Oliveiro <(E-Mail Removed)_zealand> wrote:
> In message <(E-Mail Removed)>, Anssi Saari wrote:
>> 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?


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
--
Copyright 2010, all wrongs reversed. Peter Seebach / (E-Mail Removed)
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.
 
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
dd - unequal speed from partition to partition, partition to file,file to partition bolega C Programming 1 03-28-2011 07:37 PM
Re: how to get partition information of a hard disk with python MRAB Python 0 09-21-2010 11:14 PM
Hard drive is Disk 0 CHANGES to hard drive is Disk 1??? And still works!!! Spin Computer Support 7 04-09-2008 09:04 PM
copy my first hard disk info onto my second hard disk gary Computer Support 2 10-28-2004 10:49 PM



Advertisments