1
2
3
4
5
6
7
8
9
10#ifndef _LINUX_QUOTAOPS_
11#define _LINUX_QUOTAOPS_
12
13#include <linux/smp_lock.h>
14
15#include <linux/fs.h>
16
17#if defined(CONFIG_QUOTA)
18
19
20
21
22extern void sync_dquots(struct super_block *sb, int type);
23
24extern int dquot_initialize(struct inode *inode, int type);
25extern int dquot_drop(struct inode *inode);
26
27extern int dquot_alloc_space(struct inode *inode, qsize_t number, int prealloc);
28extern int dquot_alloc_inode(const struct inode *inode, unsigned long number);
29
30extern int dquot_free_space(struct inode *inode, qsize_t number);
31extern int dquot_free_inode(const struct inode *inode, unsigned long number);
32
33extern int dquot_transfer(struct inode *inode, struct iattr *iattr);
34extern int dquot_commit(struct dquot *dquot);
35extern int dquot_acquire(struct dquot *dquot);
36extern int dquot_release(struct dquot *dquot);
37extern int dquot_commit_info(struct super_block *sb, int type);
38extern int dquot_mark_dquot_dirty(struct dquot *dquot);
39
40extern int vfs_quota_on(struct super_block *sb, int type, int format_id, char *path);
41extern int vfs_quota_on_mount(struct super_block *sb, char *qf_name,
42 int format_id, int type);
43extern int vfs_quota_off(struct super_block *sb, int type);
44#define vfs_quota_off_mount(sb, type) vfs_quota_off(sb, type)
45extern int vfs_quota_sync(struct super_block *sb, int type);
46extern int vfs_get_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
47extern int vfs_set_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
48extern int vfs_get_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di);
49extern int vfs_set_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di);
50
51
52
53
54extern struct dquot_operations dquot_operations;
55extern struct quotactl_ops vfs_quotactl_ops;
56
57#define sb_dquot_ops (&dquot_operations)
58#define sb_quotactl_ops (&vfs_quotactl_ops)
59
60
61
62static __inline__ void DQUOT_INIT(struct inode *inode)
63{
64 BUG_ON(!inode->i_sb);
65 if (sb_any_quota_enabled(inode->i_sb) && !IS_NOQUOTA(inode))
66 inode->i_sb->dq_op->initialize(inode, -1);
67}
68
69
70static __inline__ void DQUOT_DROP(struct inode *inode)
71{
72
73
74
75 if (!IS_NOQUOTA(inode) && inode->i_sb && inode->i_sb->dq_op
76 && inode->i_sb->dq_op->drop) {
77 int cnt;
78
79
80
81
82
83 for (cnt = 0; cnt < MAXQUOTAS; cnt++)
84 if (inode->i_dquot[cnt] != NODQUOT)
85 break;
86 if (cnt < MAXQUOTAS)
87 inode->i_sb->dq_op->drop(inode);
88 }
89}
90
91
92
93static __inline__ int DQUOT_PREALLOC_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
94{
95 if (sb_any_quota_enabled(inode->i_sb)) {
96
97 if (inode->i_sb->dq_op->alloc_space(inode, nr, 1) == NO_QUOTA)
98 return 1;
99 }
100 else
101 inode_add_bytes(inode, nr);
102 return 0;
103}
104
105static __inline__ int DQUOT_PREALLOC_SPACE(struct inode *inode, qsize_t nr)
106{
107 int ret;
108 if (!(ret = DQUOT_PREALLOC_SPACE_NODIRTY(inode, nr)))
109 mark_inode_dirty(inode);
110 return ret;
111}
112
113static __inline__ int DQUOT_ALLOC_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
114{
115 if (sb_any_quota_enabled(inode->i_sb)) {
116
117 if (inode->i_sb->dq_op->alloc_space(inode, nr, 0) == NO_QUOTA)
118 return 1;
119 }
120 else
121 inode_add_bytes(inode, nr);
122 return 0;
123}
124
125static __inline__ int DQUOT_ALLOC_SPACE(struct inode *inode, qsize_t nr)
126{
127 int ret;
128 if (!(ret = DQUOT_ALLOC_SPACE_NODIRTY(inode, nr)))
129 mark_inode_dirty(inode);
130 return ret;
131}
132
133static __inline__ int DQUOT_ALLOC_INODE(struct inode *inode)
134{
135 if (sb_any_quota_enabled(inode->i_sb)) {
136 DQUOT_INIT(inode);
137 if (inode->i_sb->dq_op->alloc_inode(inode, 1) == NO_QUOTA)
138 return 1;
139 }
140 return 0;
141}
142
143static __inline__ void DQUOT_FREE_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
144{
145 if (sb_any_quota_enabled(inode->i_sb))
146 inode->i_sb->dq_op->free_space(inode, nr);
147 else
148 inode_sub_bytes(inode, nr);
149}
150
151static __inline__ void DQUOT_FREE_SPACE(struct inode *inode, qsize_t nr)
152{
153 DQUOT_FREE_SPACE_NODIRTY(inode, nr);
154 mark_inode_dirty(inode);
155}
156
157static __inline__ void DQUOT_FREE_INODE(struct inode *inode)
158{
159 if (sb_any_quota_enabled(inode->i_sb))
160 inode->i_sb->dq_op->free_inode(inode, 1);
161}
162
163static __inline__ int DQUOT_TRANSFER(struct inode *inode, struct iattr *iattr)
164{
165 if (sb_any_quota_enabled(inode->i_sb) && !IS_NOQUOTA(inode)) {
166 DQUOT_INIT(inode);
167 if (inode->i_sb->dq_op->transfer(inode, iattr) == NO_QUOTA)
168 return 1;
169 }
170 return 0;
171}
172
173
174#define DQUOT_SYNC(sb) sync_dquots(sb, -1)
175
176static __inline__ int DQUOT_OFF(struct super_block *sb)
177{
178 int ret = -ENOSYS;
179
180 if (sb_any_quota_enabled(sb) && sb->s_qcop && sb->s_qcop->quota_off)
181 ret = sb->s_qcop->quota_off(sb, -1);
182 return ret;
183}
184
185#else
186
187
188
189
190#define sb_dquot_ops (NULL)
191#define sb_quotactl_ops (NULL)
192#define DQUOT_INIT(inode) do { } while(0)
193#define DQUOT_DROP(inode) do { } while(0)
194#define DQUOT_ALLOC_INODE(inode) (0)
195#define DQUOT_FREE_INODE(inode) do { } while(0)
196#define DQUOT_SYNC(sb) do { } while(0)
197#define DQUOT_OFF(sb) do { } while(0)
198#define DQUOT_TRANSFER(inode, iattr) (0)
199static inline int DQUOT_PREALLOC_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
200{
201 inode_add_bytes(inode, nr);
202 return 0;
203}
204
205static inline int DQUOT_PREALLOC_SPACE(struct inode *inode, qsize_t nr)
206{
207 DQUOT_PREALLOC_SPACE_NODIRTY(inode, nr);
208 mark_inode_dirty(inode);
209 return 0;
210}
211
212static inline int DQUOT_ALLOC_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
213{
214 inode_add_bytes(inode, nr);
215 return 0;
216}
217
218static inline int DQUOT_ALLOC_SPACE(struct inode *inode, qsize_t nr)
219{
220 DQUOT_ALLOC_SPACE_NODIRTY(inode, nr);
221 mark_inode_dirty(inode);
222 return 0;
223}
224
225static inline void DQUOT_FREE_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
226{
227 inode_sub_bytes(inode, nr);
228}
229
230static inline void DQUOT_FREE_SPACE(struct inode *inode, qsize_t nr)
231{
232 DQUOT_FREE_SPACE_NODIRTY(inode, nr);
233 mark_inode_dirty(inode);
234}
235
236#endif
237
238#define DQUOT_PREALLOC_BLOCK_NODIRTY(inode, nr) DQUOT_PREALLOC_SPACE_NODIRTY(inode, ((qsize_t)(nr)) << (inode)->i_sb->s_blocksize_bits)
239#define DQUOT_PREALLOC_BLOCK(inode, nr) DQUOT_PREALLOC_SPACE(inode, ((qsize_t)(nr)) << (inode)->i_sb->s_blocksize_bits)
240#define DQUOT_ALLOC_BLOCK_NODIRTY(inode, nr) DQUOT_ALLOC_SPACE_NODIRTY(inode, ((qsize_t)(nr)) << (inode)->i_sb->s_blocksize_bits)
241#define DQUOT_ALLOC_BLOCK(inode, nr) DQUOT_ALLOC_SPACE(inode, ((qsize_t)(nr)) << (inode)->i_sb->s_blocksize_bits)
242#define DQUOT_FREE_BLOCK_NODIRTY(inode, nr) DQUOT_FREE_SPACE_NODIRTY(inode, ((qsize_t)(nr)) << (inode)->i_sb->s_blocksize_bits)
243#define DQUOT_FREE_BLOCK(inode, nr) DQUOT_FREE_SPACE(inode, ((qsize_t)(nr)) << (inode)->i_sb->s_blocksize_bits)
244
245#endif
246