0

I am trying to learn linux file permissions. In this context most of the things are clear to me except (character device) 'c' in crwxrwxrwx, (block device) 'b' in brwxrwxrwx. Wikipedia explains Character Device as:

Character special files or character devices provide unbuffered, direct access to the hardware device. They do not necessarily allow programs to read or write single characters at a time; that is up to the device in question.

and about block device as:

Block special files or block devices provide buffered access to hardware devices, and provide some abstraction from their specifics.[5] Unlike character devices, block devices will always allow the programmer to read or write a block of any size (including single characters/bytes) and any alignment.

This explanation is a bit too much technical for me. Can anyone kindly explain this in more simple manner? Regards

3 Answers3

2

Per Character Device Vs. Block Device,

  • A Character ('c') Device is one with which the Driver communicates by sending and receiving single characters (bytes, octets).
  • A Block ('b') Device is one with which the Driver communicates by sending entire blocks of data.

For example, typing text into the terminal utilizes characters, whereas partitioning a hard drive makes use of blocks.

oxr463
  • 1,240
  • "Driver communicates..." with device or something else? – Salman Ahmed Feb 18 '20 at 14:36
  • Yes. The device driver communicates with the hardware. So for a disk, it writes the blocks to the drive. – oxr463 Feb 18 '20 at 15:19
  • You have explained it in a very easy and straight forward way. Thanks. Can you guide me in one more thing? I have not seen it myself, but mentioned by some people on forums, i.e. In permissions what is meant by (named pipe) 'p' in prwxrwxrwx and (unix domain socket) 's' in srwxrwxrwx? – Salman Ahmed Feb 18 '20 at 17:06
  • I think that should be a separate question, IMHO :) – oxr463 Feb 18 '20 at 17:23
  • 1
    man -s 7 pipe and man -s 7 socket are helpful. In general, something like man -k pipe will do a keyword search and list a summary of helpful commands and functions. – Paul_Pedant Feb 18 '20 at 17:33
0

b = block devices is basically disks (sata, sas, scsi, pata, ide connected units) (but it could be a part of another container/disk)

though a tape unit probably is a character based device (but it is connected using sas/scsi/sata/ide/pata/fc/iSCSI (sort of) ...)

All block devices is read from and written to by the using process as small/or larger number of bytes/octets.

c = Character devices: one byte/octet at a time.

Most of the devices is usually accessed by the kernel (like the file system's code which is executed in the kernel) but a disk (block-oriented) which is dumped by dd to a tape ?

Hint: a block is read into process memory and then dumped one byte at a time to the tape, while this happends another block is read into memory.

To make a tape perform properly the system must be able to keep up with the writing (in this way even a primitive tape subsystem is able to stream ie write data as fast as the tape comes forward while keeping the tape transport speed constant.) In this case the process running dd is accessing the file system directly, not by opening each file as itself and then dump that.

If you instead used tar, the process would read each file or directory using the normal open/read/close system calls.

Stefan Skoglund
  • 453
  • 3
  • 5
0

What you are looking at is the files mode:

The mode consists of permissions, file type (the bit you are focused on), and capabilities. File type has nothing to do with permissions, you don't need to understand them, to understand permissions. You don't even need to understand c and b types to use the system, it is usually sufficient to know that they are device types.

see What are the different ways to set file permissions etc on gnu/linux for more on permissions and modes.