Chapter 10. The GNU/Linux filesystem: ext2fs

Table of Contents
10.1. Everything is a file
10.2. Links
10.3. "Anonymous" pipes and named pipes
10.4. "Special" files: character mode and block mode files
10.5. Symbolic links and the limitation of "hard" links
10.6. File attributes

The User Guide may have introduced the concepts of file ownership and access permissions, but really understanding the GNU/Linux filesystem (using the ext2fs: EXTended 2 FileSystem) requires that we redefine the concept of a file itself. One reason is that:

10.1. Everything is a file

Here, "everything" really means everything. A hard disk, a partition on a hard disk, a parallel port, a connection to a web site, an Ethernet card, all these are files. Even directories are files. GNU/Linux recognizes many types of files in addition to the standard files and directories. Note that by file type here, we don't mean the type of the contents of a file: for GNU/Linux and any Unix system, a file, whether it be a GIF image, a binary file or whatever, is just a stream of bytes. Differentiating files according to their contents is left to applications.

If you remember well, when you do a ls -l, the character before the access rights identifies the type of a file. We have already seen two types of files: regular files (-) and directories (d). You can also stumble upon these other types if you wander through the file tree and list contents of directories:

  1. Character mode files These files are either special system files (such as /dev/null, which we have already discussed), or peripherals (serial or parallel ports), which share the particularity that their contents (if they have any) are not buffered (which means that they are not kept in memory). Such files are identified by the letter 'c'.

  2. Block mode files These files are peripherals, and as opposed to character files, their contents are buffered. Files entering this category are, for example, hard disks, partitions on a hard disk, floppy drives, CDROM drives and so on. Files /dev/hda, /dev/sda5 are example of block mode files. On a ls -l output, these are identified by the letter 'b'.

  3. Symbolic links These files are very common, and heavily used in the Linux-Mandrake system startup procedure (see chapter "The startup files: init "System V""). As their name implies, their purpose is to link files in a symbolic way, which means that such files may or may not point to an existing file. This will be explained later in this chapter. They are very frequently called "soft links", and are identified by an 'l'.

  4. Named pipes In case you were wondering, yes, these are very similar to pipes used in shell commands, but with the difference that these ones actually have names. Read on to learn more. They are very rare, however, and it's very unlikely that you will see one during your journey into the file tree. Just in case you do, the letter identifying them is 'p'. To learn more about it have a look at "Anonymous" pipes and named pipes.

  5. Sockets This is the file type for all network connections. Only a few of them have names, though. What's more, there are different types of sockets and only one can be linked, but this is way beyond the scope of this book. Such files are identified by the letter 's'.

Here is a sample of each file:

$ ls -l /dev/null /dev/sda  /etc/rc.d/rc3.d/S20random /proc/554/maps \
  /tmp/ssh-queen/ssh-510-agent
crw-rw-rw-    1 root     root       1,   3 May  5  1998 /dev/null
brw-rw----    1 root     disk       8,   0 May  5  1998 /dev/sda
lrwxrwxrwx    1 root     root           16 Dec  9 19:12 /etc/rc.d/rc3.d/S20random
-> ../init.d/random*
pr--r--r--    1 queen    queen           0 Dec 10 20:23 /proc/554/maps|
srwx------    1 queen    queen           0 Dec 10 20:08 /tmp/ssh-queen/ssh-510-agent=
$

We should add that ext2fs, like all other Unix filesystems, stores files, whatever their type, in an inode table. One particularity is that a file is not identified by its name, but by an inode number. In fact, not every file has a name. Names are just a consequence of a wider notion:


Tux on Star from MandrakeSoft Linux is a registered trademark of Linus Torvalds. All other trademarks and copyrights are the property of their respective owners.
Unless otherwise stated, all the content of these pages and all images are Copyright MandrakeSoft S.A. and MandrakeSoft Inc. 2000.
http://www.linux-mandrake.com/