1 // SPDX-License-Identifier: GPL-2.0 << 2 /* 1 /* 3 * Inode operations for Coda filesystem 2 * Inode operations for Coda filesystem 4 * Original version: (C) 1996 P. Braam and M. 3 * Original version: (C) 1996 P. Braam and M. Callahan 5 * Rewritten for Linux 2.1. (C) 1997 Carnegie 4 * Rewritten for Linux 2.1. (C) 1997 Carnegie Mellon University 6 * 5 * 7 * Carnegie Mellon encourages users to contrib 6 * Carnegie Mellon encourages users to contribute improvements to 8 * the Coda project. Contact Peter Braam (coda 7 * the Coda project. Contact Peter Braam (coda@cs.cmu.edu). 9 */ 8 */ 10 9 11 #include <linux/types.h> 10 #include <linux/types.h> 12 #include <linux/kernel.h> 11 #include <linux/kernel.h> 13 #include <linux/time.h> 12 #include <linux/time.h> 14 #include <linux/fs.h> 13 #include <linux/fs.h> 15 #include <linux/stat.h> 14 #include <linux/stat.h> 16 #include <linux/errno.h> 15 #include <linux/errno.h> 17 #include <linux/uaccess.h> 16 #include <linux/uaccess.h> 18 #include <linux/string.h> 17 #include <linux/string.h> 19 18 20 #include <linux/coda.h> 19 #include <linux/coda.h> 21 #include "coda_psdev.h" !! 20 #include <linux/coda_psdev.h> 22 #include "coda_linux.h" 21 #include "coda_linux.h" 23 22 24 /* initialize the debugging variables */ 23 /* initialize the debugging variables */ 25 int coda_fake_statfs; 24 int coda_fake_statfs; 26 25 27 /* print a fid */ 26 /* print a fid */ 28 char * coda_f2s(struct CodaFid *f) 27 char * coda_f2s(struct CodaFid *f) 29 { 28 { 30 static char s[60]; 29 static char s[60]; 31 30 32 sprintf(s, "(%08x.%08x.%08x.%08x)", f- 31 sprintf(s, "(%08x.%08x.%08x.%08x)", f->opaque[0], f->opaque[1], f->opaque[2], f->opaque[3]); 33 32 34 return s; 33 return s; 35 } 34 } 36 35 37 /* recognize special .CONTROL name */ 36 /* recognize special .CONTROL name */ 38 int coda_iscontrol(const char *name, size_t le 37 int coda_iscontrol(const char *name, size_t length) 39 { 38 { 40 return ((CODA_CONTROLLEN == length) && 39 return ((CODA_CONTROLLEN == length) && 41 (strncmp(name, CODA_CONTROL, C 40 (strncmp(name, CODA_CONTROL, CODA_CONTROLLEN) == 0)); 42 } 41 } 43 42 44 unsigned short coda_flags_to_cflags(unsigned s 43 unsigned short coda_flags_to_cflags(unsigned short flags) 45 { 44 { 46 unsigned short coda_flags = 0; 45 unsigned short coda_flags = 0; 47 46 48 if ((flags & O_ACCMODE) == O_RDONLY) 47 if ((flags & O_ACCMODE) == O_RDONLY) 49 coda_flags |= C_O_READ; 48 coda_flags |= C_O_READ; 50 49 51 if ((flags & O_ACCMODE) == O_RDWR) 50 if ((flags & O_ACCMODE) == O_RDWR) 52 coda_flags |= C_O_READ | C_O_W 51 coda_flags |= C_O_READ | C_O_WRITE; 53 52 54 if ((flags & O_ACCMODE) == O_WRONLY) 53 if ((flags & O_ACCMODE) == O_WRONLY) 55 coda_flags |= C_O_WRITE; 54 coda_flags |= C_O_WRITE; 56 55 57 if (flags & O_TRUNC) 56 if (flags & O_TRUNC) 58 coda_flags |= C_O_TRUNC; 57 coda_flags |= C_O_TRUNC; 59 58 60 if (flags & O_CREAT) 59 if (flags & O_CREAT) 61 coda_flags |= C_O_CREAT; 60 coda_flags |= C_O_CREAT; 62 61 63 if (flags & O_EXCL) 62 if (flags & O_EXCL) 64 coda_flags |= C_O_EXCL; 63 coda_flags |= C_O_EXCL; 65 64 66 return coda_flags; 65 return coda_flags; 67 } 66 } 68 67 69 static struct timespec64 coda_to_timespec64(st << 70 { << 71 struct timespec64 ts64 = { << 72 .tv_sec = ts.tv_sec, << 73 .tv_nsec = ts.tv_nsec, << 74 }; << 75 << 76 return ts64; << 77 } << 78 << 79 static struct coda_timespec timespec64_to_coda << 80 { << 81 struct coda_timespec ts = { << 82 .tv_sec = ts64.tv_sec, << 83 .tv_nsec = ts64.tv_nsec, << 84 }; << 85 << 86 return ts; << 87 } << 88 68 89 /* utility functions below */ 69 /* utility functions below */ 90 umode_t coda_inode_type(struct coda_vattr *att << 91 { << 92 switch (attr->va_type) { << 93 case C_VREG: << 94 return S_IFREG; << 95 case C_VDIR: << 96 return S_IFDIR; << 97 case C_VLNK: << 98 return S_IFLNK; << 99 case C_VNON: << 100 default: << 101 return 0; << 102 } << 103 } << 104 << 105 void coda_vattr_to_iattr(struct inode *inode, 70 void coda_vattr_to_iattr(struct inode *inode, struct coda_vattr *attr) 106 { 71 { 107 /* inode's i_flags, i_ino are set by i !! 72 int inode_type; 108 * XXX: is this all we need ?? !! 73 /* inode's i_flags, i_ino are set by iget 109 */ !! 74 XXX: is this all we need ?? 110 umode_t inode_type = coda_inode_type(a !! 75 */ >> 76 switch (attr->va_type) { >> 77 case C_VNON: >> 78 inode_type = 0; >> 79 break; >> 80 case C_VREG: >> 81 inode_type = S_IFREG; >> 82 break; >> 83 case C_VDIR: >> 84 inode_type = S_IFDIR; >> 85 break; >> 86 case C_VLNK: >> 87 inode_type = S_IFLNK; >> 88 break; >> 89 default: >> 90 inode_type = 0; >> 91 } 111 inode->i_mode |= inode_type; 92 inode->i_mode |= inode_type; 112 93 113 if (attr->va_mode != (u_short) -1) 94 if (attr->va_mode != (u_short) -1) 114 inode->i_mode = attr->va_mode 95 inode->i_mode = attr->va_mode | inode_type; 115 if (attr->va_uid != -1) 96 if (attr->va_uid != -1) 116 inode->i_uid = make_kuid(&init 97 inode->i_uid = make_kuid(&init_user_ns, (uid_t) attr->va_uid); 117 if (attr->va_gid != -1) 98 if (attr->va_gid != -1) 118 inode->i_gid = make_kgid(&init 99 inode->i_gid = make_kgid(&init_user_ns, (gid_t) attr->va_gid); 119 if (attr->va_nlink != -1) 100 if (attr->va_nlink != -1) 120 set_nlink(inode, attr->va_nlin 101 set_nlink(inode, attr->va_nlink); 121 if (attr->va_size != -1) 102 if (attr->va_size != -1) 122 inode->i_size = attr->va_size; 103 inode->i_size = attr->va_size; 123 if (attr->va_size != -1) 104 if (attr->va_size != -1) 124 inode->i_blocks = (attr->va_si 105 inode->i_blocks = (attr->va_size + 511) >> 9; 125 if (attr->va_atime.tv_sec != -1) 106 if (attr->va_atime.tv_sec != -1) 126 inode_set_atime_to_ts(inode, !! 107 inode->i_atime = attr->va_atime; 127 coda_to_ << 128 if (attr->va_mtime.tv_sec != -1) 108 if (attr->va_mtime.tv_sec != -1) 129 inode_set_mtime_to_ts(inode, !! 109 inode->i_mtime = attr->va_mtime; 130 coda_to_ << 131 if (attr->va_ctime.tv_sec != -1) 110 if (attr->va_ctime.tv_sec != -1) 132 inode_set_ctime_to_ts(inode, !! 111 inode->i_ctime = attr->va_ctime; 133 coda_to_ << 134 } 112 } 135 113 136 114 137 /* 115 /* 138 * BSD sets attributes that need not be modifi 116 * BSD sets attributes that need not be modified to -1. 139 * Linux uses the valid field to indicate what 117 * Linux uses the valid field to indicate what should be 140 * looked at. The BSD type field needs to be 118 * looked at. The BSD type field needs to be deduced from linux 141 * mode. 119 * mode. 142 * So we have to do some translations here. 120 * So we have to do some translations here. 143 */ 121 */ 144 122 145 void coda_iattr_to_vattr(struct iattr *iattr, 123 void coda_iattr_to_vattr(struct iattr *iattr, struct coda_vattr *vattr) 146 { 124 { 147 unsigned int valid; 125 unsigned int valid; 148 126 149 /* clean out */ 127 /* clean out */ 150 vattr->va_mode = -1; 128 vattr->va_mode = -1; 151 vattr->va_uid = (vuid_t) -1; 129 vattr->va_uid = (vuid_t) -1; 152 vattr->va_gid = (vgid_t) -1; 130 vattr->va_gid = (vgid_t) -1; 153 vattr->va_size = (off_t) -1; 131 vattr->va_size = (off_t) -1; 154 vattr->va_atime.tv_sec = (int64_t) -1; !! 132 vattr->va_atime.tv_sec = (time_t) -1; 155 vattr->va_atime.tv_nsec = (long) -1; !! 133 vattr->va_atime.tv_nsec = (time_t) -1; 156 vattr->va_mtime.tv_sec = (int64_t) -1; !! 134 vattr->va_mtime.tv_sec = (time_t) -1; 157 vattr->va_mtime.tv_nsec = (long) -1; !! 135 vattr->va_mtime.tv_nsec = (time_t) -1; 158 vattr->va_ctime.tv_sec = (int64_t) -1; !! 136 vattr->va_ctime.tv_sec = (time_t) -1; 159 vattr->va_ctime.tv_nsec = (long) -1; !! 137 vattr->va_ctime.tv_nsec = (time_t) -1; 160 vattr->va_type = C_VNON; 138 vattr->va_type = C_VNON; 161 vattr->va_fileid = -1; 139 vattr->va_fileid = -1; 162 vattr->va_gen = -1; 140 vattr->va_gen = -1; 163 vattr->va_bytes = -1; 141 vattr->va_bytes = -1; 164 vattr->va_nlink = -1; 142 vattr->va_nlink = -1; 165 vattr->va_blocksize = -1; 143 vattr->va_blocksize = -1; 166 vattr->va_rdev = -1; 144 vattr->va_rdev = -1; 167 vattr->va_flags = 0; 145 vattr->va_flags = 0; 168 146 169 /* determine the type */ 147 /* determine the type */ 170 #if 0 148 #if 0 171 mode = iattr->ia_mode; 149 mode = iattr->ia_mode; 172 if ( S_ISDIR(mode) ) { 150 if ( S_ISDIR(mode) ) { 173 vattr->va_type = C_VDIR; 151 vattr->va_type = C_VDIR; 174 } else if ( S_ISREG(mode) ) { 152 } else if ( S_ISREG(mode) ) { 175 vattr->va_type = C_VREG; 153 vattr->va_type = C_VREG; 176 } else if ( S_ISLNK(mode) ) { 154 } else if ( S_ISLNK(mode) ) { 177 vattr->va_type = C_VLNK; 155 vattr->va_type = C_VLNK; 178 } else { 156 } else { 179 /* don't do others */ 157 /* don't do others */ 180 vattr->va_type = C_VNON; 158 vattr->va_type = C_VNON; 181 } 159 } 182 #endif 160 #endif 183 161 184 /* set those vattrs that need change * 162 /* set those vattrs that need change */ 185 valid = iattr->ia_valid; 163 valid = iattr->ia_valid; 186 if ( valid & ATTR_MODE ) { 164 if ( valid & ATTR_MODE ) { 187 vattr->va_mode = iattr->ia_mod 165 vattr->va_mode = iattr->ia_mode; 188 } 166 } 189 if ( valid & ATTR_UID ) { 167 if ( valid & ATTR_UID ) { 190 vattr->va_uid = (vuid_t) from_ 168 vattr->va_uid = (vuid_t) from_kuid(&init_user_ns, iattr->ia_uid); 191 } 169 } 192 if ( valid & ATTR_GID ) { 170 if ( valid & ATTR_GID ) { 193 vattr->va_gid = (vgid_t) from_ 171 vattr->va_gid = (vgid_t) from_kgid(&init_user_ns, iattr->ia_gid); 194 } 172 } 195 if ( valid & ATTR_SIZE ) { 173 if ( valid & ATTR_SIZE ) { 196 vattr->va_size = iattr->ia_siz 174 vattr->va_size = iattr->ia_size; 197 } 175 } 198 if ( valid & ATTR_ATIME ) { 176 if ( valid & ATTR_ATIME ) { 199 vattr->va_atime = timespec64_t !! 177 vattr->va_atime = iattr->ia_atime; 200 } 178 } 201 if ( valid & ATTR_MTIME ) { 179 if ( valid & ATTR_MTIME ) { 202 vattr->va_mtime = timespec64_t !! 180 vattr->va_mtime = iattr->ia_mtime; 203 } 181 } 204 if ( valid & ATTR_CTIME ) { 182 if ( valid & ATTR_CTIME ) { 205 vattr->va_ctime = timespec64_t !! 183 vattr->va_ctime = iattr->ia_ctime; 206 } 184 } 207 } 185 } 208 186 209 187
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.