summaryrefslogtreecommitdiff
path: root/quotaio_generic.c
diff options
context:
space:
mode:
authorOssama Othman <ossama.othman@intel.com>2013-11-25 15:00:02 -0800
committerOssama Othman <ossama.othman@intel.com>2013-11-25 15:00:02 -0800
commit47ae1cde69cd6bf2c22e20902cefa3f0e25c8cb4 (patch)
treeadd9aa20a19f410a91522d4b95df3e93c57f8637 /quotaio_generic.c
parent8c82de96cd23e4823a2d29eb2de2295c0866b0c9 (diff)
downloadquota-upstream.tar.gz
quota-upstream.tar.bz2
quota-upstream.zip
Update to latest version of quota.4.01upstream
Change-Id: I2271f01ae7877d43dde2432a45b49b910ddb6f8f Signed-off-by: Ossama Othman <ossama.othman@intel.com>
Diffstat (limited to 'quotaio_generic.c')
-rw-r--r--quotaio_generic.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/quotaio_generic.c b/quotaio_generic.c
index e5df683..5001a56 100644
--- a/quotaio_generic.c
+++ b/quotaio_generic.c
@@ -8,6 +8,9 @@
#include <errno.h>
#include <string.h>
+#include <pwd.h>
+#include <grp.h>
+#include <stdlib.h>
#include <sys/types.h>
#include "pot.h"
@@ -98,3 +101,63 @@ int vfs_set_dquot(struct dquot *dquot, int flags)
}
return 0;
}
+
+static int scan_one_dquot(struct dquot *dquot, int (*get_dquot)(struct dquot *))
+{
+ int ret;
+ struct util_dqblk *dqb = &dquot->dq_dqb;
+
+ memset(dqb, 0, sizeof(struct util_dqblk));
+ ret = get_dquot(dquot);
+ if (ret < 0)
+ return ret;
+ if (!dqb->dqb_bhardlimit && !dqb->dqb_bsoftlimit && !dqb->dqb_ihardlimit && !dqb->dqb_isoftlimit && !dqb->dqb_curinodes && !dqb->dqb_curspace)
+ return 1;
+ return 0;
+}
+
+/* Generic quota scanning using passwd... */
+int generic_scan_dquots(struct quota_handle *h,
+ int (*process_dquot)(struct dquot *dquot, char *dqname),
+ int (*get_dquot)(struct dquot *dquot))
+{
+ struct dquot *dquot = get_empty_dquot();
+ int ret = 0;
+
+ dquot->dq_h = h;
+ if (h->qh_type == USRQUOTA) {
+ struct passwd *usr;
+
+ setpwent();
+ while ((usr = getpwent()) != NULL) {
+ dquot->dq_id = usr->pw_uid;
+ ret = scan_one_dquot(dquot, get_dquot);
+ if (ret < 0)
+ break;
+ if (ret > 0)
+ continue;
+ ret = process_dquot(dquot, usr->pw_name);
+ if (ret < 0)
+ break;
+ }
+ endpwent();
+ } else if (h->qh_type == GRPQUOTA) {
+ struct group *grp;
+
+ setgrent();
+ while ((grp = getgrent()) != NULL) {
+ dquot->dq_id = grp->gr_gid;
+ ret = scan_one_dquot(dquot, get_dquot);
+ if (ret < 0)
+ break;
+ if (ret > 0)
+ continue;
+ ret = process_dquot(dquot, grp->gr_name);
+ if (ret < 0)
+ break;
+ }
+ endgrent();
+ }
+ free(dquot);
+ return ret;
+}