code:closei - ikarishinjieva/unixV6-code-analyze-chs GitHub Wiki
- "释放" 指定的INODE ip
- 若ip为普通INODE,该函数与iput作用相同
- 若ip为 设备装载INODE,且"释放"的是对ip的最后一个引用,则同时关闭设备(d_close())
- 参看文件系统#装载文件系统
- 传入2个参数 ip,rw
6660
6661 /*
6662 * Decrement reference count on an
6663 * inode due to the removal of a
6664 * referencing file structure.
6665 * On the last closei, switchout
6666 * to the close entry point of special
6667 * device handler.
6668 * Note that the handler gets called
6669 * on every open and only on the last
6670 * close.
6671 */
6672 closei(ip, rw)
6673 int *ip;
6674 {
6675 register *rip;
6676 register dev, maj;
6677
6678 rip = ip;
6679 dev = rip->i_addr[0];
6680 maj = rip->i_addr[0].d_major;
6681 if(rip->i_count <= 1)
- 仅当 ip 为设备装载INODE时
- dev ← 设备号
- maj ← 主设备号
- 参看文件系统#装载文件系统
- 当ip为普通INODE,dev,maj 没有意义
6682 switch(rip->i_mode&IFMT) {
6683
6684 case IFCHR:
6685 (*cdevsw[maj].d_close)(dev, rw);
6686 break;
6687
6688 case IFBLK:
6689 (*bdevsw[maj].d_close)(dev, rw);
6690 }
6691 iput(rip);
- 仅当 ip 为设备装载INODE时
- 若"释放"的是对ip的最后一个引用,则试图关闭设备
- 参看文件系统#装载文件系统
- 6682的用法 参看 文件系统#inode类型
- 当ip为普通INODE,以上部分没有意义
6692 }
6693 /* ------------------------- */