17.5 getblk (4921)

This routine performs the same search as “incore” but goes further in that if the initial search is unsuccessful, a buffer is allocated from the “av”-list (available list).

By a call on “notavail” (4999), the buffer is removed from the “av”-list and flagged as “B_BUSY”.

“getblk” is more suspicious of its parameters than “incore”. It is called by

  exec   (3040)        writei (6304)
  exit   (3237)        iinit  (6928)
  bread  (4758)        alloc  (6981)
  breada (4781,4789)   free   (7016)
  smount (6123)        update (7216)
4940:

At this point the required buffer has been located by searching the “b”-list. Either it is “B_BUSY” in which case a “sleep” must be taken (4943), or else it is appropriated (4948);

4953:

If the required buffer has not been located, and if the “av”-list is empty, set the “B_WANTED” flag for the “av”-list and go to “sleep” (4955);

4960:

If the “av”-list is not empty, select the first member, and if it represents a “delayed write” arrange to have it written out asynchronously (4962);

4966:

“B_RELOC” is a relic! (See 4583);

4967:

The code from here until 4973 unconditionally removes the buffer from the “b”-list for its current device type and reinserts it into the bn-list for the new device type. Since this will frequently be a “no-op” i.e. the new and old device type will be the same, it would seem desirable to insert a test

 if (bp->b_dev == dev)

before executing lines 4967 to 4974.

Note the special handling for calls where
“dev == NODEV” (–1). (Such calls incidentally are made without a second parameter - tut! tut! See e.g. 3040.)

“bfreelist” serves as the “devtab” structure for the “b”-list for “NODEV”.