APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

2004/01/06 not a typewriter

This is the error message (ENOTTY, error 25 on Unix systems) you get if you try to do something that needs a character device to something that isn't. It wouldn't have helped much if it said "Not a character device" instead.

So what's the difference between a block device and a character device? Well, in /dev/, ls -l lists them with a leading "c" or "b" in the perm column:

crw-------  1 root  wheel      23,   0  5 Jan 14:27 bpf0
crw-------  1 root  wheel      23,   1  2 Jan 09:12 bpf1
crw-------  1 root  wheel      23,   2  2 Jan 09:12 bpf2
crw-------  1 root  wheel      23,   3  2 Jan 09:12 bpf3
crw-------  1 apl   staff       0,   0  5 Jan 12:11 console
crw-rw-rw-  1 root  wheel       8,   1  2 Jan 09:12 cu.modem
brw-r-----  1 root  operator   14,   0  2 Jan 09:12 disk0
br--r-----  1 root  operator   14,   1  2 Jan 09:12 disk0s1
brw-r-----  1 root  operator   14,   2  2 Jan 09:12 disk0s2
brw-r-----  1 root  operator   14,   3  2 Jan 09:12 disk0s3
br--r-----  1 root  operator   14,   4  2 Jan 09:12 disk0s4
brw-r-----  1 root  operator   14,   5  2 Jan 09:12 disk0s5

but why are there character and block devices? It gets a little confusing because it's quite possible for a device driver to treat physical hardware almost anyway it likes, but 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 (character device) raw read or write is reading or writing user space.

See http://aplawrence.com/Bofcusm/321.html for even more confusion.

Got something to add? Send me email.

Increase ad revenue 50-250% with Ezoic

More Articles by

Find me on Google+

© Tony Lawrence

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

It is difficult to free fools from the chains they revere. (Voltaire)

Any problem in computer science can be solved with another level of indirection. (David Wheeler)

This post tagged: