Operating System - HP-UX
1834814 Members
2510 Online
110070 Solutions
New Discussion

Re: Raw and character device file

 
SAM_24
Frequent Advisor

Raw and character device file

Hi,

What is the difference between block and character device files?

/dev/dsk/cNtNdN
/dev/rdsk/cNtNdN

Can I say when data is being written to raw device,it bypasses device driver?

I know when data is written to block device file it goes thru buffer.

Thanks.
Never quit
4 REPLIES 4
Pete Randall
Outstanding Contributor

Re: Raw and character device file

No, I don't think you can say that it bypasses the driver. It's just a question of whether the writing is buffered or not.


Pete

Pete
Sanjay_6
Honored Contributor

Re: Raw and character device file

The major difference between raw and block is formatting. On a blok device there is a format in which the data is written whereas on a raw there is no format.

I like to think of the two as a blank paper (RAW) compared to a paper with rows and columns (block) in it.

So on a block device you use specific blocks to write whereas on a raw you can write anywhere.

This is the most easy language that i can think of.

Hope this helps.

Regds
Geoff Wild
Honored Contributor

Re: Raw and character device file

/dev/dsk contains the "block" devices for disks; these are the devices
the OS uses for mounting and swap.

"Block devices" are buffered and do their own blocking; (no direct relation
between read/write to the device and read/write to disk)

/dev/rdsk contains the "raw" (character) devices for disks; these are used
by administrative tools like "newfs" and "fsck".

Operations on "raw devices" result in direct I/O operations on disk
and must take the underlyign block sizes of the device into consideration.


Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
A. Clay Stephenson
Acclaimed Contributor

Re: Raw and character device file

The difference between raw (or character) devices and block devices is not formatting and both types of devices have device drivers. Note the both reference the same physical device. If you do an ls -l on both of these devices you will see two numbers, a major device number and a minor device number. For example, you will see a major device number of 31 for /dev/dsk/*. The major device numbers are used as in index of an array of functions that do basic i/o operations like open,close,read,write,seek ... . So block_switch_device_array[31] controls disk block devices. There is a second array called the character_device_switch_array which performs exactly the same function for character devices.

As has been stated, the major difference between these is whether or not the UNIX buffer cache is used. Character device always bypass the buffer; block devices almost always do. For example, it is possible to bypass the buffer cache by choosing online jfs mount options.

If you want to get essentially all the benefits of raw i/o while using conventional files, that is possible with the convosync=direct,mincache=direct vxfs mount options.

If it ain't broke, I can fix that.