1e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall/*
2e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall * Definitions of structures for vfsv0 quota format
3e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall */
4e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall
5e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall#ifndef _LINUX_QUOTA_TREE_H
6e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall#define _LINUX_QUOTA_TREE_H
7e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall
8e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall#include <sys/types.h>
9e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall
10e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgralltypedef u_int32_t qid_t;        /* Type in which we store ids in memory */
11e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall
12e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall#define QT_TREEOFF	1	/* Offset of tree in file in blocks */
13e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall#define QT_TREEDEPTH	4	/* Depth of quota tree */
14e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall#define QT_BLKSIZE_BITS	10
15e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall#define QT_BLKSIZE (1 << QT_BLKSIZE_BITS)	/* Size of block with quota
16e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall						 * structures */
17e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall
18e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall/*
19e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall *  Structure of header of block with quota structures. It is padded to 16 bytes
20e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall *  so there will be space for exactly 21 quota-entries in a block
21e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall */
22e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrallstruct qt_disk_dqdbheader {
23e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall	u_int32_t dqdh_next_free;	/* Number of next block with free
24e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall					 * entry */
25e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall	u_int32_t dqdh_prev_free; /* Number of previous block with free
26e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall				   * entry */
27e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall	u_int16_t dqdh_entries; /* Number of valid entries in block */
28e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall	u_int16_t dqdh_pad1;
29e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall	u_int32_t dqdh_pad2;
30e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall} __attribute__ ((packed));
31e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall
32e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrallstruct dquot;
33e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrallstruct quota_handle;
34e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall
35e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall/* Operations */
36e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrallstruct qtree_fmt_operations {
37e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall	/* Convert given entry from in memory format to disk one */
38e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall	void (*mem2disk_dqblk)(void *disk, struct dquot *dquot);
39e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall	/* Convert given entry from disk format to in memory one */
40e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall	void (*disk2mem_dqblk)(struct dquot *dquot, void *disk);
41e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall	/* Is this structure for given id? */
42e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall	int (*is_id)(void *disk, struct dquot *dquot);
43e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall};
44e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall
45e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall/* Inmemory copy of version specific information */
46e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrallstruct qtree_mem_dqinfo {
47e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall	unsigned int dqi_blocks;	/* # of blocks in quota file */
48e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall	unsigned int dqi_free_blk;	/* First block in list of free blocks */
49e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall	unsigned int dqi_free_entry;	/* First block with free entry */
50e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall	unsigned int dqi_entry_size;	/* Size of quota entry in quota file */
51e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall	struct qtree_fmt_operations *dqi_ops;	/* Operations for entry
52e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall						 * manipulation */
53e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall};
54e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall
55e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrallvoid qtree_write_dquot(struct dquot *dquot);
56e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrallstruct dquot *qtree_read_dquot(struct quota_handle *h, qid_t id);
57e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrallvoid qtree_delete_dquot(struct dquot *dquot);
58e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrallint qtree_entry_unused(struct qtree_mem_dqinfo *info, char *disk);
59e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrallint qtree_scan_dquots(struct quota_handle *h,
60e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall		int (*process_dquot) (struct dquot *, void *), void *data);
61e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall
62e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrallint qtree_dqstr_in_blk(struct qtree_mem_dqinfo *info);
63e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall
64e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall#endif /* _LINUX_QUOTAIO_TREE_H */
65