Information Technology: An
Introduction for Today’s Digital World
,
FL: CRC Press, 2013.)
The Linux File System
◾
395
some special-purpose programs that are treated like files (for instance, a random number
generator). Let us consider each of these in turn.
10.3.1 Files versus Directories
The directory should be familiar to the reader by now. It is a named entity that contains
files and subdirectories (or devices, links, etc.). The directory offers the user the ability to
organize their files in some reasonable manner, giving the file space a hierarchical struc-
ture. Directories can be created just about anywhere in the file system and can contain just
about anything from empty directories to directories that themselves contain directories.
The directory differs from the file in a few significant ways. First, we expect directories
to be executable. Without that permission, no one (including the owner) can cd into the
directory. Second, the directory does not store content like a file; instead it merely stores
other items. That is, whereas the file ultimately is a collection of blocks of data, the direc-
tory contains a list of pointers to objects. Third, there are some commands that operate on
directories and not files (e.g., cd, pwd, mkdir) and some commands that operate on files but
not directories (e.g., wc, diff, less, more). We do find that most Linux file commands will
operate on directories themselves, including for instance cp, mv, rm (using the recursive
version), and wildcards apply to both files and directories.
10.3.2 Nonfile File Types
Many devices are treated as files in Linux. These devices are listed under the /dev directory.
We categorize these devices into two subcategories: character devices and block devices.
Character devices are those that input or output streams of characters. These will include
the keyboard, the mouse, a terminal (as in terminal window), and serial devices such as
older MODEMs and printers. Block devices communicate via blocks of data. The term
“block” is traditionally applied to disk drives where the files are broken into fixed-sized
blocks. However, here, block is applied to any device that communicates by transmitting
chunks of data at a time (as opposed to the previously mentioned character type). Aside
from hard disk, block devices include optical disk and flash drive.
Aside from the quantity of data movement, another differentiating characteristic
between character and block devices is how input and output are handled. For a character
device, a program executing a file command must wait until the character is transferred
before resuming. For a block device, blocks are buffered in memory so that the program
can continue once the instruction has been issued. Further, as blocks are only portions
of entire files, it is typically the case that a file command can request one portion of a file.
This is often known as
random access
. The idea is that we do not have to request block 1
before obtaining block 2. Having to read blocks in order is known as
sequential access
. But
in random access, we can obtain any block desired and it should take no longer to access
block j than block i.
Another type of file construct is the
domain socket
, also referred to as a local socket.
This is not to be confused with a network socket. The domain socket is used to open com-
munication between two local
processes
. This permits interprocess communication (IPC)
so that the two processes can share data. We might, for instance, want to use IPC when
396
◾
Linux with Operating System Concepts
one process is producing data that another process is to consume. This would be the case
when some application software is going to print a file. The application software produces
the data to be printed, and the printer’s device driver consumes the data. The IPC is also
used to create a rendezvous between two processes where process B must wait for some
event from process A.
There are several distinctions between a network and domain socket. The network
socket is not treated as a file (although the network itself is a device that can interact via file
system commands) while the domain socket is. The network socket is created by the oper-
ating system to maintain communication with a remote computer while domain sockets
are created by users or running software. Network sockets provide communication lines
between
Do'stlaringiz bilan baham: |