Advanced Programming in the UNIX® Environment

(lily) #1
ptg10805159

114 Files and Directories Chapter 4


If we examine the i-node and data block portion of a cylinder group in moredetail,
we could have the arrangement shown in Figure4.14.

i-node array blockdata blockdata directoryblock blockdata directoryblock

directory blocks and data blocks

i-nodei-node i-node i-node

first data blocksecond data block

thirddata block

i-node
number filename

i-node
number filename

Figure 4.14 Cylinder group’s i-nodes and data blocks in moredetail

Note the following points from Figure4.14.

•Two directory entries point to the same i-node entry.Every i-node has a link count
that contains the number of directory entries that point to it. Only when the link
count goes to 0 can the file be deleted (thereby releasing the data blocks associated
with the file). This is why the operation of ‘‘unlinking a file’’does not always mean
‘‘deleting the blocks associated with the file.’’This is why the function that removes
adirectory entry is calledunlink,not delete. In thestatstructure, the link count
is contained in thest_nlinkmember.Its primitive system data type isnlink_t.
These types of links arecalled hardlinks. Recall from Section 2.5.2 that the POSIX.1
constantLINK_MAXspecifies the maximum value for a file’s link count.
•The other type of link is called asymbolic link.With a symbolic link, the actual
contents of the file—the data blocks—storethe name of the file that the symbolic
link points to. In the following example, the filename in the directory entry is the
three-character stringliband the 7 bytes of data in the file areusr/lib:
lrwxrwxrwx 1 root 7 Sep 25 07:14 lib -> usr/lib
The file type in the i-node would beS_IFLNKso that the system knows that this is a
symbolic link.
•The i-node contains all the information about the file: the file type, the file’s access
permission bits, the size of the file, pointers to the file’s data blocks, and so on. Most
of the information in thestatstructure is obtained from the i-node. Only two items
of interest arestored in the directory entry: the filename and the i-node number.The
other items—the length of the filename and the length of the directory record—are
not of interest to this discussion. The data type for the i-node number isino_t.
Free download pdf