3 * Header of IO operations for quota utilities
7 #ifndef GUARD_QUOTAIO_H
8 #define GUARD_QUOTAIO_H
11 #include <sys/types.h>
18 #include "dqblk_rpc.h"
19 #include "dqblk_xfs.h"
21 #define QUOTAFORMATS 6
23 #define INITQFBASENAMES {\
32 #define MAX_FSTYPE_LEN 16 /* Maximum length of filesystem type name */
34 /* Values for format handling */
35 #define QF_ERROR -1 /* There was error while detecting format (maybe unknown format...) */
36 #define QF_VFSOLD 0 /* Old quota format */
37 #define QF_VFSV0 1 /* Quota files with tree quota format */
38 #define QF_VFSV1 2 /* Quota files with 64-bit tree quota format */
39 #define QF_RPC 3 /* RPC should be used on given filesystem */
40 #define QF_XFS 4 /* XFS quota format */
41 #define QF_META 5 /* Quota files are hidden, we don't care about the format */
43 static inline int is_tree_qfmt(int fmt)
45 return fmt == QF_VFSV0 || fmt == QF_VFSV1;
49 * Definitions for disk quotas imposed on the average user
50 * (big brother finally hits Linux).
52 * The following constants define the default amount of time given a user
53 * before the soft limits are treated as hard limits (usually resulting
54 * in an allocation failure). The timer is started when the user crosses
55 * their soft limit, it is reset when they go below their soft limit.
57 #define MAX_IQ_TIME 604800 /* (7*24*60*60) 1 week */
58 #define MAX_DQ_TIME 604800 /* (7*24*60*60) 1 week */
60 #define IOFL_QUOTAON 0x01 /* Is quota enabled in kernel? */
61 #define IOFL_INFODIRTY 0x02 /* Did info change? */
62 #define IOFL_RO 0x04 /* Just RO access? */
63 #define IOFL_NFS_MIXED_PATHS 0x08 /* Should we trim leading slashes
64 from NFSv4 mountpoints? */
68 /* Generic information about quotafile */
70 time_t dqi_bgrace; /* Block grace time for given quotafile */
71 time_t dqi_igrace; /* Inode grace time for given quotafile */
73 struct v2_mem_dqinfo v2_mdqi;
74 struct xfs_mem_dqinfo xfs_mdqi;
75 } u; /* Format specific info about quotafile */
78 /* Structure for one opened quota file */
80 int qh_fd; /* Handle of file (-1 when IOFL_QUOTAON) */
81 int qh_io_flags; /* IO flags for file */
82 char qh_quotadev[PATH_MAX]; /* Device file is for */
83 char qh_fstype[MAX_FSTYPE_LEN]; /* Type of the filesystem on qh_quotadev */
84 int qh_type; /* Type of quotafile */
85 int qh_fmt; /* Quotafile format */
86 struct stat qh_stat; /* stat(2) for qh_quotadev */
87 struct quotafile_ops *qh_ops; /* Operations on quotafile */
88 struct util_dqinfo qh_info; /* Generic quotafile info */
91 /* Statistics gathered from kernel */
98 u_int32_t allocated_dquots;
99 u_int32_t free_dquots;
104 /* Utility quota block */
106 qsize_t dqb_ihardlimit;
107 qsize_t dqb_isoftlimit;
108 qsize_t dqb_curinodes;
109 qsize_t dqb_bhardlimit;
110 qsize_t dqb_bsoftlimit;
111 qsize_t dqb_curspace;
115 struct v2_mem_dqblk v2_mdqb;
116 } u; /* Format specific dquot information */
119 #define DQ_FOUND 0x01 /* Dquot was found in the edquotas file */
120 #define DQ_PRINTED 0x02 /* Dquota has been already printed by repquota */
122 /* Structure for one loaded quota */
124 struct dquot *dq_next; /* Pointer to next dquot in the list */
125 qid_t dq_id; /* ID dquot belongs to */
126 int dq_flags; /* Some flags for utils */
127 struct quota_handle *dq_h; /* Handle of quotafile dquot belongs to */
128 struct util_dqblk dq_dqb; /* Parsed data of dquot */
131 /* Flags for commit function (have effect only when quota in kernel is turned on) */
132 #define COMMIT_USAGE QIF_USAGE
133 #define COMMIT_LIMITS QIF_LIMITS
134 #define COMMIT_TIMES QIF_TIMES
135 #define COMMIT_ALL (COMMIT_USAGE | COMMIT_LIMITS | COMMIT_TIMES)
137 /* Structure of quotafile operations */
138 struct quotafile_ops {
139 int (*check_file) (int fd, int type, int fmt); /* Check whether quotafile is in our format */
140 int (*init_io) (struct quota_handle * h); /* Open quotafile */
141 int (*new_io) (struct quota_handle * h); /* Create new quotafile */
142 int (*end_io) (struct quota_handle * h); /* Write all changes and close quotafile */
143 int (*write_info) (struct quota_handle * h); /* Write info about quotafile */
144 struct dquot *(*read_dquot) (struct quota_handle * h, qid_t id); /* Read dquot into memory */
145 int (*commit_dquot) (struct dquot * dquot, int flag); /* Write given dquot to disk */
146 int (*scan_dquots) (struct quota_handle * h, int (*process_dquot) (struct dquot * dquot, char * dqname)); /* Scan quotafile and call callback on every structure */
147 int (*report) (struct quota_handle * h, int verbose); /* Function called after 'repquota' to print format specific file information */
150 /* This might go into a special header file but that sounds a bit silly... */
151 extern struct quotafile_ops quotafile_ops_meta;
153 static inline void mark_quotafile_info_dirty(struct quota_handle *h)
155 h->qh_io_flags |= IOFL_INFODIRTY;
158 #define QIO_ENABLED(h) ((h)->qh_io_flags & IOFL_QUOTAON)
159 #define QIO_RO(h) ((h)->qh_io_flags & IOFL_RO)
161 /* Check quota format used on specified medium and initialize it */
162 struct quota_handle *init_io(struct mntent *mnt, int type, int fmt, int flags);
164 /* Create new quotafile of specified format on given filesystem */
165 struct quota_handle *new_io(struct mntent *mnt, int type, int fmt);
167 /* Close quotafile */
168 int end_io(struct quota_handle *h);
170 /* Get empty quota structure */
171 struct dquot *get_empty_dquot(void);
173 #endif /* GUARD_QUOTAIO_H */