2 * vfsv0 quota IO operations on file
5 #include <linux/errno.h>
7 #include <linux/mount.h>
8 #include <linux/dqblk_v2.h>
9 #include <linux/quotaio_v2.h>
10 #include <linux/kernel.h>
11 #include <linux/init.h>
12 #include <linux/module.h>
13 #include <linux/slab.h>
15 #include <asm/byteorder.h>
16 #include <asm/uaccess.h>
18 MODULE_AUTHOR("Jan Kara");
19 MODULE_DESCRIPTION("Quota format v2 support");
20 MODULE_LICENSE("GPL");
22 #define __QUOTA_V2_PARANOIA
24 typedef char *dqbuf_t
;
26 #define GETIDINDEX(id, depth) (((id) >> ((V2_DQTREEDEPTH-(depth)-1)*8)) & 0xff)
27 #define GETENTRIES(buf) ((struct v2_disk_dqblk *)(((char *)buf)+sizeof(struct v2_disk_dqdbheader)))
29 /* Check whether given file is really vfsv0 quotafile */
30 static int v2_check_quota_file(struct super_block
*sb
, int type
)
32 struct v2_disk_dqheader dqhead
;
33 struct file
*f
= sb_dqopt(sb
)->files
[type
];
37 static const uint quota_magics
[] = V2_INITQMAGICS
;
38 static const uint quota_versions
[] = V2_INITQVERSIONS
;
42 size
= f
->f_op
->read(f
, (char *)&dqhead
, sizeof(struct v2_disk_dqheader
), &offset
);
44 if (size
!= sizeof(struct v2_disk_dqheader
))
46 if (le32_to_cpu(dqhead
.dqh_magic
) != quota_magics
[type
] ||
47 le32_to_cpu(dqhead
.dqh_version
) != quota_versions
[type
])
52 /* Read information header from quota file */
53 static int v2_read_file_info(struct super_block
*sb
, int type
)
56 struct v2_disk_dqinfo dinfo
;
57 struct mem_dqinfo
*info
= sb_dqopt(sb
)->info
+type
;
58 struct file
*f
= sb_dqopt(sb
)->files
[type
];
60 loff_t offset
= V2_DQINFOOFF
;
64 size
= f
->f_op
->read(f
, (char *)&dinfo
, sizeof(struct v2_disk_dqinfo
), &offset
);
66 if (size
!= sizeof(struct v2_disk_dqinfo
)) {
67 printk(KERN_WARNING
"Can't read info structure on device %s.\n",
68 f
->f_vfsmnt
->mnt_sb
->s_id
);
71 info
->dqi_bgrace
= le32_to_cpu(dinfo
.dqi_bgrace
);
72 info
->dqi_igrace
= le32_to_cpu(dinfo
.dqi_igrace
);
73 info
->dqi_flags
= le32_to_cpu(dinfo
.dqi_flags
);
74 info
->u
.v2_i
.dqi_blocks
= le32_to_cpu(dinfo
.dqi_blocks
);
75 info
->u
.v2_i
.dqi_free_blk
= le32_to_cpu(dinfo
.dqi_free_blk
);
76 info
->u
.v2_i
.dqi_free_entry
= le32_to_cpu(dinfo
.dqi_free_entry
);
80 /* Write information header to quota file */
81 static int v2_write_file_info(struct super_block
*sb
, int type
)
84 struct v2_disk_dqinfo dinfo
;
85 struct mem_dqinfo
*info
= sb_dqopt(sb
)->info
+type
;
86 struct file
*f
= sb_dqopt(sb
)->files
[type
];
88 loff_t offset
= V2_DQINFOOFF
;
90 info
->dqi_flags
&= ~DQF_INFO_DIRTY
;
91 dinfo
.dqi_bgrace
= cpu_to_le32(info
->dqi_bgrace
);
92 dinfo
.dqi_igrace
= cpu_to_le32(info
->dqi_igrace
);
93 dinfo
.dqi_flags
= cpu_to_le32(info
->dqi_flags
& DQF_MASK
);
94 dinfo
.dqi_blocks
= cpu_to_le32(info
->u
.v2_i
.dqi_blocks
);
95 dinfo
.dqi_free_blk
= cpu_to_le32(info
->u
.v2_i
.dqi_free_blk
);
96 dinfo
.dqi_free_entry
= cpu_to_le32(info
->u
.v2_i
.dqi_free_entry
);
99 size
= f
->f_op
->write(f
, (char *)&dinfo
, sizeof(struct v2_disk_dqinfo
), &offset
);
101 if (size
!= sizeof(struct v2_disk_dqinfo
)) {
102 printk(KERN_WARNING
"Can't write info structure on device %s.\n",
103 f
->f_vfsmnt
->mnt_sb
->s_id
);
109 static void disk2memdqb(struct mem_dqblk
*m
, struct v2_disk_dqblk
*d
)
111 m
->dqb_ihardlimit
= le32_to_cpu(d
->dqb_ihardlimit
);
112 m
->dqb_isoftlimit
= le32_to_cpu(d
->dqb_isoftlimit
);
113 m
->dqb_curinodes
= le32_to_cpu(d
->dqb_curinodes
);
114 m
->dqb_itime
= le64_to_cpu(d
->dqb_itime
);
115 m
->dqb_bhardlimit
= le32_to_cpu(d
->dqb_bhardlimit
);
116 m
->dqb_bsoftlimit
= le32_to_cpu(d
->dqb_bsoftlimit
);
117 m
->dqb_curspace
= le64_to_cpu(d
->dqb_curspace
);
118 m
->dqb_btime
= le64_to_cpu(d
->dqb_btime
);
121 static void mem2diskdqb(struct v2_disk_dqblk
*d
, struct mem_dqblk
*m
, qid_t id
)
123 d
->dqb_ihardlimit
= cpu_to_le32(m
->dqb_ihardlimit
);
124 d
->dqb_isoftlimit
= cpu_to_le32(m
->dqb_isoftlimit
);
125 d
->dqb_curinodes
= cpu_to_le32(m
->dqb_curinodes
);
126 d
->dqb_itime
= cpu_to_le64(m
->dqb_itime
);
127 d
->dqb_bhardlimit
= cpu_to_le32(m
->dqb_bhardlimit
);
128 d
->dqb_bsoftlimit
= cpu_to_le32(m
->dqb_bsoftlimit
);
129 d
->dqb_curspace
= cpu_to_le64(m
->dqb_curspace
);
130 d
->dqb_btime
= cpu_to_le64(m
->dqb_btime
);
131 d
->dqb_id
= cpu_to_le32(id
);
134 static dqbuf_t
getdqbuf(void)
136 dqbuf_t buf
= kmalloc(V2_DQBLKSIZE
, GFP_KERNEL
);
138 printk(KERN_WARNING
"VFS: Not enough memory for quota buffers.\n");
142 static inline void freedqbuf(dqbuf_t buf
)
147 static ssize_t
read_blk(struct file
*filp
, uint blk
, dqbuf_t buf
)
151 loff_t offset
= blk
<<V2_DQBLKSIZE_BITS
;
153 memset(buf
, 0, V2_DQBLKSIZE
);
156 ret
= filp
->f_op
->read(filp
, (char *)buf
, V2_DQBLKSIZE
, &offset
);
161 static ssize_t
write_blk(struct file
*filp
, uint blk
, dqbuf_t buf
)
165 loff_t offset
= blk
<<V2_DQBLKSIZE_BITS
;
169 ret
= filp
->f_op
->write(filp
, (char *)buf
, V2_DQBLKSIZE
, &offset
);
175 /* Remove empty block from list and return it */
176 static int get_free_dqblk(struct file
*filp
, struct mem_dqinfo
*info
)
178 dqbuf_t buf
= getdqbuf();
179 struct v2_disk_dqdbheader
*dh
= (struct v2_disk_dqdbheader
*)buf
;
184 if (info
->u
.v2_i
.dqi_free_blk
) {
185 blk
= info
->u
.v2_i
.dqi_free_blk
;
186 if ((ret
= read_blk(filp
, blk
, buf
)) < 0)
188 info
->u
.v2_i
.dqi_free_blk
= le32_to_cpu(dh
->dqdh_next_free
);
191 memset(buf
, 0, V2_DQBLKSIZE
);
192 if ((ret
= write_blk(filp
, info
->u
.v2_i
.dqi_blocks
, buf
)) < 0) /* Assure block allocation... */
194 blk
= info
->u
.v2_i
.dqi_blocks
++;
196 mark_info_dirty(info
);
203 /* Insert empty block to the list */
204 static int put_free_dqblk(struct file
*filp
, struct mem_dqinfo
*info
, dqbuf_t buf
, uint blk
)
206 struct v2_disk_dqdbheader
*dh
= (struct v2_disk_dqdbheader
*)buf
;
209 dh
->dqdh_next_free
= cpu_to_le32(info
->u
.v2_i
.dqi_free_blk
);
210 dh
->dqdh_prev_free
= cpu_to_le32(0);
211 dh
->dqdh_entries
= cpu_to_le16(0);
212 info
->u
.v2_i
.dqi_free_blk
= blk
;
213 mark_info_dirty(info
);
214 if ((err
= write_blk(filp
, blk
, buf
)) < 0) /* Some strange block. We had better leave it... */
219 /* Remove given block from the list of blocks with free entries */
220 static int remove_free_dqentry(struct file
*filp
, struct mem_dqinfo
*info
, dqbuf_t buf
, uint blk
)
222 dqbuf_t tmpbuf
= getdqbuf();
223 struct v2_disk_dqdbheader
*dh
= (struct v2_disk_dqdbheader
*)buf
;
224 uint nextblk
= le32_to_cpu(dh
->dqdh_next_free
), prevblk
= le32_to_cpu(dh
->dqdh_prev_free
);
230 if ((err
= read_blk(filp
, nextblk
, tmpbuf
)) < 0)
232 ((struct v2_disk_dqdbheader
*)tmpbuf
)->dqdh_prev_free
= dh
->dqdh_prev_free
;
233 if ((err
= write_blk(filp
, nextblk
, tmpbuf
)) < 0)
237 if ((err
= read_blk(filp
, prevblk
, tmpbuf
)) < 0)
239 ((struct v2_disk_dqdbheader
*)tmpbuf
)->dqdh_next_free
= dh
->dqdh_next_free
;
240 if ((err
= write_blk(filp
, prevblk
, tmpbuf
)) < 0)
244 info
->u
.v2_i
.dqi_free_entry
= nextblk
;
245 mark_info_dirty(info
);
248 dh
->dqdh_next_free
= dh
->dqdh_prev_free
= cpu_to_le32(0);
249 if (write_blk(filp
, blk
, buf
) < 0) /* No matter whether write succeeds block is out of list */
250 printk(KERN_ERR
"VFS: Can't write block (%u) with free entries.\n", blk
);
257 /* Insert given block to the beginning of list with free entries */
258 static int insert_free_dqentry(struct file
*filp
, struct mem_dqinfo
*info
, dqbuf_t buf
, uint blk
)
260 dqbuf_t tmpbuf
= getdqbuf();
261 struct v2_disk_dqdbheader
*dh
= (struct v2_disk_dqdbheader
*)buf
;
266 dh
->dqdh_next_free
= cpu_to_le32(info
->u
.v2_i
.dqi_free_entry
);
267 dh
->dqdh_prev_free
= cpu_to_le32(0);
268 if ((err
= write_blk(filp
, blk
, buf
)) < 0)
270 if (info
->u
.v2_i
.dqi_free_entry
) {
271 if ((err
= read_blk(filp
, info
->u
.v2_i
.dqi_free_entry
, tmpbuf
)) < 0)
273 ((struct v2_disk_dqdbheader
*)tmpbuf
)->dqdh_prev_free
= cpu_to_le32(blk
);
274 if ((err
= write_blk(filp
, info
->u
.v2_i
.dqi_free_entry
, tmpbuf
)) < 0)
278 info
->u
.v2_i
.dqi_free_entry
= blk
;
279 mark_info_dirty(info
);
286 /* Find space for dquot */
287 static uint
find_free_dqentry(struct dquot
*dquot
, int *err
)
289 struct file
*filp
= sb_dqopt(dquot
->dq_sb
)->files
[dquot
->dq_type
];
290 struct mem_dqinfo
*info
= sb_dqopt(dquot
->dq_sb
)->info
+dquot
->dq_type
;
292 struct v2_disk_dqdbheader
*dh
;
293 struct v2_disk_dqblk
*ddquot
;
294 struct v2_disk_dqblk fakedquot
;
298 if (!(buf
= getdqbuf())) {
302 dh
= (struct v2_disk_dqdbheader
*)buf
;
303 ddquot
= GETENTRIES(buf
);
304 if (info
->u
.v2_i
.dqi_free_entry
) {
305 blk
= info
->u
.v2_i
.dqi_free_entry
;
306 if ((*err
= read_blk(filp
, blk
, buf
)) < 0)
310 blk
= get_free_dqblk(filp
, info
);
316 memset(buf
, 0, V2_DQBLKSIZE
);
317 info
->u
.v2_i
.dqi_free_entry
= blk
; /* This is enough as block is already zeroed and entry list is empty... */
318 mark_info_dirty(info
);
320 if (le16_to_cpu(dh
->dqdh_entries
)+1 >= V2_DQSTRINBLK
) /* Block will be full? */
321 if ((*err
= remove_free_dqentry(filp
, info
, buf
, blk
)) < 0) {
322 printk(KERN_ERR
"VFS: find_free_dqentry(): Can't remove block (%u) from entry free list.\n", blk
);
325 dh
->dqdh_entries
= cpu_to_le16(le16_to_cpu(dh
->dqdh_entries
)+1);
326 memset(&fakedquot
, 0, sizeof(struct v2_disk_dqblk
));
327 /* Find free structure in block */
328 for (i
= 0; i
< V2_DQSTRINBLK
&& memcmp(&fakedquot
, ddquot
+i
, sizeof(struct v2_disk_dqblk
)); i
++);
329 #ifdef __QUOTA_V2_PARANOIA
330 if (i
== V2_DQSTRINBLK
) {
331 printk(KERN_ERR
"VFS: find_free_dqentry(): Data block full but it shouldn't.\n");
336 if ((*err
= write_blk(filp
, blk
, buf
)) < 0) {
337 printk(KERN_ERR
"VFS: find_free_dqentry(): Can't write quota data block %u.\n", blk
);
340 dquot
->dq_off
= (blk
<<V2_DQBLKSIZE_BITS
)+sizeof(struct v2_disk_dqdbheader
)+i
*sizeof(struct v2_disk_dqblk
);
348 /* Insert reference to structure into the trie */
349 static int do_insert_tree(struct dquot
*dquot
, uint
*treeblk
, int depth
)
351 struct file
*filp
= sb_dqopt(dquot
->dq_sb
)->files
[dquot
->dq_type
];
352 struct mem_dqinfo
*info
= sb_dqopt(dquot
->dq_sb
)->info
+ dquot
->dq_type
;
354 int ret
= 0, newson
= 0, newact
= 0;
358 if (!(buf
= getdqbuf()))
361 ret
= get_free_dqblk(filp
, info
);
365 memset(buf
, 0, V2_DQBLKSIZE
);
369 if ((ret
= read_blk(filp
, *treeblk
, buf
)) < 0) {
370 printk(KERN_ERR
"VFS: Can't read tree quota block %u.\n", *treeblk
);
375 newblk
= le32_to_cpu(ref
[GETIDINDEX(dquot
->dq_id
, depth
)]);
378 if (depth
== V2_DQTREEDEPTH
-1) {
379 #ifdef __QUOTA_V2_PARANOIA
381 printk(KERN_ERR
"VFS: Inserting already present quota entry (block %u).\n", ref
[GETIDINDEX(dquot
->dq_id
, depth
)]);
386 newblk
= find_free_dqentry(dquot
, &ret
);
389 ret
= do_insert_tree(dquot
, &newblk
, depth
+1);
390 if (newson
&& ret
>= 0) {
391 ref
[GETIDINDEX(dquot
->dq_id
, depth
)] = cpu_to_le32(newblk
);
392 ret
= write_blk(filp
, *treeblk
, buf
);
394 else if (newact
&& ret
< 0)
395 put_free_dqblk(filp
, info
, buf
, *treeblk
);
401 /* Wrapper for inserting quota structure into tree */
402 static inline int dq_insert_tree(struct dquot
*dquot
)
404 int tmp
= V2_DQTREEOFF
;
405 return do_insert_tree(dquot
, &tmp
, 0);
409 * We don't have to be afraid of deadlocks as we never have quotas on quota files...
411 static int v2_write_dquot(struct dquot
*dquot
)
413 int type
= dquot
->dq_type
;
418 struct v2_disk_dqblk ddquot
;
421 if ((ret
= dq_insert_tree(dquot
)) < 0) {
422 printk(KERN_ERR
"VFS: Error %Zd occurred while creating quota.\n", ret
);
425 filp
= sb_dqopt(dquot
->dq_sb
)->files
[type
];
426 offset
= dquot
->dq_off
;
427 mem2diskdqb(&ddquot
, &dquot
->dq_dqb
, dquot
->dq_id
);
430 ret
= filp
->f_op
->write(filp
, (char *)&ddquot
, sizeof(struct v2_disk_dqblk
), &offset
);
432 if (ret
!= sizeof(struct v2_disk_dqblk
)) {
433 printk(KERN_WARNING
"VFS: dquota write failed on dev %s\n", dquot
->dq_sb
->s_id
);
444 /* Free dquot entry in data block */
445 static int free_dqentry(struct dquot
*dquot
, uint blk
)
447 struct file
*filp
= sb_dqopt(dquot
->dq_sb
)->files
[dquot
->dq_type
];
448 struct mem_dqinfo
*info
= sb_dqopt(dquot
->dq_sb
)->info
+ dquot
->dq_type
;
449 struct v2_disk_dqdbheader
*dh
;
450 dqbuf_t buf
= getdqbuf();
455 if (dquot
->dq_off
>> V2_DQBLKSIZE_BITS
!= blk
) {
456 printk(KERN_ERR
"VFS: Quota structure has offset to other block (%u) than it should (%u).\n", blk
, (uint
)(dquot
->dq_off
>> V2_DQBLKSIZE_BITS
));
459 if ((ret
= read_blk(filp
, blk
, buf
)) < 0) {
460 printk(KERN_ERR
"VFS: Can't read quota data block %u\n", blk
);
463 dh
= (struct v2_disk_dqdbheader
*)buf
;
464 dh
->dqdh_entries
= cpu_to_le16(le16_to_cpu(dh
->dqdh_entries
)-1);
465 if (!le16_to_cpu(dh
->dqdh_entries
)) { /* Block got free? */
466 if ((ret
= remove_free_dqentry(filp
, info
, buf
, blk
)) < 0 ||
467 (ret
= put_free_dqblk(filp
, info
, buf
, blk
)) < 0) {
468 printk(KERN_ERR
"VFS: Can't move quota data block (%u) to free list.\n", blk
);
473 memset(buf
+(dquot
->dq_off
& ((1 << V2_DQBLKSIZE_BITS
)-1)), 0, sizeof(struct v2_disk_dqblk
));
474 if (le16_to_cpu(dh
->dqdh_entries
) == V2_DQSTRINBLK
-1) {
475 /* Insert will write block itself */
476 if ((ret
= insert_free_dqentry(filp
, info
, buf
, blk
)) < 0) {
477 printk(KERN_ERR
"VFS: Can't insert quota data block (%u) to free entry list.\n", blk
);
482 if ((ret
= write_blk(filp
, blk
, buf
)) < 0) {
483 printk(KERN_ERR
"VFS: Can't write quota data block %u\n", blk
);
487 dquot
->dq_off
= 0; /* Quota is now unattached */
493 /* Remove reference to dquot from tree */
494 static int remove_tree(struct dquot
*dquot
, uint
*blk
, int depth
)
496 struct file
*filp
= sb_dqopt(dquot
->dq_sb
)->files
[dquot
->dq_type
];
497 struct mem_dqinfo
*info
= sb_dqopt(dquot
->dq_sb
)->info
+ dquot
->dq_type
;
498 dqbuf_t buf
= getdqbuf();
501 u32
*ref
= (u32
*)buf
;
505 if ((ret
= read_blk(filp
, *blk
, buf
)) < 0) {
506 printk(KERN_ERR
"VFS: Can't read quota data block %u\n", *blk
);
509 newblk
= le32_to_cpu(ref
[GETIDINDEX(dquot
->dq_id
, depth
)]);
510 if (depth
== V2_DQTREEDEPTH
-1) {
511 ret
= free_dqentry(dquot
, newblk
);
515 ret
= remove_tree(dquot
, &newblk
, depth
+1);
516 if (ret
>= 0 && !newblk
) {
518 ref
[GETIDINDEX(dquot
->dq_id
, depth
)] = cpu_to_le32(0);
519 for (i
= 0; i
< V2_DQBLKSIZE
&& !buf
[i
]; i
++); /* Block got empty? */
520 if (i
== V2_DQBLKSIZE
) {
521 put_free_dqblk(filp
, info
, buf
, *blk
);
525 if ((ret
= write_blk(filp
, *blk
, buf
)) < 0)
526 printk(KERN_ERR
"VFS: Can't write quota tree block %u.\n", *blk
);
533 /* Delete dquot from tree */
534 static int v2_delete_dquot(struct dquot
*dquot
)
536 uint tmp
= V2_DQTREEOFF
;
538 if (!dquot
->dq_off
) /* Even not allocated? */
540 return remove_tree(dquot
, &tmp
, 0);
543 /* Find entry in block */
544 static loff_t
find_block_dqentry(struct dquot
*dquot
, uint blk
)
546 struct file
*filp
= sb_dqopt(dquot
->dq_sb
)->files
[dquot
->dq_type
];
547 dqbuf_t buf
= getdqbuf();
550 struct v2_disk_dqblk
*ddquot
= GETENTRIES(buf
);
554 if ((ret
= read_blk(filp
, blk
, buf
)) < 0) {
555 printk(KERN_ERR
"VFS: Can't read quota tree block %u.\n", blk
);
559 for (i
= 0; i
< V2_DQSTRINBLK
&& le32_to_cpu(ddquot
[i
].dqb_id
) != dquot
->dq_id
; i
++);
560 else { /* ID 0 as a bit more complicated searching... */
561 struct v2_disk_dqblk fakedquot
;
563 memset(&fakedquot
, 0, sizeof(struct v2_disk_dqblk
));
564 for (i
= 0; i
< V2_DQSTRINBLK
; i
++)
565 if (!le32_to_cpu(ddquot
[i
].dqb_id
) && memcmp(&fakedquot
, ddquot
+i
, sizeof(struct v2_disk_dqblk
)))
568 if (i
== V2_DQSTRINBLK
) {
569 printk(KERN_ERR
"VFS: Quota for id %u referenced but not present.\n", dquot
->dq_id
);
574 ret
= (blk
<< V2_DQBLKSIZE_BITS
) + sizeof(struct v2_disk_dqdbheader
) + i
* sizeof(struct v2_disk_dqblk
);
580 /* Find entry for given id in the tree */
581 static loff_t
find_tree_dqentry(struct dquot
*dquot
, uint blk
, int depth
)
583 struct file
*filp
= sb_dqopt(dquot
->dq_sb
)->files
[dquot
->dq_type
];
584 dqbuf_t buf
= getdqbuf();
586 u32
*ref
= (u32
*)buf
;
590 if ((ret
= read_blk(filp
, blk
, buf
)) < 0) {
591 printk(KERN_ERR
"VFS: Can't read quota tree block %u.\n", blk
);
595 blk
= le32_to_cpu(ref
[GETIDINDEX(dquot
->dq_id
, depth
)]);
596 if (!blk
) /* No reference? */
598 if (depth
< V2_DQTREEDEPTH
-1)
599 ret
= find_tree_dqentry(dquot
, blk
, depth
+1);
601 ret
= find_block_dqentry(dquot
, blk
);
607 /* Find entry for given id in the tree - wrapper function */
608 static inline loff_t
find_dqentry(struct dquot
*dquot
)
610 return find_tree_dqentry(dquot
, V2_DQTREEOFF
, 0);
613 static int v2_read_dquot(struct dquot
*dquot
)
615 int type
= dquot
->dq_type
;
619 struct v2_disk_dqblk ddquot
;
622 filp
= sb_dqopt(dquot
->dq_sb
)->files
[type
];
624 #ifdef __QUOTA_V2_PARANOIA
625 if (!filp
|| !dquot
->dq_sb
) { /* Invalidated quota? */
626 printk(KERN_ERR
"VFS: Quota invalidated while reading!\n");
630 offset
= find_dqentry(dquot
);
631 if (offset
<= 0) { /* Entry not present? */
633 printk(KERN_ERR
"VFS: Can't read quota structure for id %u.\n", dquot
->dq_id
);
635 dquot
->dq_flags
|= DQ_FAKE
;
636 memset(&dquot
->dq_dqb
, 0, sizeof(struct mem_dqblk
));
640 dquot
->dq_off
= offset
;
643 if ((ret
= filp
->f_op
->read(filp
, (char *)&ddquot
, sizeof(struct v2_disk_dqblk
), &offset
)) != sizeof(struct v2_disk_dqblk
)) {
646 printk(KERN_ERR
"VFS: Error while reading quota structure for id %u.\n", dquot
->dq_id
);
647 memset(&ddquot
, 0, sizeof(struct v2_disk_dqblk
));
652 disk2memdqb(&dquot
->dq_dqb
, &ddquot
);
659 /* Commit changes of dquot to disk - it might also mean deleting it when quota became fake one and user has no blocks... */
660 static int v2_commit_dquot(struct dquot
*dquot
)
662 /* We clear the flag everytime so we don't loop when there was an IO error... */
663 dquot
->dq_flags
&= ~DQ_MOD
;
664 if (dquot
->dq_flags
& DQ_FAKE
&& !(dquot
->dq_dqb
.dqb_curinodes
| dquot
->dq_dqb
.dqb_curspace
))
665 return v2_delete_dquot(dquot
);
667 return v2_write_dquot(dquot
);
670 static struct quota_format_ops v2_format_ops
= {
671 .check_quota_file
= v2_check_quota_file
,
672 .read_file_info
= v2_read_file_info
,
673 .write_file_info
= v2_write_file_info
,
674 .free_file_info
= NULL
,
675 .read_dqblk
= v2_read_dquot
,
676 .commit_dqblk
= v2_commit_dquot
,
679 static struct quota_format_type v2_quota_format
= {
680 .qf_fmt_id
= QFMT_VFS_V0
,
681 .qf_ops
= &v2_format_ops
,
682 .qf_owner
= THIS_MODULE
685 static int __init
init_v2_quota_format(void)
687 return register_quota_format(&v2_quota_format
);
690 static void __exit
exit_v2_quota_format(void)
692 unregister_quota_format(&v2_quota_format
);
695 module_init(init_v2_quota_format
);
696 module_exit(exit_v2_quota_format
);