472,103 Members | 2,107 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,103 software developers and data experts.

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

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 ?

Thanks,

== Chris Glur.

Nov 9 '05 #1
1 4291
ne**@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
Nov 9 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

13 posts views Thread by sf | last post: by
2 posts views Thread by AES/newspost | last post: by
1 post views Thread by Kevin | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.