473,402 Members | 2,072 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 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 4511
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: sf | last post by:
Just started thinking about learning python. Is there any place where I can get some free examples, especially for following kind of problem ( it must be trivial for those using python) I have...
2
by: AES/newspost | last post by:
In a markup like <dd> <br> some other stuff <br> </dd> the first break seems to add a blank line before the other stuff, but the second doesn't add a blank line after the other stuff. The...
3
by: news | last post by:
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...
1
by: Kevin | last post by:
Hi All I am really having problems with the DateTime class. Please can someone tell me how to pass a simple string like "26/05/2003" or "2003/05/26" etc into a DateTime class. When I read the...
3
by: CyberLotus | last post by:
Hi, I wish to validate the date a user has entered against the format dd-mmm-yyyy using the CompareValidator, but it does not work. Does anybody have a simple solution please? Many thanks...
16
by: Filips Benoit | last post by:
Dear all, I have a datefield that sometimes should store hours and minutes too ans use following format and inputmask. dd/mm/yyyy hh\:nn 09/09/0000\ 99:99;0;* Typing date, hour and...
2
by: Arno R | last post by:
Hi all, In a converted app (converted from A97 to A2k) I just noticed that the format of a certain datefield is not working properly. This is with a control (datefield) on a bound form. When I...
3
by: yogi | last post by:
Hi, I am working on a database that has a variable with timestamp values. I wanted to convert the variable from timestamp to yyyy-mm-dd format. Thanks in advance Yogi
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.