Parent Pathname Lookup

In many cases, the real target of a lookup operation is not the last component of the pathname, but the next-to-last one. For example, when a file is created, the last component denotes the filename of the not yet existing file, and the rest of the pathname specifies the directory in which the new link must be inserted. Therefore, the lookup operation should fetch the dentry object of the next-to-last component. For another example, unlinking a file identified by the pathname /foo/bar consists of removing bar from the directory foo. Thus, the kernel is really interested in accessing the file directory foo rather than bar.

The lookup_parent flag is used whenever the lookup operation must resolve the directory containing the last component of the pathname, rather than the last component itself.

When the lookup_parent flag is set, the path_walk( ) function also sets up the last and last_type fields of the nameidata data structure. The last field stores the name of the last component in the pathname. The last_type field identifies the type of the last component; it may be set to one of the values shown in Table 12-16.

Table 12-16. The values of the last_type field in the nameidata data structure




Last component is a regular filename


Last component is "/ " (that is, the entire pathname is "/ ")


Last component is "."


Last component is ". ."


Last component is a symbolic link into a special filesystem

The last_root flag is the default value set by path_init( ) when the whole pathname lookup operation starts (see the description at the beginning of Section 12.5). If the pathname turns out to be just "/ ", the kernel does not change the initial value of the last_type field. The last_bind flag is set by the follow_link inode object's method of symbolic links in special filesystems (see the next section).

The remaining values of the last_type field are set by link_path_walk( ) when the lookup_parent flag is on; in this case, the function performs the same steps described in the previous section up to Step 7. From Step 7 onward, however, the lookup operation for the last component of the pathname is different:

1. Sets nd->last to the name of the last component

2. Initializes nd->last_type to LAST_NORM

3. If the name of the last component is "." (a single dot), sets nd->last_type to LAST DOT

4. If the name of the last component is ". ." (two dots), sets nd->last_type to LAST_DOTDOT

5. Terminates by returning the value 0 (no error)

As you can see, the last component is not interpreted at all. Thus, when the function terminates, the dentry and mnt fields of the nameidata data structure point to the objects relative to the directory that includes the last component.

0 0

Post a comment