[T106][ZXW-22]7520V3SCV2.01.01.02P42U09_VEC_V0.8_AP_VEC origin source commit
Change-Id: Ic6e05d89ecd62fc34f82b23dcf306c93764aec4b
diff --git a/ap/app/e2fsprogs/e2fsprogs-1.42.9/lib/quota/Makefile.in b/ap/app/e2fsprogs/e2fsprogs-1.42.9/lib/quota/Makefile.in
new file mode 100644
index 0000000..ec4f6c4
--- /dev/null
+++ b/ap/app/e2fsprogs/e2fsprogs-1.42.9/lib/quota/Makefile.in
@@ -0,0 +1,162 @@
+# Makefile for the QUOTA library
+#
+
+srcdir = @srcdir@
+top_srcdir = @top_srcdir@
+VPATH = @srcdir@
+top_builddir = ../..
+my_dir = lib/quota
+INSTALL = @INSTALL@
+
+@MCONFIG@
+
+all::
+
+SMANPAGES=
+
+
+OBJS= mkquota.o quotaio.o quotaio_v2.o quotaio_tree.o dict.o
+
+SRCS= $(srcdir)/mkquota.c \
+ $(srcdir)/quotaio.c \
+ $(srcdir)/quotaio_tree.c \
+ $(srcdir)/quotaio_v2.c \
+ $(srcdir)/../../e2fsck/dict.c
+
+LIBRARY= libquota
+LIBDIR= quota
+
+#ELF_VERSION = 1.0
+#ELF_SO_VERSION = 1
+#ELF_IMAGE = libquota
+#ELF_MYDIR = quota
+#ELF_INSTALL_DIR = $(root_libdir)
+#ELF_OTHER_LIBS = -lext2fs
+
+#BSDLIB_VERSION = 1.0
+#BSDLIB_IMAGE = libquota
+#BSDLIB_MYDIR = quota
+#BSDLIB_INSTALL_DIR = $(root_libdir)
+
+@MAKEFILE_LIBRARY@
+#MAKEFILE_ELF#
+#MAKEFILE_BSDLIB#
+@MAKEFILE_PROFILE@
+@MAKEFILE_CHECKER@
+
+.c.o:
+ $(E) " CC $<"
+ $(Q) $(CC) $(ALL_CFLAGS) -c $< -o $@
+ $(Q) $(CHECK_CMD) $(ALL_CFLAGS) $<
+@PROFILE_CMT@ $(Q) $(CC) $(ALL_CFLAGS) -g -pg -o profiled/$*.o -c $<
+@CHECKER_CMT@ $(Q) $(CC) $(ALL_CFLAGS) -checker -g -o checker/$*.o -c $<
+#ELF_CMT# $(Q) $(CC) $(ALL_CFLAGS) -fPIC -o elfshared/$*.o -c $<
+#BSDLIB_CMT# $(Q) $(CC) $(ALL_CFLAGS) $(BSDLIB_PIC_FLAG) -o pic/$*.o -c $<
+
+all:: $(SMANPAGES) quota.pc
+
+quota.pc: $(srcdir)/quota.pc.in $(top_builddir)/config.status
+ $(E) " CONFIG.STATUS $@"
+ $(Q) cd $(top_builddir); CONFIG_FILES=lib/quota/quota.pc ./config.status
+
+dict.o:
+ $(E) " CC $<"
+ $(Q) $(CC) -c $(ALL_CFLAGS) $(top_srcdir)/e2fsck/dict.c -o $@
+@PROFILE_CMT@ $(Q) $(CC) $(ALL_CFLAGS) -g -pg -o profiled/dict.o -c \
+@PROFILE_CMT@ $(top_srcdir)/e2fsck/dict.c
+@CHECKER_CMT@ $(Q) $(CC) $(ALL_CFLAGS) -checker -g -o checker/$*.o -c \
+@CHECKER_CMT@ $(top_srcdir)/e2fsck/dict.c
+#ELF_CMT# $(Q) $(CC) $(ALL_CFLAGS) -fPIC -o elfshared/$*.o -c \
+#ELF_CMT# $(top_srcdir)/e2fsck/dict.c
+#BSDLIB_CMT# $(Q) $(CC) $(ALL_CFLAGS) $(BSDLIB_PIC_FLAG) -o pic/$*.o -c \
+#BSDLIB_CMT# $(top_srcdir)/e2fsck/dict.c
+
+installdirs::
+ $(E) " MKINSTALLDIRS $(libdir) $(includedir)/quota $(man3dir)"
+ $(Q) $(MKINSTALLDIRS) $(DESTDIR)$(libdir) \
+ $(DESTDIR)$(includedir)/quota $(DESTDIR)$(man3dir) \
+ $(DESTDIR)$(libdir)/pkgconfig
+
+install:: all installdirs
+ $(E) " INSTALL_DATA $(libdir)/libquota.a"
+ $(Q) $(INSTALL_DATA) libquota.a $(DESTDIR)$(libdir)/libquota.a
+ -$(Q) $(RANLIB) $(DESTDIR)$(libdir)/libquota.a
+ $(Q) $(CHMOD) $(LIBMODE) $(DESTDIR)$(libdir)/libquota.a
+ $(E) " INSTALL_DATA $(includedir)/quota/mkquota.h"
+ $(Q) $(INSTALL_DATA) $(srcdir)/mkquota.h $(DESTDIR)$(includedir)/quota/mkquota.h
+ $(Q) for i in $(SMANPAGES); do \
+ $(RM) -f $(DESTDIR)$(man3dir)/$$i.gz; \
+ echo " INSTALL_DATA $(man3dir)/$$i"; \
+ $(INSTALL_DATA) $$i $(DESTDIR)$(man3dir)/$$i; \
+ done
+ $(E) " INSTALL_DATA $(libdir)/pkgconfig/quota.pc"
+ $(Q) $(INSTALL_DATA) quota.pc $(DESTDIR)$(libdir)/pkgconfig/quota.pc
+
+uninstall::
+ $(RM) -f $(DESTDIR)$(libdir)/libquota.a \
+ $(DESTDIR)$(libdir)/pkgconfig/quota.pc
+ for i in $(SMANPAGES); do \
+ $(RM) -f $(DESTDIR)$(man3dir)/$$i; \
+ done
+
+clean::
+ $(RM) -f \#* *.s *.o *.a *~ *.bak core profiled/* checker/*
+ $(RM) -f ../libquota.a ../libquota_p.a $(SMANPAGES)
+
+#check:: tst_uuid
+# LD_LIBRARY_PATH=$(LIB) DYLD_LIBRARY_PATH=$(LIB) ./tst_uuid
+
+mostlyclean:: clean
+distclean:: clean
+ $(RM) -f .depend Makefile quota.pc \
+ $(srcdir)/TAGS $(srcdir)/Makefile.in.old
+
+#
+# Hack to parallel makes recognize dependencies correctly.
+#
+../../lib/libquota.a: libquota.a
+../../lib/libquota.so: image
+../../lib/libquota.dylib: image
+
+$(OBJS):
+
+# +++ Dependency line eater +++
+#
+# Makefile dependencies follow. This must be the last section in
+# the Makefile.in file
+#
+mkquota.o: $(srcdir)/mkquota.c $(top_builddir)/lib/config.h \
+ $(top_builddir)/lib/dirpaths.h $(top_srcdir)/lib/ext2fs/ext2_fs.h \
+ $(top_builddir)/lib/ext2fs/ext2_types.h $(top_srcdir)/lib/ext2fs/ext2fs.h \
+ $(top_srcdir)/lib/ext2fs/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \
+ $(top_srcdir)/lib/ext2fs/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \
+ $(top_srcdir)/lib/ext2fs/ext2_ext_attr.h $(top_srcdir)/lib/ext2fs/bitops.h \
+ $(top_srcdir)/lib/e2p/e2p.h $(srcdir)/quotaio.h $(srcdir)/dqblk_v2.h \
+ $(srcdir)/quotaio_tree.h $(srcdir)/quotaio_v2.h $(srcdir)/mkquota.h \
+ $(top_srcdir)/lib/../e2fsck/dict.h $(srcdir)/common.h
+quotaio.o: $(srcdir)/quotaio.c $(top_builddir)/lib/config.h \
+ $(top_builddir)/lib/dirpaths.h $(srcdir)/common.h $(srcdir)/quotaio.h \
+ $(top_srcdir)/lib/ext2fs/ext2fs.h $(top_builddir)/lib/ext2fs/ext2_types.h \
+ $(top_srcdir)/lib/ext2fs/ext2_fs.h $(top_srcdir)/lib/ext2fs/ext3_extents.h \
+ $(top_srcdir)/lib/et/com_err.h $(top_srcdir)/lib/ext2fs/ext2_io.h \
+ $(top_builddir)/lib/ext2fs/ext2_err.h \
+ $(top_srcdir)/lib/ext2fs/ext2_ext_attr.h $(top_srcdir)/lib/ext2fs/bitops.h \
+ $(srcdir)/dqblk_v2.h $(srcdir)/quotaio_tree.h
+quotaio_tree.o: $(srcdir)/quotaio_tree.c $(top_builddir)/lib/config.h \
+ $(top_builddir)/lib/dirpaths.h $(srcdir)/common.h $(srcdir)/quotaio_tree.h \
+ $(srcdir)/quotaio.h $(top_srcdir)/lib/ext2fs/ext2fs.h \
+ $(top_builddir)/lib/ext2fs/ext2_types.h $(top_srcdir)/lib/ext2fs/ext2_fs.h \
+ $(top_srcdir)/lib/ext2fs/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \
+ $(top_srcdir)/lib/ext2fs/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \
+ $(top_srcdir)/lib/ext2fs/ext2_ext_attr.h $(top_srcdir)/lib/ext2fs/bitops.h \
+ $(srcdir)/dqblk_v2.h
+quotaio_v2.o: $(srcdir)/quotaio_v2.c $(top_builddir)/lib/config.h \
+ $(top_builddir)/lib/dirpaths.h $(srcdir)/common.h $(srcdir)/quotaio_v2.h \
+ $(srcdir)/quotaio.h $(top_srcdir)/lib/ext2fs/ext2fs.h \
+ $(top_builddir)/lib/ext2fs/ext2_types.h $(top_srcdir)/lib/ext2fs/ext2_fs.h \
+ $(top_srcdir)/lib/ext2fs/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \
+ $(top_srcdir)/lib/ext2fs/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \
+ $(top_srcdir)/lib/ext2fs/ext2_ext_attr.h $(top_srcdir)/lib/ext2fs/bitops.h \
+ $(srcdir)/dqblk_v2.h $(srcdir)/quotaio_tree.h
+dict.o: $(srcdir)/../../e2fsck/dict.c $(top_builddir)/lib/config.h \
+ $(top_builddir)/lib/dirpaths.h $(srcdir)/../../e2fsck/dict.h
diff --git a/ap/app/e2fsprogs/e2fsprogs-1.42.9/lib/quota/common.h b/ap/app/e2fsprogs/e2fsprogs-1.42.9/lib/quota/common.h
new file mode 100644
index 0000000..7f3f4b9
--- /dev/null
+++ b/ap/app/e2fsprogs/e2fsprogs-1.42.9/lib/quota/common.h
@@ -0,0 +1,28 @@
+/*
+ *
+ * Various things common for all utilities
+ *
+ */
+
+#ifndef __QUOTA_COMMON_H__
+#define __QUOTA_COMMON_H__
+
+#ifndef __attribute__
+# if !defined __GNUC__ || __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) || __STRICT_ANSI__
+# define __attribute__(x)
+# endif
+#endif
+
+#define log_err(format, arg ...) \
+ fprintf(stderr, "[ERROR] %s:%d:%s:: " format "\n", \
+ __FILE__, __LINE__, __func__, ## arg)
+
+#ifdef DEBUG_QUOTA
+# define log_debug(format, arg ...) \
+ fprintf(stderr, "[DEBUG] %s:%d:%s:: " format "\n", \
+ __FILE__, __LINE__, __func__, ## arg)
+#else
+# define log_debug(format, ...)
+#endif
+
+#endif /* __QUOTA_COMMON_H__ */
diff --git a/ap/app/e2fsprogs/e2fsprogs-1.42.9/lib/quota/dqblk_v2.h b/ap/app/e2fsprogs/e2fsprogs-1.42.9/lib/quota/dqblk_v2.h
new file mode 100644
index 0000000..d12512a
--- /dev/null
+++ b/ap/app/e2fsprogs/e2fsprogs-1.42.9/lib/quota/dqblk_v2.h
@@ -0,0 +1,31 @@
+/*
+ * Header file for disk format of new quotafile format
+ *
+ * Jan Kara <jack@suse.cz> - sponsored by SuSE CR
+ */
+
+#ifndef __QUOTA_DQBLK_V2_H__
+#define __QUOTA_DQBLK_V2_H__
+
+#include "quotaio_tree.h"
+
+/* Structure for format specific information */
+struct v2_mem_dqinfo {
+ struct qtree_mem_dqinfo dqi_qtree;
+ unsigned int dqi_flags; /* Flags set in quotafile */
+ unsigned int dqi_used_entries; /* Number of entries in file -
+ updated by scan_dquots */
+ unsigned int dqi_data_blocks; /* Number of data blocks in file -
+ updated by scan_dquots */
+};
+
+struct v2_mem_dqblk {
+ long long dqb_off; /* Offset of dquot in file */
+};
+
+struct quotafile_ops; /* Will be defined later in quotaio.h */
+
+/* Operations above this format */
+extern struct quotafile_ops quotafile_ops_2;
+
+#endif /* __QUOTA_DQBLK_V2_H__ */
diff --git a/ap/app/e2fsprogs/e2fsprogs-1.42.9/lib/quota/mkquota.c b/ap/app/e2fsprogs/e2fsprogs-1.42.9/lib/quota/mkquota.c
new file mode 100644
index 0000000..3aa8100
--- /dev/null
+++ b/ap/app/e2fsprogs/e2fsprogs-1.42.9/lib/quota/mkquota.c
@@ -0,0 +1,561 @@
+/*
+ * mkquota.c --- create quota files for a filesystem
+ *
+ * Aditya Kali <adityakali@google.com>
+ */
+#include "config.h"
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <errno.h>
+#include <string.h>
+#include <fcntl.h>
+
+#include "ext2fs/ext2_fs.h"
+#include "ext2fs/ext2fs.h"
+#include "e2p/e2p.h"
+
+#include "quotaio.h"
+#include "quotaio_v2.h"
+#include "quotaio_tree.h"
+#include "mkquota.h"
+#include "common.h"
+
+/* Needed for architectures where sizeof(int) != sizeof(void *) */
+#define UINT_TO_VOIDPTR(val) ((void *)(intptr_t)(val))
+#define VOIDPTR_TO_UINT(ptr) ((unsigned int)(intptr_t)(ptr))
+
+#if DEBUG_QUOTA
+static void print_inode(struct ext2_inode *inode)
+{
+ if (!inode)
+ return;
+
+ fprintf(stderr, " i_mode = %d\n", inode->i_mode);
+ fprintf(stderr, " i_uid = %d\n", inode->i_uid);
+ fprintf(stderr, " i_size = %d\n", inode->i_size);
+ fprintf(stderr, " i_atime = %d\n", inode->i_atime);
+ fprintf(stderr, " i_ctime = %d\n", inode->i_ctime);
+ fprintf(stderr, " i_mtime = %d\n", inode->i_mtime);
+ fprintf(stderr, " i_dtime = %d\n", inode->i_dtime);
+ fprintf(stderr, " i_gid = %d\n", inode->i_gid);
+ fprintf(stderr, " i_links_count = %d\n", inode->i_links_count);
+ fprintf(stderr, " i_blocks = %d\n", inode->i_blocks);
+ fprintf(stderr, " i_flags = %d\n", inode->i_flags);
+
+ return;
+}
+#endif
+
+/*
+ * Returns 0 if not able to find the quota file, otherwise returns its
+ * inode number.
+ */
+int quota_file_exists(ext2_filsys fs, int qtype, int fmt)
+{
+ char qf_name[256];
+ errcode_t ret;
+ ext2_ino_t ino;
+
+ if (qtype >= MAXQUOTAS)
+ return -EINVAL;
+
+ quota_get_qf_name(qtype, QFMT_VFS_V1, qf_name);
+
+ ret = ext2fs_lookup(fs, EXT2_ROOT_INO, qf_name, strlen(qf_name), 0,
+ &ino);
+ if (ret)
+ return 0;
+
+ return ino;
+}
+
+/*
+ * Set the value for reserved quota inode number field in superblock.
+ */
+void quota_set_sb_inum(ext2_filsys fs, ext2_ino_t ino, int qtype)
+{
+ ext2_ino_t *inump;
+
+ inump = (qtype == USRQUOTA) ? &fs->super->s_usr_quota_inum :
+ &fs->super->s_grp_quota_inum;
+
+ log_debug("setting quota ino in superblock: ino=%u, type=%d", ino,
+ qtype);
+ *inump = ino;
+ ext2fs_mark_super_dirty(fs);
+}
+
+errcode_t quota_remove_inode(ext2_filsys fs, int qtype)
+{
+ ext2_ino_t qf_ino;
+
+ ext2fs_read_bitmaps(fs);
+ qf_ino = (qtype == USRQUOTA) ? fs->super->s_usr_quota_inum :
+ fs->super->s_grp_quota_inum;
+ quota_set_sb_inum(fs, 0, qtype);
+ /* Truncate the inode only if its a reserved one. */
+ if (qf_ino < EXT2_FIRST_INODE(fs->super))
+ quota_inode_truncate(fs, qf_ino);
+
+ ext2fs_mark_super_dirty(fs);
+ fs->flags &= ~EXT2_FLAG_SUPER_ONLY;
+ ext2fs_write_bitmaps(fs);
+ return 0;
+}
+
+static void write_dquots(dict_t *dict, struct quota_handle *qh)
+{
+ dnode_t *n;
+ struct dquot *dq;
+
+ for (n = dict_first(dict); n; n = dict_next(dict, n)) {
+ dq = dnode_get(n);
+ if (dq) {
+ dq->dq_h = qh;
+ update_grace_times(dq);
+ qh->qh_ops->commit_dquot(dq);
+ }
+ }
+}
+
+errcode_t quota_write_inode(quota_ctx_t qctx, int qtype)
+{
+ int retval = 0, i;
+ dict_t *dict;
+ ext2_filsys fs;
+ struct quota_handle *h = NULL;
+ int fmt = QFMT_VFS_V1;
+
+ if (!qctx)
+ return 0;
+
+ fs = qctx->fs;
+ retval = ext2fs_get_mem(sizeof(struct quota_handle), &h);
+ if (retval) {
+ log_err("Unable to allocate quota handle");
+ goto out;
+ }
+
+ ext2fs_read_bitmaps(fs);
+
+ for (i = 0; i < MAXQUOTAS; i++) {
+ if ((qtype != -1) && (i != qtype))
+ continue;
+
+ dict = qctx->quota_dict[i];
+ if (!dict)
+ continue;
+
+ retval = quota_file_create(h, fs, i, fmt);
+ if (retval < 0) {
+ log_err("Cannot initialize io on quotafile");
+ continue;
+ }
+
+ write_dquots(dict, h);
+ retval = quota_file_close(h);
+ if (retval < 0) {
+ log_err("Cannot finish IO on new quotafile: %s",
+ strerror(errno));
+ if (h->qh_qf.e2_file)
+ ext2fs_file_close(h->qh_qf.e2_file);
+ quota_inode_truncate(fs, h->qh_qf.ino);
+ continue;
+ }
+
+ /* Set quota inode numbers in superblock. */
+ quota_set_sb_inum(fs, h->qh_qf.ino, i);
+ ext2fs_mark_super_dirty(fs);
+ ext2fs_mark_bb_dirty(fs);
+ fs->flags &= ~EXT2_FLAG_SUPER_ONLY;
+ }
+
+ ext2fs_write_bitmaps(fs);
+out:
+ if (h)
+ ext2fs_free_mem(&h);
+ return retval;
+}
+
+/******************************************************************/
+/* Helper functions for computing quota in memory. */
+/******************************************************************/
+
+static int dict_uint_cmp(const void *a, const void *b)
+{
+ unsigned int c, d;
+
+ c = VOIDPTR_TO_UINT(a);
+ d = VOIDPTR_TO_UINT(b);
+
+ return c - d;
+}
+
+static inline qid_t get_qid(struct ext2_inode *inode, int qtype)
+{
+ if (qtype == USRQUOTA)
+ return inode_uid(*inode);
+ return inode_gid(*inode);
+}
+
+static void quota_dnode_free(dnode_t *node,
+ void *context EXT2FS_ATTR((unused)))
+{
+ void *ptr = node ? dnode_get(node) : 0;
+
+ ext2fs_free_mem(&ptr);
+ free(node);
+}
+
+/*
+ * Set up the quota tracking data structures.
+ */
+errcode_t quota_init_context(quota_ctx_t *qctx, ext2_filsys fs, int qtype)
+{
+ int i, err = 0;
+ dict_t *dict;
+ quota_ctx_t ctx;
+
+ err = ext2fs_get_mem(sizeof(struct quota_ctx), &ctx);
+ if (err) {
+ log_err("Failed to allocate quota context");
+ return err;
+ }
+
+ memset(ctx, 0, sizeof(struct quota_ctx));
+ for (i = 0; i < MAXQUOTAS; i++) {
+ if ((qtype != -1) && (i != qtype))
+ continue;
+ err = ext2fs_get_mem(sizeof(dict_t), &dict);
+ if (err) {
+ log_err("Failed to allocate dictionary");
+ quota_release_context(&ctx);
+ return err;
+ }
+ ctx->quota_dict[i] = dict;
+ dict_init(dict, DICTCOUNT_T_MAX, dict_uint_cmp);
+ dict_set_allocator(dict, NULL, quota_dnode_free, NULL);
+ }
+
+ ctx->fs = fs;
+ *qctx = ctx;
+ return 0;
+}
+
+void quota_release_context(quota_ctx_t *qctx)
+{
+ dict_t *dict;
+ int i;
+ quota_ctx_t ctx;
+
+ if (!qctx)
+ return;
+
+ ctx = *qctx;
+ for (i = 0; i < MAXQUOTAS; i++) {
+ dict = ctx->quota_dict[i];
+ ctx->quota_dict[i] = 0;
+ if (dict) {
+ dict_free_nodes(dict);
+ free(dict);
+ }
+ }
+ *qctx = NULL;
+ free(ctx);
+}
+
+static struct dquot *get_dq(dict_t *dict, __u32 key)
+{
+ struct dquot *dq;
+ dnode_t *n;
+
+ n = dict_lookup(dict, UINT_TO_VOIDPTR(key));
+ if (n)
+ dq = dnode_get(n);
+ else {
+ if (ext2fs_get_mem(sizeof(struct dquot), &dq)) {
+ log_err("Unable to allocate dquot");
+ return NULL;
+ }
+ memset(dq, 0, sizeof(struct dquot));
+ dict_alloc_insert(dict, UINT_TO_VOIDPTR(key), dq);
+ dq->dq_id = key;
+ }
+ return dq;
+}
+
+
+/*
+ * Called to update the blocks used by a particular inode
+ */
+void quota_data_add(quota_ctx_t qctx, struct ext2_inode *inode, ext2_ino_t ino,
+ qsize_t space)
+{
+ struct dquot *dq;
+ dict_t *dict;
+ int i;
+
+ if (!qctx)
+ return;
+
+ log_debug("ADD_DATA: Inode: %u, UID/GID: %u/%u, space: %ld", ino,
+ inode_uid(*inode),
+ inode_gid(*inode), space);
+ for (i = 0; i < MAXQUOTAS; i++) {
+ dict = qctx->quota_dict[i];
+ if (dict) {
+ dq = get_dq(dict, get_qid(inode, i));
+ if (dq)
+ dq->dq_dqb.dqb_curspace += space;
+ }
+ }
+}
+
+/*
+ * Called to remove some blocks used by a particular inode
+ */
+void quota_data_sub(quota_ctx_t qctx, struct ext2_inode *inode, ext2_ino_t ino,
+ qsize_t space)
+{
+ struct dquot *dq;
+ dict_t *dict;
+ int i;
+
+ if (!qctx)
+ return;
+
+ log_debug("SUB_DATA: Inode: %u, UID/GID: %u/%u, space: %ld", ino,
+ inode_uid(*inode),
+ inode_gid(*inode), space);
+ for (i = 0; i < MAXQUOTAS; i++) {
+ dict = qctx->quota_dict[i];
+ if (dict) {
+ dq = get_dq(dict, get_qid(inode, i));
+ dq->dq_dqb.dqb_curspace -= space;
+ }
+ }
+}
+
+/*
+ * Called to count the files used by an inode's user/group
+ */
+void quota_data_inodes(quota_ctx_t qctx, struct ext2_inode *inode,
+ ext2_ino_t ino, int adjust)
+{
+ struct dquot *dq;
+ dict_t *dict;
+ int i;
+
+ if (!qctx)
+ return;
+
+ log_debug("ADJ_INODE: Inode: %u, UID/GID: %u/%u, adjust: %d", ino,
+ inode_uid(*inode),
+ inode_gid(*inode), adjust);
+ for (i = 0; i < MAXQUOTAS; i++) {
+ dict = qctx->quota_dict[i];
+ if (dict) {
+ dq = get_dq(dict, get_qid(inode, i));
+ dq->dq_dqb.dqb_curinodes += adjust;
+ }
+ }
+}
+
+errcode_t quota_compute_usage(quota_ctx_t qctx)
+{
+ ext2_filsys fs;
+ ext2_ino_t ino;
+ errcode_t ret;
+ struct ext2_inode inode;
+ qsize_t space;
+ ext2_inode_scan scan;
+
+ if (!qctx)
+ return 0;
+
+ fs = qctx->fs;
+ ret = ext2fs_open_inode_scan(fs, 0, &scan);
+ if (ret) {
+ log_err("while opening inode scan. ret=%ld", ret);
+ return ret;
+ }
+
+ while (1) {
+ ret = ext2fs_get_next_inode(scan, &ino, &inode);
+ if (ret) {
+ log_err("while getting next inode. ret=%ld", ret);
+ ext2fs_close_inode_scan(scan);
+ return ret;
+ }
+ if (ino == 0)
+ break;
+ if (inode.i_links_count &&
+ (ino == EXT2_ROOT_INO ||
+ ino >= EXT2_FIRST_INODE(fs->super))) {
+ space = ext2fs_inode_i_blocks(fs, &inode) << 9;
+ quota_data_add(qctx, &inode, ino, space);
+ quota_data_inodes(qctx, &inode, ino, +1);
+ }
+ }
+
+ ext2fs_close_inode_scan(scan);
+
+ return 0;
+}
+
+struct scan_dquots_data {
+ dict_t *quota_dict;
+ int update_limits; /* update limits from disk */
+ int update_usage;
+ int usage_is_inconsistent;
+};
+
+static int scan_dquots_callback(struct dquot *dquot, void *cb_data)
+{
+ struct scan_dquots_data *scan_data = cb_data;
+ dict_t *quota_dict = scan_data->quota_dict;
+ struct dquot *dq;
+
+ dq = get_dq(quota_dict, dquot->dq_id);
+ dq->dq_id = dquot->dq_id;
+ dq->dq_dqb.u.v2_mdqb.dqb_off = dquot->dq_dqb.u.v2_mdqb.dqb_off;
+
+ /* Check if there is inconsistancy. */
+ if (dq->dq_dqb.dqb_curspace != dquot->dq_dqb.dqb_curspace ||
+ dq->dq_dqb.dqb_curinodes != dquot->dq_dqb.dqb_curinodes) {
+ scan_data->usage_is_inconsistent = 1;
+ fprintf(stderr, "[QUOTA WARNING] Usage inconsistent for ID %d:"
+ "actual (%llu, %llu) != expected (%llu, %llu)\n",
+ dq->dq_id, (long long)dq->dq_dqb.dqb_curspace,
+ (long long)dq->dq_dqb.dqb_curinodes,
+ (long long)dquot->dq_dqb.dqb_curspace,
+ (long long)dquot->dq_dqb.dqb_curinodes);
+ }
+
+ if (scan_data->update_limits) {
+ dq->dq_dqb.dqb_ihardlimit = dquot->dq_dqb.dqb_ihardlimit;
+ dq->dq_dqb.dqb_isoftlimit = dquot->dq_dqb.dqb_isoftlimit;
+ dq->dq_dqb.dqb_bhardlimit = dquot->dq_dqb.dqb_bhardlimit;
+ dq->dq_dqb.dqb_bsoftlimit = dquot->dq_dqb.dqb_bsoftlimit;
+ }
+
+ if (scan_data->update_usage) {
+ dq->dq_dqb.dqb_curspace = dquot->dq_dqb.dqb_curspace;
+ dq->dq_dqb.dqb_curinodes = dquot->dq_dqb.dqb_curinodes;
+ }
+
+ return 0;
+}
+
+/*
+ * Read all dquots from quota file into memory
+ */
+static errcode_t quota_read_all_dquots(struct quota_handle *qh,
+ quota_ctx_t qctx, int update_limits)
+{
+ struct scan_dquots_data scan_data;
+
+ scan_data.quota_dict = qctx->quota_dict[qh->qh_type];
+ scan_data.update_limits = update_limits;
+ scan_data.update_usage = 0;
+
+ return qh->qh_ops->scan_dquots(qh, scan_dquots_callback, &scan_data);
+}
+
+/*
+ * Write all memory dquots into quota file
+ */
+#if 0 /* currently unused, but may be useful in the future? */
+static errcode_t quota_write_all_dquots(struct quota_handle *qh,
+ quota_ctx_t qctx)
+{
+ errcode_t err;
+
+ err = ext2fs_read_bitmaps(qctx->fs);
+ if (err)
+ return err;
+ write_dquots(qctx->quota_dict[qh->qh_type], qh);
+ ext2fs_mark_bb_dirty(qctx->fs);
+ qctx->fs->flags &= ~EXT2_FLAG_SUPER_ONLY;
+ ext2fs_write_bitmaps(qctx->fs);
+ return 0;
+}
+#endif
+
+/*
+ * Updates the in-memory quota limits from the given quota inode.
+ */
+errcode_t quota_update_limits(quota_ctx_t qctx, ext2_ino_t qf_ino, int type)
+{
+ struct quota_handle *qh;
+ errcode_t err;
+
+ if (!qctx)
+ return 0;
+
+ err = ext2fs_get_mem(sizeof(struct quota_handle), &qh);
+ if (err) {
+ log_err("Unable to allocate quota handle");
+ return err;
+ }
+
+ err = quota_file_open(qh, qctx->fs, qf_ino, type, -1, 0);
+ if (err) {
+ log_err("Open quota file failed");
+ goto out;
+ }
+
+ quota_read_all_dquots(qh, qctx, 1);
+
+ err = quota_file_close(qh);
+ if (err) {
+ log_err("Cannot finish IO on new quotafile: %s",
+ strerror(errno));
+ if (qh->qh_qf.e2_file)
+ ext2fs_file_close(qh->qh_qf.e2_file);
+ }
+out:
+ ext2fs_free_mem(&qh);
+ return err;
+}
+
+/*
+ * Compares the measured quota in qctx->quota_dict with that in the quota inode
+ * on disk and updates the limits in qctx->quota_dict. 'usage_inconsistent' is
+ * set to 1 if the supplied and on-disk quota usage values are not identical.
+ */
+errcode_t quota_compare_and_update(quota_ctx_t qctx, int qtype,
+ int *usage_inconsistent)
+{
+ ext2_filsys fs = qctx->fs;
+ struct quota_handle qh;
+ struct scan_dquots_data scan_data;
+ ext2_ino_t qf_ino;
+ errcode_t err = 0;
+
+ if (!qctx->quota_dict[qtype])
+ goto out;
+
+ qf_ino = qtype == USRQUOTA ? fs->super->s_usr_quota_inum :
+ fs->super->s_grp_quota_inum;
+ err = quota_file_open(&qh, fs, qf_ino, qtype, -1, 0);
+ if (err) {
+ log_err("Open quota file failed");
+ goto out;
+ }
+
+ scan_data.quota_dict = qctx->quota_dict[qtype];
+ scan_data.update_limits = 1;
+ scan_data.update_usage = 0;
+ scan_data.usage_is_inconsistent = 0;
+ err = qh.qh_ops->scan_dquots(&qh, scan_dquots_callback, &scan_data);
+ if (err) {
+ log_err("Error scanning dquots");
+ goto out;
+ }
+ *usage_inconsistent = scan_data.usage_is_inconsistent;
+
+out:
+ return err;
+}
diff --git a/ap/app/e2fsprogs/e2fsprogs-1.42.9/lib/quota/mkquota.h b/ap/app/e2fsprogs/e2fsprogs-1.42.9/lib/quota/mkquota.h
new file mode 100644
index 0000000..ee15071
--- /dev/null
+++ b/ap/app/e2fsprogs/e2fsprogs-1.42.9/lib/quota/mkquota.h
@@ -0,0 +1,64 @@
+/** mkquota.h
+ *
+ * Interface to the quota library.
+ *
+ * The quota library provides interface for creating and updating the quota
+ * files and the ext4 superblock fields. It supports the new VFS_V1 quota
+ * format. The quota library also provides support for keeping track of quotas
+ * in memory.
+ * The typical way to use the quota library is as follows:
+ * {
+ * quota_ctx_t qctx;
+ *
+ * quota_init_context(&qctx, fs, -1);
+ * {
+ * quota_compute_usage(qctx, -1);
+ * AND/OR
+ * quota_data_add/quota_data_sub/quota_data_inodes();
+ * }
+ * quota_write_inode(qctx, USRQUOTA);
+ * quota_write_inode(qctx, GRPQUOTA);
+ * quota_release_context(&qctx);
+ * }
+ *
+ * This initial version does not support reading the quota files. This support
+ * will be added in near future.
+ *
+ * Aditya Kali <adityakali@google.com>
+ */
+
+#ifndef __QUOTA_QUOTAIO_H__
+#define __QUOTA_QUOTAIO_H__
+
+#include "ext2fs/ext2_fs.h"
+#include "ext2fs/ext2fs.h"
+#include "quotaio.h"
+#include "../e2fsck/dict.h"
+
+typedef struct quota_ctx *quota_ctx_t;
+
+struct quota_ctx {
+ ext2_filsys fs;
+ dict_t *quota_dict[MAXQUOTAS];
+};
+
+/* In mkquota.c */
+errcode_t quota_init_context(quota_ctx_t *qctx, ext2_filsys fs, int qtype);
+void quota_data_inodes(quota_ctx_t qctx, struct ext2_inode *inode, ext2_ino_t ino,
+ int adjust);
+void quota_data_add(quota_ctx_t qctx, struct ext2_inode *inode, ext2_ino_t ino,
+ qsize_t space);
+void quota_data_sub(quota_ctx_t qctx, struct ext2_inode *inode, ext2_ino_t ino,
+ qsize_t space);
+errcode_t quota_write_inode(quota_ctx_t qctx, int qtype);
+errcode_t quota_update_limits(quota_ctx_t qctx, ext2_ino_t qf_ino, int type);
+errcode_t quota_compute_usage(quota_ctx_t qctx);
+void quota_release_context(quota_ctx_t *qctx);
+
+errcode_t quota_remove_inode(ext2_filsys fs, int qtype);
+int quota_file_exists(ext2_filsys fs, int qtype, int fmt);
+void quota_set_sb_inum(ext2_filsys fs, ext2_ino_t ino, int qtype);
+errcode_t quota_compare_and_update(quota_ctx_t qctx, int qtype,
+ int *usage_inconsistent);
+
+#endif /* __QUOTA_QUOTAIO_H__ */
diff --git a/ap/app/e2fsprogs/e2fsprogs-1.42.9/lib/quota/quota.pc.in b/ap/app/e2fsprogs/e2fsprogs-1.42.9/lib/quota/quota.pc.in
new file mode 100644
index 0000000..1e4b887
--- /dev/null
+++ b/ap/app/e2fsprogs/e2fsprogs-1.42.9/lib/quota/quota.pc.in
@@ -0,0 +1,11 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: quota
+Description: Quota management library
+Version: @E2FSPROGS_VERSION@
+Requires:
+Cflags: -I${includedir}/quota -I${includedir}
+Libs: -L${libdir} -lquota
diff --git a/ap/app/e2fsprogs/e2fsprogs-1.42.9/lib/quota/quotaio.c b/ap/app/e2fsprogs/e2fsprogs-1.42.9/lib/quota/quotaio.c
new file mode 100644
index 0000000..1bdcba6
--- /dev/null
+++ b/ap/app/e2fsprogs/e2fsprogs-1.42.9/lib/quota/quotaio.c
@@ -0,0 +1,382 @@
+/** quotaio.c
+ *
+ * Generic IO operations on quotafiles
+ * Jan Kara <jack@suse.cz> - sponsored by SuSE CR
+ * Aditya Kali <adityakali@google.com> - Ported to e2fsprogs
+ */
+
+#include "config.h"
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <time.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/file.h>
+
+#include "common.h"
+#include "quotaio.h"
+
+static const char * const extensions[MAXQUOTAS] = {"user", "group"};
+static const char * const basenames[] = {
+ "", /* undefined */
+ "quota", /* QFMT_VFS_OLD */
+ "aquota", /* QFMT_VFS_V0 */
+ "", /* QFMT_OCFS2 */
+ "aquota" /* QFMT_VFS_V1 */
+};
+
+/* Header in all newer quotafiles */
+struct disk_dqheader {
+ u_int32_t dqh_magic;
+ u_int32_t dqh_version;
+} __attribute__ ((packed));
+
+/**
+ * Convert type of quota to written representation
+ */
+const char *type2name(int type)
+{
+ return extensions[type];
+}
+
+/**
+ * Creates a quota file name for given type and format.
+ */
+const char *quota_get_qf_name(int type, int fmt, char *buf)
+{
+ if (!buf)
+ return NULL;
+ snprintf(buf, QUOTA_NAME_LEN, "%s.%s",
+ basenames[fmt], extensions[type]);
+
+ return buf;
+}
+
+const char *quota_get_qf_path(const char *mntpt, int qtype, int fmt,
+ char *path_buf, size_t path_buf_size)
+{
+ char qf_name[QUOTA_NAME_LEN];
+
+ if (!mntpt || !path_buf || !path_buf_size)
+ return NULL;
+
+ strncpy(path_buf, mntpt, path_buf_size);
+ strncat(path_buf, "/", 1);
+ strncat(path_buf, quota_get_qf_name(qtype, fmt, qf_name),
+ path_buf_size - strlen(path_buf));
+
+ return path_buf;
+}
+
+/*
+ * Set grace time if needed
+ */
+void update_grace_times(struct dquot *q)
+{
+ time_t now;
+
+ time(&now);
+ if (q->dq_dqb.dqb_bsoftlimit && toqb(q->dq_dqb.dqb_curspace) >
+ q->dq_dqb.dqb_bsoftlimit) {
+ if (!q->dq_dqb.dqb_btime)
+ q->dq_dqb.dqb_btime =
+ now + q->dq_h->qh_info.dqi_bgrace;
+ } else {
+ q->dq_dqb.dqb_btime = 0;
+ }
+
+ if (q->dq_dqb.dqb_isoftlimit && q->dq_dqb.dqb_curinodes >
+ q->dq_dqb.dqb_isoftlimit) {
+ if (!q->dq_dqb.dqb_itime)
+ q->dq_dqb.dqb_itime =
+ now + q->dq_h->qh_info.dqi_igrace;
+ } else {
+ q->dq_dqb.dqb_itime = 0;
+ }
+}
+
+static int compute_num_blocks_proc(ext2_filsys fs, blk64_t *blocknr,
+ e2_blkcnt_t blockcnt EXT2FS_ATTR((unused)),
+ blk64_t ref_block EXT2FS_ATTR((unused)),
+ int ref_offset EXT2FS_ATTR((unused)),
+ void *private)
+{
+ blk64_t *num_blocks = private;
+
+ *num_blocks += 1;
+ return 0;
+}
+
+errcode_t quota_inode_truncate(ext2_filsys fs, ext2_ino_t ino)
+{
+ struct ext2_inode inode;
+ errcode_t err;
+
+ if ((err = ext2fs_read_inode(fs, ino, &inode)))
+ return err;
+
+ if ((ino == EXT4_USR_QUOTA_INO) || (ino == EXT4_GRP_QUOTA_INO)) {
+ inode.i_dtime = fs->now ? fs->now : time(0);
+ if (!ext2fs_inode_has_valid_blocks2(fs, &inode))
+ return 0;
+ err = ext2fs_punch(fs, ino, &inode, NULL, 0, ~0ULL);
+ if (err)
+ return err;
+ fs->flags &= ~EXT2_FLAG_SUPER_ONLY;
+ memset(&inode, 0, sizeof(struct ext2_inode));
+ } else {
+ inode.i_flags &= ~EXT2_IMMUTABLE_FL;
+ }
+ err = ext2fs_write_inode(fs, ino, &inode);
+ return err;
+}
+
+static ext2_off64_t compute_inode_size(ext2_filsys fs, ext2_ino_t ino)
+{
+ blk64_t num_blocks = 0;
+
+ ext2fs_block_iterate3(fs, ino,
+ BLOCK_FLAG_READ_ONLY,
+ NULL,
+ compute_num_blocks_proc,
+ &num_blocks);
+ return num_blocks * fs->blocksize;
+}
+
+/* Functions to read/write quota file. */
+static unsigned int quota_write_nomount(struct quota_file *qf,
+ ext2_loff_t offset,
+ void *buf, unsigned int size)
+{
+ ext2_file_t e2_file = qf->e2_file;
+ unsigned int bytes_written = 0;
+ errcode_t err;
+
+ err = ext2fs_file_llseek(e2_file, offset, EXT2_SEEK_SET, NULL);
+ if (err) {
+ log_err("ext2fs_file_llseek failed: %ld", err);
+ return 0;
+ }
+
+ err = ext2fs_file_write(e2_file, buf, size, &bytes_written);
+ if (err) {
+ log_err("ext2fs_file_write failed: %ld", err);
+ return 0;
+ }
+
+ /* Correct inode.i_size is set in end_io. */
+ return bytes_written;
+}
+
+static unsigned int quota_read_nomount(struct quota_file *qf,
+ ext2_loff_t offset,
+ void *buf, unsigned int size)
+{
+ ext2_file_t e2_file = qf->e2_file;
+ unsigned int bytes_read = 0;
+ errcode_t err;
+
+ err = ext2fs_file_llseek(e2_file, offset, EXT2_SEEK_SET, NULL);
+ if (err) {
+ log_err("ext2fs_file_llseek failed: %ld", err);
+ return 0;
+ }
+
+ err = ext2fs_file_read(e2_file, buf, size, &bytes_read);
+ if (err) {
+ log_err("ext2fs_file_read failed: %ld", err);
+ return 0;
+ }
+
+ return bytes_read;
+}
+
+/*
+ * Detect quota format and initialize quota IO
+ */
+errcode_t quota_file_open(struct quota_handle *h, ext2_filsys fs,
+ ext2_ino_t qf_ino, int type, int fmt, int flags)
+{
+ ext2_file_t e2_file;
+ errcode_t err;
+
+ if (fmt == -1)
+ fmt = QFMT_VFS_V1;
+
+ err = ext2fs_read_bitmaps(fs);
+ if (err)
+ return err;
+
+ log_debug("Opening quota ino=%lu, type=%d", qf_ino, type);
+ err = ext2fs_file_open(fs, qf_ino, flags, &e2_file);
+ if (err) {
+ log_err("ext2fs_file_open failed: %s", error_message(err));
+ return err;
+ }
+ h->qh_qf.e2_file = e2_file;
+
+ h->qh_qf.fs = fs;
+ h->qh_qf.ino = qf_ino;
+ h->e2fs_write = quota_write_nomount;
+ h->e2fs_read = quota_read_nomount;
+ h->qh_io_flags = 0;
+ h->qh_type = type;
+ h->qh_fmt = fmt;
+ memset(&h->qh_info, 0, sizeof(h->qh_info));
+ h->qh_ops = "afile_ops_2;
+
+ if (h->qh_ops->check_file &&
+ (h->qh_ops->check_file(h, type, fmt) == 0)) {
+ log_err("qh_ops->check_file failed");
+ ext2fs_file_close(e2_file);
+ return -1;
+ }
+
+ if (h->qh_ops->init_io && (h->qh_ops->init_io(h) < 0)) {
+ log_err("qh_ops->init_io failed");
+ ext2fs_file_close(e2_file);
+ return -1;
+ }
+
+ return 0;
+}
+
+static errcode_t quota_inode_init_new(ext2_filsys fs, ext2_ino_t ino)
+{
+ struct ext2_inode inode;
+ errcode_t err = 0;
+
+ err = ext2fs_read_inode(fs, ino, &inode);
+ if (err) {
+ log_err("ex2fs_read_inode failed");
+ return err;
+ }
+
+ if (EXT2_I_SIZE(&inode))
+ quota_inode_truncate(fs, ino);
+
+ memset(&inode, 0, sizeof(struct ext2_inode));
+ ext2fs_iblk_set(fs, &inode, 0);
+ inode.i_atime = inode.i_mtime =
+ inode.i_ctime = fs->now ? fs->now : time(0);
+ inode.i_links_count = 1;
+ inode.i_mode = LINUX_S_IFREG | 0600;
+ inode.i_flags |= EXT2_IMMUTABLE_FL;
+ if (fs->super->s_feature_incompat &
+ EXT3_FEATURE_INCOMPAT_EXTENTS)
+ inode.i_flags |= EXT4_EXTENTS_FL;
+
+ err = ext2fs_write_new_inode(fs, ino, &inode);
+ if (err) {
+ log_err("ext2fs_write_new_inode failed: %ld", err);
+ return err;
+ }
+ return err;
+}
+
+/*
+ * Create new quotafile of specified format on given filesystem
+ */
+errcode_t quota_file_create(struct quota_handle *h, ext2_filsys fs, int type, int fmt)
+{
+ ext2_file_t e2_file;
+ int err;
+ unsigned long qf_inum;
+
+ if (fmt == -1)
+ fmt = QFMT_VFS_V1;
+
+ h->qh_qf.fs = fs;
+ if (type == USRQUOTA)
+ qf_inum = EXT4_USR_QUOTA_INO;
+ else if (type == GRPQUOTA)
+ qf_inum = EXT4_GRP_QUOTA_INO;
+ else
+ return -1;
+
+ err = ext2fs_read_bitmaps(fs);
+ if (err)
+ goto out_err;
+
+ err = quota_inode_init_new(fs, qf_inum);
+ if (err) {
+ log_err("init_new_quota_inode failed");
+ goto out_err;
+ }
+ h->qh_qf.ino = qf_inum;
+ h->e2fs_write = quota_write_nomount;
+ h->e2fs_read = quota_read_nomount;
+
+ log_debug("Creating quota ino=%lu, type=%d", qf_inum, type);
+ err = ext2fs_file_open(fs, qf_inum,
+ EXT2_FILE_WRITE | EXT2_FILE_CREATE, &e2_file);
+ if (err) {
+ log_err("ext2fs_file_open failed: %d", err);
+ goto out_err;
+ }
+ h->qh_qf.e2_file = e2_file;
+
+ h->qh_io_flags = 0;
+ h->qh_type = type;
+ h->qh_fmt = fmt;
+ memset(&h->qh_info, 0, sizeof(h->qh_info));
+ h->qh_ops = "afile_ops_2;
+
+ if (h->qh_ops->new_io && (h->qh_ops->new_io(h) < 0)) {
+ log_err("qh_ops->new_io failed");
+ goto out_err1;
+ }
+
+ return 0;
+
+out_err1:
+ ext2fs_file_close(e2_file);
+out_err:
+
+ if (qf_inum)
+ quota_inode_truncate(fs, qf_inum);
+
+ return -1;
+}
+
+/*
+ * Close quotafile and release handle
+ */
+errcode_t quota_file_close(struct quota_handle *h)
+{
+ if (h->qh_io_flags & IOFL_INFODIRTY) {
+ if (h->qh_ops->write_info && h->qh_ops->write_info(h) < 0)
+ return -1;
+ h->qh_io_flags &= ~IOFL_INFODIRTY;
+ }
+
+ if (h->qh_ops->end_io && h->qh_ops->end_io(h) < 0)
+ return -1;
+ if (h->qh_qf.e2_file) {
+ ext2fs_file_flush(h->qh_qf.e2_file);
+ ext2fs_file_set_size2(h->qh_qf.e2_file,
+ compute_inode_size(h->qh_qf.fs, h->qh_qf.ino));
+ ext2fs_file_close(h->qh_qf.e2_file);
+ }
+
+ return 0;
+}
+
+/*
+ * Create empty quota structure
+ */
+struct dquot *get_empty_dquot(void)
+{
+ struct dquot *dquot;
+
+ if (ext2fs_get_memzero(sizeof(struct dquot), &dquot)) {
+ log_err("Failed to allocate dquot");
+ return NULL;
+ }
+
+ dquot->dq_id = -1;
+ return dquot;
+}
diff --git a/ap/app/e2fsprogs/e2fsprogs-1.42.9/lib/quota/quotaio.h b/ap/app/e2fsprogs/e2fsprogs-1.42.9/lib/quota/quotaio.h
new file mode 100644
index 0000000..1c062f1
--- /dev/null
+++ b/ap/app/e2fsprogs/e2fsprogs-1.42.9/lib/quota/quotaio.h
@@ -0,0 +1,165 @@
+/** quotaio.h
+ *
+ * Header of IO operations for quota utilities
+ * Jan Kara <jack@suse.cz>
+ */
+
+#ifndef GUARD_QUOTAIO_H
+#define GUARD_QUOTAIO_H
+
+#include <limits.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include "ext2fs/ext2fs.h"
+#include "dqblk_v2.h"
+
+typedef int64_t qsize_t; /* Type in which we store size limitations */
+
+#define MAXQUOTAS 2
+#define USRQUOTA 0
+#define GRPQUOTA 1
+
+/*
+ * Definitions of magics and versions of current quota files
+ */
+#define INITQMAGICS {\
+ 0xd9c01f11, /* USRQUOTA */\
+ 0xd9c01927 /* GRPQUOTA */\
+}
+
+/* Size of blocks in which are counted size limits in generic utility parts */
+#define QUOTABLOCK_BITS 10
+#define QUOTABLOCK_SIZE (1 << QUOTABLOCK_BITS)
+#define toqb(x) (((x) + QUOTABLOCK_SIZE - 1) >> QUOTABLOCK_BITS)
+
+/* Quota format type IDs */
+#define QFMT_VFS_OLD 1
+#define QFMT_VFS_V0 2
+#define QFMT_VFS_V1 4
+
+/*
+ * The following constants define the default amount of time given a user
+ * before the soft limits are treated as hard limits (usually resulting
+ * in an allocation failure). The timer is started when the user crosses
+ * their soft limit, it is reset when they go below their soft limit.
+ */
+#define MAX_IQ_TIME 604800 /* (7*24*60*60) 1 week */
+#define MAX_DQ_TIME 604800 /* (7*24*60*60) 1 week */
+
+#define IOFL_INFODIRTY 0x01 /* Did info change? */
+
+struct quotafile_ops;
+
+/* Generic information about quotafile */
+struct util_dqinfo {
+ time_t dqi_bgrace; /* Block grace time for given quotafile */
+ time_t dqi_igrace; /* Inode grace time for given quotafile */
+ union {
+ struct v2_mem_dqinfo v2_mdqi;
+ } u; /* Format specific info about quotafile */
+};
+
+struct quota_file {
+ ext2_filsys fs;
+ ext2_ino_t ino;
+ ext2_file_t e2_file;
+};
+
+/* Structure for one opened quota file */
+struct quota_handle {
+ int qh_type; /* Type of quotafile */
+ int qh_fmt; /* Quotafile format */
+ int qh_io_flags; /* IO flags for file */
+ struct quota_file qh_qf;
+ unsigned int (*e2fs_read)(struct quota_file *qf, ext2_loff_t offset,
+ void *buf, unsigned int size);
+ unsigned int (*e2fs_write)(struct quota_file *qf, ext2_loff_t offset,
+ void *buf, unsigned int size);
+ struct quotafile_ops *qh_ops; /* Operations on quotafile */
+ struct util_dqinfo qh_info; /* Generic quotafile info */
+};
+
+/* Utility quota block */
+struct util_dqblk {
+ qsize_t dqb_ihardlimit;
+ qsize_t dqb_isoftlimit;
+ qsize_t dqb_curinodes;
+ qsize_t dqb_bhardlimit;
+ qsize_t dqb_bsoftlimit;
+ qsize_t dqb_curspace;
+ time_t dqb_btime;
+ time_t dqb_itime;
+ union {
+ struct v2_mem_dqblk v2_mdqb;
+ } u; /* Format specific dquot information */
+};
+
+/* Structure for one loaded quota */
+struct dquot {
+ struct dquot *dq_next; /* Pointer to next dquot in the list */
+ qid_t dq_id; /* ID dquot belongs to */
+ int dq_flags; /* Some flags for utils */
+ struct quota_handle *dq_h; /* Handle of quotafile for this dquot */
+ struct util_dqblk dq_dqb; /* Parsed data of dquot */
+};
+
+/* Structure of quotafile operations */
+struct quotafile_ops {
+ /* Check whether quotafile is in our format */
+ int (*check_file) (struct quota_handle *h, int type, int fmt);
+ /* Open quotafile */
+ int (*init_io) (struct quota_handle *h);
+ /* Create new quotafile */
+ int (*new_io) (struct quota_handle *h);
+ /* Write all changes and close quotafile */
+ int (*end_io) (struct quota_handle *h);
+ /* Write info about quotafile */
+ int (*write_info) (struct quota_handle *h);
+ /* Read dquot into memory */
+ struct dquot *(*read_dquot) (struct quota_handle *h, qid_t id);
+ /* Write given dquot to disk */
+ int (*commit_dquot) (struct dquot *dquot);
+ /* Scan quotafile and call callback on every structure */
+ int (*scan_dquots) (struct quota_handle *h,
+ int (*process_dquot) (struct dquot *dquot,
+ void *data),
+ void *data);
+ /* Function to print format specific file information */
+ int (*report) (struct quota_handle *h, int verbose);
+};
+
+/* This might go into a special header file but that sounds a bit silly... */
+extern struct quotafile_ops quotafile_ops_meta;
+
+/* Open existing quotafile of given type (and verify its format) on given
+ * filesystem. */
+errcode_t quota_file_open(struct quota_handle *h, ext2_filsys fs,
+ ext2_ino_t qf_ino, int type, int fmt, int flags);
+
+
+/* Create new quotafile of specified format on given filesystem */
+errcode_t quota_file_create(struct quota_handle *h, ext2_filsys fs,
+ int type, int fmt);
+
+/* Close quotafile */
+errcode_t quota_file_close(struct quota_handle *h);
+
+/* Get empty quota structure */
+struct dquot *get_empty_dquot(void);
+
+errcode_t quota_inode_truncate(ext2_filsys fs, ext2_ino_t ino);
+
+const char *type2name(int type);
+
+void update_grace_times(struct dquot *q);
+
+/* size for the buffer returned by quota_get_qf_name(); must be greater
+ than maxlen of extensions[] and fmtnames[] (plus 2) found in quotaio.c */
+#define QUOTA_NAME_LEN 16
+
+const char *quota_get_qf_name(int type, int fmt, char *buf);
+const char *quota_get_qf_path(const char *mntpt, int qtype, int fmt,
+ char *path_buf, size_t path_buf_size);
+
+#endif /* GUARD_QUOTAIO_H */
diff --git a/ap/app/e2fsprogs/e2fsprogs-1.42.9/lib/quota/quotaio_tree.c b/ap/app/e2fsprogs/e2fsprogs-1.42.9/lib/quota/quotaio_tree.c
new file mode 100644
index 0000000..c1653a3
--- /dev/null
+++ b/ap/app/e2fsprogs/e2fsprogs-1.42.9/lib/quota/quotaio_tree.c
@@ -0,0 +1,656 @@
+/*
+ * Implementation of new quotafile format
+ *
+ * Jan Kara <jack@suse.cz> - sponsored by SuSE CR
+ */
+
+#include "config.h"
+#include <sys/types.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "common.h"
+#include "quotaio_tree.h"
+#include "quotaio.h"
+
+typedef char *dqbuf_t;
+
+#define freedqbuf(buf) ext2fs_free_mem(&buf)
+
+static inline dqbuf_t getdqbuf(void)
+{
+ dqbuf_t buf;
+ if (ext2fs_get_memzero(QT_BLKSIZE, &buf)) {
+ log_err("Failed to allocate dqbuf");
+ return NULL;
+ }
+
+ return buf;
+}
+
+/* Is given dquot empty? */
+int qtree_entry_unused(struct qtree_mem_dqinfo *info, char *disk)
+{
+ int i;
+
+ for (i = 0; i < info->dqi_entry_size; i++)
+ if (disk[i])
+ return 0;
+ return 1;
+}
+
+int qtree_dqstr_in_blk(struct qtree_mem_dqinfo *info)
+{
+ return (QT_BLKSIZE - sizeof(struct qt_disk_dqdbheader)) /
+ info->dqi_entry_size;
+}
+
+static int get_index(qid_t id, int depth)
+{
+ return (id >> ((QT_TREEDEPTH - depth - 1) * 8)) & 0xff;
+}
+
+static inline void mark_quotafile_info_dirty(struct quota_handle *h)
+{
+ h->qh_io_flags |= IOFL_INFODIRTY;
+}
+
+/* Read given block */
+static void read_blk(struct quota_handle *h, uint blk, dqbuf_t buf)
+{
+ int err;
+
+ err = h->e2fs_read(&h->qh_qf, blk << QT_BLKSIZE_BITS, buf,
+ QT_BLKSIZE);
+ if (err < 0)
+ log_err("Cannot read block %u: %s", blk, strerror(errno));
+ else if (err != QT_BLKSIZE)
+ memset(buf + err, 0, QT_BLKSIZE - err);
+}
+
+/* Write block */
+static int write_blk(struct quota_handle *h, uint blk, dqbuf_t buf)
+{
+ int err;
+
+ err = h->e2fs_write(&h->qh_qf, blk << QT_BLKSIZE_BITS, buf,
+ QT_BLKSIZE);
+ if (err < 0 && errno != ENOSPC)
+ log_err("Cannot write block (%u): %s", blk, strerror(errno));
+ if (err != QT_BLKSIZE)
+ return -ENOSPC;
+ return 0;
+}
+
+/* Get free block in file (either from free list or create new one) */
+static int get_free_dqblk(struct quota_handle *h)
+{
+ dqbuf_t buf = getdqbuf();
+ struct qt_disk_dqdbheader *dh = (struct qt_disk_dqdbheader *)buf;
+ struct qtree_mem_dqinfo *info = &h->qh_info.u.v2_mdqi.dqi_qtree;
+ int blk;
+
+ if (!buf)
+ return -ENOMEM;
+
+ if (info->dqi_free_blk) {
+ blk = info->dqi_free_blk;
+ read_blk(h, blk, buf);
+ info->dqi_free_blk = ext2fs_le32_to_cpu(dh->dqdh_next_free);
+ } else {
+ memset(buf, 0, QT_BLKSIZE);
+ /* Assure block allocation... */
+ if (write_blk(h, info->dqi_blocks, buf) < 0) {
+ freedqbuf(buf);
+ log_err("Cannot allocate new quota block "
+ "(out of disk space).");
+ return -ENOSPC;
+ }
+ blk = info->dqi_blocks++;
+ }
+ mark_quotafile_info_dirty(h);
+ freedqbuf(buf);
+ return blk;
+}
+
+/* Put given block to free list */
+static void put_free_dqblk(struct quota_handle *h, dqbuf_t buf, uint blk)
+{
+ struct qt_disk_dqdbheader *dh = (struct qt_disk_dqdbheader *)buf;
+ struct qtree_mem_dqinfo *info = &h->qh_info.u.v2_mdqi.dqi_qtree;
+
+ dh->dqdh_next_free = ext2fs_cpu_to_le32(info->dqi_free_blk);
+ dh->dqdh_prev_free = ext2fs_cpu_to_le32(0);
+ dh->dqdh_entries = ext2fs_cpu_to_le16(0);
+ info->dqi_free_blk = blk;
+ mark_quotafile_info_dirty(h);
+ write_blk(h, blk, buf);
+}
+
+/* Remove given block from the list of blocks with free entries */
+static void remove_free_dqentry(struct quota_handle *h, dqbuf_t buf, uint blk)
+{
+ dqbuf_t tmpbuf = getdqbuf();
+ struct qt_disk_dqdbheader *dh = (struct qt_disk_dqdbheader *)buf;
+ uint nextblk = ext2fs_le32_to_cpu(dh->dqdh_next_free), prevblk =
+
+ ext2fs_le32_to_cpu(dh->dqdh_prev_free);
+
+ if (!tmpbuf)
+ return;
+
+ if (nextblk) {
+ read_blk(h, nextblk, tmpbuf);
+ ((struct qt_disk_dqdbheader *)tmpbuf)->dqdh_prev_free =
+ dh->dqdh_prev_free;
+ write_blk(h, nextblk, tmpbuf);
+ }
+ if (prevblk) {
+ read_blk(h, prevblk, tmpbuf);
+ ((struct qt_disk_dqdbheader *)tmpbuf)->dqdh_next_free =
+ dh->dqdh_next_free;
+ write_blk(h, prevblk, tmpbuf);
+ } else {
+ h->qh_info.u.v2_mdqi.dqi_qtree.dqi_free_entry = nextblk;
+ mark_quotafile_info_dirty(h);
+ }
+ freedqbuf(tmpbuf);
+ dh->dqdh_next_free = dh->dqdh_prev_free = ext2fs_cpu_to_le32(0);
+ write_blk(h, blk, buf); /* No matter whether write succeeds
+ * block is out of list */
+}
+
+/* Insert given block to the beginning of list with free entries */
+static void insert_free_dqentry(struct quota_handle *h, dqbuf_t buf, uint blk)
+{
+ dqbuf_t tmpbuf = getdqbuf();
+ struct qt_disk_dqdbheader *dh = (struct qt_disk_dqdbheader *)buf;
+ struct qtree_mem_dqinfo *info = &h->qh_info.u.v2_mdqi.dqi_qtree;
+
+ if (!tmpbuf)
+ return;
+
+ dh->dqdh_next_free = ext2fs_cpu_to_le32(info->dqi_free_entry);
+ dh->dqdh_prev_free = ext2fs_cpu_to_le32(0);
+ write_blk(h, blk, buf);
+ if (info->dqi_free_entry) {
+ read_blk(h, info->dqi_free_entry, tmpbuf);
+ ((struct qt_disk_dqdbheader *)tmpbuf)->dqdh_prev_free =
+ ext2fs_cpu_to_le32(blk);
+ write_blk(h, info->dqi_free_entry, tmpbuf);
+ }
+ freedqbuf(tmpbuf);
+ info->dqi_free_entry = blk;
+ mark_quotafile_info_dirty(h);
+}
+
+/* Find space for dquot */
+static uint find_free_dqentry(struct quota_handle *h, struct dquot *dquot,
+ int *err)
+{
+ int blk, i;
+ struct qt_disk_dqdbheader *dh;
+ struct qtree_mem_dqinfo *info = &h->qh_info.u.v2_mdqi.dqi_qtree;
+ char *ddquot;
+ dqbuf_t buf;
+
+ *err = 0;
+ buf = getdqbuf();
+ if (!buf) {
+ *err = -ENOMEM;
+ return 0;
+ }
+
+ dh = (struct qt_disk_dqdbheader *)buf;
+ if (info->dqi_free_entry) {
+ blk = info->dqi_free_entry;
+ read_blk(h, blk, buf);
+ } else {
+ blk = get_free_dqblk(h);
+ if (blk < 0) {
+ freedqbuf(buf);
+ *err = blk;
+ return 0;
+ }
+ memset(buf, 0, QT_BLKSIZE);
+ info->dqi_free_entry = blk;
+ mark_quotafile_info_dirty(h);
+ }
+
+ /* Block will be full? */
+ if (ext2fs_le16_to_cpu(dh->dqdh_entries) + 1 >=
+ qtree_dqstr_in_blk(info))
+ remove_free_dqentry(h, buf, blk);
+
+ dh->dqdh_entries =
+ ext2fs_cpu_to_le16(ext2fs_le16_to_cpu(dh->dqdh_entries) + 1);
+ /* Find free structure in block */
+ ddquot = buf + sizeof(struct qt_disk_dqdbheader);
+ for (i = 0;
+ i < qtree_dqstr_in_blk(info) && !qtree_entry_unused(info, ddquot);
+ i++)
+ ddquot += info->dqi_entry_size;
+
+ if (i == qtree_dqstr_in_blk(info))
+ log_err("find_free_dqentry(): Data block full unexpectedly.");
+
+ write_blk(h, blk, buf);
+ dquot->dq_dqb.u.v2_mdqb.dqb_off =
+ (blk << QT_BLKSIZE_BITS) + sizeof(struct qt_disk_dqdbheader) +
+ i * info->dqi_entry_size;
+ freedqbuf(buf);
+ return blk;
+}
+
+/* Insert reference to structure into the trie */
+static int do_insert_tree(struct quota_handle *h, struct dquot *dquot,
+ uint * treeblk, int depth)
+{
+ dqbuf_t buf;
+ int newson = 0, newact = 0;
+ u_int32_t *ref;
+ uint newblk;
+ int ret = 0;
+
+ log_debug("inserting in tree: treeblk=%u, depth=%d", *treeblk, depth);
+ buf = getdqbuf();
+ if (!buf)
+ return -ENOMEM;
+
+ if (!*treeblk) {
+ ret = get_free_dqblk(h);
+ if (ret < 0)
+ goto out_buf;
+ *treeblk = ret;
+ memset(buf, 0, QT_BLKSIZE);
+ newact = 1;
+ } else {
+ read_blk(h, *treeblk, buf);
+ }
+
+ ref = (u_int32_t *) buf;
+ newblk = ext2fs_le32_to_cpu(ref[get_index(dquot->dq_id, depth)]);
+ if (!newblk)
+ newson = 1;
+ if (depth == QT_TREEDEPTH - 1) {
+ if (newblk)
+ log_err("Inserting already present quota entry "
+ "(block %u).",
+ ref[get_index(dquot->dq_id, depth)]);
+ newblk = find_free_dqentry(h, dquot, &ret);
+ } else {
+ ret = do_insert_tree(h, dquot, &newblk, depth + 1);
+ }
+
+ if (newson && ret >= 0) {
+ ref[get_index(dquot->dq_id, depth)] =
+ ext2fs_cpu_to_le32(newblk);
+ write_blk(h, *treeblk, buf);
+ } else if (newact && ret < 0) {
+ put_free_dqblk(h, buf, *treeblk);
+ }
+
+out_buf:
+ freedqbuf(buf);
+ return ret;
+}
+
+/* Wrapper for inserting quota structure into tree */
+static void dq_insert_tree(struct quota_handle *h, struct dquot *dquot)
+{
+ uint tmp = QT_TREEOFF;
+
+ if (do_insert_tree(h, dquot, &tmp, 0) < 0)
+ log_err("Cannot write quota (id %u): %s",
+ (uint) dquot->dq_id, strerror(errno));
+}
+
+/* Write dquot to file */
+void qtree_write_dquot(struct dquot *dquot)
+{
+ ssize_t ret;
+ char *ddquot;
+ struct quota_handle *h = dquot->dq_h;
+ struct qtree_mem_dqinfo *info =
+ &dquot->dq_h->qh_info.u.v2_mdqi.dqi_qtree;
+ log_debug("writing ddquot 1: off=%llu, info->dqi_entry_size=%u",
+ dquot->dq_dqb.u.v2_mdqb.dqb_off,
+ info->dqi_entry_size);
+ ret = ext2fs_get_mem(info->dqi_entry_size, &ddquot);
+ if (ret) {
+ errno = ENOMEM;
+ log_err("Quota write failed (id %u): %s",
+ (uint)dquot->dq_id, strerror(errno));
+ return;
+ }
+
+ if (!dquot->dq_dqb.u.v2_mdqb.dqb_off)
+ dq_insert_tree(dquot->dq_h, dquot);
+ info->dqi_ops->mem2disk_dqblk(ddquot, dquot);
+ log_debug("writing ddquot 2: off=%llu, info->dqi_entry_size=%u",
+ dquot->dq_dqb.u.v2_mdqb.dqb_off,
+ info->dqi_entry_size);
+ ret = h->e2fs_write(&h->qh_qf, dquot->dq_dqb.u.v2_mdqb.dqb_off, ddquot,
+ info->dqi_entry_size);
+
+ if (ret != info->dqi_entry_size) {
+ if (ret > 0)
+ errno = ENOSPC;
+ log_err("Quota write failed (id %u): %s",
+ (uint)dquot->dq_id, strerror(errno));
+ }
+ ext2fs_free_mem(&ddquot);
+}
+
+/* Free dquot entry in data block */
+static void free_dqentry(struct quota_handle *h, struct dquot *dquot, uint blk)
+{
+ struct qt_disk_dqdbheader *dh;
+ struct qtree_mem_dqinfo *info = &h->qh_info.u.v2_mdqi.dqi_qtree;
+ dqbuf_t buf = getdqbuf();
+
+ if (!buf)
+ return;
+
+ if (dquot->dq_dqb.u.v2_mdqb.dqb_off >> QT_BLKSIZE_BITS != blk)
+ log_err("Quota structure has offset to other block (%u) "
+ "than it should (%u).", blk,
+ (uint) (dquot->dq_dqb.u.v2_mdqb.dqb_off >>
+ QT_BLKSIZE_BITS));
+
+ read_blk(h, blk, buf);
+ dh = (struct qt_disk_dqdbheader *)buf;
+ dh->dqdh_entries =
+ ext2fs_cpu_to_le16(ext2fs_le16_to_cpu(dh->dqdh_entries) - 1);
+
+ if (!ext2fs_le16_to_cpu(dh->dqdh_entries)) { /* Block got free? */
+ remove_free_dqentry(h, buf, blk);
+ put_free_dqblk(h, buf, blk);
+ } else {
+ memset(buf + (dquot->dq_dqb.u.v2_mdqb.dqb_off &
+ ((1 << QT_BLKSIZE_BITS) - 1)),
+ 0, info->dqi_entry_size);
+
+ /* First free entry? */
+ if (ext2fs_le16_to_cpu(dh->dqdh_entries) ==
+ qtree_dqstr_in_blk(info) - 1)
+ /* This will also write data block */
+ insert_free_dqentry(h, buf, blk);
+ else
+ write_blk(h, blk, buf);
+ }
+ dquot->dq_dqb.u.v2_mdqb.dqb_off = 0;
+ freedqbuf(buf);
+}
+
+/* Remove reference to dquot from tree */
+static void remove_tree(struct quota_handle *h, struct dquot *dquot,
+ uint * blk, int depth)
+{
+ dqbuf_t buf = getdqbuf();
+ uint newblk;
+ u_int32_t *ref = (u_int32_t *) buf;
+
+ if (!buf)
+ return;
+
+ read_blk(h, *blk, buf);
+ newblk = ext2fs_le32_to_cpu(ref[get_index(dquot->dq_id, depth)]);
+ if (depth == QT_TREEDEPTH - 1) {
+ free_dqentry(h, dquot, newblk);
+ newblk = 0;
+ } else {
+ remove_tree(h, dquot, &newblk, depth + 1);
+ }
+
+ if (!newblk) {
+ int i;
+
+ ref[get_index(dquot->dq_id, depth)] = ext2fs_cpu_to_le32(0);
+
+ /* Block got empty? */
+ for (i = 0; i < QT_BLKSIZE && !buf[i]; i++);
+
+ /* Don't put the root block into the free block list */
+ if (i == QT_BLKSIZE && *blk != QT_TREEOFF) {
+ put_free_dqblk(h, buf, *blk);
+ *blk = 0;
+ } else {
+ write_blk(h, *blk, buf);
+ }
+ }
+ freedqbuf(buf);
+}
+
+/* Delete dquot from tree */
+void qtree_delete_dquot(struct dquot *dquot)
+{
+ uint tmp = QT_TREEOFF;
+
+ if (!dquot->dq_dqb.u.v2_mdqb.dqb_off) /* Even not allocated? */
+ return;
+ remove_tree(dquot->dq_h, dquot, &tmp, 0);
+}
+
+/* Find entry in block */
+static ext2_loff_t find_block_dqentry(struct quota_handle *h,
+ struct dquot *dquot, uint blk)
+{
+ struct qtree_mem_dqinfo *info = &h->qh_info.u.v2_mdqi.dqi_qtree;
+ dqbuf_t buf = getdqbuf();
+ int i;
+ char *ddquot = buf + sizeof(struct qt_disk_dqdbheader);
+
+ if (!buf)
+ return -ENOMEM;
+
+ read_blk(h, blk, buf);
+ for (i = 0;
+ i < qtree_dqstr_in_blk(info) && !info->dqi_ops->is_id(ddquot, dquot);
+ i++)
+ ddquot += info->dqi_entry_size;
+
+ if (i == qtree_dqstr_in_blk(info))
+ log_err("Quota for id %u referenced but not present.",
+ dquot->dq_id);
+ freedqbuf(buf);
+ return (blk << QT_BLKSIZE_BITS) + sizeof(struct qt_disk_dqdbheader) +
+ i * info->dqi_entry_size;
+}
+
+/* Find entry for given id in the tree */
+static ext2_loff_t find_tree_dqentry(struct quota_handle *h,
+ struct dquot *dquot,
+ uint blk, int depth)
+{
+ dqbuf_t buf = getdqbuf();
+ ext2_loff_t ret = 0;
+ u_int32_t *ref = (u_int32_t *) buf;
+
+ if (!buf)
+ return -ENOMEM;
+
+ read_blk(h, blk, buf);
+ ret = 0;
+ blk = ext2fs_le32_to_cpu(ref[get_index(dquot->dq_id, depth)]);
+ if (!blk) /* No reference? */
+ goto out_buf;
+ if (depth < QT_TREEDEPTH - 1)
+ ret = find_tree_dqentry(h, dquot, blk, depth + 1);
+ else
+ ret = find_block_dqentry(h, dquot, blk);
+out_buf:
+ freedqbuf(buf);
+ return ret;
+}
+
+/* Find entry for given id in the tree - wrapper function */
+static inline ext2_loff_t find_dqentry(struct quota_handle *h,
+ struct dquot *dquot)
+{
+ return find_tree_dqentry(h, dquot, QT_TREEOFF, 0);
+}
+
+/*
+ * Read dquot from disk.
+ */
+struct dquot *qtree_read_dquot(struct quota_handle *h, qid_t id)
+{
+ struct qtree_mem_dqinfo *info = &h->qh_info.u.v2_mdqi.dqi_qtree;
+ ext2_loff_t offset;
+ ssize_t ret;
+ char *ddquot;
+ struct dquot *dquot = get_empty_dquot();
+
+ if (!dquot)
+ return NULL;
+ if (ext2fs_get_mem(info->dqi_entry_size, &ddquot)) {
+ ext2fs_free_mem(&dquot);
+ return NULL;
+ }
+
+ dquot->dq_id = id;
+ dquot->dq_h = h;
+ dquot->dq_dqb.u.v2_mdqb.dqb_off = 0;
+ memset(&dquot->dq_dqb, 0, sizeof(struct util_dqblk));
+
+ offset = find_dqentry(h, dquot);
+ if (offset > 0) {
+ dquot->dq_dqb.u.v2_mdqb.dqb_off = offset;
+ ret = h->e2fs_read(&h->qh_qf, offset, ddquot,
+ info->dqi_entry_size);
+ if (ret != info->dqi_entry_size) {
+ if (ret > 0)
+ errno = EIO;
+ log_err("Cannot read quota structure for id %u: %s",
+ dquot->dq_id, strerror(errno));
+ }
+ info->dqi_ops->disk2mem_dqblk(dquot, ddquot);
+ }
+ ext2fs_free_mem(&ddquot);
+ return dquot;
+}
+
+/*
+ * Scan all dquots in file and call callback on each
+ */
+#define set_bit(bmp, ind) ((bmp)[(ind) >> 3] |= (1 << ((ind) & 7)))
+#define get_bit(bmp, ind) ((bmp)[(ind) >> 3] & (1 << ((ind) & 7)))
+
+static int report_block(struct dquot *dquot, uint blk, char *bitmap,
+ int (*process_dquot) (struct dquot *, void *),
+ void *data)
+{
+ struct qtree_mem_dqinfo *info =
+ &dquot->dq_h->qh_info.u.v2_mdqi.dqi_qtree;
+ dqbuf_t buf = getdqbuf();
+ struct qt_disk_dqdbheader *dh;
+ char *ddata;
+ int entries, i;
+
+ if (!buf)
+ return 0;
+
+ set_bit(bitmap, blk);
+ read_blk(dquot->dq_h, blk, buf);
+ dh = (struct qt_disk_dqdbheader *)buf;
+ ddata = buf + sizeof(struct qt_disk_dqdbheader);
+ entries = ext2fs_le16_to_cpu(dh->dqdh_entries);
+ for (i = 0; i < qtree_dqstr_in_blk(info);
+ i++, ddata += info->dqi_entry_size)
+ if (!qtree_entry_unused(info, ddata)) {
+ dquot->dq_dqb.u.v2_mdqb.dqb_off =
+ (blk << QT_BLKSIZE_BITS) +
+ sizeof(struct qt_disk_dqdbheader) +
+ i * info->dqi_entry_size;
+ info->dqi_ops->disk2mem_dqblk(dquot, ddata);
+ if (process_dquot(dquot, data) < 0)
+ break;
+ }
+ freedqbuf(buf);
+ return entries;
+}
+
+static void check_reference(struct quota_handle *h, uint blk)
+{
+ if (blk >= h->qh_info.u.v2_mdqi.dqi_qtree.dqi_blocks)
+ log_err("Illegal reference (%u >= %u) in %s quota file. "
+ "Quota file is probably corrupted.\n"
+ "Please run e2fsck (8) to fix it.",
+ blk,
+ h->qh_info.u.v2_mdqi.dqi_qtree.dqi_blocks,
+ type2name(h->qh_type));
+}
+
+static int report_tree(struct dquot *dquot, uint blk, int depth, char *bitmap,
+ int (*process_dquot) (struct dquot *, void *),
+ void *data)
+{
+ int entries = 0, i;
+ dqbuf_t buf = getdqbuf();
+ u_int32_t *ref = (u_int32_t *) buf;
+
+ if (!buf)
+ return 0;
+
+ read_blk(dquot->dq_h, blk, buf);
+ if (depth == QT_TREEDEPTH - 1) {
+ for (i = 0; i < QT_BLKSIZE >> 2; i++) {
+ blk = ext2fs_le32_to_cpu(ref[i]);
+ check_reference(dquot->dq_h, blk);
+ if (blk && !get_bit(bitmap, blk))
+ entries += report_block(dquot, blk, bitmap,
+ process_dquot, data);
+ }
+ } else {
+ for (i = 0; i < QT_BLKSIZE >> 2; i++) {
+ blk = ext2fs_le32_to_cpu(ref[i]);
+ if (blk) {
+ check_reference(dquot->dq_h, blk);
+ entries += report_tree(dquot, blk, depth + 1,
+ bitmap, process_dquot,
+ data);
+ }
+ }
+ }
+ freedqbuf(buf);
+ return entries;
+}
+
+static uint find_set_bits(char *bmp, int blocks)
+{
+ uint i, used = 0;
+
+ for (i = 0; i < blocks; i++)
+ if (get_bit(bmp, i))
+ used++;
+ return used;
+}
+
+int qtree_scan_dquots(struct quota_handle *h,
+ int (*process_dquot) (struct dquot *, void *),
+ void *data)
+{
+ char *bitmap;
+ struct v2_mem_dqinfo *v2info = &h->qh_info.u.v2_mdqi;
+ struct qtree_mem_dqinfo *info = &v2info->dqi_qtree;
+ struct dquot *dquot = get_empty_dquot();
+
+ if (!dquot)
+ return -1;
+
+ dquot->dq_h = h;
+ if (ext2fs_get_memzero((info->dqi_blocks + 7) >> 3, &bitmap)) {
+ ext2fs_free_mem(&dquot);
+ return -1;
+ }
+ v2info->dqi_used_entries = report_tree(dquot, QT_TREEOFF, 0, bitmap,
+ process_dquot, data);
+ v2info->dqi_data_blocks = find_set_bits(bitmap, info->dqi_blocks);
+ ext2fs_free_mem(&bitmap);
+ ext2fs_free_mem(&dquot);
+ return 0;
+}
diff --git a/ap/app/e2fsprogs/e2fsprogs-1.42.9/lib/quota/quotaio_tree.h b/ap/app/e2fsprogs/e2fsprogs-1.42.9/lib/quota/quotaio_tree.h
new file mode 100644
index 0000000..6ee54c9
--- /dev/null
+++ b/ap/app/e2fsprogs/e2fsprogs-1.42.9/lib/quota/quotaio_tree.h
@@ -0,0 +1,64 @@
+/*
+ * Definitions of structures for vfsv0 quota format
+ */
+
+#ifndef _LINUX_QUOTA_TREE_H
+#define _LINUX_QUOTA_TREE_H
+
+#include <sys/types.h>
+
+typedef u_int32_t qid_t; /* Type in which we store ids in memory */
+
+#define QT_TREEOFF 1 /* Offset of tree in file in blocks */
+#define QT_TREEDEPTH 4 /* Depth of quota tree */
+#define QT_BLKSIZE_BITS 10
+#define QT_BLKSIZE (1 << QT_BLKSIZE_BITS) /* Size of block with quota
+ * structures */
+
+/*
+ * Structure of header of block with quota structures. It is padded to 16 bytes
+ * so there will be space for exactly 21 quota-entries in a block
+ */
+struct qt_disk_dqdbheader {
+ u_int32_t dqdh_next_free; /* Number of next block with free
+ * entry */
+ u_int32_t dqdh_prev_free; /* Number of previous block with free
+ * entry */
+ u_int16_t dqdh_entries; /* Number of valid entries in block */
+ u_int16_t dqdh_pad1;
+ u_int32_t dqdh_pad2;
+} __attribute__ ((packed));
+
+struct dquot;
+struct quota_handle;
+
+/* Operations */
+struct qtree_fmt_operations {
+ /* Convert given entry from in memory format to disk one */
+ void (*mem2disk_dqblk)(void *disk, struct dquot *dquot);
+ /* Convert given entry from disk format to in memory one */
+ void (*disk2mem_dqblk)(struct dquot *dquot, void *disk);
+ /* Is this structure for given id? */
+ int (*is_id)(void *disk, struct dquot *dquot);
+};
+
+/* Inmemory copy of version specific information */
+struct qtree_mem_dqinfo {
+ unsigned int dqi_blocks; /* # of blocks in quota file */
+ unsigned int dqi_free_blk; /* First block in list of free blocks */
+ unsigned int dqi_free_entry; /* First block with free entry */
+ unsigned int dqi_entry_size; /* Size of quota entry in quota file */
+ struct qtree_fmt_operations *dqi_ops; /* Operations for entry
+ * manipulation */
+};
+
+void qtree_write_dquot(struct dquot *dquot);
+struct dquot *qtree_read_dquot(struct quota_handle *h, qid_t id);
+void qtree_delete_dquot(struct dquot *dquot);
+int qtree_entry_unused(struct qtree_mem_dqinfo *info, char *disk);
+int qtree_scan_dquots(struct quota_handle *h,
+ int (*process_dquot) (struct dquot *, void *), void *data);
+
+int qtree_dqstr_in_blk(struct qtree_mem_dqinfo *info);
+
+#endif /* _LINUX_QUOTAIO_TREE_H */
diff --git a/ap/app/e2fsprogs/e2fsprogs-1.42.9/lib/quota/quotaio_v2.c b/ap/app/e2fsprogs/e2fsprogs-1.42.9/lib/quota/quotaio_v2.c
new file mode 100644
index 0000000..e7bf29c
--- /dev/null
+++ b/ap/app/e2fsprogs/e2fsprogs-1.42.9/lib/quota/quotaio_v2.c
@@ -0,0 +1,283 @@
+/*
+ * Implementation of new quotafile format
+ *
+ * Jan Kara <jack@suse.cz> - sponsored by SuSE CR
+ */
+
+#include "config.h"
+#include <sys/types.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "common.h"
+#include "quotaio_v2.h"
+#include "dqblk_v2.h"
+#include "quotaio.h"
+#include "quotaio_tree.h"
+
+static int v2_check_file(struct quota_handle *h, int type, int fmt);
+static int v2_init_io(struct quota_handle *h);
+static int v2_new_io(struct quota_handle *h);
+static int v2_write_info(struct quota_handle *h);
+static struct dquot *v2_read_dquot(struct quota_handle *h, qid_t id);
+static int v2_commit_dquot(struct dquot *dquot);
+static int v2_scan_dquots(struct quota_handle *h,
+ int (*process_dquot) (struct dquot *dquot,
+ void *data),
+ void *data);
+static int v2_report(struct quota_handle *h, int verbose);
+
+struct quotafile_ops quotafile_ops_2 = {
+ .check_file = v2_check_file,
+ .init_io = v2_init_io,
+ .new_io = v2_new_io,
+ .write_info = v2_write_info,
+ .read_dquot = v2_read_dquot,
+ .commit_dquot = v2_commit_dquot,
+ .scan_dquots = v2_scan_dquots,
+ .report = v2_report,
+};
+
+/*
+ * Copy dquot from disk to memory
+ */
+static void v2r1_disk2memdqblk(struct dquot *dquot, void *dp)
+{
+ struct util_dqblk *m = &dquot->dq_dqb;
+ struct v2r1_disk_dqblk *d = dp, empty;
+
+ dquot->dq_id = ext2fs_le32_to_cpu(d->dqb_id);
+ m->dqb_ihardlimit = ext2fs_le64_to_cpu(d->dqb_ihardlimit);
+ m->dqb_isoftlimit = ext2fs_le64_to_cpu(d->dqb_isoftlimit);
+ m->dqb_bhardlimit = ext2fs_le64_to_cpu(d->dqb_bhardlimit);
+ m->dqb_bsoftlimit = ext2fs_le64_to_cpu(d->dqb_bsoftlimit);
+ m->dqb_curinodes = ext2fs_le64_to_cpu(d->dqb_curinodes);
+ m->dqb_curspace = ext2fs_le64_to_cpu(d->dqb_curspace);
+ m->dqb_itime = ext2fs_le64_to_cpu(d->dqb_itime);
+ m->dqb_btime = ext2fs_le64_to_cpu(d->dqb_btime);
+
+ memset(&empty, 0, sizeof(struct v2r1_disk_dqblk));
+ empty.dqb_itime = ext2fs_cpu_to_le64(1);
+ if (!memcmp(&empty, dp, sizeof(struct v2r1_disk_dqblk)))
+ m->dqb_itime = 0;
+}
+
+/*
+ * Copy dquot from memory to disk
+ */
+static void v2r1_mem2diskdqblk(void *dp, struct dquot *dquot)
+{
+ struct util_dqblk *m = &dquot->dq_dqb;
+ struct v2r1_disk_dqblk *d = dp;
+
+ d->dqb_ihardlimit = ext2fs_cpu_to_le64(m->dqb_ihardlimit);
+ d->dqb_isoftlimit = ext2fs_cpu_to_le64(m->dqb_isoftlimit);
+ d->dqb_bhardlimit = ext2fs_cpu_to_le64(m->dqb_bhardlimit);
+ d->dqb_bsoftlimit = ext2fs_cpu_to_le64(m->dqb_bsoftlimit);
+ d->dqb_curinodes = ext2fs_cpu_to_le64(m->dqb_curinodes);
+ d->dqb_curspace = ext2fs_cpu_to_le64(m->dqb_curspace);
+ d->dqb_itime = ext2fs_cpu_to_le64(m->dqb_itime);
+ d->dqb_btime = ext2fs_cpu_to_le64(m->dqb_btime);
+ d->dqb_id = ext2fs_cpu_to_le32(dquot->dq_id);
+ if (qtree_entry_unused(&dquot->dq_h->qh_info.u.v2_mdqi.dqi_qtree, dp))
+ d->dqb_itime = ext2fs_cpu_to_le64(1);
+}
+
+static int v2r1_is_id(void *dp, struct dquot *dquot)
+{
+ struct v2r1_disk_dqblk *d = dp;
+ struct qtree_mem_dqinfo *info =
+ &dquot->dq_h->qh_info.u.v2_mdqi.dqi_qtree;
+
+ if (qtree_entry_unused(info, dp))
+ return 0;
+ return ext2fs_le32_to_cpu(d->dqb_id) == dquot->dq_id;
+}
+
+static struct qtree_fmt_operations v2r1_fmt_ops = {
+ .mem2disk_dqblk = v2r1_mem2diskdqblk,
+ .disk2mem_dqblk = v2r1_disk2memdqblk,
+ .is_id = v2r1_is_id,
+};
+
+/*
+ * Copy dqinfo from disk to memory
+ */
+static inline void v2_disk2memdqinfo(struct util_dqinfo *m,
+ struct v2_disk_dqinfo *d)
+{
+ m->dqi_bgrace = ext2fs_le32_to_cpu(d->dqi_bgrace);
+ m->dqi_igrace = ext2fs_le32_to_cpu(d->dqi_igrace);
+ m->u.v2_mdqi.dqi_flags = ext2fs_le32_to_cpu(d->dqi_flags) & V2_DQF_MASK;
+ m->u.v2_mdqi.dqi_qtree.dqi_blocks = ext2fs_le32_to_cpu(d->dqi_blocks);
+ m->u.v2_mdqi.dqi_qtree.dqi_free_blk =
+ ext2fs_le32_to_cpu(d->dqi_free_blk);
+ m->u.v2_mdqi.dqi_qtree.dqi_free_entry =
+ ext2fs_le32_to_cpu(d->dqi_free_entry);
+}
+
+/*
+ * Copy dqinfo from memory to disk
+ */
+static inline void v2_mem2diskdqinfo(struct v2_disk_dqinfo *d,
+ struct util_dqinfo *m)
+{
+ d->dqi_bgrace = ext2fs_cpu_to_le32(m->dqi_bgrace);
+ d->dqi_igrace = ext2fs_cpu_to_le32(m->dqi_igrace);
+ d->dqi_flags = ext2fs_cpu_to_le32(m->u.v2_mdqi.dqi_flags & V2_DQF_MASK);
+ d->dqi_blocks = ext2fs_cpu_to_le32(m->u.v2_mdqi.dqi_qtree.dqi_blocks);
+ d->dqi_free_blk =
+ ext2fs_cpu_to_le32(m->u.v2_mdqi.dqi_qtree.dqi_free_blk);
+ d->dqi_free_entry =
+ ext2fs_cpu_to_le32(m->u.v2_mdqi.dqi_qtree.dqi_free_entry);
+}
+
+static int v2_read_header(struct quota_handle *h, struct v2_disk_dqheader *dqh)
+{
+ if (h->e2fs_read(&h->qh_qf, 0, dqh, sizeof(struct v2_disk_dqheader)) !=
+ sizeof(struct v2_disk_dqheader))
+ return 0;
+
+ return 1;
+}
+
+/*
+ * Check whether given quota file is in our format
+ */
+static int v2_check_file(struct quota_handle *h, int type, int fmt)
+{
+ struct v2_disk_dqheader dqh;
+ int file_magics[] = INITQMAGICS;
+
+ if (fmt != QFMT_VFS_V1)
+ return 0;
+
+ if (!v2_read_header(h, &dqh))
+ return 0;
+
+ if (ext2fs_le32_to_cpu(dqh.dqh_magic) != file_magics[type]) {
+ if (ext2fs_be32_to_cpu(dqh.dqh_magic) == file_magics[type])
+ log_err("Your quota file is stored in wrong endianity");
+ return 0;
+ }
+ if (V2_VERSION != ext2fs_le32_to_cpu(dqh.dqh_version))
+ return 0;
+ return 1;
+}
+
+/*
+ * Open quotafile
+ */
+static int v2_init_io(struct quota_handle *h)
+{
+ struct v2_disk_dqinfo ddqinfo;
+
+ h->qh_info.u.v2_mdqi.dqi_qtree.dqi_entry_size =
+ sizeof(struct v2r1_disk_dqblk);
+ h->qh_info.u.v2_mdqi.dqi_qtree.dqi_ops = &v2r1_fmt_ops;
+
+ /* Read information about quotafile */
+ if (h->e2fs_read(&h->qh_qf, V2_DQINFOOFF, &ddqinfo,
+ sizeof(ddqinfo)) != sizeof(ddqinfo))
+ return -1;
+ v2_disk2memdqinfo(&h->qh_info, &ddqinfo);
+ return 0;
+}
+
+/*
+ * Initialize new quotafile
+ */
+static int v2_new_io(struct quota_handle *h)
+{
+ int file_magics[] = INITQMAGICS;
+ struct v2_disk_dqheader ddqheader;
+ struct v2_disk_dqinfo ddqinfo;
+
+ if (h->qh_fmt != QFMT_VFS_V1)
+ return -1;
+
+ /* Write basic quota header */
+ ddqheader.dqh_magic = ext2fs_cpu_to_le32(file_magics[h->qh_type]);
+ ddqheader.dqh_version = ext2fs_cpu_to_le32(V2_VERSION);
+ if (h->e2fs_write(&h->qh_qf, 0, &ddqheader, sizeof(ddqheader)) !=
+ sizeof(ddqheader))
+ return -1;
+
+ /* Write information about quotafile */
+ h->qh_info.dqi_bgrace = MAX_DQ_TIME;
+ h->qh_info.dqi_igrace = MAX_IQ_TIME;
+ h->qh_info.u.v2_mdqi.dqi_flags = 0;
+ h->qh_info.u.v2_mdqi.dqi_qtree.dqi_blocks = QT_TREEOFF + 1;
+ h->qh_info.u.v2_mdqi.dqi_qtree.dqi_free_blk = 0;
+ h->qh_info.u.v2_mdqi.dqi_qtree.dqi_free_entry = 0;
+ h->qh_info.u.v2_mdqi.dqi_qtree.dqi_entry_size =
+ sizeof(struct v2r1_disk_dqblk);
+ h->qh_info.u.v2_mdqi.dqi_qtree.dqi_ops = &v2r1_fmt_ops;
+ v2_mem2diskdqinfo(&ddqinfo, &h->qh_info);
+ if (h->e2fs_write(&h->qh_qf, V2_DQINFOOFF, &ddqinfo,
+ sizeof(ddqinfo)) !=
+ sizeof(ddqinfo))
+ return -1;
+
+ return 0;
+}
+
+/*
+ * Write information (grace times to file)
+ */
+static int v2_write_info(struct quota_handle *h)
+{
+ struct v2_disk_dqinfo ddqinfo;
+
+ v2_mem2diskdqinfo(&ddqinfo, &h->qh_info);
+ if (h->e2fs_write(&h->qh_qf, V2_DQINFOOFF, &ddqinfo, sizeof(ddqinfo)) !=
+ sizeof(ddqinfo))
+ return -1;
+
+ return 0;
+}
+
+/*
+ * Read dquot from disk
+ */
+static struct dquot *v2_read_dquot(struct quota_handle *h, qid_t id)
+{
+ return qtree_read_dquot(h, id);
+}
+
+/*
+ * Commit changes of dquot to disk - it might also mean deleting it when quota
+ * became fake one and user has no blocks.
+ * User can process use 'errno' to detect errstr.
+ */
+static int v2_commit_dquot(struct dquot *dquot)
+{
+ struct util_dqblk *b = &dquot->dq_dqb;
+
+ if (!b->dqb_curspace && !b->dqb_curinodes && !b->dqb_bsoftlimit &&
+ !b->dqb_isoftlimit && !b->dqb_bhardlimit && !b->dqb_ihardlimit)
+ qtree_delete_dquot(dquot);
+ else
+ qtree_write_dquot(dquot);
+ return 0;
+}
+
+static int v2_scan_dquots(struct quota_handle *h,
+ int (*process_dquot) (struct dquot *, void *),
+ void *data)
+{
+ return qtree_scan_dquots(h, process_dquot, data);
+}
+
+/* Report information about quotafile.
+ * TODO: Not used right now, but we should be able to use this when we add
+ * support to debugfs to read quota files.
+ */
+static int v2_report(struct quota_handle *h, int verbose)
+{
+ log_err("Not Implemented.");
+ return -1;
+}
diff --git a/ap/app/e2fsprogs/e2fsprogs-1.42.9/lib/quota/quotaio_v2.h b/ap/app/e2fsprogs/e2fsprogs-1.42.9/lib/quota/quotaio_v2.h
new file mode 100644
index 0000000..0bb4363
--- /dev/null
+++ b/ap/app/e2fsprogs/e2fsprogs-1.42.9/lib/quota/quotaio_v2.h
@@ -0,0 +1,54 @@
+/*
+ *
+ * Header file for disk format of new quotafile format
+ *
+ */
+
+#ifndef GUARD_QUOTAIO_V2_H
+#define GUARD_QUOTAIO_V2_H
+
+#include <sys/types.h>
+#include "quotaio.h"
+
+/* Offset of info header in file */
+#define V2_DQINFOOFF sizeof(struct v2_disk_dqheader)
+/* Supported version of quota-tree format */
+#define V2_VERSION 1
+
+struct v2_disk_dqheader {
+ u_int32_t dqh_magic; /* Magic number identifying file */
+ u_int32_t dqh_version; /* File version */
+} __attribute__ ((packed));
+
+/* Flags for version specific files */
+#define V2_DQF_MASK 0x0000 /* Mask for all valid ondisk flags */
+
+/* Header with type and version specific information */
+struct v2_disk_dqinfo {
+ u_int32_t dqi_bgrace; /* Time before block soft limit becomes
+ * hard limit */
+ u_int32_t dqi_igrace; /* Time before inode soft limit becomes
+ * hard limit */
+ u_int32_t dqi_flags; /* Flags for quotafile (DQF_*) */
+ u_int32_t dqi_blocks; /* Number of blocks in file */
+ u_int32_t dqi_free_blk; /* Number of first free block in the list */
+ u_int32_t dqi_free_entry; /* Number of block with at least one
+ * free entry */
+} __attribute__ ((packed));
+
+struct v2r1_disk_dqblk {
+ u_int32_t dqb_id; /* id this quota applies to */
+ u_int32_t dqb_pad;
+ u_int64_t dqb_ihardlimit; /* absolute limit on allocated inodes */
+ u_int64_t dqb_isoftlimit; /* preferred inode limit */
+ u_int64_t dqb_curinodes; /* current # allocated inodes */
+ u_int64_t dqb_bhardlimit; /* absolute limit on disk space
+ * (in QUOTABLOCK_SIZE) */
+ u_int64_t dqb_bsoftlimit; /* preferred limit on disk space
+ * (in QUOTABLOCK_SIZE) */
+ u_int64_t dqb_curspace; /* current space occupied (in bytes) */
+ u_int64_t dqb_btime; /* time limit for excessive disk use */
+ u_int64_t dqb_itime; /* time limit for excessive inode use */
+} __attribute__ ((packed));
+
+#endif