📄 edquota.c
字号:
* Convert a quotause list to an ASCII file. */writeprivs(quplist, outfd, name, quotatype) struct quotause *quplist; int outfd; char *name; int quotatype;{ register struct quotause *qup; FILE *fd; ftruncate(outfd, 0); lseek(outfd, 0, L_SET); if ((fd = fdopen(dup(outfd), "w")) == NULL) { fprintf(stderr, "edquota: "); perror(tmpfil); exit(1); } fprintf(fd, "Quotas for %s %s:\n", qfextension[quotatype], name); for (qup = quplist; qup; qup = qup->next) { fprintf(fd, "%s: %s %d, limits (soft = %d, hard = %d)\n", qup->fsname, "blocks in use:", dbtob(qup->dqblk.dqb_curblocks) / 1024, dbtob(qup->dqblk.dqb_bsoftlimit) / 1024, dbtob(qup->dqblk.dqb_bhardlimit) / 1024); fprintf(fd, "%s %d, limits (soft = %d, hard = %d)\n", "\tinodes in use:", qup->dqblk.dqb_curinodes, qup->dqblk.dqb_isoftlimit, qup->dqblk.dqb_ihardlimit); } fclose(fd); return (1);}/* * Merge changes to an ASCII file into a quotause list. */readprivs(quplist, infd) struct quotause *quplist; int infd;{ register struct quotause *qup; FILE *fd; int cnt; register char *cp; struct dqblk dqblk; char *fsp, line1[BUFSIZ], line2[BUFSIZ]; lseek(infd, 0, L_SET); fd = fdopen(dup(infd), "r"); if (fd == NULL) { fprintf(stderr, "Can't re-read temp file!!\n"); return (0); } /* * Discard title line, then read pairs of lines to process. */ (void) fgets(line1, sizeof (line1), fd); while (fgets(line1, sizeof (line1), fd) != NULL && fgets(line2, sizeof (line2), fd) != NULL) { if ((fsp = strtok(line1, " \t:")) == NULL) { fprintf(stderr, "%s: bad format\n", line1); return (0); } if ((cp = strtok((char *)0, "\n")) == NULL) { fprintf(stderr, "%s: %s: bad format\n", fsp, &fsp[strlen(fsp) + 1]); return (0); } cnt = sscanf(cp, " blocks in use: %d, limits (soft = %d, hard = %d)", &dqblk.dqb_curblocks, &dqblk.dqb_bsoftlimit, &dqblk.dqb_bhardlimit); if (cnt != 3) { fprintf(stderr, "%s:%s: bad format\n", fsp, cp); return (0); } dqblk.dqb_curblocks = btodb(dqblk.dqb_curblocks * 1024); dqblk.dqb_bsoftlimit = btodb(dqblk.dqb_bsoftlimit * 1024); dqblk.dqb_bhardlimit = btodb(dqblk.dqb_bhardlimit * 1024); if ((cp = strtok(line2, "\n")) == NULL) { fprintf(stderr, "%s: %s: bad format\n", fsp, line2); return (0); } cnt = sscanf(cp, "\tinodes in use: %d, limits (soft = %d, hard = %d)", &dqblk.dqb_curinodes, &dqblk.dqb_isoftlimit, &dqblk.dqb_ihardlimit); if (cnt != 3) { fprintf(stderr, "%s: %s: bad format\n", fsp, line2); return (0); } for (qup = quplist; qup; qup = qup->next) { if (strcmp(fsp, qup->fsname)) continue; /* * Cause time limit to be reset when the quota * is next used if previously had no soft limit * or were under it, but now have a soft limit * and are over it. */ if (dqblk.dqb_bsoftlimit && qup->dqblk.dqb_curblocks >= dqblk.dqb_bsoftlimit && (qup->dqblk.dqb_bsoftlimit == 0 || qup->dqblk.dqb_curblocks < qup->dqblk.dqb_bsoftlimit)) qup->dqblk.dqb_btime = 0; if (dqblk.dqb_isoftlimit && qup->dqblk.dqb_curinodes >= dqblk.dqb_isoftlimit && (qup->dqblk.dqb_isoftlimit == 0 || qup->dqblk.dqb_curinodes < qup->dqblk.dqb_isoftlimit)) qup->dqblk.dqb_itime = 0; qup->dqblk.dqb_bsoftlimit = dqblk.dqb_bsoftlimit; qup->dqblk.dqb_bhardlimit = dqblk.dqb_bhardlimit; qup->dqblk.dqb_isoftlimit = dqblk.dqb_isoftlimit; qup->dqblk.dqb_ihardlimit = dqblk.dqb_ihardlimit; qup->flags |= FOUND; if (dqblk.dqb_curblocks == qup->dqblk.dqb_curblocks && dqblk.dqb_curinodes == qup->dqblk.dqb_curinodes) break; fprintf(stderr, "%s: cannot change current allocation\n", fsp); break; } } fclose(fd); /* * Disable quotas for any filesystems that have not been found. */ for (qup = quplist; qup; qup = qup->next) { if (qup->flags & FOUND) { qup->flags &= ~FOUND; continue; } qup->dqblk.dqb_bsoftlimit = 0; qup->dqblk.dqb_bhardlimit = 0; qup->dqblk.dqb_isoftlimit = 0; qup->dqblk.dqb_ihardlimit = 0; } return (1);}/* * Convert a quotause list to an ASCII file of grace times. */writetimes(quplist, outfd, quotatype) struct quotause *quplist; int outfd; int quotatype;{ register struct quotause *qup; char *cvtstoa(); FILE *fd; ftruncate(outfd, 0); lseek(outfd, 0, L_SET); if ((fd = fdopen(dup(outfd), "w")) == NULL) { fprintf(stderr, "edquota: "); perror(tmpfil); exit(1); } fprintf(fd, "Time units may be: days, hours, minutes, or seconds\n"); fprintf(fd, "Grace period before enforcing soft limits for %ss:\n", qfextension[quotatype]); for (qup = quplist; qup; qup = qup->next) { fprintf(fd, "%s: block grace period: %s, ", qup->fsname, cvtstoa(qup->dqblk.dqb_btime)); fprintf(fd, "file grace period: %s\n", cvtstoa(qup->dqblk.dqb_itime)); } fclose(fd); return (1);}/* * Merge changes of grace times in an ASCII file into a quotause list. */readtimes(quplist, infd) struct quotause *quplist; int infd;{ register struct quotause *qup; FILE *fd; int cnt; register char *cp; time_t itime, btime, iseconds, bseconds; char *fsp, bunits[10], iunits[10], line1[BUFSIZ]; lseek(infd, 0, L_SET); fd = fdopen(dup(infd), "r"); if (fd == NULL) { fprintf(stderr, "Can't re-read temp file!!\n"); return (0); } /* * Discard two title lines, then read lines to process. */ (void) fgets(line1, sizeof (line1), fd); (void) fgets(line1, sizeof (line1), fd); while (fgets(line1, sizeof (line1), fd) != NULL) { if ((fsp = strtok(line1, " \t:")) == NULL) { fprintf(stderr, "%s: bad format\n", line1); return (0); } if ((cp = strtok((char *)0, "\n")) == NULL) { fprintf(stderr, "%s: %s: bad format\n", fsp, &fsp[strlen(fsp) + 1]); return (0); } cnt = sscanf(cp, " block grace period: %d %s file grace period: %d %s", &btime, bunits, &itime, iunits); if (cnt != 4) { fprintf(stderr, "%s:%s: bad format\n", fsp, cp); return (0); } if (cvtatos(btime, bunits, &bseconds) == 0) return (0); if (cvtatos(itime, iunits, &iseconds) == 0) return (0); for (qup = quplist; qup; qup = qup->next) { if (strcmp(fsp, qup->fsname)) continue; qup->dqblk.dqb_btime = bseconds; qup->dqblk.dqb_itime = iseconds; qup->flags |= FOUND; break; } } fclose(fd); /* * reset default grace periods for any filesystems * that have not been found. */ for (qup = quplist; qup; qup = qup->next) { if (qup->flags & FOUND) { qup->flags &= ~FOUND; continue; } qup->dqblk.dqb_btime = 0; qup->dqblk.dqb_itime = 0; } return (1);}/* * Convert seconds to ASCII times. */char *cvtstoa(time) time_t time;{ static char buf[20]; if (time % (24 * 60 * 60) == 0) { time /= 24 * 60 * 60; sprintf(buf, "%d day%s", time, time == 1 ? "" : "s"); } else if (time % (60 * 60) == 0) { time /= 60 * 60; sprintf(buf, "%d hour%s", time, time == 1 ? "" : "s"); } else if (time % 60 == 0) { time /= 60; sprintf(buf, "%d minute%s", time, time == 1 ? "" : "s"); } else sprintf(buf, "%d second%s", time, time == 1 ? "" : "s"); return (buf);}/* * Convert ASCII input times to seconds. */cvtatos(time, units, seconds) time_t time; char *units; time_t *seconds;{ if (bcmp(units, "second", 6) == 0) *seconds = time; else if (bcmp(units, "minute", 6) == 0) *seconds = time * 60; else if (bcmp(units, "hour", 4) == 0) *seconds = time * 60 * 60; else if (bcmp(units, "day", 3) == 0) *seconds = time * 24 * 60 * 60; else { printf("%s: bad units, specify %s\n", units, "days, hours, minutes, or seconds"); return (0); } return (1);}/* * Free a list of quotause structures. */freeprivs(quplist) struct quotause *quplist;{ register struct quotause *qup, *nextqup; for (qup = quplist; qup; qup = nextqup) { nextqup = qup->next; free(qup); }}/* * Check whether a string is completely composed of digits. */alldigits(s) register char *s;{ register c; c = *s++; do { if (!isdigit(c)) return (0); } while (c = *s++); return (1);}/* * Check to see if a particular quota is to be enabled. */hasquota(fs, type, qfnamep) register struct fstab *fs; int type; char **qfnamep;{ register char *opt; char *cp, *index(), *strtok(); static char initname, usrname[100], grpname[100]; static char buf[BUFSIZ]; if (!initname) { sprintf(usrname, "%s%s", qfextension[USRQUOTA], qfname); sprintf(grpname, "%s%s", qfextension[GRPQUOTA], qfname); initname = 1; } strcpy(buf, fs->fs_mntops); for (opt = strtok(buf, ","); opt; opt = strtok(NULL, ",")) { if (cp = index(opt, '=')) *cp++ = '\0'; if (type == USRQUOTA && strcmp(opt, usrname) == 0) break; if (type == GRPQUOTA && strcmp(opt, grpname) == 0) break; } if (!opt) return (0); if (cp) { *qfnamep = cp; return (1); } (void) sprintf(buf, "%s/%s.%s", fs->fs_file, qfname, qfextension[type]); *qfnamep = buf; return (1);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -