Home | History | Annotate | Line # | Download | only in common
vfs_syscalls_50.c revision 1.13
      1  1.13  dholland /*	$NetBSD: vfs_syscalls_50.c,v 1.13 2012/01/29 07:16:00 dholland 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.13  dholland __KERNEL_RCSID(0, "$NetBSD: vfs_syscalls_50.c,v 1.13 2012/01/29 07:16:00 dholland 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.9  dholland #include <sys/quota.h>
     66   1.9  dholland #include <quota/quotaprop.h>
     67   1.9  dholland #include <ufs/ufs/quota1.h>
     68   1.9  dholland 
     69   1.2  christos #include <compat/common/compat_util.h>
     70   1.2  christos #include <compat/sys/time.h>
     71   1.2  christos #include <compat/sys/stat.h>
     72   1.2  christos #include <compat/sys/dirent.h>
     73   1.2  christos #include <compat/sys/mount.h>
     74   1.2  christos 
     75   1.2  christos static void cvtstat(struct stat30 *, const struct stat *);
     76   1.2  christos 
     77   1.2  christos /*
     78   1.2  christos  * Convert from a new to an old stat structure.
     79   1.2  christos  */
     80   1.2  christos static void
     81   1.2  christos cvtstat(struct stat30 *ost, const struct stat *st)
     82   1.2  christos {
     83   1.2  christos 
     84   1.2  christos 	ost->st_dev = st->st_dev;
     85   1.2  christos 	ost->st_ino = st->st_ino;
     86   1.2  christos 	ost->st_mode = st->st_mode;
     87   1.2  christos 	ost->st_nlink = st->st_nlink;
     88   1.2  christos 	ost->st_uid = st->st_uid;
     89   1.2  christos 	ost->st_gid = st->st_gid;
     90   1.2  christos 	ost->st_rdev = st->st_rdev;
     91   1.2  christos 	timespec_to_timespec50(&st->st_atimespec, &ost->st_atimespec);
     92   1.2  christos 	timespec_to_timespec50(&st->st_mtimespec, &ost->st_mtimespec);
     93   1.2  christos 	timespec_to_timespec50(&st->st_ctimespec, &ost->st_ctimespec);
     94   1.2  christos 	timespec_to_timespec50(&st->st_birthtimespec, &ost->st_birthtimespec);
     95   1.2  christos 	ost->st_size = st->st_size;
     96   1.2  christos 	ost->st_blocks = st->st_blocks;
     97   1.2  christos 	ost->st_blksize = st->st_blksize;
     98   1.2  christos 	ost->st_flags = st->st_flags;
     99   1.2  christos 	ost->st_gen = st->st_gen;
    100   1.6     pooka 	memset(ost->st_spare, 0, sizeof(ost->st_spare));
    101   1.2  christos }
    102   1.2  christos 
    103   1.2  christos /*
    104   1.2  christos  * Get file status; this version follows links.
    105   1.2  christos  */
    106   1.2  christos /* ARGSUSED */
    107   1.2  christos int
    108   1.2  christos compat_50_sys___stat30(struct lwp *l, const struct compat_50_sys___stat30_args *uap, register_t *retval)
    109   1.2  christos {
    110   1.2  christos 	/* {
    111   1.2  christos 		syscallarg(const char *) path;
    112   1.2  christos 		syscallarg(struct stat30 *) ub;
    113   1.2  christos 	} */
    114   1.2  christos 	struct stat sb;
    115   1.2  christos 	struct stat30 osb;
    116   1.2  christos 	int error;
    117   1.2  christos 
    118   1.2  christos 	error = do_sys_stat(SCARG(uap, path), FOLLOW, &sb);
    119   1.2  christos 	if (error)
    120   1.2  christos 		return error;
    121   1.2  christos 	cvtstat(&osb, &sb);
    122   1.2  christos 	error = copyout(&osb, SCARG(uap, ub), sizeof (osb));
    123   1.2  christos 	return error;
    124   1.2  christos }
    125   1.2  christos 
    126   1.2  christos 
    127   1.2  christos /*
    128   1.2  christos  * Get file status; this version does not follow links.
    129   1.2  christos  */
    130   1.2  christos /* ARGSUSED */
    131   1.2  christos int
    132   1.2  christos compat_50_sys___lstat30(struct lwp *l, const struct compat_50_sys___lstat30_args *uap, register_t *retval)
    133   1.2  christos {
    134   1.2  christos 	/* {
    135   1.2  christos 		syscallarg(const char *) path;
    136   1.2  christos 		syscallarg(struct stat30 *) ub;
    137   1.2  christos 	} */
    138   1.2  christos 	struct stat sb;
    139   1.2  christos 	struct stat30 osb;
    140   1.2  christos 	int error;
    141   1.2  christos 
    142   1.2  christos 	error = do_sys_stat(SCARG(uap, path), NOFOLLOW, &sb);
    143   1.2  christos 	if (error)
    144   1.2  christos 		return error;
    145   1.2  christos 	cvtstat(&osb, &sb);
    146   1.2  christos 	error = copyout(&osb, SCARG(uap, ub), sizeof (osb));
    147   1.2  christos 	return error;
    148   1.2  christos }
    149   1.2  christos 
    150   1.2  christos /*
    151   1.2  christos  * Return status information about a file descriptor.
    152   1.2  christos  */
    153   1.2  christos /* ARGSUSED */
    154   1.2  christos int
    155   1.2  christos compat_50_sys___fstat30(struct lwp *l, const struct compat_50_sys___fstat30_args *uap, register_t *retval)
    156   1.2  christos {
    157   1.2  christos 	/* {
    158   1.2  christos 		syscallarg(int) fd;
    159   1.2  christos 		syscallarg(struct stat30 *) sb;
    160   1.2  christos 	} */
    161   1.2  christos 	struct stat sb;
    162   1.2  christos 	struct stat30 osb;
    163   1.2  christos 	int error;
    164   1.2  christos 
    165   1.4     njoly 	error = do_sys_fstat(SCARG(uap, fd), &sb);
    166   1.2  christos 	if (error)
    167   1.2  christos 		return error;
    168   1.2  christos 	cvtstat(&osb, &sb);
    169   1.2  christos 	error = copyout(&osb, SCARG(uap, sb), sizeof (osb));
    170   1.2  christos 	return error;
    171   1.2  christos }
    172   1.2  christos 
    173   1.2  christos /* ARGSUSED */
    174   1.2  christos int
    175   1.2  christos compat_50_sys___fhstat40(struct lwp *l, const struct compat_50_sys___fhstat40_args *uap, register_t *retval)
    176   1.2  christos {
    177   1.2  christos 	/* {
    178   1.2  christos 		syscallarg(const void *) fhp;
    179   1.2  christos 		syscallarg(size_t) fh_size;
    180   1.2  christos 		syscallarg(struct stat30 *) sb;
    181   1.2  christos 	} */
    182   1.2  christos 	struct stat sb;
    183   1.2  christos 	struct stat30 osb;
    184   1.2  christos 	int error;
    185   1.2  christos 
    186   1.2  christos 	error = do_fhstat(l, SCARG(uap, fhp), SCARG(uap, fh_size), &sb);
    187   1.2  christos 	if (error)
    188   1.2  christos 		return error;
    189   1.2  christos 	cvtstat(&osb, &sb);
    190   1.2  christos 	error = copyout(&osb, SCARG(uap, sb), sizeof (osb));
    191   1.2  christos 	return error;
    192   1.2  christos }
    193   1.2  christos 
    194   1.2  christos static int
    195   1.2  christos compat_50_do_sys_utimes(struct lwp *l, struct vnode *vp, const char *path,
    196   1.2  christos     int flag, const struct timeval50 *tptr)
    197   1.2  christos {
    198   1.3  christos 	struct timeval tv[2], *tvp;
    199   1.2  christos 	struct timeval50 tv50[2];
    200   1.3  christos 	if (tptr) {
    201   1.3  christos 		int error = copyin(tptr, tv50, sizeof(tv50));
    202   1.3  christos 		if (error)
    203   1.3  christos 			return error;
    204   1.3  christos 		timeval50_to_timeval(&tv50[0], &tv[0]);
    205   1.3  christos 		timeval50_to_timeval(&tv50[1], &tv[1]);
    206   1.3  christos 		tvp = tv;
    207   1.3  christos 	} else
    208   1.3  christos 		tvp = NULL;
    209   1.3  christos 	return do_sys_utimes(l, vp, path, flag, tvp, UIO_SYSSPACE);
    210   1.2  christos }
    211   1.2  christos 
    212   1.2  christos /*
    213   1.2  christos  * Set the access and modification times given a path name; this
    214   1.2  christos  * version follows links.
    215   1.2  christos  */
    216   1.2  christos /* ARGSUSED */
    217   1.2  christos int
    218   1.2  christos compat_50_sys_utimes(struct lwp *l, const struct compat_50_sys_utimes_args *uap,
    219   1.2  christos     register_t *retval)
    220   1.2  christos {
    221   1.2  christos 	/* {
    222   1.2  christos 		syscallarg(const char *) path;
    223   1.2  christos 		syscallarg(const struct timeval50 *) tptr;
    224   1.2  christos 	} */
    225   1.2  christos 
    226   1.2  christos 	return compat_50_do_sys_utimes(l, NULL, SCARG(uap, path), FOLLOW,
    227   1.2  christos 	    SCARG(uap, tptr));
    228   1.2  christos }
    229   1.2  christos 
    230   1.2  christos /*
    231   1.2  christos  * Set the access and modification times given a file descriptor.
    232   1.2  christos  */
    233   1.2  christos /* ARGSUSED */
    234   1.2  christos int
    235   1.2  christos compat_50_sys_futimes(struct lwp *l,
    236   1.2  christos     const struct compat_50_sys_futimes_args *uap, register_t *retval)
    237   1.2  christos {
    238   1.2  christos 	/* {
    239   1.2  christos 		syscallarg(int) fd;
    240   1.2  christos 		syscallarg(const struct timeval50 *) tptr;
    241   1.2  christos 	} */
    242   1.2  christos 	int error;
    243   1.2  christos 	struct file *fp;
    244   1.2  christos 
    245   1.2  christos 	/* fd_getvnode() will use the descriptor for us */
    246   1.2  christos 	if ((error = fd_getvnode(SCARG(uap, fd), &fp)) != 0)
    247   1.2  christos 		return error;
    248   1.2  christos 	error = compat_50_do_sys_utimes(l, fp->f_data, NULL, 0,
    249   1.2  christos 	    SCARG(uap, tptr));
    250   1.2  christos 	fd_putfile(SCARG(uap, fd));
    251   1.2  christos 	return error;
    252   1.2  christos }
    253   1.2  christos 
    254   1.2  christos /*
    255   1.2  christos  * Set the access and modification times given a path name; this
    256   1.2  christos  * version does not follow links.
    257   1.2  christos  */
    258   1.2  christos int
    259   1.2  christos compat_50_sys_lutimes(struct lwp *l,
    260   1.2  christos     const struct compat_50_sys_lutimes_args *uap, register_t *retval)
    261   1.2  christos {
    262   1.2  christos 	/* {
    263   1.2  christos 		syscallarg(const char *) path;
    264   1.2  christos 		syscallarg(const struct timeval50 *) tptr;
    265   1.2  christos 	} */
    266   1.2  christos 
    267   1.2  christos 	return compat_50_do_sys_utimes(l, NULL, SCARG(uap, path), NOFOLLOW,
    268   1.2  christos 	    SCARG(uap, tptr));
    269   1.2  christos }
    270   1.2  christos 
    271   1.2  christos int
    272   1.2  christos compat_50_sys_lfs_segwait(struct lwp *l,
    273   1.2  christos     const struct compat_50_sys_lfs_segwait_args *uap, register_t *retval)
    274   1.2  christos {
    275   1.2  christos 	/* {
    276   1.2  christos 		syscallarg(fsid_t *) fsidp;
    277   1.2  christos 		syscallarg(struct timeval50 *) tv;
    278   1.2  christos 	} */
    279   1.2  christos #ifdef notyet
    280   1.2  christos 	struct timeval atv;
    281   1.2  christos 	struct timeval50 atv50;
    282   1.2  christos 	fsid_t fsid;
    283   1.2  christos 	int error;
    284   1.2  christos 
    285   1.2  christos 	/* XXX need we be su to segwait? */
    286   1.2  christos 	if ((error = kauth_authorize_generic(l->l_cred, KAUTH_GENERIC_ISSUSER,
    287   1.2  christos 	    NULL)) != 0)
    288   1.2  christos 		return (error);
    289   1.2  christos 	if ((error = copyin(SCARG(uap, fsidp), &fsid, sizeof(fsid_t))) != 0)
    290   1.2  christos 		return (error);
    291   1.2  christos 
    292   1.2  christos 	if (SCARG(uap, tv)) {
    293   1.2  christos 		error = copyin(SCARG(uap, tv), &atv50, sizeof(atv50));
    294   1.2  christos 		if (error)
    295   1.2  christos 			return (error);
    296   1.2  christos 		timeval50_to_timeval(&atv50, &atv);
    297   1.2  christos 		if (itimerfix(&atv))
    298   1.2  christos 			return (EINVAL);
    299   1.2  christos 	} else /* NULL or invalid */
    300   1.2  christos 		atv.tv_sec = atv.tv_usec = 0;
    301   1.2  christos 	return lfs_segwait(&fsid, &atv);
    302   1.2  christos #else
    303   1.2  christos 	return ENOSYS;
    304   1.2  christos #endif
    305   1.2  christos }
    306   1.2  christos 
    307   1.2  christos int
    308   1.2  christos compat_50_sys_mknod(struct lwp *l,
    309   1.2  christos     const struct compat_50_sys_mknod_args *uap, register_t *retval)
    310   1.2  christos {
    311   1.2  christos 	/* {
    312   1.2  christos 		syscallarg(const char *) path;
    313   1.2  christos 		syscallarg(mode_t) mode;
    314   1.2  christos 		syscallarg(uint32_t) dev;
    315   1.2  christos 	} */
    316   1.2  christos 	return do_sys_mknod(l, SCARG(uap, path), SCARG(uap, mode),
    317   1.5      haad 	    SCARG(uap, dev), retval, UIO_USERSPACE);
    318   1.2  christos }
    319   1.7    bouyer 
    320   1.7    bouyer /* ARGSUSED */
    321   1.7    bouyer int
    322   1.7    bouyer compat_50_sys_quotactl(struct lwp *l, const struct compat_50_sys_quotactl_args *uap, register_t *retval)
    323   1.7    bouyer {
    324   1.7    bouyer 	/* {
    325   1.7    bouyer 		syscallarg(const char *) path;
    326   1.7    bouyer 		syscallarg(int) cmd;
    327   1.7    bouyer 		syscallarg(int) uid;
    328   1.7    bouyer 		syscallarg(void *) arg;
    329   1.7    bouyer 	} */
    330   1.7    bouyer 	struct mount *mp;
    331   1.7    bouyer 	int error;
    332   1.7    bouyer 	uint8_t error8;
    333   1.7    bouyer 	struct vnode *vp;
    334   1.7    bouyer 	int q1cmd = SCARG(uap, cmd);
    335   1.7    bouyer 	prop_dictionary_t dict, data, cmd;
    336   1.7    bouyer 	prop_array_t cmds, datas;
    337   1.7    bouyer 	char *bufpath;
    338   1.7    bouyer 	struct dqblk dqblk;
    339  1.10  dholland 	struct quotaval qv[QUOTA_NLIMITS];
    340   1.8    bouyer 	uint64_t *values[QUOTA_NLIMITS];
    341  1.13  dholland 	int idtype;
    342   1.8    bouyer 
    343  1.10  dholland 	values[QUOTA_LIMIT_BLOCK] = &qv[QUOTA_LIMIT_BLOCK].qv_hardlimit;
    344  1.10  dholland 	values[QUOTA_LIMIT_FILE] = &qv[QUOTA_LIMIT_FILE].qv_hardlimit;
    345   1.7    bouyer 
    346   1.7    bouyer 	error = namei_simple_user(SCARG(uap, path),
    347   1.7    bouyer 				NSM_FOLLOW_TRYEMULROOT, &vp);
    348   1.7    bouyer 	if (error != 0)
    349   1.7    bouyer 		return (error);
    350   1.7    bouyer 	error = ENOMEM;
    351   1.7    bouyer 	mp = vp->v_mount;
    352   1.8    bouyer 	if ((dict = quota_prop_create()) == NULL)
    353   1.7    bouyer 		goto out;
    354   1.7    bouyer 	if ((cmds = prop_array_create()) == NULL)
    355   1.7    bouyer 		goto out_dict;
    356   1.7    bouyer 	if ((datas = prop_array_create()) == NULL)
    357   1.7    bouyer 		goto out_cmds;
    358   1.7    bouyer 
    359   1.7    bouyer 	switch((q1cmd & ~SUBCMDMASK) >> SUBCMDSHIFT) {
    360   1.7    bouyer 	case Q_QUOTAON:
    361   1.7    bouyer 		data = prop_dictionary_create();
    362   1.7    bouyer 		if (data == NULL)
    363   1.7    bouyer 			goto out_datas;
    364   1.7    bouyer 		bufpath = malloc(PATH_MAX * sizeof(char), M_TEMP, M_WAITOK);
    365   1.7    bouyer 		if (bufpath == NULL)
    366   1.7    bouyer 			goto out_data;
    367   1.7    bouyer 		error = copyinstr(SCARG(uap, arg), bufpath, PATH_MAX, NULL);
    368   1.7    bouyer 		if (error != 0) {
    369   1.7    bouyer 			free(bufpath, M_TEMP);
    370   1.7    bouyer 			goto out_data;
    371   1.7    bouyer 		}
    372   1.7    bouyer 		if (!prop_dictionary_set_cstring(data, "quotafile", bufpath))
    373   1.7    bouyer 			error = ENOMEM;
    374   1.7    bouyer 		free(bufpath, M_TEMP);
    375   1.7    bouyer 		if (error)
    376   1.7    bouyer 			goto out_data;
    377   1.7    bouyer 		error = ENOMEM;
    378   1.7    bouyer 		if (!prop_array_add_and_rel(datas, data))
    379   1.7    bouyer 			goto out_datas;
    380  1.13  dholland 		idtype = quota_idtype_from_ufs(q1cmd & SUBCMDMASK);
    381   1.8    bouyer 		if (!quota_prop_add_command(cmds, "quotaon",
    382  1.13  dholland 		    ufs_quota_class_names[idtype],
    383   1.8    bouyer 		    datas))
    384   1.7    bouyer 			goto out_cmds;
    385   1.7    bouyer 		goto do_quotaonoff;
    386   1.7    bouyer 
    387   1.7    bouyer 	case Q_QUOTAOFF:
    388   1.7    bouyer 		error = ENOMEM;
    389  1.13  dholland 		idtype = quota_idtype_from_ufs(q1cmd & SUBCMDMASK);
    390   1.8    bouyer 		if (!quota_prop_add_command(cmds, "quotaoff",
    391  1.13  dholland 		    ufs_quota_class_names[idtype],
    392   1.8    bouyer 		    datas))
    393   1.7    bouyer 			goto out_cmds;
    394   1.7    bouyer do_quotaonoff:
    395   1.7    bouyer 		if (!prop_dictionary_set_and_rel(dict, "commands", cmds))
    396   1.7    bouyer 			goto out_dict;
    397  1.12  dholland 		error = vfs_quotactl(mp, dict);
    398   1.7    bouyer 		if (error)
    399   1.7    bouyer 			goto out_dict;
    400   1.8    bouyer 		if ((error = quota_get_cmds(dict, &cmds)) != 0)
    401   1.7    bouyer 			goto out_dict;
    402   1.7    bouyer 		cmd = prop_array_get(cmds, 0);
    403   1.7    bouyer 		if (cmd == NULL) {
    404   1.7    bouyer 			error = EINVAL;
    405   1.7    bouyer 			goto out_dict;
    406   1.7    bouyer 		}
    407   1.7    bouyer 		if (!prop_dictionary_get_int8(cmd, "return", &error8)) {
    408   1.7    bouyer 			error = EINVAL;
    409   1.7    bouyer 			goto out_dict;
    410   1.7    bouyer 		}
    411   1.7    bouyer 		error = error8;
    412   1.7    bouyer 		goto out_dict;
    413   1.7    bouyer 
    414   1.7    bouyer 	case Q_GETQUOTA:
    415   1.7    bouyer 		error = ENOMEM;
    416   1.7    bouyer 		data = prop_dictionary_create();
    417   1.7    bouyer 		if (data == NULL)
    418   1.7    bouyer 			goto out_datas;
    419   1.7    bouyer 		if (!prop_dictionary_set_uint32(data, "id", SCARG(uap, uid)))
    420   1.7    bouyer 			goto out_data;
    421   1.7    bouyer 		if (!prop_array_add_and_rel(datas, data))
    422   1.7    bouyer 			goto out_datas;
    423  1.13  dholland 		idtype = quota_idtype_from_ufs(q1cmd & SUBCMDMASK);
    424   1.8    bouyer 		if (!quota_prop_add_command(cmds, "get",
    425  1.13  dholland 		    ufs_quota_class_names[idtype],
    426   1.8    bouyer 		    datas))
    427   1.7    bouyer 			goto out_cmds;
    428   1.7    bouyer 		if (!prop_dictionary_set_and_rel(dict, "commands", cmds))
    429   1.7    bouyer 			goto out_dict;
    430  1.12  dholland 		error = vfs_quotactl(mp, dict);
    431   1.7    bouyer 		if (error)
    432   1.7    bouyer 			goto out_dict;
    433   1.8    bouyer 		if ((error = quota_get_cmds(dict, &cmds)) != 0)
    434   1.7    bouyer 			goto out_dict;
    435   1.7    bouyer 		cmd = prop_array_get(cmds, 0);
    436   1.7    bouyer 		if (cmd == NULL) {
    437   1.7    bouyer 			error = EINVAL;
    438   1.7    bouyer 			goto out_dict;
    439   1.7    bouyer 		}
    440   1.7    bouyer 		if (!prop_dictionary_get_int8(cmd, "return", &error8)) {
    441   1.7    bouyer 			error = EINVAL;
    442   1.7    bouyer 			goto out_dict;
    443   1.7    bouyer 		}
    444   1.7    bouyer 		error = error8;
    445   1.7    bouyer 		if (error)
    446   1.7    bouyer 			goto out_dict;
    447   1.7    bouyer 		datas = prop_dictionary_get(cmd, "data");
    448   1.7    bouyer 		error = EINVAL;
    449   1.7    bouyer 		if (datas == NULL)
    450   1.7    bouyer 			goto out_dict;
    451   1.7    bouyer 		data = prop_array_get(datas, 0);
    452   1.7    bouyer 		if (data == NULL)
    453   1.7    bouyer 			goto out_dict;
    454   1.8    bouyer 		error = proptoquota64(data, values,
    455   1.8    bouyer 		    ufs_quota_entry_names, UFS_QUOTA_NENTRIES,
    456   1.8    bouyer 		    ufs_quota_limit_names, QUOTA_NLIMITS);
    457   1.7    bouyer 		if (error)
    458   1.7    bouyer 			goto out_dict;
    459  1.11  dholland 		quotavals_to_dqblk(&qv[QUOTA_LIMIT_BLOCK],
    460  1.11  dholland 				   &qv[QUOTA_LIMIT_FILE],
    461  1.11  dholland 				   &dqblk);
    462   1.7    bouyer 		error = copyout(&dqblk, SCARG(uap, arg), sizeof(dqblk));
    463   1.7    bouyer 		goto out_dict;
    464   1.7    bouyer 
    465   1.7    bouyer 	case Q_SETQUOTA:
    466   1.7    bouyer 		error = copyin(SCARG(uap, arg), &dqblk, sizeof(dqblk));
    467   1.7    bouyer 		if (error)
    468   1.7    bouyer 			goto out_datas;
    469  1.11  dholland 		dqblk_to_quotavals(&dqblk, &qv[QUOTA_LIMIT_BLOCK],
    470  1.11  dholland 				   &qv[QUOTA_LIMIT_FILE]);
    471   1.7    bouyer 
    472   1.7    bouyer 		error = ENOMEM;
    473   1.8    bouyer 		data = quota64toprop(SCARG(uap, uid), 0, values,
    474   1.8    bouyer 		    ufs_quota_entry_names, UFS_QUOTA_NENTRIES,
    475   1.8    bouyer 		    ufs_quota_limit_names, QUOTA_NLIMITS);
    476   1.7    bouyer 		if (data == NULL)
    477   1.7    bouyer 			goto out_data;
    478   1.7    bouyer 		if (!prop_array_add_and_rel(datas, data))
    479   1.7    bouyer 			goto out_datas;
    480  1.13  dholland 		idtype = quota_idtype_from_ufs(q1cmd & SUBCMDMASK);
    481   1.8    bouyer 		if (!quota_prop_add_command(cmds, "set",
    482  1.13  dholland 		    ufs_quota_class_names[idtype],
    483   1.8    bouyer 		    datas))
    484   1.7    bouyer 			goto out_cmds;
    485   1.7    bouyer 		if (!prop_dictionary_set_and_rel(dict, "commands", cmds))
    486   1.7    bouyer 			goto out_dict;
    487  1.12  dholland 		error = vfs_quotactl(mp, dict);
    488   1.7    bouyer 		if (error)
    489   1.7    bouyer 			goto out_dict;
    490   1.8    bouyer 		if ((error = quota_get_cmds(dict, &cmds)) != 0)
    491   1.7    bouyer 			goto out_dict;
    492   1.7    bouyer 		cmd = prop_array_get(cmds, 0);
    493   1.7    bouyer 		if (cmd == NULL) {
    494   1.7    bouyer 			error = EINVAL;
    495   1.7    bouyer 			goto out_dict;
    496   1.7    bouyer 		}
    497   1.7    bouyer 		if (!prop_dictionary_get_int8(cmd, "return", &error8)) {
    498   1.7    bouyer 			error = EINVAL;
    499   1.7    bouyer 			goto out_dict;
    500   1.7    bouyer 		}
    501   1.7    bouyer 		error = error8;
    502   1.7    bouyer 		goto out_dict;
    503   1.7    bouyer 
    504   1.7    bouyer 	case Q_SYNC:
    505   1.7    bouyer 		/*
    506   1.7    bouyer 		 * not supported but used only to see if quota is supported,
    507   1.7    bouyer 		 * emulate with a "get version"
    508   1.7    bouyer 		 */
    509   1.7    bouyer 		error = ENOMEM;
    510  1.13  dholland 		idtype = quota_idtype_from_ufs(q1cmd & SUBCMDMASK);
    511   1.8    bouyer 		if (!quota_prop_add_command(cmds, "get version",
    512  1.13  dholland 		    ufs_quota_class_names[idtype],
    513   1.8    bouyer 		    datas))
    514   1.7    bouyer 			goto out_cmds;
    515   1.7    bouyer 		if (!prop_dictionary_set_and_rel(dict, "commands", cmds))
    516   1.7    bouyer 			goto out_dict;
    517  1.12  dholland 		error = vfs_quotactl(mp, dict);
    518   1.7    bouyer 		if (error)
    519   1.7    bouyer 			goto out_dict;
    520   1.8    bouyer 		if ((error = quota_get_cmds(dict, &cmds)) != 0)
    521   1.7    bouyer 			goto out_dict;
    522   1.7    bouyer 		cmd = prop_array_get(cmds, 0);
    523   1.7    bouyer 		if (cmd == NULL) {
    524   1.7    bouyer 			error = EINVAL;
    525   1.7    bouyer 			goto out_dict;
    526   1.7    bouyer 		}
    527   1.7    bouyer 		if (!prop_dictionary_get_int8(cmd, "return", &error8)) {
    528   1.7    bouyer 			error = EINVAL;
    529   1.7    bouyer 			goto out_dict;
    530   1.7    bouyer 		}
    531   1.7    bouyer 		error = error8;
    532   1.7    bouyer 		goto out_dict;
    533   1.7    bouyer 
    534   1.7    bouyer 	case Q_SETUSE:
    535   1.7    bouyer 	default:
    536   1.7    bouyer 		error = EOPNOTSUPP;
    537   1.7    bouyer 		goto out_datas;
    538   1.7    bouyer 	}
    539   1.7    bouyer out_data:
    540   1.7    bouyer 	prop_object_release(data);
    541   1.7    bouyer out_datas:
    542   1.7    bouyer 	prop_object_release(datas);
    543   1.7    bouyer out_cmds:
    544   1.7    bouyer 	prop_object_release(cmds);
    545   1.7    bouyer out_dict:
    546   1.7    bouyer 	prop_object_release(dict);
    547   1.7    bouyer out:
    548   1.7    bouyer 	vrele(vp);
    549   1.7    bouyer 	return error;
    550   1.7    bouyer }
    551