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

Source

  • 实现系统调用umount的函数
  • 卸载当前的装载文件系统

6140

6141 /*

6142  * the umount system call.

6143  */

6144 sumount()

6145 {

6146     int d;

6147     register struct inode *ip;

6148     register struct mount *mp;

6149

6150     update();

  • 将被修改过的超级块与INODE更新回磁盘
6151     d = getmdev();
6152     if(u.u_error)

6153           return;

  • 若有错误,直接返回
6154     for(mp = &mount[0]; mp < &mount[NMOUNT]; mp++)

6155               if(mp->m_bufp!=NULL && d==mp->m_dev)

6156                     goto found;

6157     u.u_error = EINVAL;

6158     return;

  • 遍历装载块数组,寻找当前 装载文件系统对应的装载块
    • 若找到,跳转至6160行
    • 若没有找到,抛出错误EINVAL,参见错误代码
6159

6160 found:

6161     for(ip = &inode[0]; ip < &inode[NINODE]; ip++)

6162           if(ip->i_number!=0 && d==ip->i_dev) {

6163                     u.u_error = EBUSY;

6164                     return;

6165           }

6166     (*bdevsw[d.d_major].d_close)(d, 0);

  • 关闭设备
6167     ip = mp->m_inodp;

6168     ip->i_flag =& ~IMOUNT;

6169     iput(ip);

  • 对于装载INODE,清IMOUNT标识
  • 勾连数减1
6170     ip = mp->m_bufp;

6171     mp->m_bufp = NULL;

6172     brelse(ip);

  • 使 装载块m_bufp指针 指向空
  • 释放 当前装载文件系统 超级块 对应的 缓存块
6173 }

6174 /* ------------------------- */

Ref

Param

(umount = 22.)
sys umount; special
⚠️ **GitHub.com Fallback** ⚠️