Home | History | Annotate | Line # | Download | only in common
vfs_syscalls_50.c revision 1.2
      1 /*	$NetBSD: vfs_syscalls_50.c,v 1.2 2009/01/11 02:45:47 christos Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2008 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Christos Zoulas.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *        This product includes software developed by the NetBSD
     21  *        Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 #include <sys/cdefs.h>
     39 __KERNEL_RCSID(0, "$NetBSD: vfs_syscalls_50.c,v 1.2 2009/01/11 02:45:47 christos Exp $");
     40 
     41 #include <sys/param.h>
     42 #include <sys/systm.h>
     43 #include <sys/namei.h>
     44 #include <sys/filedesc.h>
     45 #include <sys/kernel.h>
     46 #include <sys/file.h>
     47 #include <sys/stat.h>
     48 #include <sys/socketvar.h>
     49 #include <sys/vnode.h>
     50 #include <sys/mount.h>
     51 #include <sys/proc.h>
     52 #include <sys/uio.h>
     53 #include <sys/dirent.h>
     54 #include <sys/malloc.h>
     55 #include <sys/kauth.h>
     56 #include <sys/time.h>
     57 #include <sys/vfs_syscalls.h>
     58 #ifndef LFS
     59 #define LFS
     60 #endif
     61 #include <sys/syscallargs.h>
     62 
     63 #include <ufs/lfs/lfs_extern.h>
     64 
     65 #include <compat/common/compat_util.h>
     66 #include <compat/sys/time.h>
     67 #include <compat/sys/stat.h>
     68 #include <compat/sys/dirent.h>
     69 #include <compat/sys/mount.h>
     70 
     71 static void cvtstat(struct stat30 *, const struct stat *);
     72 
     73 /*
     74  * Convert from a new to an old stat structure.
     75  */
     76 static void
     77 cvtstat(struct stat30 *ost, const struct stat *st)
     78 {
     79 
     80 	ost->st_dev = st->st_dev;
     81 	ost->st_ino = st->st_ino;
     82 	ost->st_mode = st->st_mode;
     83 	ost->st_nlink = st->st_nlink;
     84 	ost->st_uid = st->st_uid;
     85 	ost->st_gid = st->st_gid;
     86 	ost->st_rdev = st->st_rdev;
     87 	timespec_to_timespec50(&st->st_atimespec, &ost->st_atimespec);
     88 	timespec_to_timespec50(&st->st_mtimespec, &ost->st_mtimespec);
     89 	timespec_to_timespec50(&st->st_ctimespec, &ost->st_ctimespec);
     90 	timespec_to_timespec50(&st->st_birthtimespec, &ost->st_birthtimespec);
     91 	ost->st_size = st->st_size;
     92 	ost->st_blocks = st->st_blocks;
     93 	ost->st_blksize = st->st_blksize;
     94 	ost->st_flags = st->st_flags;
     95 	ost->st_gen = st->st_gen;
     96 }
     97 
     98 /*
     99  * Get file status; this version follows links.
    100  */
    101 /* ARGSUSED */
    102 int
    103 compat_50_sys___stat30(struct lwp *l, const struct compat_50_sys___stat30_args *uap, register_t *retval)
    104 {
    105 	/* {
    106 		syscallarg(const char *) path;
    107 		syscallarg(struct stat30 *) ub;
    108 	} */
    109 	struct stat sb;
    110 	struct stat30 osb;
    111 	int error;
    112 
    113 	error = do_sys_stat(SCARG(uap, path), FOLLOW, &sb);
    114 	if (error)
    115 		return error;
    116 	cvtstat(&osb, &sb);
    117 	error = copyout(&osb, SCARG(uap, ub), sizeof (osb));
    118 	return error;
    119 }
    120 
    121 
    122 /*
    123  * Get file status; this version does not follow links.
    124  */
    125 /* ARGSUSED */
    126 int
    127 compat_50_sys___lstat30(struct lwp *l, const struct compat_50_sys___lstat30_args *uap, register_t *retval)
    128 {
    129 	/* {
    130 		syscallarg(const char *) path;
    131 		syscallarg(struct stat30 *) ub;
    132 	} */
    133 	struct stat sb;
    134 	struct stat30 osb;
    135 	int error;
    136 
    137 	error = do_sys_stat(SCARG(uap, path), NOFOLLOW, &sb);
    138 	if (error)
    139 		return error;
    140 	cvtstat(&osb, &sb);
    141 	error = copyout(&osb, SCARG(uap, ub), sizeof (osb));
    142 	return error;
    143 }
    144 
    145 /*
    146  * Return status information about a file descriptor.
    147  */
    148 /* ARGSUSED */
    149 int
    150 compat_50_sys___fstat30(struct lwp *l, const struct compat_50_sys___fstat30_args *uap, register_t *retval)
    151 {
    152 	/* {
    153 		syscallarg(int) fd;
    154 		syscallarg(struct stat30 *) sb;
    155 	} */
    156 	int fd = SCARG(uap, fd);
    157 	struct file *fp;
    158 	struct stat sb;
    159 	struct stat30 osb;
    160 	int error;
    161 
    162 	if ((fp = fd_getfile(fd)) == NULL)
    163 		return EBADF;
    164 
    165 	error = (*fp->f_ops->fo_stat)(fp, &sb);
    166 	fd_putfile(fd);
    167 
    168 	if (error)
    169 		return error;
    170 	cvtstat(&osb, &sb);
    171 	error = copyout(&osb, SCARG(uap, sb), sizeof (osb));
    172 	return error;
    173 }
    174 
    175 /* ARGSUSED */
    176 int
    177 compat_50_sys___fhstat40(struct lwp *l, const struct compat_50_sys___fhstat40_args *uap, register_t *retval)
    178 {
    179 	/* {
    180 		syscallarg(const void *) fhp;
    181 		syscallarg(size_t) fh_size;
    182 		syscallarg(struct stat30 *) sb;
    183 	} */
    184 	struct stat sb;
    185 	struct stat30 osb;
    186 	int error;
    187 
    188 	error = do_fhstat(l, SCARG(uap, fhp), SCARG(uap, fh_size), &sb);
    189 	if (error)
    190 		return error;
    191 	cvtstat(&osb, &sb);
    192 	error = copyout(&osb, SCARG(uap, sb), sizeof (osb));
    193 	return error;
    194 }
    195 
    196 static int
    197 compat_50_do_sys_utimes(struct lwp *l, struct vnode *vp, const char *path,
    198     int flag, const struct timeval50 *tptr)
    199 {
    200 	struct timeval tv[2];
    201 	struct timeval50 tv50[2];
    202 	int error = copyin(tptr, tv50, sizeof(tv50));
    203 	if (error)
    204 		return error;
    205 	timeval50_to_timeval(&tv50[0], &tv[0]);
    206 	timeval50_to_timeval(&tv50[1], &tv[1]);
    207 	return do_sys_utimes(l, vp, path, flag, tv, UIO_SYSSPACE);
    208 }
    209 
    210 /*
    211  * Set the access and modification times given a path name; this
    212  * version follows links.
    213  */
    214 /* ARGSUSED */
    215 int
    216 compat_50_sys_utimes(struct lwp *l, const struct compat_50_sys_utimes_args *uap,
    217     register_t *retval)
    218 {
    219 	/* {
    220 		syscallarg(const char *) path;
    221 		syscallarg(const struct timeval50 *) tptr;
    222 	} */
    223 
    224 	return compat_50_do_sys_utimes(l, NULL, SCARG(uap, path), FOLLOW,
    225 	    SCARG(uap, tptr));
    226 }
    227 
    228 /*
    229  * Set the access and modification times given a file descriptor.
    230  */
    231 /* ARGSUSED */
    232 int
    233 compat_50_sys_futimes(struct lwp *l,
    234     const struct compat_50_sys_futimes_args *uap, register_t *retval)
    235 {
    236 	/* {
    237 		syscallarg(int) fd;
    238 		syscallarg(const struct timeval50 *) tptr;
    239 	} */
    240 	int error;
    241 	struct file *fp;
    242 
    243 	/* fd_getvnode() will use the descriptor for us */
    244 	if ((error = fd_getvnode(SCARG(uap, fd), &fp)) != 0)
    245 		return error;
    246 	error = compat_50_do_sys_utimes(l, fp->f_data, NULL, 0,
    247 	    SCARG(uap, tptr));
    248 	fd_putfile(SCARG(uap, fd));
    249 	return error;
    250 }
    251 
    252 /*
    253  * Set the access and modification times given a path name; this
    254  * version does not follow links.
    255  */
    256 int
    257 compat_50_sys_lutimes(struct lwp *l,
    258     const struct compat_50_sys_lutimes_args *uap, register_t *retval)
    259 {
    260 	/* {
    261 		syscallarg(const char *) path;
    262 		syscallarg(const struct timeval50 *) tptr;
    263 	} */
    264 
    265 	return compat_50_do_sys_utimes(l, NULL, SCARG(uap, path), NOFOLLOW,
    266 	    SCARG(uap, tptr));
    267 }
    268 
    269 int
    270 compat_50_sys_lfs_segwait(struct lwp *l,
    271     const struct compat_50_sys_lfs_segwait_args *uap, register_t *retval)
    272 {
    273 	/* {
    274 		syscallarg(fsid_t *) fsidp;
    275 		syscallarg(struct timeval50 *) tv;
    276 	} */
    277 #ifdef notyet
    278 	struct timeval atv;
    279 	struct timeval50 atv50;
    280 	fsid_t fsid;
    281 	int error;
    282 
    283 	/* XXX need we be su to segwait? */
    284 	if ((error = kauth_authorize_generic(l->l_cred, KAUTH_GENERIC_ISSUSER,
    285 	    NULL)) != 0)
    286 		return (error);
    287 	if ((error = copyin(SCARG(uap, fsidp), &fsid, sizeof(fsid_t))) != 0)
    288 		return (error);
    289 
    290 	if (SCARG(uap, tv)) {
    291 		error = copyin(SCARG(uap, tv), &atv50, sizeof(atv50));
    292 		if (error)
    293 			return (error);
    294 		timeval50_to_timeval(&atv50, &atv);
    295 		if (itimerfix(&atv))
    296 			return (EINVAL);
    297 	} else /* NULL or invalid */
    298 		atv.tv_sec = atv.tv_usec = 0;
    299 	return lfs_segwait(&fsid, &atv);
    300 #else
    301 	return ENOSYS;
    302 #endif
    303 }
    304 
    305 int
    306 compat_50_sys_mknod(struct lwp *l,
    307     const struct compat_50_sys_mknod_args *uap, register_t *retval)
    308 {
    309 	/* {
    310 		syscallarg(const char *) path;
    311 		syscallarg(mode_t) mode;
    312 		syscallarg(uint32_t) dev;
    313 	} */
    314 	return do_sys_mknod(l, SCARG(uap, path), SCARG(uap, mode),
    315 	    SCARG(uap, dev), retval);
    316 }
    317