xref: /linux/include/linux/dqblk_qtree.h (revision 1ccd14b9c271c1ac6eec5c5ec5def433100e7248)
1*1ccd14b9SJan Kara /*
2*1ccd14b9SJan Kara  *	Definitions of structures and functions for quota formats using trie
3*1ccd14b9SJan Kara  */
4*1ccd14b9SJan Kara 
5*1ccd14b9SJan Kara #ifndef _LINUX_DQBLK_QTREE_H
6*1ccd14b9SJan Kara #define _LINUX_DQBLK_QTREE_H
7*1ccd14b9SJan Kara 
8*1ccd14b9SJan Kara #include <linux/types.h>
9*1ccd14b9SJan Kara 
10*1ccd14b9SJan Kara /* Numbers of blocks needed for updates - we count with the smallest
11*1ccd14b9SJan Kara  * possible block size (1024) */
12*1ccd14b9SJan Kara #define QTREE_INIT_ALLOC 4
13*1ccd14b9SJan Kara #define QTREE_INIT_REWRITE 2
14*1ccd14b9SJan Kara #define QTREE_DEL_ALLOC 0
15*1ccd14b9SJan Kara #define QTREE_DEL_REWRITE 6
16*1ccd14b9SJan Kara 
17*1ccd14b9SJan Kara struct dquot;
18*1ccd14b9SJan Kara 
19*1ccd14b9SJan Kara /* Operations */
20*1ccd14b9SJan Kara struct qtree_fmt_operations {
21*1ccd14b9SJan Kara 	void (*mem2disk_dqblk)(void *disk, struct dquot *dquot);	/* Convert given entry from in memory format to disk one */
22*1ccd14b9SJan Kara 	void (*disk2mem_dqblk)(struct dquot *dquot, void *disk);	/* Convert given entry from disk format to in memory one */
23*1ccd14b9SJan Kara 	int (*is_id)(void *disk, struct dquot *dquot);	/* Is this structure for given id? */
24*1ccd14b9SJan Kara };
25*1ccd14b9SJan Kara 
26*1ccd14b9SJan Kara /* Inmemory copy of version specific information */
27*1ccd14b9SJan Kara struct qtree_mem_dqinfo {
28*1ccd14b9SJan Kara 	struct super_block *dqi_sb;	/* Sb quota is on */
29*1ccd14b9SJan Kara 	int dqi_type;			/* Quota type */
30*1ccd14b9SJan Kara 	unsigned int dqi_blocks;	/* # of blocks in quota file */
31*1ccd14b9SJan Kara 	unsigned int dqi_free_blk;	/* First block in list of free blocks */
32*1ccd14b9SJan Kara 	unsigned int dqi_free_entry;	/* First block with free entry */
33*1ccd14b9SJan Kara 	unsigned int dqi_blocksize_bits;	/* Block size of quota file */
34*1ccd14b9SJan Kara 	unsigned int dqi_entry_size;	/* Size of quota entry in quota file */
35*1ccd14b9SJan Kara 	unsigned int dqi_usable_bs;	/* Space usable in block for quota data */
36*1ccd14b9SJan Kara 	unsigned int dqi_qtree_depth;	/* Precomputed depth of quota tree */
37*1ccd14b9SJan Kara 	struct qtree_fmt_operations *dqi_ops;	/* Operations for entry manipulation */
38*1ccd14b9SJan Kara };
39*1ccd14b9SJan Kara 
40*1ccd14b9SJan Kara int qtree_write_dquot(struct qtree_mem_dqinfo *info, struct dquot *dquot);
41*1ccd14b9SJan Kara int qtree_read_dquot(struct qtree_mem_dqinfo *info, struct dquot *dquot);
42*1ccd14b9SJan Kara int qtree_delete_dquot(struct qtree_mem_dqinfo *info, struct dquot *dquot);
43*1ccd14b9SJan Kara int qtree_release_dquot(struct qtree_mem_dqinfo *info, struct dquot *dquot);
44*1ccd14b9SJan Kara int qtree_entry_unused(struct qtree_mem_dqinfo *info, char *disk);
45*1ccd14b9SJan Kara static inline int qtree_depth(struct qtree_mem_dqinfo *info)
46*1ccd14b9SJan Kara {
47*1ccd14b9SJan Kara 	unsigned int epb = info->dqi_usable_bs >> 2;
48*1ccd14b9SJan Kara 	unsigned long long entries = epb;
49*1ccd14b9SJan Kara 	int i;
50*1ccd14b9SJan Kara 
51*1ccd14b9SJan Kara 	for (i = 1; entries < (1ULL << 32); i++)
52*1ccd14b9SJan Kara 		entries *= epb;
53*1ccd14b9SJan Kara 	return i;
54*1ccd14b9SJan Kara }
55*1ccd14b9SJan Kara 
56*1ccd14b9SJan Kara #endif /* _LINUX_DQBLK_QTREE_H */
57