[BACK]Return to quota2.h CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / ufs / ufs

File: [cvs.NetBSD.org] / src / sys / ufs / ufs / quota2.h (download)

Revision 1.9, Sun Feb 5 14:19:04 2012 UTC (12 years, 1 month ago) by dholland
Branch: MAIN
CVS Tags: yamt-pagecache-base9, yamt-pagecache-base8, yamt-pagecache-base7, yamt-pagecache-base6, yamt-pagecache-base5, yamt-pagecache-base4, tls-maxphys-base, tls-earlyentropy-base, tls-earlyentropy, rmind-smpnet-nbase, rmind-smpnet-base, rmind-smpnet, riastradh-xf86-video-intel-2-7-1-pre-2-21-15, riastradh-drm2-base3, riastradh-drm2-base2, riastradh-drm2-base1, riastradh-drm2-base, riastradh-drm2, prg-localcount2-base3, prg-localcount2-base2, prg-localcount2-base1, prg-localcount2-base, prg-localcount2, pgoyette-localcount-base, pgoyette-localcount-20170426, pgoyette-localcount-20170320, pgoyette-localcount-20170107, pgoyette-localcount-20161104, pgoyette-localcount-20160806, pgoyette-localcount-20160726, pgoyette-localcount, perseant-stdc-iso10646-base, perseant-stdc-iso10646, nick-nhusb-base-20170825, nick-nhusb-base-20170204, nick-nhusb-base-20161204, nick-nhusb-base-20161004, nick-nhusb-base-20160907, nick-nhusb-base-20160529, nick-nhusb-base-20160422, nick-nhusb-base-20160319, nick-nhusb-base-20151226, nick-nhusb-base-20150921, nick-nhusb-base-20150606, nick-nhusb-base-20150406, nick-nhusb-base, nick-nhusb, netbsd-8-base, netbsd-8-2-RELEASE, netbsd-8-1-RELEASE, netbsd-8-1-RC1, netbsd-8-0-RELEASE, netbsd-8-0-RC2, netbsd-8-0-RC1, netbsd-8, netbsd-7-nhusb-base-20170116, netbsd-7-nhusb-base, netbsd-7-nhusb, netbsd-7-base, netbsd-7-2-RELEASE, netbsd-7-1-RELEASE, netbsd-7-1-RC2, netbsd-7-1-RC1, netbsd-7-1-2-RELEASE, netbsd-7-1-1-RELEASE, netbsd-7-1, netbsd-7-0-RELEASE, netbsd-7-0-RC3, netbsd-7-0-RC2, netbsd-7-0-RC1, netbsd-7-0-2-RELEASE, netbsd-7-0-1-RELEASE, netbsd-7-0, netbsd-7, netbsd-6-base, netbsd-6-1-RELEASE, netbsd-6-1-RC4, netbsd-6-1-RC3, netbsd-6-1-RC2, netbsd-6-1-RC1, netbsd-6-1-5-RELEASE, netbsd-6-1-4-RELEASE, netbsd-6-1-3-RELEASE, netbsd-6-1-2-RELEASE, netbsd-6-1-1-RELEASE, netbsd-6-1, netbsd-6-0-RELEASE, netbsd-6-0-RC2, netbsd-6-0-RC1, netbsd-6-0-6-RELEASE, netbsd-6-0-5-RELEASE, netbsd-6-0-4-RELEASE, netbsd-6-0-3-RELEASE, netbsd-6-0-2-RELEASE, netbsd-6-0-1-RELEASE, netbsd-6-0, netbsd-6, matt-nb8-mediatek-base, matt-nb8-mediatek, matt-nb6-plus-nbase, matt-nb6-plus-base, matt-nb6-plus, localcount-20160914, khorben-n900, jmcneill-usbmp-base9, jmcneill-usbmp-base8, jmcneill-usbmp-base7, jmcneill-usbmp-base6, jmcneill-usbmp-base5, jmcneill-usbmp-base4, jmcneill-usbmp-base3, jmcneill-usbmp-base2, jmcneill-usbmp-base10, jdolecek-ncq-base, jdolecek-ncq, bouyer-socketcan-base1, bouyer-socketcan-base, bouyer-socketcan, agc-symver-base, agc-symver
Branch point for: tls-maxphys
Changes since 1.8: +18 -1 lines

Migrate one last leftover bit (used only by the kernel now) to
sys/ufs/ufs and remove the old quota headers and no-longer-used shared
code. Ok by releng.

/* $NetBSD: quota2.h,v 1.9 2012/02/05 14:19:04 dholland Exp $ */
/*-
  * Copyright (c) 2010 Manuel Bouyer
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
  * 1. Redistributions of source code must retain the above copyright
  *    notice, this list of conditions and the following disclaimer.
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
  *
  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
  */

#ifndef _UFS_UFS_QUOTA2_H_
#define _UFS_UFS_QUOTA2_H_
#include <ufs/ufs/quota.h>


/* New disk quota implementation. In this implementation, the quota datas
 * (default values, user limits and current usage) are part of the filesystem
 * metadata. On FFS, this will be in a hidden, unlinked inode. fsck_ffs is
 * responsible for checking quotas with the rest of the filesystem integrity,
 * and quotas metadata are also covered by the filesystem journal if any.
 * quota enable/disable is done on a filesystem basis via flags in the
 * superblock
 */

/*
 * The quota file is comprised of 2 parts, the header and the entries.
 * The header contains global informations, and head of list of quota entries.
 * A quota entry can either be in the free list, or one of the hash lists.
 */

/* description of a block or inode quota */
struct quota2_val {
	uint64_t q2v_hardlimit; /* absolute limit */
	uint64_t q2v_softlimit; /* overflowable limit */
	uint64_t q2v_cur; /* current usage */
	int64_t q2v_time; /* grace expiration date for softlimit overflow */
	int64_t q2v_grace; /* allowed time for softlimit overflow */
};

/*
 * On-disk description of a user or group quota
 * These entries are keept as linked list, either in one of the hash HEAD,
 * or in the free list.
 */

#define N_QL 2
#define QL_BLOCK 0
#define QL_FILE 1
#define INITQLNAMES { \
	[QL_BLOCK] = "block",	\
	[QL_FILE] =  "file",	\
}

struct quota2_entry {
	/* block & inode limits and status */
	struct quota2_val q2e_val[N_QL];
	/* pointer to next entry for this list (offset in the file) */
	uint64_t q2e_next;
	/* ownership information */
	uint32_t q2e_uid;
	uint32_t q2e_pad;
};

/* header present at the start of the quota file */
struct quota2_header {
	uint32_t q2h_magic_number;
	uint8_t  q2h_type; /* quota type, see below */
	uint8_t  q2h_hash_shift; /* bytes used for hash index */
	uint16_t q2h_hash_size; /* size of hash table */
	/* default values applied to new entries */
	struct quota2_entry q2h_defentry;
	/* head of free quota2_entry list */
	uint64_t q2h_free;
	/* variable-sized hash table */
	uint64_t q2h_entries[0];
};

#define Q2_HEAD_MAGIC	0xb746915e

/* superblock flags */
#define FS_Q2_DO_TYPE(type)	(0x01 << (type))

#define off2qindex(hsize, off) (((off) - (hsize)) / sizeof(struct quota2_entry))
#define qindex2off(hsize, idx) \
	((daddr_t)(idx) * sizeof(struct quota2_entry) + (hsize))

/* quota2_subr.c */
void quota2_addfreeq2e(struct quota2_header *, void *, uint64_t, uint64_t, int);
void quota2_create_blk0(uint64_t, void *bp, int, int, int);
void quota2_ufs_rwq2v(const struct quota2_val *, struct quota2_val *, int);
void quota2_ufs_rwq2e(const struct quota2_entry *, struct quota2_entry *, int);

/*
 * Return codes for quota_check_limit()
 */

#define QL_S_ALLOW_OK	0x00 /* below soft limit */
#define QL_S_ALLOW_SOFT	0x01 /* over soft limit */
#define QL_S_DENY_GRACE	0x02 /* over soft limit, grace time expired */
#define QL_S_DENY_HARD	0x03 /* over hard limit */
 
#define QL_F_CROSS	0x80 /* crossing soft limit */

#define QL_STATUS(x)	((x) & 0x0f)
#define QL_FLAGS(x)	((x) & 0xf0)

/* check a quota usage against limits (assumes UFS semantic) */
int quota_check_limit(uint64_t, uint64_t,  uint64_t, uint64_t, time_t, time_t);

#endif /*  _UFS_UFS_QUOTA2_H_ */