2 * Implementation of communication with kernel generic interface
4 * Jan Kara <jack@suse.cz> - sponsored by SuSE CR
11 #include <sys/types.h>
19 /* Convert kernel quotablock format to utility one */
20 static inline void generic_kern2utildqblk(struct util_dqblk *u, struct if_dqblk *k)
22 u->dqb_ihardlimit = k->dqb_ihardlimit;
23 u->dqb_isoftlimit = k->dqb_isoftlimit;
24 u->dqb_bhardlimit = k->dqb_bhardlimit;
25 u->dqb_bsoftlimit = k->dqb_bsoftlimit;
26 u->dqb_curinodes = k->dqb_curinodes;
27 u->dqb_curspace = k->dqb_curspace;
28 u->dqb_itime = k->dqb_itime;
29 u->dqb_btime = k->dqb_btime;
32 /* Convert utility quotablock format to kernel one */
33 static inline void generic_util2kerndqblk(struct if_dqblk *k, struct util_dqblk *u)
35 k->dqb_ihardlimit = u->dqb_ihardlimit;
36 k->dqb_isoftlimit = u->dqb_isoftlimit;
37 k->dqb_bhardlimit = u->dqb_bhardlimit;
38 k->dqb_bsoftlimit = u->dqb_bsoftlimit;
39 k->dqb_curinodes = u->dqb_curinodes;
40 k->dqb_curspace = u->dqb_curspace;
41 k->dqb_itime = u->dqb_itime;
42 k->dqb_btime = u->dqb_btime;
45 /* Get info from kernel to handle */
46 int vfs_get_info(struct quota_handle *h)
48 struct if_dqinfo kinfo;
50 if (quotactl(QCMD(Q_GETINFO, h->qh_type), h->qh_quotadev, 0, (void *)&kinfo) < 0) {
51 errstr(_("Cannot get info for %s quota file from kernel on %s: %s\n"), type2name(h->qh_type), h->qh_quotadev, strerror(errno));
54 h->qh_info.dqi_bgrace = kinfo.dqi_bgrace;
55 h->qh_info.dqi_igrace = kinfo.dqi_igrace;
59 /* Set info in kernel from handle */
60 int vfs_set_info(struct quota_handle *h, int flags)
62 struct if_dqinfo kinfo;
64 kinfo.dqi_bgrace = h->qh_info.dqi_bgrace;
65 kinfo.dqi_igrace = h->qh_info.dqi_igrace;
66 kinfo.dqi_valid = flags;
68 if (quotactl(QCMD(Q_SETINFO, h->qh_type), h->qh_quotadev, 0, (void *)&kinfo) < 0) {
69 errstr(_("Cannot set info for %s quota file from kernel on %s: %s\n"), type2name(h->qh_type), h->qh_quotadev, strerror(errno));
75 /* Get dquot from kernel */
76 int vfs_get_dquot(struct dquot *dquot)
78 struct if_dqblk kdqblk;
80 if (quotactl(QCMD(Q_GETQUOTA, dquot->dq_h->qh_type), dquot->dq_h->qh_quotadev, dquot->dq_id, (void *)&kdqblk) < 0) {
81 errstr(_("Cannot get quota for %s %d from kernel on %s: %s\n"), type2name(dquot->dq_h->qh_type), dquot->dq_id, dquot->dq_h->qh_quotadev, strerror(errno));
84 generic_kern2utildqblk(&dquot->dq_dqb, &kdqblk);
88 /* Set dquot in kernel */
89 int vfs_set_dquot(struct dquot *dquot, int flags)
91 struct if_dqblk kdqblk;
93 generic_util2kerndqblk(&kdqblk, &dquot->dq_dqb);
94 kdqblk.dqb_valid = flags;
95 if (quotactl(QCMD(Q_SETQUOTA, dquot->dq_h->qh_type), dquot->dq_h->qh_quotadev, dquot->dq_id, (void *)&kdqblk) < 0) {
96 errstr(_("Cannot set quota for %s %d from kernel on %s: %s\n"), type2name(dquot->dq_h->qh_type), dquot->dq_id, dquot->dq_h->qh_quotadev, strerror(errno));