1 /* $NetBSD: ulfs_quota2.h,v 1.4 2013/06/06 00:49:28 dholland Exp $ */ 2 /* from NetBSD: quota2.h,v 1.9 2012/02/05 14:19:04 dholland Exp */ 3 4 /*- 5 * Copyright (c) 2010 Manuel Bouyer 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 * POSSIBILITY OF SUCH DAMAGE. 28 */ 29 30 #ifndef _UFS_LFS_ULFS_QUOTA2_H_ 31 #define _UFS_LFS_ULFS_QUOTA2_H_ 32 #include <ufs/lfs/ulfs_quotacommon.h> 33 34 35 /* New disk quota implementation. In this implementation, the quota datas 36 * (default values, user limits and current usage) are part of the filesystem 37 * metadata. On FFS, this will be in a hidden, unlinked inode. fsck_ffs is 38 * responsible for checking quotas with the rest of the filesystem integrity, 39 * and quotas metadata are also covered by the filesystem journal if any. 40 * quota enable/disable is done on a filesystem basis via flags in the 41 * superblock 42 */ 43 44 /* 45 * The quota file is comprised of 2 parts, the header and the entries. 46 * The header contains global informations, and head of list of quota entries. 47 * A quota entry can either be in the free list, or one of the hash lists. 48 */ 49 50 /* description of a block or inode quota */ 51 struct quota2_val { 52 uint64_t q2v_hardlimit; /* absolute limit */ 53 uint64_t q2v_softlimit; /* overflowable limit */ 54 uint64_t q2v_cur; /* current usage */ 55 int64_t q2v_time; /* grace expiration date for softlimit overflow */ 56 int64_t q2v_grace; /* allowed time for softlimit overflow */ 57 }; 58 59 /* 60 * On-disk description of a user or group quota 61 * These entries are keept as linked list, either in one of the hash HEAD, 62 * or in the free list. 63 */ 64 65 #define N_QL 2 66 #define QL_BLOCK 0 67 #define QL_FILE 1 68 #define INITQLNAMES { \ 69 [QL_BLOCK] = "block", \ 70 [QL_FILE] = "file", \ 71 } 72 73 struct quota2_entry { 74 /* block & inode limits and status */ 75 struct quota2_val q2e_val[N_QL]; 76 /* pointer to next entry for this list (offset in the file) */ 77 uint64_t q2e_next; 78 /* ownership information */ 79 uint32_t q2e_uid; 80 uint32_t q2e_pad; 81 }; 82 83 /* header present at the start of the quota file */ 84 struct quota2_header { 85 uint32_t q2h_magic_number; 86 uint8_t q2h_type; /* quota type, see below */ 87 uint8_t q2h_hash_shift; /* bytes used for hash index */ 88 uint16_t q2h_hash_size; /* size of hash table */ 89 /* default values applied to new entries */ 90 struct quota2_entry q2h_defentry; 91 /* head of free quota2_entry list */ 92 uint64_t q2h_free; 93 /* variable-sized hash table */ 94 uint64_t q2h_entries[0]; 95 }; 96 97 #define Q2_HEAD_MAGIC 0xb746915e 98 99 /* superblock flags */ 100 #define FS_Q2_DO_TYPE(type) (0x01 << (type)) 101 102 #define off2qindex(hsize, off) (((off) - (hsize)) / sizeof(struct quota2_entry)) 103 #define qindex2off(hsize, idx) \ 104 ((daddr_t)(idx) * sizeof(struct quota2_entry) + (hsize)) 105 106 /* quota2_subr.c */ 107 void lfsquota2_addfreeq2e(struct quota2_header *, void *, uint64_t, uint64_t, int); 108 void lfsquota2_create_blk0(uint64_t, void *bp, int, int, int); 109 void lfsquota2_ulfs_rwq2v(const struct quota2_val *, struct quota2_val *, int); 110 void lfsquota2_ulfs_rwq2e(const struct quota2_entry *, struct quota2_entry *, int); 111 112 /* 113 * Return codes for lfsquota_check_limit() 114 */ 115 116 #define QL_S_ALLOW_OK 0x00 /* below soft limit */ 117 #define QL_S_ALLOW_SOFT 0x01 /* over soft limit */ 118 #define QL_S_DENY_GRACE 0x02 /* over soft limit, grace time expired */ 119 #define QL_S_DENY_HARD 0x03 /* over hard limit */ 120 121 #define QL_F_CROSS 0x80 /* crossing soft limit */ 122 123 #define QL_STATUS(x) ((x) & 0x0f) 124 #define QL_FLAGS(x) ((x) & 0xf0) 125 126 /* check a quota usage against limits */ 127 int lfsquota_check_limit(uint64_t, uint64_t, uint64_t, uint64_t, time_t, time_t); 128 129 #endif /* _UFS_LFS_ULFS_QUOTA2_H_ */ 130