3 * Header of IO operations for quota utilities
4 * Jan Kara <jack@suse.cz>
7 #ifndef GUARD_QUOTAIO_H
8 #define GUARD_QUOTAIO_H
11 #include <sys/types.h>
14 #include "ext2fs/ext2fs.h"
19 * Definitions for disk quotas imposed on the average user
20 * (big brother finally hits Linux).
22 * The following constants define the default amount of time given a user
23 * before the soft limits are treated as hard limits (usually resulting
24 * in an allocation failure). The timer is started when the user crosses
25 * their soft limit, it is reset when they go below their soft limit.
27 #define MAX_IQ_TIME 604800 /* (7*24*60*60) 1 week */
28 #define MAX_DQ_TIME 604800 /* (7*24*60*60) 1 week */
30 #define IOFL_QUOTAON 0x01 /* Is quota enabled in kernel? */
31 #define IOFL_INFODIRTY 0x02 /* Did info change? */
32 #define IOFL_RO 0x04 /* Just RO access? */
33 #define IOFL_NFS_MIXED_PATHS 0x08 /* Should we trim leading slashes
34 from NFSv4 mountpoints? */
38 /* Generic information about quotafile */
40 time_t dqi_bgrace; /* Block grace time for given quotafile */
41 time_t dqi_igrace; /* Inode grace time for given quotafile */
43 struct v2_mem_dqinfo v2_mdqi;
44 } u; /* Format specific info about quotafile */
53 /* Structure for one opened quota file */
55 int qh_type; /* Type of quotafile */
56 int qh_fmt; /* Quotafile format */
57 int qh_io_flags; /* IO flags for file */
58 struct quota_file qh_qf;
59 unsigned int (*e2fs_read)(struct quota_file *qf, loff_t offset,
60 void *buf, unsigned int size);
61 unsigned int (*e2fs_write)(struct quota_file *qf, loff_t offset,
62 void *buf, unsigned int size);
63 struct quotafile_ops *qh_ops; /* Operations on quotafile */
64 struct util_dqinfo qh_info; /* Generic quotafile info */
67 /* Statistics gathered from kernel */
74 u_int32_t allocated_dquots;
75 u_int32_t free_dquots;
80 /* Utility quota block */
82 qsize_t dqb_ihardlimit;
83 qsize_t dqb_isoftlimit;
84 qsize_t dqb_curinodes;
85 qsize_t dqb_bhardlimit;
86 qsize_t dqb_bsoftlimit;
91 struct v2_mem_dqblk v2_mdqb;
92 } u; /* Format specific dquot information */
95 /* Structure for one loaded quota */
97 struct dquot *dq_next; /* Pointer to next dquot in the list */
98 qid_t dq_id; /* ID dquot belongs to */
99 int dq_flags; /* Some flags for utils */
100 struct quota_handle *dq_h; /* Handle of quotafile for this dquot */
101 struct util_dqblk dq_dqb; /* Parsed data of dquot */
104 /* Flags for commit function (have effect only when quota in kernel is
106 #define COMMIT_USAGE QIF_USAGE
107 #define COMMIT_LIMITS QIF_LIMITS
108 #define COMMIT_TIMES QIF_TIMES
109 #define COMMIT_ALL (COMMIT_USAGE | COMMIT_LIMITS | COMMIT_TIMES)
111 /* Structure of quotafile operations */
112 struct quotafile_ops {
113 /* Check whether quotafile is in our format */
114 int (*check_file) (struct quota_handle *h, int type, int fmt);
116 int (*init_io) (struct quota_handle *h);
117 /* Create new quotafile */
118 int (*new_io) (struct quota_handle *h);
119 /* Write all changes and close quotafile */
120 int (*end_io) (struct quota_handle *h);
121 /* Write info about quotafile */
122 int (*write_info) (struct quota_handle *h);
123 /* Read dquot into memory */
124 struct dquot *(*read_dquot) (struct quota_handle *h, qid_t id);
125 /* Write given dquot to disk */
126 int (*commit_dquot) (struct dquot *dquot, int flag);
127 /* Scan quotafile and call callback on every structure */
128 int (*scan_dquots) (struct quota_handle *h,
129 int (*process_dquot) (struct dquot *dquot,
131 /* Function to print format specific file information */
132 int (*report) (struct quota_handle *h, int verbose);
135 /* This might go into a special header file but that sounds a bit silly... */
136 extern struct quotafile_ops quotafile_ops_meta;
138 static inline void mark_quotafile_info_dirty(struct quota_handle *h)
140 h->qh_io_flags |= IOFL_INFODIRTY;
143 #define QIO_ENABLED(h) ((h)->qh_io_flags & IOFL_QUOTAON)
144 #define QIO_RO(h) ((h)->qh_io_flags & IOFL_RO)
146 /* Check quota format used on specified medium and initialize it */
147 struct quota_handle *init_io(ext2_filsys fs, const char *mntpt, int type,
150 /* Create new quotafile of specified format on given filesystem */
151 int new_io(struct quota_handle *h, ext2_filsys fs, int type, int fmt);
153 /* Close quotafile */
154 int end_io(struct quota_handle *h);
156 /* Get empty quota structure */
157 struct dquot *get_empty_dquot(void);
159 void truncate_quota_inode(ext2_filsys fs, ext2_ino_t ino);
161 const char *type2name(int type);
163 void update_grace_times(struct dquot *q);
165 #endif /* GUARD_QUOTAIO_H */