1*b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 21ccd14b9SJan Kara /* 31ccd14b9SJan Kara * Definitions of structures and functions for quota formats using trie 41ccd14b9SJan Kara */ 51ccd14b9SJan Kara 61ccd14b9SJan Kara #ifndef _LINUX_DQBLK_QTREE_H 71ccd14b9SJan Kara #define _LINUX_DQBLK_QTREE_H 81ccd14b9SJan Kara 91ccd14b9SJan Kara #include <linux/types.h> 101ccd14b9SJan Kara 111ccd14b9SJan Kara /* Numbers of blocks needed for updates - we count with the smallest 121ccd14b9SJan Kara * possible block size (1024) */ 131ccd14b9SJan Kara #define QTREE_INIT_ALLOC 4 141ccd14b9SJan Kara #define QTREE_INIT_REWRITE 2 151ccd14b9SJan Kara #define QTREE_DEL_ALLOC 0 161ccd14b9SJan Kara #define QTREE_DEL_REWRITE 6 171ccd14b9SJan Kara 181ccd14b9SJan Kara struct dquot; 190066373dSJan Kara struct kqid; 201ccd14b9SJan Kara 211ccd14b9SJan Kara /* Operations */ 221ccd14b9SJan Kara struct qtree_fmt_operations { 231ccd14b9SJan Kara void (*mem2disk_dqblk)(void *disk, struct dquot *dquot); /* Convert given entry from in memory format to disk one */ 241ccd14b9SJan Kara void (*disk2mem_dqblk)(struct dquot *dquot, void *disk); /* Convert given entry from disk format to in memory one */ 251ccd14b9SJan Kara int (*is_id)(void *disk, struct dquot *dquot); /* Is this structure for given id? */ 261ccd14b9SJan Kara }; 271ccd14b9SJan Kara 281ccd14b9SJan Kara /* Inmemory copy of version specific information */ 291ccd14b9SJan Kara struct qtree_mem_dqinfo { 301ccd14b9SJan Kara struct super_block *dqi_sb; /* Sb quota is on */ 311ccd14b9SJan Kara int dqi_type; /* Quota type */ 321ccd14b9SJan Kara unsigned int dqi_blocks; /* # of blocks in quota file */ 331ccd14b9SJan Kara unsigned int dqi_free_blk; /* First block in list of free blocks */ 341ccd14b9SJan Kara unsigned int dqi_free_entry; /* First block with free entry */ 351ccd14b9SJan Kara unsigned int dqi_blocksize_bits; /* Block size of quota file */ 361ccd14b9SJan Kara unsigned int dqi_entry_size; /* Size of quota entry in quota file */ 371ccd14b9SJan Kara unsigned int dqi_usable_bs; /* Space usable in block for quota data */ 381ccd14b9SJan Kara unsigned int dqi_qtree_depth; /* Precomputed depth of quota tree */ 39d1b98c23SJulia Lawall const struct qtree_fmt_operations *dqi_ops; /* Operations for entry manipulation */ 401ccd14b9SJan Kara }; 411ccd14b9SJan Kara 421ccd14b9SJan Kara int qtree_write_dquot(struct qtree_mem_dqinfo *info, struct dquot *dquot); 431ccd14b9SJan Kara int qtree_read_dquot(struct qtree_mem_dqinfo *info, struct dquot *dquot); 441ccd14b9SJan Kara int qtree_delete_dquot(struct qtree_mem_dqinfo *info, struct dquot *dquot); 451ccd14b9SJan Kara int qtree_release_dquot(struct qtree_mem_dqinfo *info, struct dquot *dquot); 461ccd14b9SJan Kara int qtree_entry_unused(struct qtree_mem_dqinfo *info, char *disk); qtree_depth(struct qtree_mem_dqinfo * info)471ccd14b9SJan Karastatic inline int qtree_depth(struct qtree_mem_dqinfo *info) 481ccd14b9SJan Kara { 491ccd14b9SJan Kara unsigned int epb = info->dqi_usable_bs >> 2; 501ccd14b9SJan Kara unsigned long long entries = epb; 511ccd14b9SJan Kara int i; 521ccd14b9SJan Kara 531ccd14b9SJan Kara for (i = 1; entries < (1ULL << 32); i++) 541ccd14b9SJan Kara entries *= epb; 551ccd14b9SJan Kara return i; 561ccd14b9SJan Kara } 570066373dSJan Kara int qtree_get_next_id(struct qtree_mem_dqinfo *info, struct kqid *qid); 581ccd14b9SJan Kara 591ccd14b9SJan Kara #endif /* _LINUX_DQBLK_QTREE_H */ 60