Linux Audio

Check our new training course

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