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, ext2_loff_t offset,
60 void *buf, unsigned int size);
61 unsigned int (*e2fs_write)(struct quota_file *qf, ext2_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 /* Structure of quotafile operations */
105 struct quotafile_ops {
106 /* Check whether quotafile is in our format */
107 int (*check_file) (struct quota_handle *h, int type, int fmt);
109 int (*init_io) (struct quota_handle *h);
110 /* Create new quotafile */
111 int (*new_io) (struct quota_handle *h);
112 /* Write all changes and close quotafile */
113 int (*end_io) (struct quota_handle *h);
114 /* Write info about quotafile */
115 int (*write_info) (struct quota_handle *h);
116 /* Read dquot into memory */
117 struct dquot *(*read_dquot) (struct quota_handle *h, qid_t id);
118 /* Write given dquot to disk */
119 int (*commit_dquot) (struct dquot *dquot);
120 /* Scan quotafile and call callback on every structure */
121 int (*scan_dquots) (struct quota_handle *h,
122 int (*process_dquot) (struct dquot *dquot,
125 /* Function to print format specific file information */
126 int (*report) (struct quota_handle *h, int verbose);
129 /* This might go into a special header file but that sounds a bit silly... */
130 extern struct quotafile_ops quotafile_ops_meta;
132 static inline void mark_quotafile_info_dirty(struct quota_handle *h)
134 h->qh_io_flags |= IOFL_INFODIRTY;
137 #define QIO_ENABLED(h) ((h)->qh_io_flags & IOFL_QUOTAON)
138 #define QIO_RO(h) ((h)->qh_io_flags & IOFL_RO)
140 /* Open existing quotafile of given type (and verify its format) on given
142 errcode_t quota_file_open(struct quota_handle *h, ext2_filsys fs,
143 ext2_ino_t qf_ino, int type, int fmt, int flags);
146 /* Create new quotafile of specified format on given filesystem */
147 errcode_t quota_file_create(struct quota_handle *h, ext2_filsys fs,
150 /* Close quotafile */
151 errcode_t quota_file_close(struct quota_handle *h);
153 /* Get empty quota structure */
154 struct dquot *get_empty_dquot(void);
156 errcode_t quota_inode_truncate(ext2_filsys fs, ext2_ino_t ino);
158 const char *type2name(int type);
160 void update_grace_times(struct dquot *q);
162 /* size for the buffer returned by quota_get_qf_name(); must be greater
163 than maxlen of extensions[] and fmtnames[] (plus 2) found in quotaio.c */
164 #define QUOTA_NAME_LEN 16
166 const char *quota_get_qf_name(int type, int fmt, char *buf);
167 const char *quota_get_qf_path(const char *mntpt, int qtype, int fmt,
168 char *path_buf, size_t path_buf_size);
170 #endif /* GUARD_QUOTAIO_H */