Home | History | Annotate | Line # | Download | only in common
vfs_syscalls_50.c revision 1.5.4.2
      1  1.5.4.1     rmind /*	$NetBSD: vfs_syscalls_50.c,v 1.5.4.2 2011/04/21 01:41:36 rmind Exp $	*/
      2      1.2  christos 
      3      1.2  christos /*-
      4      1.2  christos  * Copyright (c) 2008 The NetBSD Foundation, Inc.
      5      1.2  christos  * All rights reserved.
      6      1.2  christos  *
      7      1.2  christos  * This code is derived from software contributed to The NetBSD Foundation
      8      1.2  christos  * by Christos Zoulas.
      9      1.2  christos  *
     10      1.2  christos  * Redistribution and use in source and binary forms, with or without
     11      1.2  christos  * modification, are permitted provided that the following conditions
     12      1.2  christos  * are met:
     13      1.2  christos  * 1. Redistributions of source code must retain the above copyright
     14      1.2  christos  *    notice, this list of conditions and the following disclaimer.
     15      1.2  christos  * 2. Redistributions in binary form must reproduce the above copyright
     16      1.2  christos  *    notice, this list of conditions and the following disclaimer in the
     17      1.2  christos  *    documentation and/or other materials provided with the distribution.
     18      1.2  christos  * 3. All advertising materials mentioning features or use of this software
     19      1.2  christos  *    must display the following acknowledgement:
     20      1.2  christos  *        This product includes software developed by the NetBSD
     21      1.2  christos  *        Foundation, Inc. and its contributors.
     22      1.2  christos  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23      1.2  christos  *    contributors may be used to endorse or promote products derived
     24      1.2  christos  *    from this software without specific prior written permission.
     25      1.2  christos  *
     26      1.2  christos  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27      1.2  christos  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28      1.2  christos  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29      1.2  christos  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30      1.2  christos  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31      1.2  christos  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32      1.2  christos  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33      1.2  christos  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34      1.2  christos  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35      1.2  christos  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36      1.2  christos  * POSSIBILITY OF SUCH DAMAGE.
     37      1.2  christos  */
     38      1.2  christos #include <sys/cdefs.h>
     39  1.5.4.1     rmind __KERNEL_RCSID(0, "$NetBSD: vfs_syscalls_50.c,v 1.5.4.2 2011/04/21 01:41:36 rmind Exp $");
     40      1.2  christos 
     41      1.2  christos #include <sys/param.h>
     42      1.2  christos #include <sys/systm.h>
     43      1.2  christos #include <sys/namei.h>
     44      1.2  christos #include <sys/filedesc.h>
     45      1.2  christos #include <sys/kernel.h>
     46      1.2  christos #include <sys/file.h>
     47      1.2  christos #include <sys/stat.h>
     48      1.2  christos #include <sys/socketvar.h>
     49      1.2  christos #include <sys/vnode.h>
     50      1.2  christos #include <sys/mount.h>
     51      1.2  christos #include <sys/proc.h>
     52      1.2  christos #include <sys/uio.h>
     53      1.2  christos #include <sys/dirent.h>
     54      1.2  christos #include <sys/malloc.h>
     55      1.2  christos #include <sys/kauth.h>
     56      1.2  christos #include <sys/time.h>
     57      1.2  christos #include <sys/vfs_syscalls.h>
     58      1.2  christos #ifndef LFS
     59      1.2  christos #define LFS
     60      1.2  christos #endif
     61      1.2  christos #include <sys/syscallargs.h>
     62      1.2  christos 
     63      1.2  christos #include <ufs/lfs/lfs_extern.h>
     64      1.2  christos 
     65      1.2  christos #include <compat/common/compat_util.h>
     66      1.2  christos #include <compat/sys/time.h>
     67      1.2  christos #include <compat/sys/stat.h>
     68      1.2  christos #include <compat/sys/dirent.h>
     69      1.2  christos #include <compat/sys/mount.h>
     70      1.2  christos 
     71      1.2  christos static void cvtstat(struct stat30 *, const struct stat *);
     72      1.2  christos 
     73      1.2  christos /*
     74      1.2  christos  * Convert from a new to an old stat structure.
     75      1.2  christos  */
     76      1.2  christos static void
     77      1.2  christos cvtstat(struct stat30 *ost, const struct stat *st)
     78      1.2  christos {
     79      1.2  christos 
     80      1.2  christos 	ost->st_dev = st->st_dev;
     81      1.2  christos 	ost->st_ino = st->st_ino;
     82      1.2  christos 	ost->st_mode = st->st_mode;
     83      1.2  christos 	ost->st_nlink = st->st_nlink;
     84      1.2  christos 	ost->st_uid = st->st_uid;
     85      1.2  christos 	ost->st_gid = st->st_gid;
     86      1.2  christos 	ost->st_rdev = st->st_rdev;
     87      1.2  christos 	timespec_to_timespec50(&st->st_atimespec, &ost->st_atimespec);
     88      1.2  christos 	timespec_to_timespec50(&st->st_mtimespec, &ost->st_mtimespec);
     89      1.2  christos 	timespec_to_timespec50(&st->st_ctimespec, &ost->st_ctimespec);
     90      1.2  christos 	timespec_to_timespec50(&st->st_birthtimespec, &ost->st_birthtimespec);
     91      1.2  christos 	ost->st_size = st->st_size;
     92      1.2  christos 	ost->st_blocks = st->st_blocks;
     93      1.2  christos 	ost->st_blksize = st->st_blksize;
     94      1.2  christos 	ost->st_flags = st->st_flags;
     95      1.2  christos 	ost->st_gen = st->st_gen;
     96  1.5.4.1     rmind 	memset(ost->st_spare, 0, sizeof(ost->st_spare));
     97      1.2  christos }
     98      1.2  christos 
     99      1.2  christos /*
    100      1.2  christos  * Get file status; this version follows links.
    101      1.2  christos  */
    102      1.2  christos /* ARGSUSED */
    103      1.2  christos int
    104      1.2  christos compat_50_sys___stat30(struct lwp *l, const struct compat_50_sys___stat30_args *uap, register_t *retval)
    105      1.2  christos {
    106      1.2  christos 	/* {
    107      1.2  christos 		syscallarg(const char *) path;
    108      1.2  christos 		syscallarg(struct stat30 *) ub;
    109      1.2  christos 	} */
    110      1.2  christos 	struct stat sb;
    111      1.2  christos 	struct stat30 osb;
    112      1.2  christos 	int error;
    113      1.2  christos 
    114      1.2  christos 	error = do_sys_stat(SCARG(uap, path), FOLLOW, &sb);
    115      1.2  christos 	if (error)
    116      1.2  christos 		return error;
    117      1.2  christos 	cvtstat(&osb, &sb);
    118      1.2  christos 	error = copyout(&osb, SCARG(uap, ub), sizeof (osb));
    119      1.2  christos 	return error;
    120      1.2  christos }
    121      1.2  christos 
    122      1.2  christos 
    123      1.2  christos /*
    124      1.2  christos  * Get file status; this version does not follow links.
    125      1.2  christos  */
    126      1.2  christos /* ARGSUSED */
    127      1.2  christos int
    128      1.2  christos compat_50_sys___lstat30(struct lwp *l, const struct compat_50_sys___lstat30_args *uap, register_t *retval)
    129      1.2  christos {
    130      1.2  christos 	/* {
    131      1.2  christos 		syscallarg(const char *) path;
    132      1.2  christos 		syscallarg(struct stat30 *) ub;
    133      1.2  christos 	} */
    134      1.2  christos 	struct stat sb;
    135      1.2  christos 	struct stat30 osb;
    136      1.2  christos 	int error;
    137      1.2  christos 
    138      1.2  christos 	error = do_sys_stat(SCARG(uap, path), NOFOLLOW, &sb);
    139      1.2  christos 	if (error)
    140      1.2  christos 		return error;
    141      1.2  christos 	cvtstat(&osb, &sb);
    142      1.2  christos 	error = copyout(&osb, SCARG(uap, ub), sizeof (osb));
    143      1.2  christos 	return error;
    144      1.2  christos }
    145      1.2  christos 
    146      1.2  christos /*
    147      1.2  christos  * Return status information about a file descriptor.
    148      1.2  christos  */
    149      1.2  christos /* ARGSUSED */
    150      1.2  christos int
    151      1.2  christos compat_50_sys___fstat30(struct lwp *l, const struct compat_50_sys___fstat30_args *uap, register_t *retval)
    152      1.2  christos {
    153      1.2  christos 	/* {
    154      1.2  christos 		syscallarg(int) fd;
    155      1.2  christos 		syscallarg(struct stat30 *) sb;
    156      1.2  christos 	} */
    157      1.2  christos 	struct stat sb;
    158      1.2  christos 	struct stat30 osb;
    159      1.2  christos 	int error;
    160      1.2  christos 
    161      1.4     njoly 	error = do_sys_fstat(SCARG(uap, fd), &sb);
    162      1.2  christos 	if (error)
    163      1.2  christos 		return error;
    164      1.2  christos 	cvtstat(&osb, &sb);
    165      1.2  christos 	error = copyout(&osb, SCARG(uap, sb), sizeof (osb));
    166      1.2  christos 	return error;
    167      1.2  christos }
    168      1.2  christos 
    169      1.2  christos /* ARGSUSED */
    170      1.2  christos int
    171      1.2  christos compat_50_sys___fhstat40(struct lwp *l, const struct compat_50_sys___fhstat40_args *uap, register_t *retval)
    172      1.2  christos {
    173      1.2  christos 	/* {
    174      1.2  christos 		syscallarg(const void *) fhp;
    175      1.2  christos 		syscallarg(size_t) fh_size;
    176      1.2  christos 		syscallarg(struct stat30 *) sb;
    177      1.2  christos 	} */
    178      1.2  christos 	struct stat sb;
    179      1.2  christos 	struct stat30 osb;
    180      1.2  christos 	int error;
    181      1.2  christos 
    182      1.2  christos 	error = do_fhstat(l, SCARG(uap, fhp), SCARG(uap, fh_size), &sb);
    183      1.2  christos 	if (error)
    184      1.2  christos 		return error;
    185      1.2  christos 	cvtstat(&osb, &sb);
    186      1.2  christos 	error = copyout(&osb, SCARG(uap, sb), sizeof (osb));
    187      1.2  christos 	return error;
    188      1.2  christos }
    189      1.2  christos 
    190      1.2  christos static int
    191      1.2  christos compat_50_do_sys_utimes(struct lwp *l, struct vnode *vp, const char *path,
    192      1.2  christos     int flag, const struct timeval50 *tptr)
    193      1.2  christos {
    194      1.3  christos 	struct timeval tv[2], *tvp;
    195      1.2  christos 	struct timeval50 tv50[2];
    196      1.3  christos 	if (tptr) {
    197      1.3  christos 		int error = copyin(tptr, tv50, sizeof(tv50));
    198      1.3  christos 		if (error)
    199      1.3  christos 			return error;
    200      1.3  christos 		timeval50_to_timeval(&tv50[0], &tv[0]);
    201      1.3  christos 		timeval50_to_timeval(&tv50[1], &tv[1]);
    202      1.3  christos 		tvp = tv;
    203      1.3  christos 	} else
    204      1.3  christos 		tvp = NULL;
    205      1.3  christos 	return do_sys_utimes(l, vp, path, flag, tvp, UIO_SYSSPACE);
    206      1.2  christos }
    207      1.2  christos 
    208      1.2  christos /*
    209      1.2  christos  * Set the access and modification times given a path name; this
    210      1.2  christos  * version follows links.
    211      1.2  christos  */
    212      1.2  christos /* ARGSUSED */
    213      1.2  christos int
    214      1.2  christos compat_50_sys_utimes(struct lwp *l, const struct compat_50_sys_utimes_args *uap,
    215      1.2  christos     register_t *retval)
    216      1.2  christos {
    217      1.2  christos 	/* {
    218      1.2  christos 		syscallarg(const char *) path;
    219      1.2  christos 		syscallarg(const struct timeval50 *) tptr;
    220      1.2  christos 	} */
    221      1.2  christos 
    222      1.2  christos 	return compat_50_do_sys_utimes(l, NULL, SCARG(uap, path), FOLLOW,
    223      1.2  christos 	    SCARG(uap, tptr));
    224      1.2  christos }
    225      1.2  christos 
    226      1.2  christos /*
    227      1.2  christos  * Set the access and modification times given a file descriptor.
    228      1.2  christos  */
    229      1.2  christos /* ARGSUSED */
    230      1.2  christos int
    231      1.2  christos compat_50_sys_futimes(struct lwp *l,
    232      1.2  christos     const struct compat_50_sys_futimes_args *uap, register_t *retval)
    233      1.2  christos {
    234      1.2  christos 	/* {
    235      1.2  christos 		syscallarg(int) fd;
    236      1.2  christos 		syscallarg(const struct timeval50 *) tptr;
    237      1.2  christos 	} */
    238      1.2  christos 	int error;
    239      1.2  christos 	struct file *fp;
    240      1.2  christos 
    241      1.2  christos 	/* fd_getvnode() will use the descriptor for us */
    242      1.2  christos 	if ((error = fd_getvnode(SCARG(uap, fd), &fp)) != 0)
    243      1.2  christos 		return error;
    244      1.2  christos 	error = compat_50_do_sys_utimes(l, fp->f_data, NULL, 0,
    245      1.2  christos 	    SCARG(uap, tptr));
    246      1.2  christos 	fd_putfile(SCARG(uap, fd));
    247      1.2  christos 	return error;
    248      1.2  christos }
    249      1.2  christos 
    250      1.2  christos /*
    251      1.2  christos  * Set the access and modification times given a path name; this
    252      1.2  christos  * version does not follow links.
    253      1.2  christos  */
    254      1.2  christos int
    255      1.2  christos compat_50_sys_lutimes(struct lwp *l,
    256      1.2  christos     const struct compat_50_sys_lutimes_args *uap, register_t *retval)
    257      1.2  christos {
    258      1.2  christos 	/* {
    259      1.2  christos 		syscallarg(const char *) path;
    260      1.2  christos 		syscallarg(const struct timeval50 *) tptr;
    261      1.2  christos 	} */
    262      1.2  christos 
    263      1.2  christos 	return compat_50_do_sys_utimes(l, NULL, SCARG(uap, path), NOFOLLOW,
    264      1.2  christos 	    SCARG(uap, tptr));
    265      1.2  christos }
    266      1.2  christos 
    267      1.2  christos int
    268      1.2  christos compat_50_sys_lfs_segwait(struct lwp *l,
    269      1.2  christos     const struct compat_50_sys_lfs_segwait_args *uap, register_t *retval)
    270      1.2  christos {
    271      1.2  christos 	/* {
    272      1.2  christos 		syscallarg(fsid_t *) fsidp;
    273      1.2  christos 		syscallarg(struct timeval50 *) tv;
    274      1.2  christos 	} */
    275      1.2  christos #ifdef notyet
    276      1.2  christos 	struct timeval atv;
    277      1.2  christos 	struct timeval50 atv50;
    278      1.2  christos 	fsid_t fsid;
    279      1.2  christos 	int error;
    280      1.2  christos 
    281      1.2  christos 	/* XXX need we be su to segwait? */
    282      1.2  christos 	if ((error = kauth_authorize_generic(l->l_cred, KAUTH_GENERIC_ISSUSER,
    283      1.2  christos 	    NULL)) != 0)
    284      1.2  christos 		return (error);
    285      1.2  christos 	if ((error = copyin(SCARG(uap, fsidp), &fsid, sizeof(fsid_t))) != 0)
    286      1.2  christos 		return (error);
    287      1.2  christos 
    288      1.2  christos 	if (SCARG(uap, tv)) {
    289      1.2  christos 		error = copyin(SCARG(uap, tv), &atv50, sizeof(atv50));
    290      1.2  christos 		if (error)
    291      1.2  christos 			return (error);
    292      1.2  christos 		timeval50_to_timeval(&atv50, &atv);
    293      1.2  christos 		if (itimerfix(&atv))
    294      1.2  christos 			return (EINVAL);
    295      1.2  christos 	} else /* NULL or invalid */
    296      1.2  christos 		atv.tv_sec = atv.tv_usec = 0;
    297      1.2  christos 	return lfs_segwait(&fsid, &atv);
    298      1.2  christos #else
    299      1.2  christos 	return ENOSYS;
    300      1.2  christos #endif
    301      1.2  christos }
    302      1.2  christos 
    303      1.2  christos int
    304      1.2  christos compat_50_sys_mknod(struct lwp *l,
    305      1.2  christos     const struct compat_50_sys_mknod_args *uap, register_t *retval)
    306      1.2  christos {
    307      1.2  christos 	/* {
    308      1.2  christos 		syscallarg(const char *) path;
    309      1.2  christos 		syscallarg(mode_t) mode;
    310      1.2  christos 		syscallarg(uint32_t) dev;
    311      1.2  christos 	} */
    312      1.2  christos 	return do_sys_mknod(l, SCARG(uap, path), SCARG(uap, mode),
    313      1.5      haad 	    SCARG(uap, dev), retval, UIO_USERSPACE);
    314      1.2  christos }
    315  1.5.4.2     rmind 
    316  1.5.4.2     rmind #include <ufs/ufs/quota1.h>
    317  1.5.4.2     rmind #include <quota/quotaprop.h>
    318  1.5.4.2     rmind 
    319  1.5.4.2     rmind /* ARGSUSED */
    320  1.5.4.2     rmind int
    321  1.5.4.2     rmind compat_50_sys_quotactl(struct lwp *l, const struct compat_50_sys_quotactl_args *uap, register_t *retval)
    322  1.5.4.2     rmind {
    323  1.5.4.2     rmind 	/* {
    324  1.5.4.2     rmind 		syscallarg(const char *) path;
    325  1.5.4.2     rmind 		syscallarg(int) cmd;
    326  1.5.4.2     rmind 		syscallarg(int) uid;
    327  1.5.4.2     rmind 		syscallarg(void *) arg;
    328  1.5.4.2     rmind 	} */
    329  1.5.4.2     rmind 	struct mount *mp;
    330  1.5.4.2     rmind 	int error;
    331  1.5.4.2     rmind 	uint8_t error8;
    332  1.5.4.2     rmind 	struct vnode *vp;
    333  1.5.4.2     rmind 	int q1cmd = SCARG(uap, cmd);
    334  1.5.4.2     rmind 	prop_dictionary_t dict, data, cmd;
    335  1.5.4.2     rmind 	prop_array_t cmds, datas;
    336  1.5.4.2     rmind 	char *bufpath;
    337  1.5.4.2     rmind 	struct dqblk dqblk;
    338  1.5.4.2     rmind 	struct ufs_quota_entry qe[QUOTA_NLIMITS];
    339  1.5.4.2     rmind 	uint64_t *values[QUOTA_NLIMITS];
    340  1.5.4.2     rmind 
    341  1.5.4.2     rmind 	values[QUOTA_LIMIT_BLOCK] = &qe[QUOTA_LIMIT_BLOCK].ufsqe_hardlimit;
    342  1.5.4.2     rmind 	values[QUOTA_LIMIT_FILE] = &qe[QUOTA_LIMIT_FILE].ufsqe_hardlimit;
    343  1.5.4.2     rmind 
    344  1.5.4.2     rmind 	error = namei_simple_user(SCARG(uap, path),
    345  1.5.4.2     rmind 				NSM_FOLLOW_TRYEMULROOT, &vp);
    346  1.5.4.2     rmind 	if (error != 0)
    347  1.5.4.2     rmind 		return (error);
    348  1.5.4.2     rmind 	error = ENOMEM;
    349  1.5.4.2     rmind 	mp = vp->v_mount;
    350  1.5.4.2     rmind 	if ((dict = quota_prop_create()) == NULL)
    351  1.5.4.2     rmind 		goto out;
    352  1.5.4.2     rmind 	if ((cmds = prop_array_create()) == NULL)
    353  1.5.4.2     rmind 		goto out_dict;
    354  1.5.4.2     rmind 	if ((datas = prop_array_create()) == NULL)
    355  1.5.4.2     rmind 		goto out_cmds;
    356  1.5.4.2     rmind 
    357  1.5.4.2     rmind 	switch((q1cmd & ~SUBCMDMASK) >> SUBCMDSHIFT) {
    358  1.5.4.2     rmind 	case Q_QUOTAON:
    359  1.5.4.2     rmind 		data = prop_dictionary_create();
    360  1.5.4.2     rmind 		if (data == NULL)
    361  1.5.4.2     rmind 			goto out_datas;
    362  1.5.4.2     rmind 		bufpath = malloc(PATH_MAX * sizeof(char), M_TEMP, M_WAITOK);
    363  1.5.4.2     rmind 		if (bufpath == NULL)
    364  1.5.4.2     rmind 			goto out_data;
    365  1.5.4.2     rmind 		error = copyinstr(SCARG(uap, arg), bufpath, PATH_MAX, NULL);
    366  1.5.4.2     rmind 		if (error != 0) {
    367  1.5.4.2     rmind 			free(bufpath, M_TEMP);
    368  1.5.4.2     rmind 			goto out_data;
    369  1.5.4.2     rmind 		}
    370  1.5.4.2     rmind 		if (!prop_dictionary_set_cstring(data, "quotafile", bufpath))
    371  1.5.4.2     rmind 			error = ENOMEM;
    372  1.5.4.2     rmind 		free(bufpath, M_TEMP);
    373  1.5.4.2     rmind 		if (error)
    374  1.5.4.2     rmind 			goto out_data;
    375  1.5.4.2     rmind 		error = ENOMEM;
    376  1.5.4.2     rmind 		if (!prop_array_add_and_rel(datas, data))
    377  1.5.4.2     rmind 			goto out_datas;
    378  1.5.4.2     rmind 		if (!quota_prop_add_command(cmds, "quotaon",
    379  1.5.4.2     rmind 		    ufs_quota_class_names[qtype2ufsclass(q1cmd & SUBCMDMASK)],
    380  1.5.4.2     rmind 		    datas))
    381  1.5.4.2     rmind 			goto out_cmds;
    382  1.5.4.2     rmind 		goto do_quotaonoff;
    383  1.5.4.2     rmind 
    384  1.5.4.2     rmind 	case Q_QUOTAOFF:
    385  1.5.4.2     rmind 		error = ENOMEM;
    386  1.5.4.2     rmind 		if (!quota_prop_add_command(cmds, "quotaoff",
    387  1.5.4.2     rmind 		    ufs_quota_class_names[qtype2ufsclass(q1cmd & SUBCMDMASK)],
    388  1.5.4.2     rmind 		    datas))
    389  1.5.4.2     rmind 			goto out_cmds;
    390  1.5.4.2     rmind do_quotaonoff:
    391  1.5.4.2     rmind 		if (!prop_dictionary_set_and_rel(dict, "commands", cmds))
    392  1.5.4.2     rmind 			goto out_dict;
    393  1.5.4.2     rmind 		error = VFS_QUOTACTL(mp, dict);
    394  1.5.4.2     rmind 		if (error)
    395  1.5.4.2     rmind 			goto out_dict;
    396  1.5.4.2     rmind 		if ((error = quota_get_cmds(dict, &cmds)) != 0)
    397  1.5.4.2     rmind 			goto out_dict;
    398  1.5.4.2     rmind 		cmd = prop_array_get(cmds, 0);
    399  1.5.4.2     rmind 		if (cmd == NULL) {
    400  1.5.4.2     rmind 			error = EINVAL;
    401  1.5.4.2     rmind 			goto out_dict;
    402  1.5.4.2     rmind 		}
    403  1.5.4.2     rmind 		if (!prop_dictionary_get_int8(cmd, "return", &error8)) {
    404  1.5.4.2     rmind 			error = EINVAL;
    405  1.5.4.2     rmind 			goto out_dict;
    406  1.5.4.2     rmind 		}
    407  1.5.4.2     rmind 		error = error8;
    408  1.5.4.2     rmind 		goto out_dict;
    409  1.5.4.2     rmind 
    410  1.5.4.2     rmind 	case Q_GETQUOTA:
    411  1.5.4.2     rmind 		error = ENOMEM;
    412  1.5.4.2     rmind 		data = prop_dictionary_create();
    413  1.5.4.2     rmind 		if (data == NULL)
    414  1.5.4.2     rmind 			goto out_datas;
    415  1.5.4.2     rmind 		if (!prop_dictionary_set_uint32(data, "id", SCARG(uap, uid)))
    416  1.5.4.2     rmind 			goto out_data;
    417  1.5.4.2     rmind 		if (!prop_array_add_and_rel(datas, data))
    418  1.5.4.2     rmind 			goto out_datas;
    419  1.5.4.2     rmind 		if (!quota_prop_add_command(cmds, "get",
    420  1.5.4.2     rmind 		    ufs_quota_class_names[qtype2ufsclass(q1cmd & SUBCMDMASK)],
    421  1.5.4.2     rmind 		    datas))
    422  1.5.4.2     rmind 			goto out_cmds;
    423  1.5.4.2     rmind 		if (!prop_dictionary_set_and_rel(dict, "commands", cmds))
    424  1.5.4.2     rmind 			goto out_dict;
    425  1.5.4.2     rmind 		error = VFS_QUOTACTL(mp, dict);
    426  1.5.4.2     rmind 		if (error)
    427  1.5.4.2     rmind 			goto out_dict;
    428  1.5.4.2     rmind 		if ((error = quota_get_cmds(dict, &cmds)) != 0)
    429  1.5.4.2     rmind 			goto out_dict;
    430  1.5.4.2     rmind 		cmd = prop_array_get(cmds, 0);
    431  1.5.4.2     rmind 		if (cmd == NULL) {
    432  1.5.4.2     rmind 			error = EINVAL;
    433  1.5.4.2     rmind 			goto out_dict;
    434  1.5.4.2     rmind 		}
    435  1.5.4.2     rmind 		if (!prop_dictionary_get_int8(cmd, "return", &error8)) {
    436  1.5.4.2     rmind 			error = EINVAL;
    437  1.5.4.2     rmind 			goto out_dict;
    438  1.5.4.2     rmind 		}
    439  1.5.4.2     rmind 		error = error8;
    440  1.5.4.2     rmind 		if (error)
    441  1.5.4.2     rmind 			goto out_dict;
    442  1.5.4.2     rmind 		datas = prop_dictionary_get(cmd, "data");
    443  1.5.4.2     rmind 		error = EINVAL;
    444  1.5.4.2     rmind 		if (datas == NULL)
    445  1.5.4.2     rmind 			goto out_dict;
    446  1.5.4.2     rmind 		data = prop_array_get(datas, 0);
    447  1.5.4.2     rmind 		if (data == NULL)
    448  1.5.4.2     rmind 			goto out_dict;
    449  1.5.4.2     rmind 		error = proptoquota64(data, values,
    450  1.5.4.2     rmind 		    ufs_quota_entry_names, UFS_QUOTA_NENTRIES,
    451  1.5.4.2     rmind 		    ufs_quota_limit_names, QUOTA_NLIMITS);
    452  1.5.4.2     rmind 		if (error)
    453  1.5.4.2     rmind 			goto out_dict;
    454  1.5.4.2     rmind 		ufsqe2dqblk(qe, &dqblk);
    455  1.5.4.2     rmind 		error = copyout(&dqblk, SCARG(uap, arg), sizeof(dqblk));
    456  1.5.4.2     rmind 		goto out_dict;
    457  1.5.4.2     rmind 
    458  1.5.4.2     rmind 	case Q_SETQUOTA:
    459  1.5.4.2     rmind 		error = copyin(SCARG(uap, arg), &dqblk, sizeof(dqblk));
    460  1.5.4.2     rmind 		if (error)
    461  1.5.4.2     rmind 			goto out_datas;
    462  1.5.4.2     rmind 		dqblk2ufsqe(&dqblk, qe);
    463  1.5.4.2     rmind 
    464  1.5.4.2     rmind 		error = ENOMEM;
    465  1.5.4.2     rmind 		data = quota64toprop(SCARG(uap, uid), 0, values,
    466  1.5.4.2     rmind 		    ufs_quota_entry_names, UFS_QUOTA_NENTRIES,
    467  1.5.4.2     rmind 		    ufs_quota_limit_names, QUOTA_NLIMITS);
    468  1.5.4.2     rmind 		if (data == NULL)
    469  1.5.4.2     rmind 			goto out_data;
    470  1.5.4.2     rmind 		if (!prop_array_add_and_rel(datas, data))
    471  1.5.4.2     rmind 			goto out_datas;
    472  1.5.4.2     rmind 		if (!quota_prop_add_command(cmds, "set",
    473  1.5.4.2     rmind 		    ufs_quota_class_names[qtype2ufsclass(q1cmd & SUBCMDMASK)],
    474  1.5.4.2     rmind 		    datas))
    475  1.5.4.2     rmind 			goto out_cmds;
    476  1.5.4.2     rmind 		if (!prop_dictionary_set_and_rel(dict, "commands", cmds))
    477  1.5.4.2     rmind 			goto out_dict;
    478  1.5.4.2     rmind 		error = VFS_QUOTACTL(mp, dict);
    479  1.5.4.2     rmind 		if (error)
    480  1.5.4.2     rmind 			goto out_dict;
    481  1.5.4.2     rmind 		if ((error = quota_get_cmds(dict, &cmds)) != 0)
    482  1.5.4.2     rmind 			goto out_dict;
    483  1.5.4.2     rmind 		cmd = prop_array_get(cmds, 0);
    484  1.5.4.2     rmind 		if (cmd == NULL) {
    485  1.5.4.2     rmind 			error = EINVAL;
    486  1.5.4.2     rmind 			goto out_dict;
    487  1.5.4.2     rmind 		}
    488  1.5.4.2     rmind 		if (!prop_dictionary_get_int8(cmd, "return", &error8)) {
    489  1.5.4.2     rmind 			error = EINVAL;
    490  1.5.4.2     rmind 			goto out_dict;
    491  1.5.4.2     rmind 		}
    492  1.5.4.2     rmind 		error = error8;
    493  1.5.4.2     rmind 		goto out_dict;
    494  1.5.4.2     rmind 
    495  1.5.4.2     rmind 	case Q_SYNC:
    496  1.5.4.2     rmind 		/*
    497  1.5.4.2     rmind 		 * not supported but used only to see if quota is supported,
    498  1.5.4.2     rmind 		 * emulate with a "get version"
    499  1.5.4.2     rmind 		 */
    500  1.5.4.2     rmind 		error = ENOMEM;
    501  1.5.4.2     rmind 		if (!quota_prop_add_command(cmds, "get version",
    502  1.5.4.2     rmind 		    ufs_quota_class_names[qtype2ufsclass(q1cmd & SUBCMDMASK)],
    503  1.5.4.2     rmind 		    datas))
    504  1.5.4.2     rmind 			goto out_cmds;
    505  1.5.4.2     rmind 		if (!prop_dictionary_set_and_rel(dict, "commands", cmds))
    506  1.5.4.2     rmind 			goto out_dict;
    507  1.5.4.2     rmind 		error = VFS_QUOTACTL(mp, dict);
    508  1.5.4.2     rmind 		if (error)
    509  1.5.4.2     rmind 			goto out_dict;
    510  1.5.4.2     rmind 		if ((error = quota_get_cmds(dict, &cmds)) != 0)
    511  1.5.4.2     rmind 			goto out_dict;
    512  1.5.4.2     rmind 		cmd = prop_array_get(cmds, 0);
    513  1.5.4.2     rmind 		if (cmd == NULL) {
    514  1.5.4.2     rmind 			error = EINVAL;
    515  1.5.4.2     rmind 			goto out_dict;
    516  1.5.4.2     rmind 		}
    517  1.5.4.2     rmind 		if (!prop_dictionary_get_int8(cmd, "return", &error8)) {
    518  1.5.4.2     rmind 			error = EINVAL;
    519  1.5.4.2     rmind 			goto out_dict;
    520  1.5.4.2     rmind 		}
    521  1.5.4.2     rmind 		error = error8;
    522  1.5.4.2     rmind 		goto out_dict;
    523  1.5.4.2     rmind 
    524  1.5.4.2     rmind 	case Q_SETUSE:
    525  1.5.4.2     rmind 	default:
    526  1.5.4.2     rmind 		error = EOPNOTSUPP;
    527  1.5.4.2     rmind 		goto out_datas;
    528  1.5.4.2     rmind 	}
    529  1.5.4.2     rmind out_data:
    530  1.5.4.2     rmind 	prop_object_release(data);
    531  1.5.4.2     rmind out_datas:
    532  1.5.4.2     rmind 	prop_object_release(datas);
    533  1.5.4.2     rmind out_cmds:
    534  1.5.4.2     rmind 	prop_object_release(cmds);
    535  1.5.4.2     rmind out_dict:
    536  1.5.4.2     rmind 	prop_object_release(dict);
    537  1.5.4.2     rmind out:
    538  1.5.4.2     rmind 	vrele(vp);
    539  1.5.4.2     rmind 	return error;
    540  1.5.4.2     rmind }
    541