code:sumount - ikarishinjieva/unixV6-code-analyze-chs GitHub Wiki
- 实现系统调用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();
6151 d = getmdev();
- 将被修改过的超级块与INODE更新回磁盘
6152 if(u.u_error)
- 获取当前 装载文件系统 的设备号 赋给d
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;
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;
6170 ip = mp->m_bufp;
- 对于装载INODE,清IMOUNT标识
- 勾连数减1
6171 mp->m_bufp = NULL;
6173 }
- 使 装载块m_bufp指针 指向空
- 释放 当前装载文件系统 超级块 对应的 缓存块
6174 /* ------------------------- */
- (umount = 22.)
- sys umount; special