+static void handle_quota_options(ext2_filsys fs)
+{
+ quota_ctx_t qctx;
+ ext2_ino_t qf_ino;
+
+ if (!usrquota && !grpquota)
+ /* Nothing to do. */
+ return;
+
+ quota_init_context(&qctx, fs, -1);
+
+ if (usrquota == QOPT_ENABLE || grpquota == QOPT_ENABLE)
+ quota_compute_usage(qctx);
+
+ if (usrquota == QOPT_ENABLE && !fs->super->s_usr_quota_inum) {
+ if ((qf_ino = quota_file_exists(fs, USRQUOTA,
+ QFMT_VFS_V1)) > 0)
+ quota_update_limits(qctx, qf_ino, USRQUOTA);
+ quota_write_inode(qctx, USRQUOTA);
+ } else if (usrquota == QOPT_DISABLE) {
+ quota_remove_inode(fs, USRQUOTA);
+ }
+
+ if (grpquota == QOPT_ENABLE && !fs->super->s_grp_quota_inum) {
+ if ((qf_ino = quota_file_exists(fs, GRPQUOTA,
+ QFMT_VFS_V1)) > 0)
+ quota_update_limits(qctx, qf_ino, GRPQUOTA);
+ quota_write_inode(qctx, GRPQUOTA);
+ } else if (grpquota == QOPT_DISABLE) {
+ quota_remove_inode(fs, GRPQUOTA);
+ }
+
+ quota_release_context(&qctx);
+
+ if ((usrquota == QOPT_ENABLE) || (grpquota == QOPT_ENABLE)) {
+ fs->super->s_feature_ro_compat |= EXT4_FEATURE_RO_COMPAT_QUOTA;
+ ext2fs_mark_super_dirty(fs);
+ } else if (!fs->super->s_usr_quota_inum &&
+ !fs->super->s_grp_quota_inum) {
+ fs->super->s_feature_ro_compat &= ~EXT4_FEATURE_RO_COMPAT_QUOTA;
+ ext2fs_mark_super_dirty(fs);
+ }
+
+ return;
+}
+
+#ifdef CONFIG_QUOTA
+static void parse_quota_opts(const char *opts)
+{
+ char *buf, *token, *next, *p;
+ int len;
+
+ len = strlen(opts);
+ buf = malloc(len+1);
+ if (!buf) {
+ fputs(_("Couldn't allocate memory to parse quota "
+ "options!\n"), stderr);
+ exit(1);
+ }
+ strcpy(buf, opts);
+ for (token = buf; token && *token; token = next) {
+ p = strchr(token, ',');
+ next = 0;
+ if (p) {
+ *p = 0;
+ next = p+1;
+ }
+
+ if (strcmp(token, "usrquota") == 0) {
+ usrquota = QOPT_ENABLE;
+ } else if (strcmp(token, "^usrquota") == 0) {
+ usrquota = QOPT_DISABLE;
+ } else if (strcmp(token, "grpquota") == 0) {
+ grpquota = QOPT_ENABLE;
+ } else if (strcmp(token, "^grpquota") == 0) {
+ grpquota = QOPT_DISABLE;
+ } else {
+ fputs(_("\nBad quota options specified.\n\n"
+ "Following valid quota options are available "
+ "(pass by separating with comma):\n"
+ "\t[^]usrquota\n"
+ "\t[^]grpquota\n"
+ "\n\n"), stderr);
+ free(buf);
+ exit(1);
+ }
+ }
+ free(buf);
+}
+#endif