Linux 2.2.0
[davej-history.git] / fs / coda / coda_linux.c
blobf684f3a78ca563f3fd114ea4c369b28a3d49cd6c
1 /*
2 * Inode operations for Coda filesystem
3 * Original version: (C) 1996 P. Braam and M. Callahan
4 * Rewritten for Linux 2.1. (C) 1997 Carnegie Mellon University
5 *
6 * Carnegie Mellon encourages users to contribute improvements to
7 * the Coda project. Contact Peter Braam (coda@cs.cmu.edu).
8 */
10 #include <linux/version.h>
11 #include <linux/types.h>
12 #include <linux/kernel.h>
13 #include <linux/sched.h>
14 #include <linux/fs.h>
15 #include <linux/stat.h>
16 #include <linux/errno.h>
17 #include <linux/locks.h>
18 #include <asm/segment.h>
19 #include <asm/uaccess.h>
20 #include <linux/string.h>
22 #include <linux/coda.h>
23 #include <linux/coda_linux.h>
24 #include <linux/coda_psdev.h>
25 #include <linux/coda_fs_i.h>
26 #include <linux/coda_cache.h>
28 /* initialize the debugging variables */
29 int coda_debug = 0;
30 int coda_print_entry = 0;
31 int coda_access_cache = 1;
33 /* print a fid */
34 char * coda_f2s(ViceFid *f)
36 static char s[60];
37 if ( f ) {
38 sprintf(s, "(%-#lx,%-#lx,%-#lx)",
39 f->Volume, f->Vnode, f->Unique);
41 return s;
44 /* print another fid */
45 char * coda_f2s2(ViceFid *f)
47 static char s[60];
48 if ( f ) {
49 sprintf(s, "(%-#lx,%-#lx,%-#lx)",
50 f->Volume, f->Vnode, f->Unique);
52 return s;
55 /* recognize special .CONTROL name */
56 int coda_iscontrol(const char *name, size_t length)
58 if ((CODA_CONTROLLEN == length) &&
59 (strncmp(name, CODA_CONTROL, CODA_CONTROLLEN) == 0))
60 return 1;
61 return 0;
64 /* recognize /coda inode */
65 int coda_isroot(struct inode *i)
67 if ( i->i_sb->s_root->d_inode == i ) {
68 return 1;
69 } else {
70 return 0;
74 /* is this a volume root FID */
75 int coda_fid_is_volroot(struct ViceFid *fid)
77 return ( (fid->Vnode == 1) && (fid->Unique == 1 ) );
80 int coda_fid_is_weird(struct ViceFid *fid)
82 /* volume roots */
83 if ( (fid->Vnode == 1) && (fid->Unique == 1 ) )
84 return 1;
85 /* tmpfid unique (simulate.cc) */
86 if ( fid->Unique == 0xffffffff )
87 return 1;
88 /* LocalFakeVnode (local.h) */
89 if ( fid->Vnode == 0xfffffffd )
90 return 1;
91 /* LocalFileVnode (venus.private.h) */
92 if ( fid->Vnode == 0xfffffffe )
93 return 1;
94 /* local fake vid (local.h) */
95 if ( fid->Volume == 0xffffffff )
96 return 1;
97 /* local DirVnode (venus.private.h) */
98 if ( fid->Vnode == 0xffffffff )
99 return 1;
100 /* FakeVnode (venus.private.h) */
101 if ( fid->Vnode == 0xfffffffc )
102 return 1;
104 return 0;
110 /* put the current process credentials in the cred */
111 void coda_load_creds(struct coda_cred *cred)
113 cred->cr_uid = (vuid_t) current->uid;
114 cred->cr_euid = (vuid_t) current->euid;
115 cred->cr_suid = (vuid_t) current->suid;
116 cred->cr_fsuid = (vuid_t) current->fsuid;
118 cred->cr_groupid = (vgid_t) current->gid;
119 cred->cr_egid = (vgid_t) current->egid;
120 cred->cr_sgid = (vgid_t) current->sgid;
121 cred->cr_fsgid = (vgid_t) current->fsgid;
124 int coda_cred_ok(struct coda_cred *cred)
126 return(current->fsuid == cred->cr_fsuid);
129 int coda_cred_eq(struct coda_cred *cred1, struct coda_cred *cred2)
131 return (cred1->cr_fsuid == cred2->cr_fsuid);
134 unsigned short coda_flags_to_cflags(unsigned short flags)
136 unsigned short coda_flags = 0;
138 if ( (flags & O_ACCMODE) == O_RDONLY ){
139 CDEBUG(D_FILE, "--> C_O_READ added\n");
140 coda_flags |= C_O_READ;
143 if ( (flags & O_ACCMODE) == O_RDWR ) {
144 CDEBUG(D_FILE, "--> C_O_READ | C_O_WRITE added\n");
145 coda_flags |= C_O_READ | C_O_WRITE;
148 if ( (flags & O_ACCMODE) == O_WRONLY ){
149 CDEBUG(D_FILE, "--> C_O_WRITE added\n");
150 coda_flags |= C_O_WRITE;
153 if ( flags & O_TRUNC ) {
154 CDEBUG(D_FILE, "--> C_O_TRUNC added\n");
155 coda_flags |= C_O_TRUNC;
158 if ( flags & O_CREAT ) {
159 CDEBUG(D_FILE, "--> C_O_CREAT added\n");
160 coda_flags |= C_O_CREAT;
163 if ( flags & O_EXCL ) {
164 coda_flags |= C_O_EXCL;
165 CDEBUG(D_FILE, "--> C_O_EXCL added\n");
168 return coda_flags;
172 /* utility functions below */
173 void coda_vattr_to_iattr(struct inode *inode, struct coda_vattr *attr)
175 int inode_type;
176 /* inode's i_dev, i_flags, i_ino are set by iget
177 XXX: is this all we need ??
179 switch (attr->va_type) {
180 case C_VNON:
181 inode_type = 0;
182 break;
183 case C_VREG:
184 inode_type = S_IFREG;
185 break;
186 case C_VDIR:
187 inode_type = S_IFDIR;
188 break;
189 case C_VLNK:
190 inode_type = S_IFLNK;
191 break;
192 default:
193 inode_type = 0;
195 inode->i_mode |= inode_type;
197 if (attr->va_mode != (u_short) -1)
198 inode->i_mode = attr->va_mode | inode_type;
199 if (attr->va_uid != -1)
200 inode->i_uid = (uid_t) attr->va_uid;
201 if (attr->va_gid != -1)
202 inode->i_gid = (gid_t) attr->va_gid;
203 if (attr->va_nlink != -1)
204 inode->i_nlink = attr->va_nlink;
205 if (attr->va_size != -1)
206 inode->i_size = attr->va_size;
207 if (attr->va_blocksize != -1)
208 inode->i_blksize = attr->va_blocksize;
209 if (attr->va_size != -1)
210 inode->i_blocks = (attr->va_size + 511) >> 9;
211 if (attr->va_atime.tv_sec != -1)
212 inode->i_atime = attr->va_atime.tv_sec;
213 if (attr->va_mtime.tv_sec != -1)
214 inode->i_mtime = attr->va_mtime.tv_sec;
215 if (attr->va_ctime.tv_sec != -1)
216 inode->i_ctime = attr->va_ctime.tv_sec;
219 * BSD sets attributes that need not be modified to -1.
220 * Linux uses the valid field to indicate what should be
221 * looked at. The BSD type field needs to be deduced from linux
222 * mode.
223 * So we have to do some translations here.
226 void coda_iattr_to_vattr(struct iattr *iattr, struct coda_vattr *vattr)
228 unsigned int valid;
230 /* clean out */
231 vattr->va_mode = (umode_t) -1;
232 vattr->va_uid = (vuid_t) -1;
233 vattr->va_gid = (vgid_t) -1;
234 vattr->va_size = (off_t) -1;
235 vattr->va_atime.tv_sec = (time_t) -1;
236 vattr->va_mtime.tv_sec = (time_t) -1;
237 vattr->va_ctime.tv_sec = (time_t) -1;
238 vattr->va_atime.tv_nsec = (time_t) -1;
239 vattr->va_mtime.tv_nsec = (time_t) -1;
240 vattr->va_ctime.tv_nsec = (time_t) -1;
241 vattr->va_type = C_VNON;
242 vattr->va_fileid = -1;
243 vattr->va_gen = -1;
244 vattr->va_bytes = -1;
245 vattr->va_nlink = -1;
246 vattr->va_blocksize = -1;
247 vattr->va_rdev = -1;
248 vattr->va_flags = 0;
250 /* determine the type */
251 #if 0
252 mode = iattr->ia_mode;
253 if ( S_ISDIR(mode) ) {
254 vattr->va_type = C_VDIR;
255 } else if ( S_ISREG(mode) ) {
256 vattr->va_type = C_VREG;
257 } else if ( S_ISLNK(mode) ) {
258 vattr->va_type = C_VLNK;
259 } else {
260 /* don't do others */
261 vattr->va_type = C_VNON;
263 #endif
265 /* set those vattrs that need change */
266 valid = iattr->ia_valid;
267 if ( valid & ATTR_MODE ) {
268 vattr->va_mode = iattr->ia_mode;
270 if ( valid & ATTR_UID ) {
271 vattr->va_uid = (vuid_t) iattr->ia_uid;
273 if ( valid & ATTR_GID ) {
274 vattr->va_gid = (vgid_t) iattr->ia_gid;
276 if ( valid & ATTR_SIZE ) {
277 vattr->va_size = iattr->ia_size;
279 if ( valid & ATTR_ATIME ) {
280 vattr->va_atime.tv_sec = iattr->ia_atime;
281 vattr->va_atime.tv_nsec = 0;
283 if ( valid & ATTR_MTIME ) {
284 vattr->va_mtime.tv_sec = iattr->ia_mtime;
285 vattr->va_mtime.tv_nsec = 0;
287 if ( valid & ATTR_CTIME ) {
288 vattr->va_ctime.tv_sec = iattr->ia_ctime;
289 vattr->va_ctime.tv_nsec = 0;
294 void print_vattr(struct coda_vattr *attr)
296 char *typestr;
298 switch (attr->va_type) {
299 case C_VNON:
300 typestr = "C_VNON";
301 break;
302 case C_VREG:
303 typestr = "C_VREG";
304 break;
305 case C_VDIR:
306 typestr = "C_VDIR";
307 break;
308 case C_VBLK:
309 typestr = "C_VBLK";
310 break;
311 case C_VCHR:
312 typestr = "C_VCHR";
313 break;
314 case C_VLNK:
315 typestr = "C_VLNK";
316 break;
317 case C_VSOCK:
318 typestr = "C_VSCK";
319 break;
320 case C_VFIFO:
321 typestr = "C_VFFO";
322 break;
323 case C_VBAD:
324 typestr = "C_VBAD";
325 break;
326 default:
327 typestr = "????";
328 break;
332 printk("attr: type %s (%o) mode %o uid %d gid %d rdev %d\n",
333 typestr, (int)attr->va_type, (int)attr->va_mode,
334 (int)attr->va_uid, (int)attr->va_gid, (int)attr->va_rdev);
336 printk(" fileid %d nlink %d size %d blocksize %d bytes %d\n",
337 (int)attr->va_fileid, (int)attr->va_nlink,
338 (int)attr->va_size,
339 (int)attr->va_blocksize,(int)attr->va_bytes);
340 printk(" gen %ld flags %ld\n",
341 attr->va_gen, attr->va_flags);
342 printk(" atime sec %d nsec %d\n",
343 (int)attr->va_atime.tv_sec, (int)attr->va_atime.tv_nsec);
344 printk(" mtime sec %d nsec %d\n",
345 (int)attr->va_mtime.tv_sec, (int)attr->va_mtime.tv_nsec);
346 printk(" ctime sec %d nsec %d\n",
347 (int)attr->va_ctime.tv_sec, (int)attr->va_ctime.tv_nsec);