static void state_quotafile_mount( FILE *fp, uint type, fs_path_t *mount, uint flags) { fs_quota_stat_t s; char *dev = mount->fs_name; if (xfsquotactl(XFS_GETQSTAT, dev, type, 0, (void *)&s) < 0) { if (flags & VERBOSE_FLAG) fprintf(fp, _("%s quota are not enabled on %s\n"), type_to_string(type), dev); return; } if (type & XFS_USER_QUOTA) state_qfilestat(fp, mount, XFS_USER_QUOTA, &s.qs_uquota, s.qs_flags & XFS_QUOTA_UDQ_ACCT, s.qs_flags & XFS_QUOTA_UDQ_ENFD); if (type & XFS_GROUP_QUOTA) state_qfilestat(fp, mount, XFS_GROUP_QUOTA, &s.qs_gquota, s.qs_flags & XFS_QUOTA_GDQ_ACCT, s.qs_flags & XFS_QUOTA_GDQ_ENFD); if (type & XFS_PROJ_QUOTA) state_qfilestat(fp, mount, XFS_PROJ_QUOTA, &s.qs_gquota, s.qs_flags & XFS_QUOTA_PDQ_ACCT, s.qs_flags & XFS_QUOTA_PDQ_ENFD); state_timelimit(fp, XFS_BLOCK_QUOTA, s.qs_btimelimit); state_timelimit(fp, XFS_INODE_QUOTA, s.qs_itimelimit); state_timelimit(fp, XFS_RTBLOCK_QUOTA, s.qs_rtbtimelimit); }
static void dump_file( FILE *fp, uint id, uint type, char *dev) { fs_disk_quota_t d; if (xfsquotactl(XFS_GETQUOTA, dev, type, id, (void *)&d) < 0) { if (errno != ENOENT && errno != ENOSYS) perror("XFS_GETQUOTA"); return; } 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) return; fprintf(fp, "fs = %s\n", dev); /* this branch is for backward compatibility reasons */ if (d.d_rtb_softlimit || d.d_rtb_hardlimit) fprintf(fp, "%-10d %7llu %7llu %7llu %7llu %7llu %7llu\n", id, (unsigned long long)d.d_blk_softlimit, (unsigned long long)d.d_blk_hardlimit, (unsigned long long)d.d_ino_softlimit, (unsigned long long)d.d_ino_hardlimit, (unsigned long long)d.d_rtb_softlimit, (unsigned long long)d.d_rtb_hardlimit); else fprintf(fp, "%-10d %7llu %7llu %7llu %7llu\n", id, (unsigned long long)d.d_blk_softlimit, (unsigned long long)d.d_blk_hardlimit, (unsigned long long)d.d_ino_softlimit, (unsigned long long)d.d_ino_hardlimit); }
static int report_mount( FILE *fp, __uint32_t id, char *name, uint form, uint type, fs_path_t *mount, uint flags) { fs_disk_quota_t d; char *dev = mount->fs_name; char c[8], h[8], s[8]; uint qflags; int count; if (xfsquotactl(XFS_GETQUOTA, dev, type, id, (void *)&d) < 0) { if (errno != ENOENT && errno != ENOSYS) perror("XFS_GETQUOTA"); return 0; } if (flags & TERSE_FLAG) { count = 0; if ((form & XFS_BLOCK_QUOTA) && d.d_bcount) count++; if ((form & XFS_INODE_QUOTA) && d.d_icount) count++; if ((form & XFS_RTBLOCK_QUOTA) && d.d_rtbcount) count++; if (!count) return 0; } if (!(flags & NO_HEADER_FLAG)) report_header(fp, form, type, mount, flags); fprintf(fp, "%-10s", name); if (form & XFS_BLOCK_QUOTA) { qflags = (flags & HUMAN_FLAG); if (d.d_blk_hardlimit && d.d_bcount > d.d_blk_hardlimit) qflags |= LIMIT_FLAG; if (d.d_blk_softlimit && d.d_bcount > d.d_blk_softlimit) qflags |= QUOTA_FLAG; if (flags & HUMAN_FLAG) fprintf(fp, " %6s %6s %6s %02d %8s", bbs_to_string(d.d_bcount, c, sizeof(c)), bbs_to_string(d.d_blk_softlimit, s, sizeof(s)), bbs_to_string(d.d_blk_hardlimit, h, sizeof(h)), d.d_bwarns, time_to_string(d.d_btimer, qflags)); else fprintf(fp, " %10llu %10llu %10llu %02d %9s", (unsigned long long)d.d_bcount >> 1, (unsigned long long)d.d_blk_softlimit >> 1, (unsigned long long)d.d_blk_hardlimit >> 1, d.d_bwarns, time_to_string(d.d_btimer, qflags)); }
static int remove_qtype_extents( char *dir, uint type) { int error = 0; if ((error = xfsquotactl(XFS_QUOTARM, dir, type, 0, (void *)&type)) < 0) perror("XFS_QUOTARM"); return error; }
static void printpath( struct fs_path *path, int index, int number, int braces) { fs_quota_stat_t qstat; fs_project_t *prj; int c; if (index == 0) { printf(_("%sFilesystem Pathname\n"), number ? _(" ") : ""); } if (number) { printf(_("%c%03d%c "), braces? '[':' ', index, braces? ']':' '); } printf(_("%-19s %s"), path->fs_dir, path->fs_name); if (path->fs_flags & FS_PROJECT_PATH) { prj = getprprid(path->fs_prid); printf(_(" (project %u"), path->fs_prid); if (prj) printf(_(", %s"), prj->pr_name); printf(")"); } else if (xfsquotactl(XFS_GETQSTAT, path->fs_name, 0, 0, (void *)&qstat) == 0 && qstat.qs_flags) { c = 0; printf(" ("); if (qstat.qs_flags & XFS_QUOTA_UDQ_ENFD) c = printf("uquota"); else if (qstat.qs_flags & XFS_QUOTA_UDQ_ACCT) c = printf("uqnoenforce"); if (qstat.qs_flags & XFS_QUOTA_GDQ_ENFD) c = printf("%sgquota", c ? ", " : ""); else if (qstat.qs_flags & XFS_QUOTA_GDQ_ACCT) c = printf("%sgqnoenforce", c ? ", " : ""); if (qstat.qs_flags & XFS_QUOTA_PDQ_ENFD) printf("%spquota", c ? ", " : ""); else if (qstat.qs_flags & XFS_QUOTA_PDQ_ACCT) printf("%spqnoenforce", c ? ", " : ""); printf(")"); } printf("\n"); }
static void quotaoff( char *dir, uint type, uint qflags, uint flags) { fs_path_t *mount; mount = fs_table_lookup(dir, FS_MOUNT_POINT); if (!mount) { exitcode = 1; fprintf(stderr, "%s: unknown mount point %s\n", progname, dir); return; } dir = mount->fs_name; if (xfsquotactl(XFS_QUOTAOFF, dir, type, 0, (void *)&qflags) < 0) perror("XFS_QUOTAOFF"); else if (flags & VERBOSE_FLAG) state_quotafile_mount(stdout, type, mount, flags); }
/* * The data and realtime block counts returned (count, used, and * free) are all in basic block units. */ static int projects_free_space_data( struct fs_path *path, __uint64_t *bcount, __uint64_t *bused, __uint64_t *bfree, __uint64_t *icount, __uint64_t *iused, __uint64_t *ifree, __uint64_t *rcount, __uint64_t *rused, __uint64_t *rfree) { fs_quota_stat_t qfs; fs_disk_quota_t d; struct fsxattr fsx; uint type = XFS_PROJ_QUOTA; char *dev = path->fs_name; int fd; if (xfsquotactl(XFS_GETQSTAT, dev, type, 0, &qfs) < 0 || !(qfs.qs_flags & XFS_QUOTA_PDQ_ACCT)) return 0; if ((fd = open(path->fs_dir, O_RDONLY)) < 0) { exitcode = 1; fprintf(stderr, "%s: cannot open %s: %s\n", progname, path->fs_dir, strerror(errno)); return 0; } if ((xfsctl(path->fs_dir, fd, XFS_IOC_FSGETXATTR, &fsx)) < 0) { exitcode = 1; perror("XFS_IOC_FSGETXATTR"); close(fd); return 0; } if (!(fsx.fsx_xflags & XFS_XFLAG_PROJINHERIT)) { exitcode = 1; fprintf(stderr, _("%s: project quota flag not set on %s\n"), progname, path->fs_dir); close(fd); return 0; } if (path->fs_prid != fsx.fsx_projid) { exitcode = 1; fprintf(stderr, _("%s: project ID %u (%s) doesn't match ID %u (%s)\n"), progname, path->fs_prid, projects_file, fsx.fsx_projid, path->fs_dir); close(fd); return 0; } xfsquotactl(XFS_QSYNC, dev, type, fsx.fsx_projid, NULL); if (xfsquotactl(XFS_GETQUOTA, dev, type, fsx.fsx_projid, &d) < 0) { perror("XFS_GETQUOTA"); close(fd); return 0; } /* If no softlimit is set for any of blk/ino/rt, get actual usage */ if (!d.d_blk_softlimit || !d.d_ino_softlimit || !d.d_rtb_softlimit) { mount_free_space_data(path, bcount, bused, bfree, icount, iused, ifree, rcount, rused, rfree); } if (d.d_blk_softlimit) { *bcount = d.d_blk_softlimit; *bfree = (d.d_blk_softlimit - d.d_bcount); } *bused = d.d_bcount; if (d.d_ino_softlimit) { *icount = d.d_ino_softlimit; *ifree = (d.d_ino_softlimit - d.d_icount); } *iused = d.d_icount; if (d.d_rtb_softlimit) { *rcount = d.d_rtb_softlimit; *rfree = (d.d_rtb_softlimit - d.d_rtbcount); } *rused = d.d_rtbcount; close(fd); return 1; }
static int quota_mount( FILE *fp, __uint32_t id, char *name, uint form, uint type, fs_path_t *mount, uint flags) { fs_disk_quota_t d; char *dev = mount->fs_name; char c[8], h[8], s[8]; uint qflags; int count; xfsquotactl(XFS_QSYNC, dev, type, 0, NULL); if (xfsquotactl(XFS_GETQUOTA, dev, type, id, (void *)&d) < 0) return 0; if (!(flags & VERBOSE_FLAG)) { count = 0; if ((form & XFS_BLOCK_QUOTA) && d.d_bcount) count++; if ((form & XFS_INODE_QUOTA) && d.d_icount) count++; if ((form & XFS_RTBLOCK_QUOTA) && d.d_rtbcount) count++; if (!count) return 0; } if (!(flags & NO_HEADER_FLAG)) { fprintf(fp, _("Disk quotas for %s %s (%u)\nFilesystem%s"), type_to_string(type), name, id, (flags & HUMAN_FLAG) ? " " : " "); if (form & XFS_BLOCK_QUOTA) fprintf(fp, (flags & HUMAN_FLAG) ? _(" Blocks Quota Limit Warn/Time ") : _(" Blocks Quota Limit Warn/Time ")); if (form & XFS_INODE_QUOTA) fprintf(fp, (flags & HUMAN_FLAG) ? _(" Files Quota Limit Warn/Time ") : _(" Files Quota Limit Warn/Time ")); if (form & XFS_RTBLOCK_QUOTA) fprintf(fp, (flags & HUMAN_FLAG) ? _("Realtime Quota Limit Warn/Time ") : _(" Realtime Quota Limit Warn/Time ")); fputs("Mounted on\n", fp); } if (flags & HUMAN_FLAG) { count = fprintf(fp, "%-12s", dev); if (count > 13) fprintf(fp, "\n%12s", " "); } else { count = fprintf(fp, "%-19s", dev); if (count > 20) fprintf(fp, "\n%19s", " "); } if (form & XFS_BLOCK_QUOTA) { qflags = (flags & HUMAN_FLAG); if (d.d_blk_hardlimit && d.d_bcount > d.d_blk_hardlimit) qflags |= LIMIT_FLAG; if (d.d_blk_softlimit && d.d_bcount > d.d_blk_softlimit) qflags |= QUOTA_FLAG; if (flags & HUMAN_FLAG) fprintf(fp, " %6s %6s %6s %02d %8s ", bbs_to_string(d.d_bcount, c, sizeof(c)), bbs_to_string(d.d_blk_softlimit, s, sizeof(s)), bbs_to_string(d.d_blk_hardlimit, h, sizeof(h)), d.d_bwarns, time_to_string(d.d_btimer, qflags)); else fprintf(fp, " %10llu %10llu %10llu %02d %9s ", (unsigned long long)d.d_bcount >> 1, (unsigned long long)d.d_blk_softlimit >> 1, (unsigned long long)d.d_blk_hardlimit >> 1, d.d_bwarns, time_to_string(d.d_btimer, qflags)); }