11.4Sdholland/*	$NetBSD: ulfs_quota2.h,v 1.4 2013/06/06 00:49:28 dholland Exp $	*/
21.1Sdholland/*  from NetBSD: quota2.h,v 1.9 2012/02/05 14:19:04 dholland Exp  */
31.1Sdholland
41.1Sdholland/*-
51.1Sdholland  * Copyright (c) 2010 Manuel Bouyer
61.1Sdholland  * All rights reserved.
71.1Sdholland  *
81.1Sdholland  * Redistribution and use in source and binary forms, with or without
91.1Sdholland  * modification, are permitted provided that the following conditions
101.1Sdholland  * are met:
111.1Sdholland  * 1. Redistributions of source code must retain the above copyright
121.1Sdholland  *    notice, this list of conditions and the following disclaimer.
131.1Sdholland  * 2. Redistributions in binary form must reproduce the above copyright
141.1Sdholland  *    notice, this list of conditions and the following disclaimer in the
151.1Sdholland  *    documentation and/or other materials provided with the distribution.
161.1Sdholland  *
171.1Sdholland  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
181.1Sdholland  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
191.1Sdholland  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
201.1Sdholland  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
211.1Sdholland  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
221.1Sdholland  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
231.1Sdholland  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
241.1Sdholland  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
251.1Sdholland  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
261.1Sdholland  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
271.1Sdholland  * POSSIBILITY OF SUCH DAMAGE.
281.1Sdholland  */
291.1Sdholland
301.3Sdholland#ifndef _UFS_LFS_ULFS_QUOTA2_H_
311.3Sdholland#define _UFS_LFS_ULFS_QUOTA2_H_
321.2Sdholland#include <ufs/lfs/ulfs_quotacommon.h>
331.1Sdholland
341.1Sdholland
351.1Sdholland/* New disk quota implementation. In this implementation, the quota datas
361.1Sdholland * (default values, user limits and current usage) are part of the filesystem
371.1Sdholland * metadata. On FFS, this will be in a hidden, unlinked inode. fsck_ffs is
381.1Sdholland * responsible for checking quotas with the rest of the filesystem integrity,
391.1Sdholland * and quotas metadata are also covered by the filesystem journal if any.
401.1Sdholland * quota enable/disable is done on a filesystem basis via flags in the
411.1Sdholland * superblock
421.1Sdholland */
431.1Sdholland
441.1Sdholland/*
451.1Sdholland * The quota file is comprised of 2 parts, the header and the entries.
461.1Sdholland * The header contains global informations, and head of list of quota entries.
471.1Sdholland * A quota entry can either be in the free list, or one of the hash lists.
481.1Sdholland */
491.1Sdholland
501.1Sdholland/* description of a block or inode quota */
511.1Sdhollandstruct quota2_val {
521.1Sdholland	uint64_t q2v_hardlimit; /* absolute limit */
531.1Sdholland	uint64_t q2v_softlimit; /* overflowable limit */
541.1Sdholland	uint64_t q2v_cur; /* current usage */
551.1Sdholland	int64_t q2v_time; /* grace expiration date for softlimit overflow */
561.1Sdholland	int64_t q2v_grace; /* allowed time for softlimit overflow */
571.1Sdholland};
581.1Sdholland
591.1Sdholland/*
601.1Sdholland * On-disk description of a user or group quota
611.1Sdholland * These entries are keept as linked list, either in one of the hash HEAD,
621.1Sdholland * or in the free list.
631.1Sdholland */
641.1Sdholland
651.1Sdholland#define N_QL 2
661.1Sdholland#define QL_BLOCK 0
671.1Sdholland#define QL_FILE 1
681.1Sdholland#define INITQLNAMES { \
691.1Sdholland	[QL_BLOCK] = "block",	\
701.1Sdholland	[QL_FILE] =  "file",	\
711.1Sdholland}
721.1Sdholland
731.1Sdhollandstruct quota2_entry {
741.1Sdholland	/* block & inode limits and status */
751.1Sdholland	struct quota2_val q2e_val[N_QL];
761.1Sdholland	/* pointer to next entry for this list (offset in the file) */
771.1Sdholland	uint64_t q2e_next;
781.1Sdholland	/* ownership information */
791.1Sdholland	uint32_t q2e_uid;
801.1Sdholland	uint32_t q2e_pad;
811.1Sdholland};
821.1Sdholland
831.1Sdholland/* header present at the start of the quota file */
841.1Sdhollandstruct quota2_header {
851.1Sdholland	uint32_t q2h_magic_number;
861.1Sdholland	uint8_t  q2h_type; /* quota type, see below */
871.1Sdholland	uint8_t  q2h_hash_shift; /* bytes used for hash index */
881.1Sdholland	uint16_t q2h_hash_size; /* size of hash table */
891.1Sdholland	/* default values applied to new entries */
901.1Sdholland	struct quota2_entry q2h_defentry;
911.1Sdholland	/* head of free quota2_entry list */
921.1Sdholland	uint64_t q2h_free;
931.1Sdholland	/* variable-sized hash table */
941.1Sdholland	uint64_t q2h_entries[0];
951.1Sdholland};
961.1Sdholland
971.1Sdholland#define Q2_HEAD_MAGIC	0xb746915e
981.1Sdholland
991.1Sdholland/* superblock flags */
1001.1Sdholland#define FS_Q2_DO_TYPE(type)	(0x01 << (type))
1011.1Sdholland
1021.1Sdholland#define off2qindex(hsize, off) (((off) - (hsize)) / sizeof(struct quota2_entry))
1031.1Sdholland#define qindex2off(hsize, idx) \
1041.1Sdholland	((daddr_t)(idx) * sizeof(struct quota2_entry) + (hsize))
1051.1Sdholland
1061.1Sdholland/* quota2_subr.c */
1071.4Sdhollandvoid lfsquota2_addfreeq2e(struct quota2_header *, void *, uint64_t, uint64_t, int);
1081.4Sdhollandvoid lfsquota2_create_blk0(uint64_t, void *bp, int, int, int);
1091.4Sdhollandvoid lfsquota2_ulfs_rwq2v(const struct quota2_val *, struct quota2_val *, int);
1101.4Sdhollandvoid lfsquota2_ulfs_rwq2e(const struct quota2_entry *, struct quota2_entry *, int);
1111.1Sdholland
1121.1Sdholland/*
1131.4Sdholland * Return codes for lfsquota_check_limit()
1141.1Sdholland */
1151.1Sdholland
1161.1Sdholland#define QL_S_ALLOW_OK	0x00 /* below soft limit */
1171.1Sdholland#define QL_S_ALLOW_SOFT	0x01 /* over soft limit */
1181.1Sdholland#define QL_S_DENY_GRACE	0x02 /* over soft limit, grace time expired */
1191.1Sdholland#define QL_S_DENY_HARD	0x03 /* over hard limit */
1201.1Sdholland
1211.1Sdholland#define QL_F_CROSS	0x80 /* crossing soft limit */
1221.1Sdholland
1231.1Sdholland#define QL_STATUS(x)	((x) & 0x0f)
1241.1Sdholland#define QL_FLAGS(x)	((x) & 0xf0)
1251.1Sdholland
1261.3Sdholland/* check a quota usage against limits */
1271.4Sdhollandint lfsquota_check_limit(uint64_t, uint64_t, uint64_t, uint64_t, time_t, time_t);
1281.1Sdholland
1291.3Sdholland#endif /*  _UFS_LFS_ULFS_QUOTA2_H_ */
130