Whamcloud - gitweb
libext2fs: fix block iterator for extents when truncating inodes
[tools/e2fsprogs.git] / lib / quota / quotaio_v2.c
index 7c9e4f7..f8d553b 100644 (file)
@@ -18,8 +18,6 @@
 #include "quotaio.h"
 #include "quotaio_tree.h"
 
-typedef char *dqbuf_t;
-
 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);
@@ -28,7 +26,8 @@ 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,
-                                               char *dqname));
+                                               void *data),
+                         void *data);
 static int v2_report(struct quota_handle *h, int verbose);
 
 struct quotafile_ops quotafile_ops_2 = {
@@ -42,9 +41,6 @@ struct quotafile_ops quotafile_ops_2 = {
        .report         = v2_report,
 };
 
-#define getdqbuf() smalloc(V2_DQBLKSIZE)
-#define freedqbuf(buf) free(buf)
-
 /*
  * Copy dquot from disk to memory
  */
@@ -139,34 +135,6 @@ static inline void v2_mem2diskdqinfo(struct v2_disk_dqinfo *d,
                ext2fs_cpu_to_le32(m->u.v2_mdqi.dqi_qtree.dqi_free_entry);
 }
 
-/* Convert kernel quotablock format to utility one */
-static inline void v2_kern2utildqblk(struct util_dqblk *u,
-                                    struct v2_kern_dqblk *k)
-{
-       u->dqb_ihardlimit = k->dqb_ihardlimit;
-       u->dqb_isoftlimit = k->dqb_isoftlimit;
-       u->dqb_bhardlimit = k->dqb_bhardlimit;
-       u->dqb_bsoftlimit = k->dqb_bsoftlimit;
-       u->dqb_curinodes = k->dqb_curinodes;
-       u->dqb_curspace = k->dqb_curspace;
-       u->dqb_itime = k->dqb_itime;
-       u->dqb_btime = k->dqb_btime;
-}
-
-/* Convert utility quotablock format to kernel one */
-static inline void v2_util2kerndqblk(struct v2_kern_dqblk *k,
-                                    struct util_dqblk *u)
-{
-       k->dqb_ihardlimit = u->dqb_ihardlimit;
-       k->dqb_isoftlimit = u->dqb_isoftlimit;
-       k->dqb_bhardlimit = u->dqb_bhardlimit;
-       k->dqb_bsoftlimit = u->dqb_bsoftlimit;
-       k->dqb_curinodes = u->dqb_curinodes;
-       k->dqb_curspace = u->dqb_curspace;
-       k->dqb_itime = u->dqb_itime;
-       k->dqb_btime = u->dqb_btime;
-}
-
 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)) !=
@@ -183,27 +151,20 @@ static int v2_check_file(struct quota_handle *h, int type, int fmt)
 {
        struct v2_disk_dqheader dqh;
        int file_magics[] = INITQMAGICS;
-       int known_versions[] = INIT_V2_VERSIONS;
-       int version;
 
-       if (!v2_read_header(h, &dqh))
+       if (fmt != QFMT_VFS_V1)
                return 0;
-       if (fmt == QFMT_VFS_V0)
-               version = 0;
-       else if (fmt == QFMT_VFS_V1)
-               version = 1;
-       else
+
+       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_fatal(3, "Your quota file is stored in wrong "
-                                 "endianity.", "");
+                       log_err("Your quota file is stored in wrong "
+                               "endianity.", "");
                return 0;
        }
-       if (ext2fs_le32_to_cpu(dqh.dqh_version) > known_versions[type])
-               return 0;
-       if (version != ext2fs_le32_to_cpu(dqh.dqh_version))
+       if (V2_VERSION != ext2fs_le32_to_cpu(dqh.dqh_version))
                return 0;
        return 1;
 }
@@ -213,8 +174,17 @@ static int v2_check_file(struct quota_handle *h, int type, int fmt)
  */
 static int v2_init_io(struct quota_handle *h)
 {
-       log_err("Not Implemented.", "");
-       BUG_ON(1);
+       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;
 }
 
@@ -226,13 +196,13 @@ static int v2_new_io(struct quota_handle *h)
        int file_magics[] = INITQMAGICS;
        struct v2_disk_dqheader ddqheader;
        struct v2_disk_dqinfo ddqinfo;
-       int version = 1;
 
-       BUG_ON(h->qh_fmt != QFMT_VFS_V1);
+       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(version);
+       ddqheader.dqh_version = ext2fs_cpu_to_le32(V2_VERSION);
        if (h->e2fs_write(&h->qh_qf, 0, &ddqheader, sizeof(ddqheader)) !=
                        sizeof(ddqheader))
                return -1;
@@ -272,8 +242,7 @@ static int v2_write_info(struct quota_handle *h)
 }
 
 /*
- * Read dquot (either from disk or from kernel)
- * User can use errno to detect errstr when NULL is returned
+ * Read dquot from disk
  */
 static struct dquot *v2_read_dquot(struct quota_handle *h, qid_t id)
 {
@@ -298,9 +267,10 @@ static int v2_commit_dquot(struct dquot *dquot)
 }
 
 static int v2_scan_dquots(struct quota_handle *h,
-                         int (*process_dquot) (struct dquot *, char *))
+                         int (*process_dquot) (struct dquot *, void *),
+                         void *data)
 {
-       return qtree_scan_dquots(h, process_dquot);
+       return qtree_scan_dquots(h, process_dquot, data);
 }
 
 /* Report information about quotafile.
@@ -310,6 +280,5 @@ static int v2_scan_dquots(struct quota_handle *h,
 static int v2_report(struct quota_handle *h, int verbose)
 {
        log_err("Not Implemented.", "");
-       BUG_ON(1);
-       return 0;
+       return -1;
 }