• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/linux/linux-2.6.36/fs/coda/
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 */
9
10#include <linux/types.h>
11#include <linux/kernel.h>
12#include <linux/time.h>
13#include <linux/fs.h>
14#include <linux/stat.h>
15#include <linux/errno.h>
16#include <asm/uaccess.h>
17#include <linux/string.h>
18
19#include <linux/coda.h>
20#include <linux/coda_linux.h>
21#include <linux/coda_psdev.h>
22#include <linux/coda_fs_i.h>
23
24/* initialize the debugging variables */
25int coda_fake_statfs;
26
27/* print a fid */
28char * coda_f2s(struct CodaFid *f)
29{
30	static char s[60];
31
32 	sprintf(s, "(%08x.%08x.%08x.%08x)", f->opaque[0], f->opaque[1], f->opaque[2], f->opaque[3]);
33
34	return s;
35}
36
37/* recognize special .CONTROL name */
38int coda_iscontrol(const char *name, size_t length)
39{
40	return ((CODA_CONTROLLEN == length) &&
41                (strncmp(name, CODA_CONTROL, CODA_CONTROLLEN) == 0));
42}
43
44/* recognize /coda inode */
45int coda_isroot(struct inode *i)
46{
47    return ( i->i_sb->s_root->d_inode == i );
48}
49
50unsigned short coda_flags_to_cflags(unsigned short flags)
51{
52	unsigned short coda_flags = 0;
53
54	if ((flags & O_ACCMODE) == O_RDONLY)
55		coda_flags |= C_O_READ;
56
57	if ((flags & O_ACCMODE) == O_RDWR)
58		coda_flags |= C_O_READ | C_O_WRITE;
59
60	if ((flags & O_ACCMODE) == O_WRONLY)
61		coda_flags |= C_O_WRITE;
62
63	if (flags & O_TRUNC)
64		coda_flags |= C_O_TRUNC;
65
66	if (flags & O_CREAT)
67		coda_flags |= C_O_CREAT;
68
69	if (flags & O_EXCL)
70		coda_flags |= C_O_EXCL;
71
72	return coda_flags;
73}
74
75
76/* utility functions below */
77void coda_vattr_to_iattr(struct inode *inode, struct coda_vattr *attr)
78{
79        int inode_type;
80        switch (attr->va_type) {
81        case C_VNON:
82                inode_type  = 0;
83                break;
84        case C_VREG:
85                inode_type = S_IFREG;
86                break;
87        case C_VDIR:
88                inode_type = S_IFDIR;
89                break;
90        case C_VLNK:
91                inode_type = S_IFLNK;
92                break;
93        default:
94                inode_type = 0;
95        }
96	inode->i_mode |= inode_type;
97
98	if (attr->va_mode != (u_short) -1)
99	        inode->i_mode = attr->va_mode | inode_type;
100        if (attr->va_uid != -1)
101	        inode->i_uid = (uid_t) attr->va_uid;
102        if (attr->va_gid != -1)
103	        inode->i_gid = (gid_t) attr->va_gid;
104	if (attr->va_nlink != -1)
105	        inode->i_nlink = attr->va_nlink;
106	if (attr->va_size != -1)
107	        inode->i_size = attr->va_size;
108	if (attr->va_size != -1)
109		inode->i_blocks = (attr->va_size + 511) >> 9;
110	if (attr->va_atime.tv_sec != -1)
111	        inode->i_atime = attr->va_atime;
112	if (attr->va_mtime.tv_sec != -1)
113	        inode->i_mtime = attr->va_mtime;
114        if (attr->va_ctime.tv_sec != -1)
115	        inode->i_ctime = attr->va_ctime;
116}
117
118
119/*
120 * BSD sets attributes that need not be modified to -1.
121 * Linux uses the valid field to indicate what should be
122 * looked at.  The BSD type field needs to be deduced from linux
123 * mode.
124 * So we have to do some translations here.
125 */
126
127void coda_iattr_to_vattr(struct iattr *iattr, struct coda_vattr *vattr)
128{
129        unsigned int valid;
130
131        /* clean out */
132	vattr->va_mode = -1;
133        vattr->va_uid = (vuid_t) -1;
134        vattr->va_gid = (vgid_t) -1;
135        vattr->va_size = (off_t) -1;
136	vattr->va_atime.tv_sec = (time_t) -1;
137	vattr->va_atime.tv_nsec =  (time_t) -1;
138        vattr->va_mtime.tv_sec = (time_t) -1;
139        vattr->va_mtime.tv_nsec = (time_t) -1;
140	vattr->va_ctime.tv_sec = (time_t) -1;
141	vattr->va_ctime.tv_nsec = (time_t) -1;
142        vattr->va_type = C_VNON;
143	vattr->va_fileid = -1;
144	vattr->va_gen = -1;
145	vattr->va_bytes = -1;
146	vattr->va_nlink = -1;
147	vattr->va_blocksize = -1;
148	vattr->va_rdev = -1;
149        vattr->va_flags = 0;
150
151        /* determine the type */
152
153        /* set those vattrs that need change */
154        valid = iattr->ia_valid;
155        if ( valid & ATTR_MODE ) {
156                vattr->va_mode = iattr->ia_mode;
157	}
158        if ( valid & ATTR_UID ) {
159                vattr->va_uid = (vuid_t) iattr->ia_uid;
160	}
161        if ( valid & ATTR_GID ) {
162                vattr->va_gid = (vgid_t) iattr->ia_gid;
163	}
164        if ( valid & ATTR_SIZE ) {
165                vattr->va_size = iattr->ia_size;
166	}
167        if ( valid & ATTR_ATIME ) {
168                vattr->va_atime = iattr->ia_atime;
169	}
170        if ( valid & ATTR_MTIME ) {
171                vattr->va_mtime = iattr->ia_mtime;
172	}
173        if ( valid & ATTR_CTIME ) {
174                vattr->va_ctime = iattr->ia_ctime;
175	}
176}
177