LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-25-2010, 08:23 AM   #1
aneeshcav
LQ Newbie
 
Registered: Feb 2010
Posts: 8

Rep: Reputation: 0
Accessing the hard disk using the /dev/sda interface


Hi,
I am developing a program which can access the SATA-hard disk. I have to use the /dev/sda interface for accessing the hard disk. What are all the commands i can use to perform the sector read, write (Both DMA and PIO), sending the smart commands etc. Or is there any easier way?

I saw that i can make use of hdparm call for getting some of the attributes.

Regards,
Aneesh
 
Old 03-25-2010, 09:59 AM   #2
onebuck
Moderator
 
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: Slackware®
Posts: 12,768
Blog Entries: 27

Rep: Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082
Hi,

You query is not very clear. Why do you need device level access? What exactly are you attempting to do? Please expand with more detail.
 
Old 03-28-2010, 10:34 PM   #3
aneeshcav
LQ Newbie
 
Registered: Feb 2010
Posts: 8

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by onebuck View Post
Hi,

You query is not very clear. Why do you need device level access? What exactly are you attempting to do? Please expand with more detail.
Hi,
Thanks for the reply. Sorry i could not respond fast.

Actually i am working on a target platform onto which a SATA disk will be connected. Unfortunately the platform doesn't have the drivers to directly communicate to the hard disk.
So i was thinking about accessing the hardware via the device file interface.

Regards,
Aneesh
 
Old 03-28-2010, 10:46 PM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
You don't say if you want (or already have) a filesystem on the device.

Regardless, if you can access the raw data using a tool like dd, then I would think you need a filesystem driver and not a SATA driver. My assumption is that the /dev/sda interface does not work if there is no SATA driver.

First, can you read from the drive using dd?---eg:
Code:
dd if=/dev/sda bs=1024 count=50 | hexdump -C
(Reads the first 100 sectors and displays data in hex and ascii.)
 
Old 03-29-2010, 07:01 AM   #5
onebuck
Moderator
 
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: Slackware®
Posts: 12,768
Blog Entries: 27

Rep: Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082
Hi,

Quote:
Originally Posted by aneeshcav View Post
Hi,
Thanks for the reply. Sorry i could not respond fast.

Actually i am working on a target platform onto which a SATA disk will be connected. Unfortunately the platform doesn't have the drivers to directly communicate to the hard disk.
So i was thinking about accessing the hardware via the device file interface.

Regards,
Aneesh
No wonder the about packet errors. How are you accessing?

Again your formulation of the original Thread/query with lack of information not describing the problem so we can aid you. Please read the referenced link.

Please explain the problem in detail and what you are attempting and how you attempt to perform the action that resulted in the presented error(s).
 
Old 03-29-2010, 07:28 AM   #6
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,073

Rep: Reputation: 384Reputation: 384Reputation: 384Reputation: 384
Quote:
Originally Posted by aneeshcav View Post
Hi,
Thanks for the reply. Sorry i could not respond fast.

Actually i am working on a target platform onto which a SATA disk will be connected. Unfortunately the platform doesn't have the drivers to directly communicate to the hard disk.
Right. Well, if there's no driver, then there's no sda in first place. You have to be very specific about what the exact problem is. If you can access the device using /dev/sda (or whatever device node) then definitely there's a driver in your kernel that speaks to that concrete device. It doesn't really matter it's an HD or whatever else at this point.

What exactly do you mean when you say "communicate to the hard disk"?

No use land tool in the Linux world has such kind of direct access to the hardware. The only way to do that is by writing a kernel driver just like virtualbox or qemu, or vhba or fuse-based stuff do.

Another possibility is that the HD is formated (in the most generic meaning of the term "format") on a way that Linux can't understand, in that case you'll see the device nodes, but you won't be able to mount them, and hence you won't be able to interact with the contents of the disk with regular tools. Here writing your own tool can be of help, yes.
 
Old 03-29-2010, 11:17 PM   #7
aneeshcav
LQ Newbie
 
Registered: Feb 2010
Posts: 8

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by i92guboj View Post
Right. Well, if there's no driver, then there's no sda in first place. You have to be very specific about what the exact problem is. If you can access the device using /dev/sda (or whatever device node) then definitely there's a driver in your kernel that speaks to that concrete device. It doesn't really matter it's an HD or whatever else at this point.

What exactly do you mean when you say "communicate to the hard disk"?

No use land tool in the Linux world has such kind of direct access to the hardware. The only way to do that is by writing a kernel driver just like virtualbox or qemu, or vhba or fuse-based stuff do.

Another possibility is that the HD is formated (in the most generic meaning of the term "format") on a way that Linux can't understand, in that case you'll see the device nodes, but you won't be able to mount them, and hence you won't be able to interact with the contents of the disk with regular tools. Here writing your own tool can be of help, yes.


Hi,
Thanks for all the inputs. To be more specific for Linux OS the platform does not have the exact APIs to communicate to hard disk. But for another OS, this support is available. Hence i need to access the HDD through any other interface.

By communicating to hard disk, i mean performing the read/write operations to the HDD. Also sending the smart commands and getting the attributes.

Regards,
Aneesh
 
Old 03-30-2010, 02:49 AM   #8
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,073

Rep: Reputation: 384Reputation: 384Reputation: 384Reputation: 384
Quote:
Originally Posted by aneeshcav View Post
Hi,
Thanks for all the inputs. To be more specific for Linux OS the platform does not have the exact APIs to communicate to hard disk. But for another OS, this support is available. Hence i need to access the HDD through any other interface.
I have no idea what do you mean by "API" here. You don't need such thing to write to the disk. Once the disk is attached to a device node you just write to or read from there. If you want raw access you use a tool like dd (or look into its source code to do your own), if you want regular access you format the device using whatever fs you prefer, then you just use regular APIs or user land tools to create files, directories, modify them, etc.

I still don't get what exactly do you want to do, unless you are using some kind of esoteric device that I am not aware of.

Quote:
By communicating to hard disk, i mean performing the read/write operations to the HDD. Also sending the smart commands and getting the attributes.
For SMART stuff look into smartmontools. Again, you can just use the tool straight away on the device node, or you can take a look into its source to roll your own.

For the rest, read my comments above.

Again, once the driver is handling the device and you have a device node, what else do you need?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Smartd: Device /dev/sda: using '-d sat' for ATA disk behind SAT layer. deathsfriend99 Linux - Newbie 0 12-09-2009 12:47 PM
clone hard disk with: cat /dev/sda >/media/disk/backup deathalele Linux - Security 3 04-17-2009 12:29 AM
boot disk no longer /dev/sda when adding ext. disks rspielma Linux - Hardware 5 12-26-2007 06:21 PM
[SOLVED] system disk moves from /dev/sda to /dev/sdm gdevaucorbeil Linux - Hardware 4 03-10-2007 09:30 AM
Accessing a second hard disk martinpanda Linux - General 9 03-11-2002 09:07 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration