]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blobdiff - quota/report.c
xfs_quota: separate quota info acquisition into get_dquot()
[thirdparty/xfsprogs-dev.git] / quota / report.c
index 2eb5b5a91e8c7aaac2e9f492ed3e8fdd4a39de57..6994cba6f46975a3333443457c8f59a9bb239410 100644 (file)
@@ -59,16 +59,15 @@ report_help(void)
 "\n"));
 }
 
-static int 
-dump_file(
-       FILE            *fp,
+static int
+get_dquot(
+       struct fs_disk_quota *d,
        uint            id,
        uint            *oid,
        uint            type,
        char            *dev,
        int             flags)
 {
-       fs_disk_quota_t d;
        int             cmd;
 
        if (flags & GETNEXTQUOTA_FLAG)
@@ -77,7 +76,7 @@ dump_file(
                cmd = XFS_GETQUOTA;
 
        /* Fall back silently if XFS_GETNEXTQUOTA fails, warn on XFS_GETQUOTA */
-       if (xfsquotactl(cmd, dev, type, id, (void *)&d) < 0) {
+       if (xfsquotactl(cmd, dev, type, id, (void *)d) < 0) {
                if (errno != ENOENT && errno != ENOSYS && errno != ESRCH &&
                    cmd == XFS_GETQUOTA)
                        perror("XFS_GETQUOTA");
@@ -85,12 +84,29 @@ dump_file(
        }
 
        if (oid) {
-               *oid = d.d_id;
+               *oid = d->d_id;
                /* Did kernelspace wrap? */
                if (*oid < id)
                        return 0;
        }
 
+       return 1;
+}
+
+static int
+dump_file(
+       FILE            *fp,
+       uint            id,
+       uint            *oid,
+       uint            type,
+       char            *dev,
+       int             flags)
+{
+       struct fs_disk_quota d;
+
+       if (!get_dquot(&d, id, oid, type, dev, flags))
+               return 0;
+
        if (!d.d_blk_softlimit && !d.d_blk_hardlimit &&
            !d.d_ino_softlimit && !d.d_ino_hardlimit &&
            !d.d_rtb_softlimit && !d.d_rtb_hardlimit)
@@ -329,31 +345,12 @@ report_mount(
 {
        fs_disk_quota_t d;
        time64_t        timer;
-       char            *dev = mount->fs_name;
        char            c[8], h[8], s[8];
        uint            qflags;
        int             count;
-       int             cmd;
 
-       if (flags & GETNEXTQUOTA_FLAG)
-               cmd = XFS_GETNEXTQUOTA;
-       else
-               cmd = XFS_GETQUOTA;
-
-       /* Fall back silently if XFS_GETNEXTQUOTA fails, warn on XFS_GETQUOTA*/
-       if (xfsquotactl(cmd, dev, type, id, (void *)&d) < 0) {
-               if (errno != ENOENT && errno != ENOSYS && errno != ESRCH &&
-                   cmd == XFS_GETQUOTA)
-                       perror("XFS_GETQUOTA");
+       if (!get_dquot(&d, id, oid, type, mount->fs_name, flags))
                return 0;
-       }
-
-       if (oid) {
-               *oid = d.d_id;
-               /* Did kernelspace wrap? */
-               if (* oid < id)
-                       return 0;
-       }
 
        if (flags & TERSE_FLAG) {
                count = 0;