code:getfs - ikarishinjieva/unixV6-code-analyze-chs GitHub Wiki

Source

  • 返回 指定设备 的超级块,参考文件系统
  • 共传入一个参数 dev
    • dev : 指定设备 的设备号
  • 返回 对应的超级块,类型为 struct filsys
  • 若无匹配,则抛出错误

7149 /*

7150  * getfs maps a device number into

7151  * a pointer to the incore super

7152  * block.

7153  * The algorithm is a linear

7154  * search through the mount table.

7155  * A consistency check of the

7156  * in core free-block and i-node

7157  * counts.

7158  *

7159  * bad count on dev x/y -- the count

7160  * check failed. At this point, all

7161  * the counts are zeroed which will

7162  * almost certainly lead to "no space"

7163  * diagnostic

7164  * panic: no fs -- the device is not mounted.

7165  * this "cannot happen"

7166  */

7167 getfs(dev)

7168 {

7169     register struct mount *p;

7170     register char *n1, *n2;

7171

7172     for(p = &mount[0]; p < &mount[NMOUNT]; p++)

  • 遍历 mount 数组,寻找匹配的文件系统
  • 参考文件系统
7173     if(p->m_bufp != NULL && p->m_dev == dev) {

7174          p = p->m_bufp->b_addr;

7175          n1 = p->s_nfree;

7176          n2 = p->s_ninode;

7177          if(n1 > 100 || n2 > 100) {

7178           prdev("bad count", dev);

7179           p->s_nfree = 0;

7180           p->s_ninode = 0;

7181          }

  • 若参数错误(s_nfree s_ninode),则输出错误,并修正错误
7182          return(p);
7183     }

7184     panic("no fs");

  • 若无匹配,抛出错误
7185 }

7186 /* ------------------------- */

7187 /* ------------------------- */

Ref

Caller

⚠️ **GitHub.com Fallback** ⚠️