char * fmthumanvalblks(int64_t blocks) { static char numbuf[20]; if (hflag) { humanize_number(numbuf, blocks < 0 ? 7 : 6, dbtob(blocks), "", HN_AUTOSCALE, HN_NOSPACE); return (numbuf); } snprintf(numbuf, sizeof(numbuf), "%juk", (uintmax_t)dbtokb(blocks)); return(numbuf); }
static void prthumanval(int64_t blocks) { char buf[7]; int flags; if (!hflag) { printf(" %6ju", (uintmax_t)dbtokb(blocks)); return; } flags = HN_NOSPACE | HN_DECIMAL; if (blocks != 0) flags |= HN_B; humanize_number(buf, sizeof(buf) - (blocks < 0 ? 0 : 1), dbtob(blocks), "", HN_AUTOSCALE, flags); (void)printf("%7s", buf); }
int repquota(struct fstab *fs, int type, char *qfpathname) { struct fileusage *fup; FILE *qf; u_long id; struct ufs_dqblk dqbuf; static struct ufs_dqblk zerodqblk; static int warned = 0; static int multiple = 0; if (quotactl(fs->fs_file, QCMD(Q_SYNC, type), 0, 0) < 0 && errno == EOPNOTSUPP && !warned && vflag) { warned++; fprintf(stdout, "*** Warning: Quotas are not compiled into this kernel\n"); } if (multiple++) printf("\n"); if (vflag) fprintf(stdout, "*** Report for %s quotas on %s (%s)\n", qfextension[type], fs->fs_file, fs->fs_spec); if ((qf = fopen(qfpathname, "r")) == NULL) { warn("%s", qfpathname); return (1); } for (id = 0; ; id++) { fread(&dqbuf, sizeof(struct ufs_dqblk), 1, qf); if (feof(qf)) break; if (dqbuf.dqb_curinodes == 0 && dqbuf.dqb_curblocks == 0) continue; if ((fup = lookup(id, type)) == 0) fup = addid(id, type, NULL); fup->fu_dqblk = dqbuf; } fclose(qf); printf("%*s Block limits File limits\n", max(UT_NAMESIZE,10), " "); printf("User%*s used soft hard grace used soft hard grace\n", max(UT_NAMESIZE,10), " "); for (id = 0; id <= highid[type]; id++) { fup = lookup(id, type); if (fup == 0) continue; if (fup->fu_dqblk.dqb_curinodes == 0 && fup->fu_dqblk.dqb_curblocks == 0) continue; printf("%-*s", max(UT_NAMESIZE,10), fup->fu_name); printf("%c%c %8lu %8lu %8lu %6s", fup->fu_dqblk.dqb_bsoftlimit && fup->fu_dqblk.dqb_curblocks >= fup->fu_dqblk.dqb_bsoftlimit ? '+' : '-', fup->fu_dqblk.dqb_isoftlimit && fup->fu_dqblk.dqb_curinodes >= fup->fu_dqblk.dqb_isoftlimit ? '+' : '-', (u_long)(dbtokb(fup->fu_dqblk.dqb_curblocks)), (u_long)(dbtokb(fup->fu_dqblk.dqb_bsoftlimit)), (u_long)(dbtokb(fup->fu_dqblk.dqb_bhardlimit)), fup->fu_dqblk.dqb_bsoftlimit && fup->fu_dqblk.dqb_curblocks >= fup->fu_dqblk.dqb_bsoftlimit ? timeprt(fup->fu_dqblk.dqb_btime) : "-"); printf(" %7lu %7lu %7lu %6s\n", (u_long)fup->fu_dqblk.dqb_curinodes, (u_long)fup->fu_dqblk.dqb_isoftlimit, (u_long)fup->fu_dqblk.dqb_ihardlimit, fup->fu_dqblk.dqb_isoftlimit && fup->fu_dqblk.dqb_curinodes >= fup->fu_dqblk.dqb_isoftlimit ? timeprt(fup->fu_dqblk.dqb_itime) : "-"); fup->fu_dqblk = zerodqblk; } return (0); }