More cleaning ...
[linux-2.6/linux-mips.git] / include / linux / quotaops.h
blobad88acfd7b70fef5cdaefd7389af97f73bd161e7
1 /*
2 * Definitions for diskquota-operations. When diskquota is configured these
3 * macros expand to the right source-code.
5 * Author: Marco van Wieringen <mvw@planets.elm.net>
7 * Version: $Id: quotaops.h,v 1.2 1998/01/15 16:22:26 ecd Exp $
9 */
10 #ifndef _LINUX_QUOTAOPS_
11 #define _LINUX_QUOTAOPS_
13 #include <linux/config.h>
14 #include <linux/smp_lock.h>
16 #include <linux/fs.h>
18 #if defined(CONFIG_QUOTA)
21 * declaration of quota_function calls in kernel.
23 extern void sync_dquots(struct super_block *sb, int type);
25 extern void dquot_initialize(struct inode *inode, int type);
26 extern void dquot_drop(struct inode *inode);
28 extern int dquot_alloc_space(struct inode *inode, qsize_t number, int prealloc);
29 extern int dquot_alloc_inode(const struct inode *inode, unsigned long number);
31 extern void dquot_free_space(struct inode *inode, qsize_t number);
32 extern void dquot_free_inode(const struct inode *inode, unsigned long number);
34 extern int dquot_transfer(struct inode *inode, struct iattr *iattr);
37 * Operations supported for diskquotas.
39 extern struct dquot_operations dquot_operations;
40 extern struct quotactl_ops vfs_quotactl_ops;
42 #define sb_dquot_ops (&dquot_operations)
43 #define sb_quotactl_ops (&vfs_quotactl_ops)
45 static __inline__ void DQUOT_INIT(struct inode *inode)
47 if (!inode->i_sb)
48 BUG();
49 if (sb_any_quota_enabled(inode->i_sb) && !IS_NOQUOTA(inode))
50 inode->i_sb->dq_op->initialize(inode, -1);
53 static __inline__ void DQUOT_DROP(struct inode *inode)
55 if (IS_QUOTAINIT(inode)) {
56 if (!inode->i_sb)
57 BUG();
58 inode->i_sb->dq_op->drop(inode); /* Ops must be set when there's any quota... */
62 static __inline__ int DQUOT_PREALLOC_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
64 if (sb_any_quota_enabled(inode->i_sb)) {
65 /* Used space is updated in alloc_space() */
66 if (inode->i_sb->dq_op->alloc_space(inode, nr, 1) == NO_QUOTA)
67 return 1;
69 else {
70 spin_lock(&dq_data_lock);
71 inode_add_bytes(inode, nr);
72 spin_unlock(&dq_data_lock);
74 return 0;
77 static __inline__ int DQUOT_PREALLOC_SPACE(struct inode *inode, qsize_t nr)
79 int ret;
80 if (!(ret = DQUOT_PREALLOC_SPACE_NODIRTY(inode, nr)))
81 mark_inode_dirty(inode);
82 return ret;
85 static __inline__ int DQUOT_ALLOC_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
87 if (sb_any_quota_enabled(inode->i_sb)) {
88 /* Used space is updated in alloc_space() */
89 if (inode->i_sb->dq_op->alloc_space(inode, nr, 0) == NO_QUOTA)
90 return 1;
92 else {
93 spin_lock(&dq_data_lock);
94 inode_add_bytes(inode, nr);
95 spin_unlock(&dq_data_lock);
97 return 0;
100 static __inline__ int DQUOT_ALLOC_SPACE(struct inode *inode, qsize_t nr)
102 int ret;
103 if (!(ret = DQUOT_ALLOC_SPACE_NODIRTY(inode, nr)))
104 mark_inode_dirty(inode);
105 return ret;
108 static __inline__ int DQUOT_ALLOC_INODE(struct inode *inode)
110 if (sb_any_quota_enabled(inode->i_sb)) {
111 DQUOT_INIT(inode);
112 if (inode->i_sb->dq_op->alloc_inode(inode, 1) == NO_QUOTA)
113 return 1;
115 return 0;
118 static __inline__ void DQUOT_FREE_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
120 if (sb_any_quota_enabled(inode->i_sb))
121 inode->i_sb->dq_op->free_space(inode, nr);
122 else {
123 spin_lock(&dq_data_lock);
124 inode_sub_bytes(inode, nr);
125 spin_unlock(&dq_data_lock);
129 static __inline__ void DQUOT_FREE_SPACE(struct inode *inode, qsize_t nr)
131 DQUOT_FREE_SPACE_NODIRTY(inode, nr);
132 mark_inode_dirty(inode);
135 static __inline__ void DQUOT_FREE_INODE(struct inode *inode)
137 if (sb_any_quota_enabled(inode->i_sb))
138 inode->i_sb->dq_op->free_inode(inode, 1);
141 static __inline__ int DQUOT_TRANSFER(struct inode *inode, struct iattr *iattr)
143 if (sb_any_quota_enabled(inode->i_sb) && !IS_NOQUOTA(inode)) {
144 DQUOT_INIT(inode);
145 if (inode->i_sb->dq_op->transfer(inode, iattr) == NO_QUOTA)
146 return 1;
148 return 0;
151 #define DQUOT_SYNC(sb) sync_dquots(sb, -1)
153 static __inline__ int DQUOT_OFF(struct super_block *sb)
155 int ret = -ENOSYS;
157 if (sb->s_qcop && sb->s_qcop->quota_off)
158 ret = sb->s_qcop->quota_off(sb, -1);
159 return ret;
162 #else
165 * NO-OP when quota not configured.
167 #define sb_dquot_ops (NULL)
168 #define sb_quotactl_ops (NULL)
169 #define sync_dquots_dev(dev,type) (NULL)
170 #define DQUOT_INIT(inode) do { } while(0)
171 #define DQUOT_DROP(inode) do { } while(0)
172 #define DQUOT_ALLOC_INODE(inode) (0)
173 #define DQUOT_FREE_INODE(inode) do { } while(0)
174 #define DQUOT_SYNC(sb) do { } while(0)
175 #define DQUOT_OFF(sb) do { } while(0)
176 #define DQUOT_TRANSFER(inode, iattr) (0)
177 extern __inline__ int DQUOT_PREALLOC_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
179 inode_add_bytes(inode, nr);
180 return 0;
183 extern __inline__ int DQUOT_PREALLOC_SPACE(struct inode *inode, qsize_t nr)
185 DQUOT_PREALLOC_SPACE_NODIRTY(inode, nr);
186 mark_inode_dirty(inode);
187 return 0;
190 extern __inline__ int DQUOT_ALLOC_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
192 inode_add_bytes(inode, nr);
193 return 0;
196 extern __inline__ int DQUOT_ALLOC_SPACE(struct inode *inode, qsize_t nr)
198 DQUOT_ALLOC_SPACE_NODIRTY(inode, nr);
199 mark_inode_dirty(inode);
200 return 0;
203 extern __inline__ void DQUOT_FREE_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
205 inode_sub_bytes(inode, nr);
208 extern __inline__ void DQUOT_FREE_SPACE(struct inode *inode, qsize_t nr)
210 DQUOT_FREE_SPACE_NODIRTY(inode, nr);
211 mark_inode_dirty(inode);
214 #endif /* CONFIG_QUOTA */
216 #define DQUOT_PREALLOC_BLOCK_NODIRTY(inode, nr) DQUOT_PREALLOC_SPACE_NODIRTY(inode, ((qsize_t)(nr)) << (inode)->i_sb->s_blocksize_bits)
217 #define DQUOT_PREALLOC_BLOCK(inode, nr) DQUOT_PREALLOC_SPACE(inode, ((qsize_t)(nr)) << (inode)->i_sb->s_blocksize_bits)
218 #define DQUOT_ALLOC_BLOCK_NODIRTY(inode, nr) DQUOT_ALLOC_SPACE_NODIRTY(inode, ((qsize_t)(nr)) << (inode)->i_sb->s_blocksize_bits)
219 #define DQUOT_ALLOC_BLOCK(inode, nr) DQUOT_ALLOC_SPACE(inode, ((qsize_t)(nr)) << (inode)->i_sb->s_blocksize_bits)
220 #define DQUOT_FREE_BLOCK_NODIRTY(inode, nr) DQUOT_FREE_SPACE_NODIRTY(inode, ((qsize_t)(nr)) << (inode)->i_sb->s_blocksize_bits)
221 #define DQUOT_FREE_BLOCK(inode, nr) DQUOT_FREE_SPACE(inode, ((qsize_t)(nr)) << (inode)->i_sb->s_blocksize_bits)
223 #endif /* _LINUX_QUOTAOPS_ */