Can python 'read disk sectors' like/via linux:dd ?

Tauno Voipio tauno.voipio at INVALIDiki.fi
Wed Nov 9 14:39:14 EST 2005


news at absamail.co.za wrote:
> OP wrote:
> }in order to justify learning another language I'd first need to be
> }convinced that python could easily do the following:-
> }
> }ReadSectors2Bufr(hdx, StartSectr, SectrCnt, Bufr); <-- like linux:dd
> }PrintDecOf4Bytes(Offset, Bufr);   <-- and also 1 and 2 byte values
> }OverWriteBufr(Offset, Bufr, Byte);
> }WriteBufr2Sectors ..... <-- like linux: dd
> }
> }I guess one would normally use bash, but I'd rather invest effort
> }in python if it can do this.
> }
> }Thanks for any info.
> -----------
> 
> Pascal Bourguignon wrote:
> 
>>>In unix, disks are files like any other file.   
>>>So if your programming language allows you to 
>>>read and write files, it allows you to read and
>>>write disks.
>>>Just write the equivalent of:
>>>   int fd=open("/dev/hda",O_RDWR,0);
>>>   if(0<==fd){
>>>         check_errors(lseek(fd,SECT_SIZE*sect_num,SEEK_SET));
>>>         check_errors(read(fd,buffer,SECT_SIZE));
>>>         modify(buffer);
>>>         check_errors(lseek(fd,SECT_SIZE*sect_num,SEEK_SET));
>>>         check_errors(write(fd,buffer,SECT_SIZE));          close(fd); }
>>>and be sure to have the access rights on /dev/hda (and to know
>>>what you're doing!).
> 
> 
> Tauno Voipio wrote:
> 
>>Are you attempting to create a boot block virus?
> 
> 
> Firstly, if you asked me advice on where to buy some goats-milk,
> I'd answer in the context of where YOU stand now [especially
> since you told me], NOT form where I'm standing.
> 
> For several reasons I need many partitions on my IDEs.
> The one lost the chain of logical partitions at hdx26.
> It's not linux, but that's not important.
> The most convenient tool for ME [at my present status] to
> read/write blocks is linux: dd; and to see/edit is linux:mc.
> This involves a lot of tiring manual work.
> I previously read of a contributor who automated the steps
> of linux:fdisk [iterating through size guesses] inside of a bash 
> script, to recover his lost [last] partition.
> I'm not keen on investing time to become more fluent in Bash,
> which could drive dd.
> I have other reasons to invest time in Python.
> If Pyton could 'drive' dd, I would try it.
> 
> My normal OS is oberon S3, which can do better than the 
> C-code above, but I want to work at the highest level.
> 
> Understand ?

Yes, I do.

But, there is a good tool to repair partition tables.
Google for 'gpart'.

-- 

Tauno Voipio
tauno voipio (at) iki fi



More information about the Python-list mailing list