18.18 readi (6221)

6230:

If no characters are to be transferred, do nothing;

6232:

Set the “inode” flag to indicate that the “inode” has been accessed;

6233:

If the file is a character special file, call the appropriate device “read” procedure, passing the device identification as parameter;

6238:

Begin a loop to transfer data in amounts up to 512 characters at a time until (6262) either an irrecoverable error condition has been encountered or the requested number of characters has been transferred;

6239:

“lshift” (1410) concatenates the two words of the array “u.u_offset”, shifts right by nine places, and truncates to 16 bits. This defines the “logical block number” of the file which is to be referenced;

6240:

“on” is a character offset within the block;

6241:

“n” is determined initially as the minimum of the number of characters beyond “on” in the block, and the number requested for transfer. (Note that “min” (6339) treats its arguments as unsigned integers.)

6242:

If the file is not a special block file then ...

6243:

Compare the file offset with the current file size;

6246:

Reset “n” as the minimum of the characters requested and the remaining characters in the file;

6248:

Call “bmap” to convert the logical block number for the file to a physical block number for its host device. There will be more on “bmap” shortly. For now, note that “bmap” sets “rablock” as a side effect;

6250:

Set “dn” as the device identification from the “inode”;

6251:

If the file is a special block file then ...

6252:

Set “dn” from the “i_addr” field of the “inode” entry. (Presumably this will nearly always be the same as the “i_dev” field, so why the distinction?)

6253:

Set the “read ahead block” to the next physical block;

6255:

If the blocks of the file are apparently being read sequentially then ...

6256:

Call “breada” to read the desired block and to initiate reading of the “read ahead block”;

6258:

else just read the desired block;

6260:

Call “iomove” to transfer information from the buffer to the user area;

6261:

Return the buffer to the “av”-list.