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

Source

  • 根据给定的路径名找到一个inode
  • 判断当前用户是否为该inode对应的文件拥有者,参看权限管理
  • 返回
    • 返回为空:
      • 该路径名无法找到对应inode
      • 当前用户不是该inode对应的文件拥有者
      • 当前用户不是超级用户
    • 返回得到的inode:
      • 当前用户为该inode对应的文件拥有者
      • 当前用户是超级用户

6782

6783 /*

6784  * Look up a pathname and test if

6785  * the resultant inode is owned by the

6786  * current user.

6787  * If not, try for super-user.

6788  * If permission is granted,

6789  * return inode pointer.

6790  */

6791 owner()

6792 {

6793     register struct inode *ip;

6794     extern uchar();

6795

6796     if ((ip = namei(uchar, 0)) == NULL)

6797          return(NULL);

  • 获取路径名对应的inode,并赋给ip
  • 若获取失败,返回空
6798     if(u.u_uid == ip->i_uid)

6799          return(ip);

  • 如果当前用户为文件拥有者,返回ip
6800     if (suser())

6801          return(ip);

  • 如果当前用户为超级用户,返回ip
6802     iput(ip);
  • 如果当前用户既非文件拥有者又非超级用户,释放ip
6803     return(NULL);

6804 }

6805 /* -------------------------*/

Ref

Caller

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