A general description of the function of “bmap” may be found on Page 2 of “FILE SYSTEM (V)” of the UPM.
Files of more than 2**15 blocks (2**24 characters) are not supported;
Start with the “small” file algorithm (file is not greater than eight blocks i.e. 4096 characters);
If the block number is 8 or more, the “small” file must converted into a large file. Note this is a side effect of “bmap”, and should occur only when “bmap” has been called by “writei” (and never by “readi” – see line 6245). Thus all files start life as “small” files and are never explicitly changed to “large” files. Note also that the change is irreversible!
“alloc” (6956) allocates a block on device “d” from the device’s free list. It then assigns a buffer to this block and returns a pointer to the buffer header;
The eight buffer addresses in the “i_addr” array for the “inode” are copied into the buffer area and then erased;
“i_addr[0]” is set to point to the buffer which is set up for a “delayed” write;
The file is still small. Get the next block if necessary;
Note the setting of “rablock”;