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

Source

  • "释放" 指定的INODE ip
    • 若ip为普通INODE,该函数与iput作用相同
    • 若ip为 设备装载INODE,且"释放"的是对ip的最后一个引用,则同时关闭设备(d_close())
    • 参看文件系统#装载文件系统
  • 传入2个参数 ip,rw
    • ip : 指向指定的INODE
    • rw : 读写模式,模式常量参看file.h
      • 读写模式只在调用 d_close()时使用,含义不明,列入遗留问题

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;

  • 仅当 ip 为设备装载INODE时
  • 当ip为普通INODE,dev,maj 没有意义
6681     if(rip->i_count <= 1)

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);

6692 }

6693 /* ------------------------- */

Ref

Caller

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