Difference between /dev/sr0 and /dev/scd0 and what is a character device vs. a block device?

There isn't necessarily any difference at all.

This sometimes comes up because somebody is having trouble accessing a cd - perhaps for reading, but more likely for burning. One device node doesn't work, so they try another.

If a "ls -l" of the two devices gives the same major/minor numbers (see Understanding Unix Devices), the device IS going to behave identically in the kernel, because the major and minor numbers are all that the kernel gets. It picks the driver based on the first number and passes the second number to that driver.

Sure, some silly piece of software might insist that you use some particular name (some serial software does that) but internally, none of that matters.

And what do the minor numbers mean? Whatever the person who wrote the driver wants them to mean. For Linux, there's a good list at http://www.lanana.org/docs/device-list/devices.txt but without documentation like that or source, a minor number doesn't tell you anything.

That is especially true when looking at different operating systems. You might have noticed that tty devices have a major number of "3" on your Ubuntu Linux.On a SCO Unix system, "5" would be used. Different systems will use different schemes.

By the way, these files are NOT driver code. They are pointers to driver code in the kernel, but the actual files contain no data, only the metadata in their inode. These aren't programs, they aren't drivers, they are just pointers.

Older systems would often have device entries for devices that didn't exist. You might see /dev/lp0, /dev/lp1 and /dev/lp2 even if you had no parallel printer ports at all. Nowadays, most systems create device files as and when needed.

What is the difference between character raw and block devices?

The driver for a (physical) block device is reading n-sized blocks, and only n-sized blocks. If it implements a raw interface, then it buffers those blocks and gives you whatever you ask for.

A block device is usually a block device because the actual hardware works that way- returning some specific number of characters whenever it is tickled appropriately. Of course a driver can hide that and make x characters become y, or could even make a phyically raw device appear to be a block device- but that doesn't change the underlying nature of the device. When you access a raw device that is actually mechanically a block device, x-sized character blocks get read.

What I am trying to get at is that this all does depend on the driver, but the underlying hardware does have some influence on it. You could easily (easy being a relative term, of course) make a block interface for tapes. It wouldn't be so easy to treat an rs232 port that way unless you also had control of whatever was feeding it. Therefor a tty port is not likely to ever be implemented as anything but a character device.

The real important differences is what routines get called- a block open gets a buffer allocated by the kernel and that's where its data is, while a raw read or write is reading or writing user space. That is an important point - a device that is physically a block device can have a driver that implements only a raw interface- and tapes are an excellent example.

As to the rules for mounting, formatting, etc., in some OS's they have become rather arbitrary because the programs themselves will ignore what you actually typed and open the corresponding block or raw device that they actually need.



Got something to add? Send me email.





(OLDER) <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

-> -> Difference between /dev/sr0 and /dev/scd0 and block vs. character devices


4 comments



Increase ad revenue 50-250% with Ezoic


More Articles by

Find me on Google+

© Tony Lawrence







Thu Apr 6 19:00:01 2006: 1870   anonymous


So if you map a device via raw (i.e. raw /dev/raw/raw1 8 96), then you get character access to it, but the device itself won't see the reads/writes any differently, it just buffers differently in the kernel?
So with the advent of 2.6 deprecating the raw system, and plans to completely remove it in 2.7, if one wants to get the character access to a block device, how would they do it without using O_DIRECT when opening. I ask because I'm trying to provide a means to give a target to some I/O generating stuff that does not differentiate between block and character. Unfortunately the performance of the two access types are different, so I need a way to differentiate before I give the target to the I/O generator. So while giving it the device /dev/sdg gives me nice block access and giving it the aforementioned /dev/raw/raw1 gives me nice character access, this will soon not be the case. Also, what's up with Red Had Enterprise Linux 4 Advanced Server's raw mapping. If you've got a virtual machine with it, take a snapshot and try the following:
raw /dev/raw/raw0 0 0
it'll correctly disassociate raw0 from its device, but then, inexplicably, /dev/rawctl disappears and you can't map ANYTHING anywhere. This is driving me nuts.



Thu Apr 6 19:21:07 2006: 1871   TonyLawrence

gravatar
I haven't followed kernel development very closely, so can't really comment except to note that you are always free to do your own buffering or even your own driver.

But it does seem odd to me: they are really dropping raw access? Must be more to it than that..



Sat Mar 20 06:52:47 2010: 8244   anonymous

gravatar


when a cd writing process is going on then which of the file is responsible to interact with scsi drier or how does cdrecord work?



Sat Mar 20 11:39:29 2010: 8245   TonyLawrence

gravatar


I'm sorry - I do not understand your question. Can you rephrase?

------------------------
Kerio Samepage


Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.

Contact us





Thunder is good, thunder is impressive; but it is lightning that does the work. (Mark Twain)

That's the thing about people who think they hate computers. What they really hate is lousy programmers. (Larry Niven)








This post tagged: