Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 */ |
| 25 | int coda_fake_statfs; |
| 26 | |
| 27 | /* print a fid */ |
| 28 | char * coda_f2s(struct CodaFid *f) |
| 29 | { |
| 30 | static char s[60]; |
| 31 | #ifdef CONFIG_CODA_FS_OLD_API |
| 32 | sprintf(s, "(%08x.%08x.%08x)", f->opaque[0], f->opaque[1], f->opaque[2]); |
| 33 | #else |
| 34 | sprintf(s, "(%08x.%08x.%08x.%08x)", f->opaque[0], f->opaque[1], f->opaque[2], f->opaque[3]); |
| 35 | #endif |
| 36 | return s; |
| 37 | } |
| 38 | |
| 39 | /* recognize special .CONTROL name */ |
| 40 | int coda_iscontrol(const char *name, size_t length) |
| 41 | { |
| 42 | return ((CODA_CONTROLLEN == length) && |
| 43 | (strncmp(name, CODA_CONTROL, CODA_CONTROLLEN) == 0)); |
| 44 | } |
| 45 | |
| 46 | /* recognize /coda inode */ |
| 47 | int coda_isroot(struct inode *i) |
| 48 | { |
| 49 | return ( i->i_sb->s_root->d_inode == i ); |
| 50 | } |
| 51 | |
| 52 | unsigned short coda_flags_to_cflags(unsigned short flags) |
| 53 | { |
| 54 | unsigned short coda_flags = 0; |
| 55 | |
| 56 | if ((flags & O_ACCMODE) == O_RDONLY) |
| 57 | coda_flags |= C_O_READ; |
| 58 | |
| 59 | if ((flags & O_ACCMODE) == O_RDWR) |
| 60 | coda_flags |= C_O_READ | C_O_WRITE; |
| 61 | |
| 62 | if ((flags & O_ACCMODE) == O_WRONLY) |
| 63 | coda_flags |= C_O_WRITE; |
| 64 | |
| 65 | if (flags & O_TRUNC) |
| 66 | coda_flags |= C_O_TRUNC; |
| 67 | |
| 68 | if (flags & O_CREAT) |
| 69 | coda_flags |= C_O_CREAT; |
| 70 | |
| 71 | if (flags & O_EXCL) |
| 72 | coda_flags |= C_O_EXCL; |
| 73 | |
| 74 | return coda_flags; |
| 75 | } |
| 76 | |
| 77 | |
| 78 | /* utility functions below */ |
| 79 | void coda_vattr_to_iattr(struct inode *inode, struct coda_vattr *attr) |
| 80 | { |
| 81 | int inode_type; |
| 82 | /* inode's i_flags, i_ino are set by iget |
| 83 | XXX: is this all we need ?? |
| 84 | */ |
| 85 | switch (attr->va_type) { |
| 86 | case C_VNON: |
| 87 | inode_type = 0; |
| 88 | break; |
| 89 | case C_VREG: |
| 90 | inode_type = S_IFREG; |
| 91 | break; |
| 92 | case C_VDIR: |
| 93 | inode_type = S_IFDIR; |
| 94 | break; |
| 95 | case C_VLNK: |
| 96 | inode_type = S_IFLNK; |
| 97 | break; |
| 98 | default: |
| 99 | inode_type = 0; |
| 100 | } |
| 101 | inode->i_mode |= inode_type; |
| 102 | |
| 103 | if (attr->va_mode != (u_short) -1) |
| 104 | inode->i_mode = attr->va_mode | inode_type; |
| 105 | if (attr->va_uid != -1) |
| 106 | inode->i_uid = (uid_t) attr->va_uid; |
| 107 | if (attr->va_gid != -1) |
| 108 | inode->i_gid = (gid_t) attr->va_gid; |
| 109 | if (attr->va_nlink != -1) |
| 110 | inode->i_nlink = attr->va_nlink; |
| 111 | if (attr->va_size != -1) |
| 112 | inode->i_size = attr->va_size; |
| 113 | if (attr->va_blocksize != -1) |
| 114 | inode->i_blksize = attr->va_blocksize; |
| 115 | if (attr->va_size != -1) |
| 116 | inode->i_blocks = (attr->va_size + 511) >> 9; |
| 117 | if (attr->va_atime.tv_sec != -1) |
| 118 | inode->i_atime = attr->va_atime; |
| 119 | if (attr->va_mtime.tv_sec != -1) |
| 120 | inode->i_mtime = attr->va_mtime; |
| 121 | if (attr->va_ctime.tv_sec != -1) |
| 122 | inode->i_ctime = attr->va_ctime; |
| 123 | } |
| 124 | |
| 125 | |
| 126 | /* |
| 127 | * BSD sets attributes that need not be modified to -1. |
| 128 | * Linux uses the valid field to indicate what should be |
| 129 | * looked at. The BSD type field needs to be deduced from linux |
| 130 | * mode. |
| 131 | * So we have to do some translations here. |
| 132 | */ |
| 133 | |
| 134 | void coda_iattr_to_vattr(struct iattr *iattr, struct coda_vattr *vattr) |
| 135 | { |
| 136 | unsigned int valid; |
| 137 | |
| 138 | /* clean out */ |
| 139 | vattr->va_mode = (umode_t) -1; |
| 140 | vattr->va_uid = (vuid_t) -1; |
| 141 | vattr->va_gid = (vgid_t) -1; |
| 142 | vattr->va_size = (off_t) -1; |
| 143 | vattr->va_atime.tv_sec = (time_t) -1; |
| 144 | vattr->va_atime.tv_nsec = (time_t) -1; |
| 145 | vattr->va_mtime.tv_sec = (time_t) -1; |
| 146 | vattr->va_mtime.tv_nsec = (time_t) -1; |
| 147 | vattr->va_ctime.tv_sec = (time_t) -1; |
| 148 | vattr->va_ctime.tv_nsec = (time_t) -1; |
| 149 | vattr->va_type = C_VNON; |
| 150 | vattr->va_fileid = -1; |
| 151 | vattr->va_gen = -1; |
| 152 | vattr->va_bytes = -1; |
| 153 | vattr->va_nlink = -1; |
| 154 | vattr->va_blocksize = -1; |
| 155 | vattr->va_rdev = -1; |
| 156 | vattr->va_flags = 0; |
| 157 | |
| 158 | /* determine the type */ |
| 159 | #if 0 |
| 160 | mode = iattr->ia_mode; |
| 161 | if ( S_ISDIR(mode) ) { |
| 162 | vattr->va_type = C_VDIR; |
| 163 | } else if ( S_ISREG(mode) ) { |
| 164 | vattr->va_type = C_VREG; |
| 165 | } else if ( S_ISLNK(mode) ) { |
| 166 | vattr->va_type = C_VLNK; |
| 167 | } else { |
| 168 | /* don't do others */ |
| 169 | vattr->va_type = C_VNON; |
| 170 | } |
| 171 | #endif |
| 172 | |
| 173 | /* set those vattrs that need change */ |
| 174 | valid = iattr->ia_valid; |
| 175 | if ( valid & ATTR_MODE ) { |
| 176 | vattr->va_mode = iattr->ia_mode; |
| 177 | } |
| 178 | if ( valid & ATTR_UID ) { |
| 179 | vattr->va_uid = (vuid_t) iattr->ia_uid; |
| 180 | } |
| 181 | if ( valid & ATTR_GID ) { |
| 182 | vattr->va_gid = (vgid_t) iattr->ia_gid; |
| 183 | } |
| 184 | if ( valid & ATTR_SIZE ) { |
| 185 | vattr->va_size = iattr->ia_size; |
| 186 | } |
| 187 | if ( valid & ATTR_ATIME ) { |
| 188 | vattr->va_atime = iattr->ia_atime; |
| 189 | } |
| 190 | if ( valid & ATTR_MTIME ) { |
| 191 | vattr->va_mtime = iattr->ia_mtime; |
| 192 | } |
| 193 | if ( valid & ATTR_CTIME ) { |
| 194 | vattr->va_ctime = iattr->ia_ctime; |
| 195 | } |
| 196 | } |
| 197 | |