Re: format discs.

Discussion in 'Python' started by =?ISO-8859-1?Q?Gerhard_H=E4ring?=, Jul 9, 2003.

  1. 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
    =?ISO-8859-1?Q?Gerhard_H=E4ring?=, Jul 9, 2003
    #1
    1. Advertising

  2. 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
    =?ISO-8859-2?Q?Gerhard_H=E4ring?=, Jul 9, 2003
    #2
    1. Advertising

  3. 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
    =?ISO-8859-2?Q?Gerhard_H=E4ring?=, Jul 9, 2003
    #3
  4. 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
    Greg Ewing (using news.cis.dfn.de), Jul 10, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brian Candy
    Replies:
    2
    Views:
    1,137
    Janaka
    Feb 18, 2004
  2. Andy
    Replies:
    7
    Views:
    6,236
    Roedy Green
    May 10, 2004
  3. shannon
    Replies:
    1
    Views:
    8,575
  4. shannon
    Replies:
    0
    Views:
    554
    shannon
    Feb 1, 2006
  5. Replies:
    6
    Views:
    450
    Thomas Ganss
    Jan 15, 2006
Loading...

Share This Page