Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static struct inode *namex(char *path, int nameiparent, char *name)
- {
- struct inode *ip, *next;
- if (*path == '/')
- ip = iget(ROOTDEV, ROOTINO);
- else
- ip = idup(myproc()->cwd);
- while ((path = skipelem(path, name)) != 0)
- {
- ilock(ip);
- if (ip->type != T_DIR)
- {
- iunlockput(ip);
- return 0;
- }
- if (nameiparent == 1 && *path == '\0')
- {
- // Stop one level early.
- iunlock(ip);
- return ip;
- }
- if ((next = dirlookup(ip, name, 0)) == 0)
- {
- iunlockput(ip);
- return 0;
- }
- if(nameiparent == 2 && *path == '\0'){
- iunlockput(ip);
- return next;
- }
- if(ip->mode != M_READ && ip->mode != M_ALL){
- iunlockput(ip);
- return 0;
- }
- iunlockput(ip);
- ilock(next);
- char buf[MAXPATH];
- while(next->type == T_SYMLINK){
- int len = 0;
- readi(next, 0, (uint64)&len, 0, sizeof(int));
- readi(next, 0, (uint64)buf, sizeof(int), len + 1);
- iunlockput(next);
- if((next = namei(buf, 0)) == 0){
- end_op();
- return 0;
- }
- ilock(next);
- }
- iunlock(next);
- ip = next;
- }
- if (nameiparent)
- {
- iput(ip);
- return 0;
- }
- return ip;
- }
- struct inode *namei(char *path, int trace)
- {
- char name[DIRSIZ];
- return namex(path, trace, name);
- }
- struct inode *nameiparent(char *path, char *name)
- {
- return namex(path, 1, name);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement