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

3 views
Skip to first unread message

ne...@absamail.co.za

unread,
Nov 6, 2005, 1:03:51 AM11/6/05
to
Hi,
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.

== Chris Glur.

Message has been deleted

Tauno Voipio

unread,
Nov 6, 2005, 4:10:40 AM11/6/05
to
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!).

This means in practice that your program has to run
with root rights to handle complete disks or partitions.

Are you attempting to create a boot block virus?

--

Tauno Voipio
tauno voipio (at) iki fi

Message has been deleted

ne...@absamail.co.za

unread,
Nov 9, 2005, 12:07:55 AM11/9/05
to
-----------

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 ?

Thanks,

== Chris Glur.

Tauno Voipio

unread,
Nov 9, 2005, 2:39:14 PM11/9/05
to

Yes, I do.

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

Reply all
Reply to author
Forward
0 new messages