Operating System - Linux
1821244 Members
2821 Online
109632 Solutions
New Discussion юеВ

how to find the raw device file in linux

 
SOLVED
Go to solution
senthil_kumar_1
Super Advisor

how to find the raw device file in linux

Hi

In HP-UX, There is two files available for each disk

1) block device file "/dev/dsk/c0t5d0"
2) raw device file "/dev/rdsk/c0t5d0"

But in linux only one file available for each disk

1) block device file "/dev/sda1"

I want answer for following questions.

1) is raw device file available defaultly in linux for all disks?

2) if yes, where it is available.

3) if not, how to create that file.

8 REPLIES 8
Ivan Ferreira
Honored Contributor

Re: how to find the raw device file in linux

>> 1) is raw device file available defaultly in linux for all disks?

No.

>> 3) if not, how to create that file.

http://magazine.redhat.com/2008/09/17/tips-and-tricks-how-do-i-add-raw-device-mapping-in-red-hat-enterprise-linux-5/

http://youngcow.net/doc/oracle10g/install.102/b14203/storage.htm
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Matti_Kurkela
Honored Contributor

Re: how to find the raw device file in linux

The use of /dev/raw/raw* device files is an old, deprecated interface.

The new, recommended way to access disks in raw mode is to open the regular device file using the O_DIRECT option. This is something that must be done in the source code of the application.

In this sense, the answer for your question 1) is "yes".
For your question 2) we can say that a raw device file for e.g. /dev/sda1 is /dev/sda1.

If, for some reason, you need to use the old /dev/raw/raw* interface, Ivan's first link had instructions for that.

MK
MK
Ivan Ferreira
Honored Contributor

Re: how to find the raw device file in linux

>> 2) we can say that a raw device file for e.g. /dev/sda1 is /dev/sda1.

I disagree partially with this. /dev/sda1 in this case is a block device. RAW devices are character devices. The access pattern is different and I had different results when doing performance tests with block and raw devices.
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
dirk dierickx
Honored Contributor

Re: how to find the raw device file in linux

indeed, afaik o_direct is used for access to the fs while bypassing the buffers/cache. this is not the same thing as raw device access.
Matti_Kurkela
Honored Contributor

Re: how to find the raw device file in linux

Then *what* do we mean with "raw device access", exactly?

As far as I see, there are at least three possible definitions:

1.) - bypassing all OS buffering and accessing the disk blocks as directly as possible

In this case, you have to observe the hardware-imposed limitations (mainly alignment requirements for DMA operations).

In Linux 2.6.* kernels, O_DIRECT on a disk device does exactly this.

2.) - accessing a block device like a character device or a fixed-size file

In this case, you cannot always skip all buffering: a proper character device has no block size or data alignment requirements, but if the hardware has them, the OS must hide the restrictions by using a buffer at some level.

I don't know how (or *if*) this can be done in Linux.

3.) - giving raw SCSI commands to a disk device

In Linux 2.6.* kernels, this is possible using the standard block device file, using the correct ioctls. Of course, this often requires special privileges (= being root, usually).

-----
And if you think /dev/raw/raw* is somehow different from or more raw than using O_DIRECT with a block device, please let me invite you to examine the source code.

The driver for /dev/raw devices is located in linux-/drivers/char/raw.c within the kernel source package.

The very first function in that file is the one that handles opening and closing the /dev/raw/raw* devices. I think the comments speak for themselves:

/*
* Open/close code for raw IO.
*
* We just rewrite the i_mapping for the /dev/raw/rawN file descriptor to
* point at the blockdev's address_space and set the file handle to use
* O_DIRECT.
*
* Set the device's soft blocksize to the minimum possible. This gives the
* finest possible alignment and has no adverse impact on performance.
*/
static int raw_open(struct inode *inode, struct file *filp)

If you are talking about ioctls, a bit later there is another function raw_ioctl() which just forwards any ioctls to the underlying block device.

So *everything* you can achieve by using /dev/raw/raw*, you can also achieve by using O_DIRECT on a block device, because /dev/raw is implemented by using O_DIRECT on a block device.

Note: in older kernels, this was implemented in a very different way.

MK
MK
senthil_kumar_1
Super Advisor

Re: how to find the raw device file in linux

pls explain me how to use O_DIRECT to get raw device files.
Matti_Kurkela
Honored Contributor

Re: how to find the raw device file in linux

O_DIRECT is *not* a way to get additional device files. It is a special way to use the block device file so that it works the same as a raw device file.

O_DIRECT is not a command. It is an option flag you must set in the system call you use to open the disk device. You must edit the source code of your program to use it.

MK
MK
dirk dierickx
Honored Contributor
Solution

Re: how to find the raw device file in linux

the age old meaning of raw device access is just that, a device as it is, no FS of any type present. mostly used by databases (but i think these days there is hardly any benefit anymore to this approach).