Solved

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

Posted on 2007-12-02
3
893 Views
Last Modified: 2008-02-18
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.
0
Comment
Question by:Philsh
3 Comments
 
LVL 43

Accepted Solution

by:
ravenpl earned 250 total points
ID: 20391907
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
 
LVL 25

Assisted Solution

by:kode99
kode99 earned 250 total points
ID: 20394176
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

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Your hard drive is full! Do you know what is filling it up? A small free (trial period) utility will solve the problem.  It is SpaceMonger.  It can show you visually the content of your hard drive as blocks with different color and sizes depending…
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now