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