Whamcloud - gitweb
libquota: clean up some gcc -Wall warnings
[tools/e2fsprogs.git] / lib / quota / quotaio.h
1 /** quotaio.h
2  *
3  * Header of IO operations for quota utilities
4  * Jan Kara <jack@suse.cz>
5  */
6
7 #ifndef GUARD_QUOTAIO_H
8 #define GUARD_QUOTAIO_H
9
10 #include <limits.h>
11 #include <sys/types.h>
12 #include <sys/stat.h>
13
14 #include "ext2fs/ext2fs.h"
15 #include "quota.h"
16 #include "dqblk_v2.h"
17
18 /*
19  * Definitions for disk quotas imposed on the average user
20  * (big brother finally hits Linux).
21  *
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.
26  */
27 #define MAX_IQ_TIME  604800     /* (7*24*60*60) 1 week */
28 #define MAX_DQ_TIME  604800     /* (7*24*60*60) 1 week */
29
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? */
35
36 struct quotafile_ops;
37
38 /* Generic information about quotafile */
39 struct util_dqinfo {
40         time_t dqi_bgrace;      /* Block grace time for given quotafile */
41         time_t dqi_igrace;      /* Inode grace time for given quotafile */
42         union {
43                 struct v2_mem_dqinfo v2_mdqi;
44         } u;                    /* Format specific info about quotafile */
45 };
46
47 struct quota_file {
48         ext2_filsys fs;
49         ext2_ino_t ino;
50         ext2_file_t e2_file;
51 };
52
53 /* Structure for one opened quota file */
54 struct quota_handle {
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 */
65 };
66
67 /* Statistics gathered from kernel */
68 struct util_dqstats {
69         u_int32_t lookups;
70         u_int32_t drops;
71         u_int32_t reads;
72         u_int32_t writes;
73         u_int32_t cache_hits;
74         u_int32_t allocated_dquots;
75         u_int32_t free_dquots;
76         u_int32_t syncs;
77         u_int32_t version;
78 };
79
80 /* Utility quota block */
81 struct util_dqblk {
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;
87         qsize_t dqb_curspace;
88         time_t dqb_btime;
89         time_t dqb_itime;
90         union {
91                 struct v2_mem_dqblk v2_mdqb;
92         } u;                    /* Format specific dquot information */
93 };
94
95 /* Structure for one loaded quota */
96 struct dquot {
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 */
102 };
103
104 /* Flags for commit function (have effect only when quota in kernel is
105  * turned on) */
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)
110
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);
115         /* Open quotafile */
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,
130                                                   char *dqname));
131         /* Function to print format specific file information */
132         int (*report) (struct quota_handle *h, int verbose);
133 };
134
135 /* This might go into a special header file but that sounds a bit silly... */
136 extern struct quotafile_ops quotafile_ops_meta;
137
138 static inline void mark_quotafile_info_dirty(struct quota_handle *h)
139 {
140         h->qh_io_flags |= IOFL_INFODIRTY;
141 }
142
143 #define QIO_ENABLED(h)  ((h)->qh_io_flags & IOFL_QUOTAON)
144 #define QIO_RO(h)       ((h)->qh_io_flags & IOFL_RO)
145
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,
148                              int fmt, int flags);
149
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);
152
153 /* Close quotafile */
154 int end_io(struct quota_handle *h);
155
156 /* Get empty quota structure */
157 struct dquot *get_empty_dquot(void);
158
159 void truncate_quota_inode(ext2_filsys fs, ext2_ino_t ino);
160
161 const char *type2name(int type);
162
163 void update_grace_times(struct dquot *q);
164
165 #endif /* GUARD_QUOTAIO_H */