5 #include <linux/errno.h>
9 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/slab.h>
15 #include <asm/byteorder.h>
23 #define __QUOTA_QT_PARANOIA
43 static char *getdqbuf(
size_t size)
48 "VFS: Not enough memory for quota buffers.\n");
69 quota_error(sb,
"dquota write failed");
87 ret = read_blk(info, blk, buf);
116 err = write_blk(info, blk, buf);
137 err = read_blk(info, nextblk, tmpbuf);
142 err = write_blk(info, nextblk, tmpbuf);
147 err = read_blk(info, prevblk, tmpbuf);
152 err = write_blk(info, prevblk, tmpbuf);
162 if (write_blk(info, blk, buf) < 0)
163 quota_error(info->
dqi_sb,
"Can't write block (%u) "
164 "with free entries", blk);
183 err = write_blk(info, blk, buf);
234 *err = read_blk(info, blk, buf);
238 blk = get_free_dqblk(info);
252 *err = remove_free_dqentry(info, buf, blk);
254 quota_error(dquot->
dq_sb,
"Can't remove block (%u) "
255 "from entry free list", blk);
262 for (i = 0; i < qtree_dqstr_in_blk(info); i++) {
267 #ifdef __QUOTA_QT_PARANOIA
268 if (i == qtree_dqstr_in_blk(info)) {
269 quota_error(dquot->
dq_sb,
"Data block full but it shouldn't");
274 *err = write_blk(info, blk, buf);
276 quota_error(dquot->
dq_sb,
"Can't write quota data block %u",
291 static int do_insert_tree(
struct qtree_mem_dqinfo *info,
struct dquot *dquot,
295 int ret = 0, newson = 0, newact = 0;
302 ret = get_free_dqblk(info);
309 ret = read_blk(info, *treeblk, buf);
311 quota_error(dquot->
dq_sb,
"Can't read tree quota "
312 "block %u", *treeblk);
321 #ifdef __QUOTA_QT_PARANOIA
323 quota_error(dquot->
dq_sb,
"Inserting already present "
324 "quota entry (block %u)",
326 dquot->
dq_id, depth)]));
331 newblk = find_free_dqentry(info, dquot, &ret);
333 ret = do_insert_tree(info, dquot, &newblk, depth+1);
335 if (newson && ret >= 0) {
336 ref[get_index(info, dquot->
dq_id, depth)] =
338 ret = write_blk(info, *treeblk, buf);
339 }
else if (newact && ret < 0) {
340 put_free_dqblk(info, buf, *treeblk);
352 return do_insert_tree(info, dquot, &tmp, 0);
371 ret = dq_insert_tree(info, dquot);
373 quota_error(sb,
"Error %zd occurred while creating "
380 info->
dqi_ops->mem2disk_dqblk(ddquot, dquot);
385 quota_error(sb,
"dquota write failed");
409 quota_error(dquot->
dq_sb,
"Quota structure has offset to "
410 "other block (%u) than it should (%u)", blk,
414 ret = read_blk(info, blk, buf);
416 quota_error(dquot->
dq_sb,
"Can't read quota data block %u",
423 ret = remove_free_dqentry(info, buf, blk);
425 ret = put_free_dqblk(info, buf, blk);
427 quota_error(dquot->
dq_sb,
"Can't move quota data block "
428 "(%u) to free list", blk);
436 qtree_dqstr_in_blk(info) - 1) {
438 ret = insert_free_dqentry(info, buf, blk);
440 quota_error(dquot->
dq_sb,
"Can't insert quota "
441 "data block (%u) to free entry list", blk);
445 ret = write_blk(info, blk, buf);
447 quota_error(dquot->
dq_sb,
"Can't write quota "
448 "data block %u", blk);
461 uint *blk,
int depth)
470 ret = read_blk(info, *blk, buf);
472 quota_error(dquot->
dq_sb,
"Can't read quota data block %u",
478 ret = free_dqentry(info, dquot, newblk);
481 ret = remove_tree(info, dquot, &newblk, depth+1);
483 if (ret >= 0 && !newblk) {
492 put_free_dqblk(info, buf, *blk);
495 ret = write_blk(info, *blk, buf);
497 quota_error(dquot->
dq_sb,
498 "Can't write quota tree block %u",
514 return remove_tree(info, dquot, &tmp, 0);
520 struct dquot *dquot,
uint blk)
529 ret = read_blk(info, blk, buf);
531 quota_error(dquot->
dq_sb,
"Can't read quota tree "
536 for (i = 0; i < qtree_dqstr_in_blk(info); i++) {
537 if (info->
dqi_ops->is_id(ddquot, dquot))
541 if (i == qtree_dqstr_in_blk(info)) {
542 quota_error(dquot->
dq_sb,
543 "Quota for id %u referenced but not present",
558 struct dquot *dquot,
uint blk,
int depth)
566 ret = read_blk(info, blk, buf);
568 quota_error(dquot->
dq_sb,
"Can't read quota tree block %u",
576 if (depth < info->dqi_qtree_depth - 1)
577 ret = find_tree_dqentry(info, dquot, blk, depth+1);
579 ret = find_block_dqentry(info, dquot, blk);
589 return find_tree_dqentry(info, dquot,
QT_TREEOFF, 0);
600 #ifdef __QUOTA_QT_PARANOIA
602 if (!sb_dqopt(dquot->
dq_sb)->files[type]) {
603 quota_error(sb,
"Quota invalidated while reading!");
609 offset = find_dqentry(info, dquot);
612 quota_error(sb,
"Can't read quota structure "
632 quota_error(sb,
"Error while reading quota structure for id %u",
640 info->
dqi_ops->disk2mem_dqblk(dquot, ddquot);
641 if (!dquot->
dq_dqb.dqb_bhardlimit &&
642 !dquot->
dq_dqb.dqb_bsoftlimit &&
643 !dquot->
dq_dqb.dqb_ihardlimit &&
644 !dquot->
dq_dqb.dqb_isoftlimit)
659 !(dquot->
dq_dqb.dqb_curinodes | dquot->
dq_dqb.dqb_curspace))