Skip to content

Instantly share code, notes, and snippets.

@hiboma
Created June 24, 2012 13:54
Show Gist options
  • Save hiboma/2983301 to your computer and use it in GitHub Desktop.
Save hiboma/2983301 to your computer and use it in GitHub Desktop.
quotactl(2) to get xfs project quota
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/quota.h>
#include <xfs/xfs.h>
#include <xfs/xqm.h>
int main(int argc, const char *argv[]) {
fs_disk_quota_t d;
uint id;
uint type;
const char *dev = "/dev/vdc1";
fs_disk_quota_t c;
if(quotactl(QCMD(Q_XGETQUOTA,XFS_PROJ_QUOTA), dev, 9999999, (caddr_t)&c) < 0) {
perror("quotactl(Q_XGETQUOTA|XFS_PROJ_QUOTA)");
exit(1);
}
printf("%d\n", c.d_id);
printf("%d %d\n", c.d_bcount >> 1, c.d_blk_softlimit >> 1);
printf("%d\n", c.d_ino_softlimit);
printf("%d\n", c.d_ino_hardlimit);
exit(0);
}
@hiboma
Copy link
Author

hiboma commented Jun 24, 2012

 30 #define Q_XGETQUOTA     XQM_CMD(3)      /* get disk limits and usage */

 43 #define FS_DQUOT_VERSION        1       /* fs_disk_quota.d_version */
 44 typedef struct fs_disk_quota {
 45         __s8            d_version;      /* version of this structure */
 46         __s8            d_flags;        /* XFS_{USER,PROJ,GROUP}_QUOTA */
 47         __u16           d_fieldmask;    /* field specifier */
 48         __u32           d_id;           /* user, project, or group ID */
 49         __u64           d_blk_hardlimit;/* absolute limit on disk blks */
 50         __u64           d_blk_softlimit;/* preferred limit on disk blks */
 51         __u64           d_ino_hardlimit;/* maximum # allocated inodes */
 52         __u64           d_ino_softlimit;/* preferred inode limit */
 53         __u64           d_bcount;       /* # disk blocks owned by the user */
 54         __u64           d_icount;       /* # inodes owned by the user */
 55         __s32           d_itimer;       /* zero if within inode limits */
 56                                         /* if not, we refuse service */
 57         __s32           d_btimer;       /* similar to above; for disk blocks */
 58         __u16           d_iwarns;       /* # warnings issued wrt num inodes */
 59         __u16           d_bwarns;       /* # warnings issued wrt disk blocks */
 60         __s32           d_padding2;     /* padding2 - for future use */
 61         __u64           d_rtb_hardlimit;/* absolute limit on realtime blks */
 62         __u64           d_rtb_softlimit;/* preferred limit on RT disk blks */
 63         __u64           d_rtbcount;     /* # realtime blocks owned */
 64         __s32           d_rtbtimer;     /* similar to above; for RT disk blks */
 65         __u16           d_rtbwarns;     /* # warnings issued wrt RT disk blks */
 66         __s16           d_padding3;     /* padding3 - for future use */
 67         char            d_padding4[8];  /* yet more padding */
 68 } fs_disk_quota_t;

117 #define XFS_PROJ_QUOTA          (1<<1)  /* project quota type */


 75 static void
 76 dump_file(
 77         FILE            *fp,
 78         uint            id,

 79         uint            type,
 80         char            *dev)
 81 {
 82         fs_disk_quota_t d;
 83
 84         if (xfsquotactl(XFS_GETQUOTA, dev, type, id, (void *)&d) < 0) {
 85                 if (errno != ENOENT && errno != ENOSYS)
 86                         perror("XFS_GETQUOTA");
 87                 return;
 88         }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment