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"
17 typedef int64_t qsize_t; /* Type in which we store size limitations */
24 * Definitions of magics and versions of current quota files
26 #define INITQMAGICS {\
27 0xd9c01f11, /* USRQUOTA */\
28 0xd9c01927 /* GRPQUOTA */\
31 /* Size of blocks in which are counted size limits in generic utility parts */
32 #define QUOTABLOCK_BITS 10
33 #define QUOTABLOCK_SIZE (1 << QUOTABLOCK_BITS)
34 #define toqb(x) (((x) + QUOTABLOCK_SIZE - 1) >> QUOTABLOCK_BITS)
36 /* Quota format type IDs */
37 #define QFMT_VFS_OLD 1
42 * The following constants define the default amount of time given a user
43 * before the soft limits are treated as hard limits (usually resulting
44 * in an allocation failure). The timer is started when the user crosses
45 * their soft limit, it is reset when they go below their soft limit.
47 #define MAX_IQ_TIME 604800 /* (7*24*60*60) 1 week */
48 #define MAX_DQ_TIME 604800 /* (7*24*60*60) 1 week */
50 #define IOFL_INFODIRTY 0x01 /* Did info change? */
54 /* Generic information about quotafile */
56 time_t dqi_bgrace; /* Block grace time for given quotafile */
57 time_t dqi_igrace; /* Inode grace time for given quotafile */
59 struct v2_mem_dqinfo v2_mdqi;
60 } u; /* Format specific info about quotafile */
69 /* Structure for one opened quota file */
71 int qh_type; /* Type of quotafile */
72 int qh_fmt; /* Quotafile format */
73 int qh_io_flags; /* IO flags for file */
74 struct quota_file qh_qf;
75 unsigned int (*e2fs_read)(struct quota_file *qf, ext2_loff_t offset,
76 void *buf, unsigned int size);
77 unsigned int (*e2fs_write)(struct quota_file *qf, ext2_loff_t offset,
78 void *buf, unsigned int size);
79 struct quotafile_ops *qh_ops; /* Operations on quotafile */
80 struct util_dqinfo qh_info; /* Generic quotafile info */
83 /* Utility quota block */
85 qsize_t dqb_ihardlimit;
86 qsize_t dqb_isoftlimit;
87 qsize_t dqb_curinodes;
88 qsize_t dqb_bhardlimit;
89 qsize_t dqb_bsoftlimit;
94 struct v2_mem_dqblk v2_mdqb;
95 } u; /* Format specific dquot information */
98 /* Structure for one loaded quota */
100 struct dquot *dq_next; /* Pointer to next dquot in the list */
101 qid_t dq_id; /* ID dquot belongs to */
102 int dq_flags; /* Some flags for utils */
103 struct quota_handle *dq_h; /* Handle of quotafile for this dquot */
104 struct util_dqblk dq_dqb; /* Parsed data of dquot */
107 /* Structure of quotafile operations */
108 struct quotafile_ops {
109 /* Check whether quotafile is in our format */
110 int (*check_file) (struct quota_handle *h, int type, int fmt);
112 int (*init_io) (struct quota_handle *h);
113 /* Create new quotafile */
114 int (*new_io) (struct quota_handle *h);
115 /* Write all changes and close quotafile */
116 int (*end_io) (struct quota_handle *h);
117 /* Write info about quotafile */
118 int (*write_info) (struct quota_handle *h);
119 /* Read dquot into memory */
120 struct dquot *(*read_dquot) (struct quota_handle *h, qid_t id);
121 /* Write given dquot to disk */
122 int (*commit_dquot) (struct dquot *dquot);
123 /* Scan quotafile and call callback on every structure */
124 int (*scan_dquots) (struct quota_handle *h,
125 int (*process_dquot) (struct dquot *dquot,
128 /* Function to print format specific file information */
129 int (*report) (struct quota_handle *h, int verbose);
132 /* This might go into a special header file but that sounds a bit silly... */
133 extern struct quotafile_ops quotafile_ops_meta;
135 /* Open existing quotafile of given type (and verify its format) on given
137 errcode_t quota_file_open(struct quota_handle *h, ext2_filsys fs,
138 ext2_ino_t qf_ino, int type, int fmt, int flags);
141 /* Create new quotafile of specified format on given filesystem */
142 errcode_t quota_file_create(struct quota_handle *h, ext2_filsys fs,
145 /* Close quotafile */
146 errcode_t quota_file_close(struct quota_handle *h);
148 /* Get empty quota structure */
149 struct dquot *get_empty_dquot(void);
151 errcode_t quota_inode_truncate(ext2_filsys fs, ext2_ino_t ino);
153 const char *type2name(int type);
155 void update_grace_times(struct dquot *q);
157 /* size for the buffer returned by quota_get_qf_name(); must be greater
158 than maxlen of extensions[] and fmtnames[] (plus 2) found in quotaio.c */
159 #define QUOTA_NAME_LEN 16
161 const char *quota_get_qf_name(int type, int fmt, char *buf);
162 const char *quota_get_qf_path(const char *mntpt, int qtype, int fmt,
163 char *path_buf, size_t path_buf_size);
165 #endif /* GUARD_QUOTAIO_H */