What is the best way to program for direct disk access?

I am experimenting with some database technology and would like to write a protoype system that can access a disk drive directly. Note that I do not want to use a filesystem managed by the OS. I will manage the access to each sector on the drive. I would like to build this prototype in a high-level language and thus would like the simplest way to access a specific sector on a drive. What is the best way to accomplish this? Is one drive interface technology easier to do this than another? (EIDE, SCSI, SATA, etc.) Will the new drive already have the current bad blocks mapped out or will I need to take care of this myself? I would prefer to use Windows XP but would consider Linux if it is easier to accomplish this.
PhilshAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
ravenplConnect With a Mentor Commented:
Linux is very easy. You just opening file like
/dev/sdb # for whole second sata/scsi drive
or
/dev/sdb2 # for second partition

Then You operate just like on regular file (eg. pread() pwrite())
No filesystem overhead - just direct raw device access(via driver of course).
0
 
kode99Connect With a Mentor Commented:
Its not that hard in windows either.  Pretty similar to linux,  open the device/partition with a CreateFile then access  and then use ReadFile or WriteFile to do the work.

MS article which just mentions roughly how to do it,

http://support.microsoft.com/kb/q100027/

Here's an example in C,  the example covers win98 which is different from xp/2000

http://www.codeguru.com/cpp/w-p/system/misc/article.php/c5765/

If you are so inclinded here is a Delphi wrapper for direct access.  Includes source and is free to use.

http://www.e-f-w.com/content.php?cid=rda

Since you are not trying to work with a filesystem it is fairly straight forward as you do not need to worry about the data structures that a given filesystem uses.  

You will need to keep track of bad sectors though.  So you will probably want to create your own virtual layer between the application and the raw read/writes that will take care of avoiding bad spots. Possibly also do some level of write verification too.

It does not make a difference what type of drive you access.

0
All Courses

From novice to tech pro — start learning today.