quotaio.h revision 198d20fc74a6124548b96e4c14c38ff8d5a95ae5
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
36struct quotafile_ops;
37
38/* Generic information about quotafile */
39struct 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
47struct 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 */
54struct 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, 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 */
65};
66
67/* Statistics gathered from kernel */
68struct 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 */
81struct 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 */
96struct 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/* Structure of quotafile operations */
105struct quotafile_ops {
106	/* Check whether quotafile is in our format */
107	int (*check_file) (struct quota_handle *h, int type, int fmt);
108	/* Open quotafile */
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,
123						  void *data),
124			    void *data);
125	/* Function to print format specific file information */
126	int (*report) (struct quota_handle *h, int verbose);
127};
128
129/* This might go into a special header file but that sounds a bit silly... */
130extern struct quotafile_ops quotafile_ops_meta;
131
132static inline void mark_quotafile_info_dirty(struct quota_handle *h)
133{
134	h->qh_io_flags |= IOFL_INFODIRTY;
135}
136
137#define QIO_ENABLED(h)	((h)->qh_io_flags & IOFL_QUOTAON)
138#define QIO_RO(h)	((h)->qh_io_flags & IOFL_RO)
139
140/* Open existing quotafile of given type (and verify its format) on given
141 * filesystem. */
142errcode_t quota_file_open(struct quota_handle *h, ext2_filsys fs,
143			  ext2_ino_t qf_ino, int type, int fmt, int flags);
144
145
146/* Create new quotafile of specified format on given filesystem */
147errcode_t quota_file_create(struct quota_handle *h, ext2_filsys fs,
148			    int type, int fmt);
149
150/* Close quotafile */
151errcode_t quota_file_close(struct quota_handle *h);
152
153/* Get empty quota structure */
154struct dquot *get_empty_dquot(void);
155
156errcode_t quota_inode_truncate(ext2_filsys fs, ext2_ino_t ino);
157
158const char *type2name(int type);
159
160void update_grace_times(struct dquot *q);
161
162#endif /* GUARD_QUOTAIO_H */
163