18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *	Definitions of structures and functions for quota formats using trie
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#ifndef _LINUX_DQBLK_QTREE_H
78c2ecf20Sopenharmony_ci#define _LINUX_DQBLK_QTREE_H
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#include <linux/types.h>
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci/* Numbers of blocks needed for updates - we count with the smallest
128c2ecf20Sopenharmony_ci * possible block size (1024) */
138c2ecf20Sopenharmony_ci#define QTREE_INIT_ALLOC 4
148c2ecf20Sopenharmony_ci#define QTREE_INIT_REWRITE 2
158c2ecf20Sopenharmony_ci#define QTREE_DEL_ALLOC 0
168c2ecf20Sopenharmony_ci#define QTREE_DEL_REWRITE 6
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_cistruct dquot;
198c2ecf20Sopenharmony_cistruct kqid;
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci/* Operations */
228c2ecf20Sopenharmony_cistruct qtree_fmt_operations {
238c2ecf20Sopenharmony_ci	void (*mem2disk_dqblk)(void *disk, struct dquot *dquot);	/* Convert given entry from in memory format to disk one */
248c2ecf20Sopenharmony_ci	void (*disk2mem_dqblk)(struct dquot *dquot, void *disk);	/* Convert given entry from disk format to in memory one */
258c2ecf20Sopenharmony_ci	int (*is_id)(void *disk, struct dquot *dquot);	/* Is this structure for given id? */
268c2ecf20Sopenharmony_ci};
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci/* Inmemory copy of version specific information */
298c2ecf20Sopenharmony_cistruct qtree_mem_dqinfo {
308c2ecf20Sopenharmony_ci	struct super_block *dqi_sb;	/* Sb quota is on */
318c2ecf20Sopenharmony_ci	int dqi_type;			/* Quota type */
328c2ecf20Sopenharmony_ci	unsigned int dqi_blocks;	/* # of blocks in quota file */
338c2ecf20Sopenharmony_ci	unsigned int dqi_free_blk;	/* First block in list of free blocks */
348c2ecf20Sopenharmony_ci	unsigned int dqi_free_entry;	/* First block with free entry */
358c2ecf20Sopenharmony_ci	unsigned int dqi_blocksize_bits;	/* Block size of quota file */
368c2ecf20Sopenharmony_ci	unsigned int dqi_entry_size;	/* Size of quota entry in quota file */
378c2ecf20Sopenharmony_ci	unsigned int dqi_usable_bs;	/* Space usable in block for quota data */
388c2ecf20Sopenharmony_ci	unsigned int dqi_qtree_depth;	/* Precomputed depth of quota tree */
398c2ecf20Sopenharmony_ci	const struct qtree_fmt_operations *dqi_ops; /* Operations for entry manipulation */
408c2ecf20Sopenharmony_ci};
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ciint qtree_write_dquot(struct qtree_mem_dqinfo *info, struct dquot *dquot);
438c2ecf20Sopenharmony_ciint qtree_read_dquot(struct qtree_mem_dqinfo *info, struct dquot *dquot);
448c2ecf20Sopenharmony_ciint qtree_delete_dquot(struct qtree_mem_dqinfo *info, struct dquot *dquot);
458c2ecf20Sopenharmony_ciint qtree_release_dquot(struct qtree_mem_dqinfo *info, struct dquot *dquot);
468c2ecf20Sopenharmony_ciint qtree_entry_unused(struct qtree_mem_dqinfo *info, char *disk);
478c2ecf20Sopenharmony_cistatic inline int qtree_depth(struct qtree_mem_dqinfo *info)
488c2ecf20Sopenharmony_ci{
498c2ecf20Sopenharmony_ci	unsigned int epb = info->dqi_usable_bs >> 2;
508c2ecf20Sopenharmony_ci	unsigned long long entries = epb;
518c2ecf20Sopenharmony_ci	int i;
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci	for (i = 1; entries < (1ULL << 32); i++)
548c2ecf20Sopenharmony_ci		entries *= epb;
558c2ecf20Sopenharmony_ci	return i;
568c2ecf20Sopenharmony_ci}
578c2ecf20Sopenharmony_ciint qtree_get_next_id(struct qtree_mem_dqinfo *info, struct kqid *qid);
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci#endif /* _LINUX_DQBLK_QTREE_H */
60