purge EFS stuff
[unix-history] / usr / src / sys / kern / vfs_vnops.c
CommitLineData
4147b3f6 1/* fio.c 4.25 82/07/17 */
fc96c615
BJ
2
3#include "../h/param.h"
4#include "../h/systm.h"
5#include "../h/dir.h"
6#include "../h/user.h"
6459ebe0 7#include "../h/fs.h"
fc96c615
BJ
8#include "../h/file.h"
9#include "../h/conf.h"
10#include "../h/inode.h"
11#include "../h/reg.h"
12#include "../h/acct.h"
f5b8937b 13#include "../h/mount.h"
ae921915
BJ
14#include "../h/socket.h"
15#include "../h/socketvar.h"
f3156a73 16#include "../h/proc.h"
b99ef750
BJ
17#ifdef EFS
18#include "../net/in.h"
19#include "../h/efs.h"
20#endif
fc96c615 21
fc96c615 22/*
fdd90ee3 23 * Openi called to allow handler
fc96c615
BJ
24 * of special files to initialize and
25 * validate before actual IO.
26 */
b99ef750
BJ
27#ifdef EFS
28openi(ip, rw, trf)
29#else
fc96c615 30openi(ip, rw)
b99ef750 31#endif
fdd90ee3 32 register struct inode *ip;
fc96c615
BJ
33{
34 dev_t dev;
35 register unsigned int maj;
36
6459ebe0 37 dev = (dev_t)ip->i_rdev;
fc96c615 38 maj = major(dev);
fdd90ee3 39 switch (ip->i_mode&IFMT) {
fc96c615
BJ
40
41 case IFCHR:
fdd90ee3 42 if (maj >= nchrdev)
fc96c615 43 goto bad;
b99ef750
BJ
44#ifdef EFS
45 (*cdevsw[maj].d_open)(dev, rw, trf);
46#else
fc96c615 47 (*cdevsw[maj].d_open)(dev, rw);
b99ef750 48#endif
fc96c615
BJ
49 break;
50
51 case IFBLK:
fdd90ee3 52 if (maj >= nblkdev)
fc96c615
BJ
53 goto bad;
54 (*bdevsw[maj].d_open)(dev, rw);
55 }
56 return;
57
58bad:
59 u.u_error = ENXIO;
60}
61
62/*
63 * Check mode permission on inode pointer.
64 * Mode is READ, WRITE or EXEC.
65 * In the case of WRITE, the
66 * read-only status of the file
67 * system is checked.
68 * Also in WRITE, prototype text
69 * segments cannot be written.
70 * The mode is shifted to select
71 * the owner/group/other fields.
72 * The super user is granted all
73 * permissions.
74 */
75access(ip, mode)
fdd90ee3
BJ
76 register struct inode *ip;
77 int mode;
fc96c615
BJ
78{
79 register m;
80
81 m = mode;
fdd90ee3 82 if (m == IWRITE) {
6459ebe0 83 if (ip->i_fs->fs_ronly != 0) {
fc96c615 84 u.u_error = EROFS;
fdd90ee3 85 return (1);
fc96c615
BJ
86 }
87 if (ip->i_flag&ITEXT) /* try to free text */
88 xrele(ip);
fdd90ee3 89 if (ip->i_flag & ITEXT) {
fc96c615 90 u.u_error = ETXTBSY;
fdd90ee3 91 return (1);
fc96c615
BJ
92 }
93 }
fdd90ee3
BJ
94 if (u.u_uid == 0)
95 return (0);
96 if (u.u_uid != ip->i_uid) {
fc96c615 97 m >>= 3;
4f4caf05
BJ
98 if (ip->i_gid >= NGRPS ||
99 (u.u_grps[ip->i_gid/(sizeof(int)*8)] &
100 (1 << ip->i_gid%(sizeof(int)*8)) == 0))
fc96c615
BJ
101 m >>= 3;
102 }
fdd90ee3
BJ
103 if ((ip->i_mode&m) != 0)
104 return (0);
fc96c615 105 u.u_error = EACCES;
fdd90ee3 106 return (1);
fc96c615
BJ
107}
108
109/*
110 * Look up a pathname and test if
111 * the resultant inode is owned by the
112 * current user.
113 * If not, try for super-user.
114 * If permission is granted,
115 * return inode pointer.
116 */
117struct inode *
5485e062
BJ
118owner(follow)
119 int follow;
fc96c615
BJ
120{
121 register struct inode *ip;
122
5485e062 123 ip = namei(uchar, 0, follow);
fdd90ee3
BJ
124 if (ip == NULL)
125 return (NULL);
b99ef750
BJ
126#ifdef EFS
127 /*
128 * References to extended file system are
129 * returned to the caller.
130 */
131 if (efsinode(ip))
132 return (ip);
133#endif
fdd90ee3
BJ
134 if (u.u_uid == ip->i_uid)
135 return (ip);
136 if (suser())
137 return (ip);
fc96c615 138 iput(ip);
fdd90ee3 139 return (NULL);
fc96c615
BJ
140}
141
142/*
143 * Test if the current user is the
144 * super user.
145 */
146suser()
147{
148
fdd90ee3 149 if (u.u_uid == 0) {
fc96c615 150 u.u_acflag |= ASU;
fdd90ee3 151 return (1);
fc96c615
BJ
152 }
153 u.u_error = EPERM;
fdd90ee3 154 return (0);
fc96c615 155}