20.7 iget (7276)

This procedure is called by “main” (1616,1618), “unlink” (3519), “ialloc” (7078) and “namei” (7534, 7664) with two parameters which together uniquely identify a file: a device, and the “inode” number of a file on the device. “iget” returns a reference to an entry in the core “inode” table.

When “iget” is called, the core “inode” table is searched first to see if an entry already exists for the file in the core “inode” table. If not, then “iget” creates one.

7285:

Search the core “inode” table ...

7286:

If an entry for the designated file already exists ...

7287:

Then if it is locked go to sleep;

7290:

Try again. (Note the whole table needs to be searched again from the beginning, because the entry may have vanished!);

7292:

If the IMOUNT flag is on ... this is an important possibility for which we will delay the discussion;

7302:

If the “IMOUNT” flag is not set, increase the “inode” reference count, set the “ILOCK” flag and return a pointer to the “inode”;

7306:

Make a note of the first empty slot in the “inode” table;

7309:

If the “inode” table is full, send a message to the operator, and take an error exit;

7314:

At this point, a new entry is to be made in the “inode” table;

7319:

Read the block which contains the file system volume “inode”. Note the use of “bread” instead of “readi”, the assumption that “inode” information begins in block #2 and the convention that valid “inode” numbers begin at one (not zero);

7326:

A read error at this point isn’t very well reported to the rest of the system;

7328:

Copy the relevant “inode” information. This code makes implicit use of the contents of the file “ino.h” (Sheet 56), which isn’t referenced explicitly anywhere.

Let us now return to unfinished business:

7292:

The “IMOUNT” flag is found to be set. This flag was set by “smount”, when a file system volume was mounted;

7293:

Search the “mount” table to find the entry which points to the curent “inode”. (Although searching this table is not a horrendous overhead, it does seem possible that a “back pointer” could be conveniently stored in in the “inode” e.g. in the “i_lastr” field. This would save both time and code space.;

7396:

Reset “dev” and “ino” to the mounted device number and the “inode” number of the root directory on the mounted file system volume. Start again.

Clearly, since “iget” is called by “namei” (7534, 7664), this technique allows the whole directory structure on the mounted file system volume to be integrated into the pre-existing directory structure. If we momentarily ignore the possible deviations of directory structures away from tree structures, we have the situation where a leaf of the existing tree is being replaced by an entire subtree.