aboutsummaryrefslogtreecommitdiffstats
path: root/fs/quota_v1.c
diff options
context:
space:
mode:
authorJan Kara <jack@suse.cz>2009-01-26 09:28:09 -0500
committerJan Kara <jack@suse.cz>2009-03-25 21:18:35 -0400
commit884d179dff3aa98a73c3ba9dee05fd6050d664f0 (patch)
tree68c18e3ff8decd2af861e807bed96cca2dea30d4 /fs/quota_v1.c
parent60e58e0f30e723464c2a7d34b71b8675566c572d (diff)
quota: Move quota files into separate directory
Quota subsystem has more and more files. It's time to create a dir for it. Signed-off-by: Jan Kara <jack@suse.cz>
Diffstat (limited to 'fs/quota_v1.c')
-rw-r--r--fs/quota_v1.c218
1 files changed, 0 insertions, 218 deletions
diff --git a/fs/quota_v1.c b/fs/quota_v1.c
deleted file mode 100644
index b4af1c69ad16..000000000000
--- a/fs/quota_v1.c
+++ /dev/null
@@ -1,218 +0,0 @@
1#include <linux/errno.h>
2#include <linux/fs.h>
3#include <linux/quota.h>
4#include <linux/quotaops.h>
5#include <linux/dqblk_v1.h>
6#include <linux/kernel.h>
7#include <linux/init.h>
8#include <linux/module.h>
9
10#include <asm/byteorder.h>
11
12#include "quotaio_v1.h"
13
14MODULE_AUTHOR("Jan Kara");
15MODULE_DESCRIPTION("Old quota format support");
16MODULE_LICENSE("GPL");
17
18#define QUOTABLOCK_BITS 10
19#define QUOTABLOCK_SIZE (1 << QUOTABLOCK_BITS)
20
21static inline qsize_t v1_stoqb(qsize_t space)
22{
23 return (space + QUOTABLOCK_SIZE - 1) >> QUOTABLOCK_BITS;
24}
25
26static inline qsize_t v1_qbtos(qsize_t blocks)
27{
28 return blocks << QUOTABLOCK_BITS;
29}
30
31static void v1_disk2mem_dqblk(struct mem_dqblk *m, struct v1_disk_dqblk *d)
32{
33 m->dqb_ihardlimit = d->dqb_ihardlimit;
34 m->dqb_isoftlimit = d->dqb_isoftlimit;
35 m->dqb_curinodes = d->dqb_curinodes;
36 m->dqb_bhardlimit = v1_qbtos(d->dqb_bhardlimit);
37 m->dqb_bsoftlimit = v1_qbtos(d->dqb_bsoftlimit);
38 m->dqb_curspace = v1_qbtos(d->dqb_curblocks);
39 m->dqb_itime = d->dqb_itime;
40 m->dqb_btime = d->dqb_btime;
41}
42
43static void v1_mem2disk_dqblk(struct v1_disk_dqblk *d, struct mem_dqblk *m)
44{
45 d->dqb_ihardlimit = m->dqb_ihardlimit;
46 d->dqb_isoftlimit = m->dqb_isoftlimit;
47 d->dqb_curinodes = m->dqb_curinodes;
48 d->dqb_bhardlimit = v1_stoqb(m->dqb_bhardlimit);
49 d->dqb_bsoftlimit = v1_stoqb(m->dqb_bsoftlimit);
50 d->dqb_curblocks = v1_stoqb(m->dqb_curspace);
51 d->dqb_itime = m->dqb_itime;
52 d->dqb_btime = m->dqb_btime;
53}
54
55static int v1_read_dqblk(struct dquot *dquot)
56{
57 int type = dquot->dq_type;
58 struct v1_disk_dqblk dqblk;
59
60 if (!sb_dqopt(dquot->dq_sb)->files[type])
61 return -EINVAL;
62
63 /* Set structure to 0s in case read fails/is after end of file */
64 memset(&dqblk, 0, sizeof(struct v1_disk_dqblk));
65 dquot->dq_sb->s_op->quota_read(dquot->dq_sb, type, (char *)&dqblk, sizeof(struct v1_disk_dqblk), v1_dqoff(dquot->dq_id));
66
67 v1_disk2mem_dqblk(&dquot->dq_dqb, &dqblk);
68 if (dquot->dq_dqb.dqb_bhardlimit == 0 && dquot->dq_dqb.dqb_bsoftlimit == 0 &&
69 dquot->dq_dqb.dqb_ihardlimit == 0 && dquot->dq_dqb.dqb_isoftlimit == 0)
70 set_bit(DQ_FAKE_B, &dquot->dq_flags);
71 dqstats.reads++;
72
73 return 0;
74}
75
76static int v1_commit_dqblk(struct dquot *dquot)
77{
78 short type = dquot->dq_type;
79 ssize_t ret;
80 struct v1_disk_dqblk dqblk;
81
82 v1_mem2disk_dqblk(&dqblk, &dquot->dq_dqb);
83 if (dquot->dq_id == 0) {
84 dqblk.dqb_btime = sb_dqopt(dquot->dq_sb)->info[type].dqi_bgrace;
85 dqblk.dqb_itime = sb_dqopt(dquot->dq_sb)->info[type].dqi_igrace;
86 }
87 ret = 0;
88 if (sb_dqopt(dquot->dq_sb)->files[type])
89 ret = dquot->dq_sb->s_op->quota_write(dquot->dq_sb, type, (char *)&dqblk,
90 sizeof(struct v1_disk_dqblk), v1_dqoff(dquot->dq_id));
91 if (ret != sizeof(struct v1_disk_dqblk)) {
92 printk(KERN_WARNING "VFS: dquota write failed on dev %s\n",
93 dquot->dq_sb->s_id);
94 if (ret >= 0)
95 ret = -EIO;
96 goto out;
97 }
98 ret = 0;
99
100out:
101 dqstats.writes++;
102
103 return ret;
104}
105
106/* Magics of new quota format */
107#define V2_INITQMAGICS {\
108 0xd9c01f11, /* USRQUOTA */\
109 0xd9c01927 /* GRPQUOTA */\
110}
111
112/* Header of new quota format */
113struct v2_disk_dqheader {
114 __le32 dqh_magic; /* Magic number identifying file */
115 __le32 dqh_version; /* File version */
116};
117
118static int v1_check_quota_file(struct super_block *sb, int type)
119{
120 struct inode *inode = sb_dqopt(sb)->files[type];
121 ulong blocks;
122 size_t off;
123 struct v2_disk_dqheader dqhead;
124 ssize_t size;
125 loff_t isize;
126 static const uint quota_magics[] = V2_INITQMAGICS;
127
128 isize = i_size_read(inode);
129 if (!isize)
130 return 0;
131 blocks = isize >> BLOCK_SIZE_BITS;
132 off = isize & (BLOCK_SIZE - 1);
133 if ((blocks % sizeof(struct v1_disk_dqblk) * BLOCK_SIZE + off) % sizeof(struct v1_disk_dqblk))
134 return 0;
135 /* Doublecheck whether we didn't get file with new format - with old quotactl() this could happen */
136 size = sb->s_op->quota_read(sb, type, (char *)&dqhead, sizeof(struct v2_disk_dqheader), 0);
137 if (size != sizeof(struct v2_disk_dqheader))
138 return 1; /* Probably not new format */
139 if (le32_to_cpu(dqhead.dqh_magic) != quota_magics[type])
140 return 1; /* Definitely not new format */
141 printk(KERN_INFO "VFS: %s: Refusing to turn on old quota format on given file. It probably contains newer quota format.\n", sb->s_id);
142 return 0; /* Seems like a new format file -> refuse it */
143}
144
145static int v1_read_file_info(struct super_block *sb, int type)
146{
147 struct quota_info *dqopt = sb_dqopt(sb);
148 struct v1_disk_dqblk dqblk;
149 int ret;
150
151 if ((ret = sb->s_op->quota_read(sb, type, (char *)&dqblk, sizeof(struct v1_disk_dqblk), v1_dqoff(0))) != sizeof(struct v1_disk_dqblk)) {
152 if (ret >= 0)
153 ret = -EIO;
154 goto out;
155 }
156 ret = 0;
157 /* limits are stored as unsigned 32-bit data */
158 dqopt->info[type].dqi_maxblimit = 0xffffffff;
159 dqopt->info[type].dqi_maxilimit = 0xffffffff;
160 dqopt->info[type].dqi_igrace = dqblk.dqb_itime ? dqblk.dqb_itime : MAX_IQ_TIME;
161 dqopt->info[type].dqi_bgrace = dqblk.dqb_btime ? dqblk.dqb_btime : MAX_DQ_TIME;
162out:
163 return ret;
164}
165
166static int v1_write_file_info(struct super_block *sb, int type)
167{
168 struct quota_info *dqopt = sb_dqopt(sb);
169 struct v1_disk_dqblk dqblk;
170 int ret;
171
172 dqopt->info[type].dqi_flags &= ~DQF_INFO_DIRTY;
173 if ((ret = sb->s_op->quota_read(sb, type, (char *)&dqblk,
174 sizeof(struct v1_disk_dqblk), v1_dqoff(0))) != sizeof(struct v1_disk_dqblk)) {
175 if (ret >= 0)
176 ret = -EIO;
177 goto out;
178 }
179 dqblk.dqb_itime = dqopt->info[type].dqi_igrace;
180 dqblk.dqb_btime = dqopt->info[type].dqi_bgrace;
181 ret = sb->s_op->quota_write(sb, type, (char *)&dqblk,
182 sizeof(struct v1_disk_dqblk), v1_dqoff(0));
183 if (ret == sizeof(struct v1_disk_dqblk))
184 ret = 0;
185 else if (ret > 0)
186 ret = -EIO;
187out:
188 return ret;
189}
190
191static struct quota_format_ops v1_format_ops = {
192 .check_quota_file = v1_check_quota_file,
193 .read_file_info = v1_read_file_info,
194 .write_file_info = v1_write_file_info,
195 .free_file_info = NULL,
196 .read_dqblk = v1_read_dqblk,
197 .commit_dqblk = v1_commit_dqblk,
198};
199
200static struct quota_format_type v1_quota_format = {
201 .qf_fmt_id = QFMT_VFS_OLD,
202 .qf_ops = &v1_format_ops,
203 .qf_owner = THIS_MODULE
204};
205
206static int __init init_v1_quota_format(void)
207{
208 return register_quota_format(&v1_quota_format);
209}
210
211static void __exit exit_v1_quota_format(void)
212{
213 unregister_quota_format(&v1_quota_format);
214}
215
216module_init(init_v1_quota_format);
217module_exit(exit_v1_quota_format);
218