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