Home | History | Annotate | Line # | Download | only in common
      1  1.4  dholland /*	$NetBSD: compat_50_quota.c,v 1.4 2022/09/21 07:15:24 dholland Exp $ */
      2  1.1  pgoyette 
      3  1.1  pgoyette /*-
      4  1.1  pgoyette  * Copyright (c) 2008 The NetBSD Foundation, Inc.
      5  1.1  pgoyette  * All rights reserved.
      6  1.1  pgoyette  *
      7  1.1  pgoyette  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1  pgoyette  * by Christos Zoulas.
      9  1.1  pgoyette  *
     10  1.1  pgoyette  * Redistribution and use in source and binary forms, with or without
     11  1.1  pgoyette  * modification, are permitted provided that the following conditions
     12  1.1  pgoyette  * are met:
     13  1.1  pgoyette  * 1. Redistributions of source code must retain the above copyright
     14  1.1  pgoyette  *    notice, this list of conditions and the following disclaimer.
     15  1.1  pgoyette  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1  pgoyette  *    notice, this list of conditions and the following disclaimer in the
     17  1.1  pgoyette  *    documentation and/or other materials provided with the distribution.
     18  1.1  pgoyette  *
     19  1.1  pgoyette  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.1  pgoyette  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.1  pgoyette  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.1  pgoyette  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.1  pgoyette  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.1  pgoyette  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.1  pgoyette  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.1  pgoyette  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.1  pgoyette  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.1  pgoyette  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.1  pgoyette  * POSSIBILITY OF SUCH DAMAGE.
     30  1.1  pgoyette  */
     31  1.1  pgoyette #include <sys/cdefs.h>
     32  1.4  dholland __KERNEL_RCSID(0, "$NetBSD: compat_50_quota.c,v 1.4 2022/09/21 07:15:24 dholland Exp $");
     33  1.1  pgoyette 
     34  1.1  pgoyette #if defined(_KERNEL_OPT)
     35  1.1  pgoyette #include "opt_compat_netbsd.h"
     36  1.1  pgoyette #endif
     37  1.1  pgoyette 
     38  1.1  pgoyette #include <sys/module.h>
     39  1.1  pgoyette #include <sys/namei.h>
     40  1.1  pgoyette #include <sys/param.h>
     41  1.1  pgoyette #include <sys/quota.h>
     42  1.1  pgoyette #include <sys/quotactl.h>
     43  1.1  pgoyette #include <sys/systm.h>
     44  1.1  pgoyette #include <sys/syscall.h>
     45  1.1  pgoyette #include <sys/syscallvar.h>
     46  1.1  pgoyette #include <sys/syscallargs.h>
     47  1.1  pgoyette #include <sys/vfs_syscalls.h>
     48  1.1  pgoyette #include <sys/vnode.h>
     49  1.1  pgoyette 
     50  1.1  pgoyette #include <ufs/ufs/quota1.h>
     51  1.1  pgoyette 
     52  1.1  pgoyette static const struct syscall_package vfs_syscalls_50_quota_syscalls[] = {
     53  1.1  pgoyette 	{ SYS_compat_50_quotactl, 0, (sy_call_t *)compat_50_sys_quotactl },
     54  1.1  pgoyette 	{ 0, 0, NULL }
     55  1.1  pgoyette };
     56  1.1  pgoyette 
     57  1.1  pgoyette /* ARGSUSED */
     58  1.1  pgoyette int
     59  1.1  pgoyette compat_50_sys_quotactl(struct lwp *l, const struct compat_50_sys_quotactl_args *uap, register_t *retval)
     60  1.1  pgoyette {
     61  1.1  pgoyette 	/* {
     62  1.1  pgoyette 		syscallarg(const char *) path;
     63  1.1  pgoyette 		syscallarg(int) cmd;
     64  1.1  pgoyette 		syscallarg(int) uid;
     65  1.1  pgoyette 		syscallarg(void *) arg;
     66  1.1  pgoyette 	} */
     67  1.1  pgoyette 	struct vnode *vp;
     68  1.1  pgoyette 	struct mount *mp;
     69  1.1  pgoyette 	int q1cmd;
     70  1.1  pgoyette 	int idtype;
     71  1.1  pgoyette 	char *qfile;
     72  1.1  pgoyette 	struct dqblk dqblk;
     73  1.1  pgoyette 	struct quotakey key;
     74  1.1  pgoyette 	struct quotaval blocks, files;
     75  1.1  pgoyette 	struct quotastat qstat;
     76  1.1  pgoyette 	int error;
     77  1.1  pgoyette 
     78  1.1  pgoyette 	error = namei_simple_user(SCARG(uap, path),
     79  1.1  pgoyette 				NSM_FOLLOW_TRYEMULROOT, &vp);
     80  1.1  pgoyette 	if (error != 0)
     81  1.1  pgoyette 		return (error);
     82  1.1  pgoyette 
     83  1.1  pgoyette 	mp = vp->v_mount;
     84  1.1  pgoyette 	q1cmd = SCARG(uap, cmd);
     85  1.1  pgoyette 	idtype = quota_idtype_from_ufs(q1cmd & SUBCMDMASK);
     86  1.4  dholland 	if (idtype == -1) {
     87  1.4  dholland 		return EINVAL;
     88  1.4  dholland 	}
     89  1.1  pgoyette 
     90  1.1  pgoyette 	switch ((q1cmd & ~SUBCMDMASK) >> SUBCMDSHIFT) {
     91  1.1  pgoyette 	case Q_QUOTAON:
     92  1.1  pgoyette 		qfile = PNBUF_GET();
     93  1.1  pgoyette 		error = copyinstr(SCARG(uap, arg), qfile, PATH_MAX, NULL);
     94  1.1  pgoyette 		if (error != 0) {
     95  1.1  pgoyette 			PNBUF_PUT(qfile);
     96  1.1  pgoyette 			break;
     97  1.1  pgoyette 		}
     98  1.1  pgoyette 
     99  1.1  pgoyette 		error = vfs_quotactl_quotaon(mp, idtype, qfile);
    100  1.1  pgoyette 
    101  1.1  pgoyette 		PNBUF_PUT(qfile);
    102  1.1  pgoyette 		break;
    103  1.1  pgoyette 
    104  1.1  pgoyette 	case Q_QUOTAOFF:
    105  1.1  pgoyette 		error = vfs_quotactl_quotaoff(mp, idtype);
    106  1.1  pgoyette 		break;
    107  1.1  pgoyette 
    108  1.1  pgoyette 	case Q_GETQUOTA:
    109  1.1  pgoyette 		key.qk_idtype = idtype;
    110  1.1  pgoyette 		key.qk_id = SCARG(uap, uid);
    111  1.1  pgoyette 
    112  1.1  pgoyette 		key.qk_objtype = QUOTA_OBJTYPE_BLOCKS;
    113  1.1  pgoyette 		error = vfs_quotactl_get(mp, &key, &blocks);
    114  1.1  pgoyette 		if (error) {
    115  1.1  pgoyette 			break;
    116  1.1  pgoyette 		}
    117  1.1  pgoyette 
    118  1.1  pgoyette 		key.qk_objtype = QUOTA_OBJTYPE_FILES;
    119  1.1  pgoyette 		error = vfs_quotactl_get(mp, &key, &files);
    120  1.1  pgoyette 		if (error) {
    121  1.1  pgoyette 			break;
    122  1.1  pgoyette 		}
    123  1.1  pgoyette 
    124  1.1  pgoyette 		quotavals_to_dqblk(&blocks, &files, &dqblk);
    125  1.1  pgoyette 		error = copyout(&dqblk, SCARG(uap, arg), sizeof(dqblk));
    126  1.1  pgoyette 		break;
    127  1.1  pgoyette 
    128  1.1  pgoyette 	case Q_SETQUOTA:
    129  1.1  pgoyette 		error = copyin(SCARG(uap, arg), &dqblk, sizeof(dqblk));
    130  1.1  pgoyette 		if (error) {
    131  1.1  pgoyette 			break;
    132  1.1  pgoyette 		}
    133  1.1  pgoyette 		dqblk_to_quotavals(&dqblk, &blocks, &files);
    134  1.1  pgoyette 
    135  1.1  pgoyette 		key.qk_idtype = idtype;
    136  1.1  pgoyette 		key.qk_id = SCARG(uap, uid);
    137  1.1  pgoyette 
    138  1.1  pgoyette 		key.qk_objtype = QUOTA_OBJTYPE_BLOCKS;
    139  1.1  pgoyette 		error = vfs_quotactl_put(mp, &key, &blocks);
    140  1.1  pgoyette 		if (error) {
    141  1.1  pgoyette 			break;
    142  1.1  pgoyette 		}
    143  1.1  pgoyette 
    144  1.1  pgoyette 		key.qk_objtype = QUOTA_OBJTYPE_FILES;
    145  1.1  pgoyette 		error = vfs_quotactl_put(mp, &key, &files);
    146  1.1  pgoyette 		break;
    147  1.1  pgoyette 
    148  1.1  pgoyette 	case Q_SYNC:
    149  1.1  pgoyette 		/*
    150  1.1  pgoyette 		 * not supported but used only to see if quota is supported,
    151  1.1  pgoyette 		 * emulate with stat
    152  1.1  pgoyette 		 *
    153  1.1  pgoyette 		 * XXX should probably be supported
    154  1.1  pgoyette 		 */
    155  1.1  pgoyette 		(void)idtype; /* not used */
    156  1.1  pgoyette 
    157  1.1  pgoyette 		error = vfs_quotactl_stat(mp, &qstat);
    158  1.1  pgoyette 		break;
    159  1.1  pgoyette 
    160  1.1  pgoyette 	case Q_SETUSE:
    161  1.1  pgoyette 	default:
    162  1.1  pgoyette 		error = EOPNOTSUPP;
    163  1.1  pgoyette 		break;
    164  1.1  pgoyette 	}
    165  1.1  pgoyette 
    166  1.1  pgoyette 	vrele(vp);
    167  1.1  pgoyette 	return error;
    168  1.1  pgoyette }
    169  1.1  pgoyette 
    170  1.3  pgoyette MODULE(MODULE_CLASS_EXEC, compat_50_quota, "compat_50,ufs");
    171  1.1  pgoyette 
    172  1.1  pgoyette static int
    173  1.1  pgoyette compat_50_quota_modcmd(modcmd_t cmd, void *arg)
    174  1.1  pgoyette {
    175  1.1  pgoyette 
    176  1.1  pgoyette 	switch (cmd) {
    177  1.1  pgoyette 	case MODULE_CMD_INIT:
    178  1.1  pgoyette         	return syscall_establish(NULL, vfs_syscalls_50_quota_syscalls);
    179  1.1  pgoyette 	case MODULE_CMD_FINI:
    180  1.1  pgoyette         	return syscall_disestablish(NULL, vfs_syscalls_50_quota_syscalls);
    181  1.1  pgoyette 	default:
    182  1.1  pgoyette 		return ENOTTY;
    183  1.1  pgoyette 	}
    184  1.1  pgoyette }
    185