code:iput - ikarishinjieva/unixV6-code-analyze-chs GitHub Wiki
- 指定inode结构的 引用数-1,此时
- 若引用数为0(内存中没有使用该inode块的进程),则
- 若没有勾连(该inode代表的文件在文件系统中已无效),则释放inode结构和其文件块
- 否则,只释放内存inode结构(磁盘inode结构和其文件块在文件系统中仍有效,不可释放)
- 若引用数为0(内存中没有使用该inode块的进程),则
7336
7337 /*
7338 * Decrement reference count of
7339 * an inode structure.
7340 * On the last reference,
7341 * write the inode out and if necessary,
7342 * truncate and deallocate the file.
7343 */
7344 iput(p)
7345 struct inode *p;
7346 {
7347 register *rp;
7348
7349 rp = p;
7350 if(rp->i_count == 1) {
7351 rp->i_flag =| ILOCK;
7352 if(rp->i_nlink <= 0) {
7353 itrunc(rp);
7354 rp->i_mode = 0;
7355 ifree(rp->i_dev, rp->i_number);
7356 }
7357 iupdat(rp, time);
7358 prele(rp);
7359 rp->i_flag = 0;
- 7358 与 7363 在此分支执行时重复
- 7358 是为了在释放内存inode块之前 解锁并唤醒等待进程
- 7363在此分支执行时 多余
7360 rp->i_number = 0;
7361 }
- 相当于释放内存inode块
7362 rp->i_count--;
7363 prele(rp);
7364 }
7365 /* ------------------------- */