Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: format discs.

Reply
Thread Tools

Re: format discs.

 
 
=?ISO-8859-1?Q?Gerhard_H=E4ring?=
Guest
Posts: n/a
 
      07-09-2003
Taka wrote:
> On Wed, 09 Jul 2003 06:26:38 +0000, Flanagan wrote:
>>hello to all
>>
>>somebody can say to me whereupon I modulate of python I can format
>>discs.
>>
>>
>>thanks flanagan

>
> Let's presume you want to format a unix partition and that it is
> /dev/hda1.
> The do this:
>
> #!/bin/python
>
> import os
> partition = open ('/dev/hda1', 'w')
>
> for x in range(os.path.getsize('/dev/hda1'):
> partition.write ('0')
>
> partition.close()
>
>
>


Didn't you mean instead of ?

Your approach is hard to beat in inefficiency.

-- Gerhard

 
Reply With Quote
 
 
 
 
=?ISO-8859-2?Q?Gerhard_H=E4ring?=
Guest
Posts: n/a
 
      07-09-2003
Taka wrote:
> On Wed, 09 Jul 2003 15:00:33 +0200, Gerhard Häring wrote:
>>Taka wrote:
>>>#!/bin/python
>>>
>>>import os
>>>partition = open ('/dev/hda1', 'w')
>>>
>>>for x in range(os.path.getsize('/dev/hda1'):
>>> partition.write ('0')
>>>
>>>partition.close()

>> [...]
>>Your approach is hard to beat in inefficiency.

>
> Yes, but since file partitions are usualy bigger than your physical RAM,
> you cannot do
>
> import string
> partition.write (string.zfill('0', partition.getsize('/dev/hda10')-1)


Certainly there are good block sizes between 1 and the size of the
partion, right? In my experience, the optimum is somewhere between 2 kb
and 8 kb.

If I ever needed to overwrite a partition with zeros on Unix from within
Python I'd most probably do something like:

import os
os.system("dd if=/dev/zero of=/dev/myblockdevice bs=8192")

-- Gerhard

 
Reply With Quote
 
 
 
 
=?ISO-8859-2?Q?Gerhard_H=E4ring?=
Guest
Posts: n/a
 
      07-09-2003
Taka wrote:
> On Wed, 09 Jul 2003 15:00:33 +0200, Gerhard Häring wrote:
>>Taka wrote:
>>>#!/bin/python
>>>
>>>import os
>>>partition = open ('/dev/hda1', 'w')
>>>
>>>for x in range(os.path.getsize('/dev/hda1'):
>>> partition.write ('0')
>>>
>>>partition.close()

>> [...]
>>Your approach is hard to beat in inefficiency.

>
> Yes, but since file partitions are usualy bigger than your physical RAM,
> you cannot do
>
> import string
> partition.write (string.zfill('0', partition.getsize('/dev/hda10')-1)


Certainly there are good block sizes between 1 and the size of the
partion, right? In my experience, the optimum is somewhere between 2 kb
and 8 kb.

If I ever needed to overwrite a partition with zeros on Unix from within
Python I'd most probably do something like:

import os
os.system("dd if=/dev/zero of=/dev/myblockdevice bs=8192")

-- Gerhard

 
Reply With Quote
 
Greg Ewing (using news.cis.dfn.de)
Guest
Posts: n/a
 
      07-10-2003
Taka wrote:
> Yes, but since file partitions are usualy bigger than your physical RAM,
> you cannot do
>
> import string
> partition.write (string.zfill('0', partition.getsize('/dev/hda10')-1)


Given that, it would have been advisable to have used xrange instead
of range.

All he needs then is a Python implementation of mkfs and he's done...

--
Greg Ewing, Computer Science Dept,
University of Canterbury,
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg

 
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
Money Format + Decimal Place Format shannon Java 1 02-02-2006 03:47 PM
Money Format + Decimal Place Format shannon Java 0 02-01-2006 10:02 PM
need code to convert float format to internal java float format which is kept in 4 bytes integer Andy Java 7 05-10-2004 09:26 PM
NTFS quick format and normal format Guan Foo Wah MCSE 2 05-08-2004 11:35 PM
Date Format - best way of converting a string into a date format Brian Candy ASP .Net 2 02-18-2004 02:13 PM



Advertisments