|
|
1.1 root 1: #include "sys/param.h"
2: #include "sys/inode.h"
3: #include "sys/user.h"
4: #include "sys/buf.h"
5: #include "sys/conf.h"
6:
7: /*
8: * default namei flagp argument
9: * use as is for simple searches;
10: * copy and fill in the blanks for more complicated things
11: */
12: struct argnamei nilargnamei = {NI_SEARCH};
13:
14: /*
15: * Convert a pathname into a pointer to
16: * a locked inode.
17: *
18: * str = address of pathname; might be user or kernel space address
19: * seg = segment where str lives; save values as u_segflg
20: * flagp = address of structure with miscellaneous parameters
21: * follow = 1 if links are to be followed at the end of the name
22: *
23: * Most of the work is done in the different filesystem namei routines,
24: * which are called with a structure full of value-result parameters
25: * (in effect a bundle of global variables on the stack):
26: * dp, the current inode
27: * cp, the current character pointer
28: * nlink, the current symlink count (to catch loops)
29: * nbuf and nlen, the address and length of the buffer
30: * where the pathname is stored
31: * If the fs namei routine returns 1, there is more work to do;
32: * call the namei routine for the current dp->i_fstyp
33: * (perhaps different from the one that returned)
34: * If the routine returns 0, all is done;
35: * p.dp contains the inode to return, which may be NULL
36: * u.u_error may contain an error code
37: */
38:
39: struct inode *
40: namei(str, seg, flagp, follow)
41: char *str;
42: int seg;
43: struct argnamei *flagp;
44: int follow;
45: {
46: register char *cp;
47: struct nx p;
48: register struct buf *bp;
49:
50: bp = geteblk();
51: p.nbuf = bp->b_un.b_addr;
52: p.nlen = bp->b_bcount;
53: p.dp = NULL; /* in case of error */
54: switch (seg) {
55: case SEGSYS:
56: /* assume it fits in the buffer for now */
57: strcpy(p.nbuf, str);
58: break;
59:
60: case SEGUDATA:
61: if (fustrncpy(p.nbuf, str, p.nlen) < 0) {
62: u.u_error = EFAULT;
63: goto out;
64: }
65: break;
66:
67: default:
68: u.u_error = EFAULT;
69: goto out;
70: }
71: cp = p.nbuf;
72: if(*cp == '/') {
73: while(*cp == '/')
74: cp++;
75: if((p.dp = u.u_rdir) == NULL)
76: p.dp = rootdir;
77: } else
78: p.dp = u.u_cdir;
79: p.nlink = 0;
80: p.cp = cp;
81: plock(p.dp);
82: p.dp->i_count++;
83: while ((*fstypsw[p.dp->i_fstyp]->t_nami)(&p, flagp, follow))
84: ;
85: out:
86: brelse(bp);
87: return (p.dp);
88: }
89:
90: /*
91: * for filesystems without namei code
92: * allow ordinary lookups;
93: * pretend create worked (hence open for write)
94: * reject anything else
95: */
96:
97: int
98: nullnami(p, flagp, follow)
99: register struct nx *p;
100: register struct argnamei *flagp;
101: int follow;
102: {
103:
104: switch (flagp->flag) {
105: case NI_CREAT:
106: flagp->un.mode = ~flagp->un.mode; /* magic */
107: /* fall through */
108: case NI_SEARCH:
109: return (0);
110:
111: default:
112: u.u_error = EACCES;
113: iput(p->dp);
114: p->dp = NULL;
115: return (0);
116: }
117: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.