Solved

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

Posted on 2007-12-02
3
892 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
this article is a guided solution for most of the common server issues in server hardware tasks we are facing in our routine job works. the topics in the following article covered are, 1) dell hardware raidlevel (Perc) 2) adding HDD 3) how t…
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.

762 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

19 Experts available now in Live!

Get 1:1 Help Now