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