LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Accessing the hard disk using the /dev/sda interface (https://www.linuxquestions.org/questions/linux-newbie-8/accessing-the-hard-disk-using-the-dev-sda-interface-797795/)

aneeshcav 03-25-2010 08:23 AM

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

onebuck 03-25-2010 09:59 AM

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.
:hattip:

aneeshcav 03-28-2010 10:34 PM

Quote:

Originally Posted by onebuck (Post 3911794)
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.
:hattip:

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

pixellany 03-28-2010 10:46 PM

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.)

onebuck 03-29-2010 07:01 AM

Hi,

Quote:

Originally Posted by aneeshcav (Post 3916127)
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).

i92guboj 03-29-2010 07:28 AM

Quote:

Originally Posted by aneeshcav (Post 3916127)
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.

aneeshcav 03-29-2010 11:17 PM

Quote:

Originally Posted by i92guboj (Post 3916626)
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

i92guboj 03-30-2010 02:49 AM

Quote:

Originally Posted by aneeshcav (Post 3917464)
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?


All times are GMT -5. The time now is 02:05 AM.