code:open1 - ikarishinjieva/unixV6-code-analyze-chs GitHub Wiki
但是不是很好理解,因为功能很难说明 并且有很重的修改痕迹,对此LIONS代码分析中也提出了相近的评论5798
5799 /*
5800 * common code for open and creat.
5801 * Check permissions, allocate an open file structure,
5802 * and call the device open routine if any.
5803 */
5804 open1(ip, mode, trf)
5805 int *ip;
5806 {
5807 register struct file *fp;
5808 register *rip, m;
5809 int i;
5810
5811 rip = ip;
5812 m = mode;
5813 if(trf != 2) {
5814 if(m&FREAD)
5816 if(m&FWRITE) {
5818 if((rip->i_mode&IFMT) == IFDIR)
5819 u.u_error = EISDIR;
- 此处技巧,参看文件系统之inode类型
5820 }
- 错误代码 : EISDIR
5821 }
5822 if(u.u_error)
5823 goto out;
5824 if(trf)
- 此处若检到错误,是
- 由access抛出
- 由5819抛出
5826 prele(rip);
- LIONS 代码分析 在此提出将测试条件改为 trf==1,会改变性能
- 个人认为 LIONS代码分析 出现了错误,应当与5794行(creat)笔误有关
5827 if ((fp = falloc()) == NULL)
5828 goto out;
5829 fp->f_flag = m&(FREAD|FWRITE);
- falloc 中 置u.u_ar0[R0],将在5831使用
5831 i = u.u_ar0[R0];
5833 if(u.u_error == 0)
- 此句意图不明,列入遗留问题
5834 return;
5835 u.u_ofile[i] = NULL;
5836 fp->f_count--;
5837
5838 out:
5840 }
5841 /* ------------------------- */