Update to 4.01.
[profile/ivi/quota.git] / quotaio_meta.c
1 /*
2  *      Implementation of handling of quotafiles which are hidden
3  *
4  *      Jan Kara <jack@suse.cz>
5  */
6
7 #include "config.h"
8
9 #include <string.h>
10 #include <stdlib.h>
11
12 #include <sys/types.h>
13
14 #include "pot.h"
15 #include "common.h"
16 #include "quotasys.h"
17 #include "quotaio_generic.h"
18
19 static int meta_init_io(struct quota_handle *h)
20 {
21         if (!QIO_ENABLED(h)) {
22                 errstr(_("Metadata init_io called when kernel support is not enabled.\n"));
23                 return -1;
24         }
25         if (kernel_iface != IFACE_GENERIC) {
26                 errstr(_("Metadata init_io called when kernel does not support generic quota interface!\n"));
27                 return -1;
28         }
29         return vfs_get_info(h);
30 }
31
32 static int meta_write_info(struct quota_handle *h)
33 {
34         return vfs_set_info(h, IIF_BGRACE | IIF_IGRACE);
35 }
36
37 static struct dquot *meta_read_dquot(struct quota_handle *h, qid_t id)
38 {
39         struct dquot *dquot = get_empty_dquot();
40
41         dquot->dq_id = id;
42         dquot->dq_h = h;
43         memset(&dquot->dq_dqb, 0, sizeof(struct util_dqblk));
44         if (vfs_get_dquot(dquot) < 0) {
45                 free(dquot);
46                 return NULL;
47         }
48         return dquot;
49 }
50
51 static int meta_commit_dquot(struct dquot *dquot, int flags)
52 {
53         return vfs_set_dquot(dquot, flags);
54 }
55
56 static int meta_scan_dquots(struct quota_handle *h, int (*process_dquot)(struct dquot *dquot, char *dqname))
57 {
58         return generic_scan_dquots(h, process_dquot, vfs_get_dquot);
59 }
60
61 struct quotafile_ops quotafile_ops_meta = {
62 init_io:        meta_init_io,
63 write_info:     meta_write_info,
64 read_dquot:     meta_read_dquot,
65 commit_dquot:   meta_commit_dquot,
66 scan_dquots:    meta_scan_dquots,
67 };