Home | History | Annotate | Line # | Download | only in libquota
      1 /*	$NetBSD: quota_schema.c,v 1.7 2012/02/01 05:46:46 dholland Exp $	*/
      2 /*-
      3  * Copyright (c) 2011 The NetBSD Foundation, Inc.
      4  * All rights reserved.
      5  *
      6  * This code is derived from software contributed to The NetBSD Foundation
      7  * by David A. Holland.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     19  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     20  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     21  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     22  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     28  * POSSIBILITY OF SUCH DAMAGE.
     29  */
     30 
     31 #include <sys/cdefs.h>
     32 __RCSID("$NetBSD: quota_schema.c,v 1.7 2012/02/01 05:46:46 dholland Exp $");
     33 
     34 #include <sys/types.h>
     35 #include <sys/statvfs.h>
     36 #include <stdlib.h>
     37 #include <string.h>
     38 #include <errno.h>
     39 
     40 #include <quota.h>
     41 #include "quotapvt.h"
     42 
     43 /*
     44  * Functions for getting information about idtypes and such.
     45  */
     46 
     47 const char *
     48 quota_getimplname(struct quotahandle *qh)
     49 {
     50 	switch (qh->qh_mode) {
     51 	    case QUOTA_MODE_NFS:
     52 		/* XXX this should maybe report the rquotad protocol version */
     53 		return "nfs via rquotad";
     54 
     55 	    case QUOTA_MODE_OLDFILES:
     56 		return __quota_oldfiles_getimplname(qh);
     57 
     58 	    case QUOTA_MODE_KERNEL:
     59 		return __quota_kernel_getimplname(qh);
     60 
     61 	    default:
     62 		break;
     63 	}
     64 	errno = EINVAL;
     65 	return NULL;
     66 }
     67 
     68 unsigned
     69 quota_getrestrictions(struct quotahandle *qh)
     70 {
     71 	switch (qh->qh_mode) {
     72 	    case QUOTA_MODE_NFS:
     73 		/* XXX this should maybe report the rquotad protocol version */
     74 		return QUOTA_RESTRICT_32BIT | QUOTA_RESTRICT_READONLY;
     75 
     76 	    case QUOTA_MODE_OLDFILES:
     77 		return QUOTA_RESTRICT_NEEDSQUOTACHECK |
     78 			QUOTA_RESTRICT_UNIFORMGRACE |
     79 			QUOTA_RESTRICT_32BIT;
     80 
     81 	    case QUOTA_MODE_KERNEL:
     82 		return __quota_kernel_getrestrictions(qh);
     83 
     84 	    default:
     85 		break;
     86 	}
     87 	errno = EINVAL;
     88 	return 0;
     89 }
     90 
     91 int
     92 quota_getnumidtypes(struct quotahandle *qh)
     93 {
     94 	switch (qh->qh_mode) {
     95 	    case QUOTA_MODE_NFS:
     96 		/* XXX for old rquotad versions this should be 1... */
     97 		return 2;
     98 
     99 	    case QUOTA_MODE_KERNEL:
    100 		return __quota_kernel_getnumidtypes(qh);
    101 
    102 	    case QUOTA_MODE_OLDFILES:
    103 	    default:
    104 		break;
    105 	}
    106 	return 2;
    107 }
    108 
    109 const char *
    110 quota_idtype_getname(struct quotahandle *qh, int idtype)
    111 {
    112 	switch (qh->qh_mode) {
    113 	    case QUOTA_MODE_KERNEL:
    114 		return __quota_kernel_idtype_getname(qh, idtype);
    115 
    116 	    case QUOTA_MODE_NFS:
    117 	    case QUOTA_MODE_OLDFILES:
    118 		break;
    119 	}
    120 
    121 	switch (idtype) {
    122 	    case QUOTA_IDTYPE_USER:
    123 		return "user";
    124 
    125 	    case QUOTA_IDTYPE_GROUP:
    126 		return "group";
    127 
    128 	    default:
    129 		break;
    130 	}
    131 	errno = EINVAL;
    132 	return "???";
    133 }
    134 
    135 int
    136 quota_getnumobjtypes(struct quotahandle *qh)
    137 {
    138 	switch (qh->qh_mode) {
    139 	    case QUOTA_MODE_KERNEL:
    140 		return __quota_kernel_getnumobjtypes(qh);
    141 
    142 	    case QUOTA_MODE_NFS:
    143 	    case QUOTA_MODE_OLDFILES:
    144 	    default:
    145 		break;
    146 	}
    147 	return 2;
    148 }
    149 
    150 const char *
    151 quota_objtype_getname(struct quotahandle *qh, int objtype)
    152 {
    153 	switch (qh->qh_mode) {
    154 	    case QUOTA_MODE_KERNEL:
    155 		return __quota_kernel_objtype_getname(qh, objtype);
    156 	    case QUOTA_MODE_NFS:
    157 	    case QUOTA_MODE_OLDFILES:
    158 	    default:
    159 		break;
    160 	}
    161 
    162 	switch (objtype) {
    163 	    case QUOTA_OBJTYPE_BLOCKS:
    164 		return "block";
    165 	    case QUOTA_OBJTYPE_FILES:
    166 		return "file";
    167 	    default:
    168 		break;
    169 	}
    170 	errno = EINVAL;
    171 	return "???"; /* ? */
    172 }
    173 
    174 int
    175 quota_objtype_isbytes(struct quotahandle *qh, int objtype)
    176 {
    177 	switch (qh->qh_mode) {
    178 	    case QUOTA_MODE_KERNEL:
    179 		return __quota_kernel_objtype_isbytes(qh, objtype);
    180 	    case QUOTA_MODE_NFS:
    181 	    case QUOTA_MODE_OLDFILES:
    182 	    default:
    183 		break;
    184 	}
    185 
    186 	switch (objtype) {
    187 	    case QUOTA_OBJTYPE_BLOCKS:
    188 		return 1;
    189 	    case QUOTA_OBJTYPE_FILES:
    190 		return 0;
    191 	    default:
    192 		break;
    193 	}
    194 	errno = EINVAL;
    195 	return 0; /* ? */
    196 }
    197