* Check to see if a particular quota is to be enabled. */
| 65 | * Check to see if a particular quota is to be enabled. |
| 66 | */ |
| 67 | static int |
| 68 | hasquota(struct fstab *fs, int type, char *qfnamep, int qfbufsize) |
| 69 | { |
| 70 | char *opt; |
| 71 | char *cp; |
| 72 | struct statfs sfb; |
| 73 | char buf[BUFSIZ]; |
| 74 | static char initname, usrname[100], grpname[100]; |
| 75 | |
| 76 | /* |
| 77 | * 1) we only need one of these |
| 78 | * 2) fstab may specify a different filename |
| 79 | */ |
| 80 | if (!initname) { |
| 81 | (void)snprintf(usrname, sizeof(usrname), "%s%s", |
| 82 | qfextension[USRQUOTA], QUOTAFILENAME); |
| 83 | (void)snprintf(grpname, sizeof(grpname), "%s%s", |
| 84 | qfextension[GRPQUOTA], QUOTAFILENAME); |
| 85 | initname = 1; |
| 86 | } |
| 87 | strcpy(buf, fs->fs_mntops); |
| 88 | for (opt = strtok(buf, ","); opt; opt = strtok(NULL, ",")) { |
| 89 | if ((cp = strchr(opt, '='))) |
| 90 | *cp++ = '\0'; |
| 91 | if (type == USRQUOTA && strcmp(opt, usrname) == 0) |
| 92 | break; |
| 93 | if (type == GRPQUOTA && strcmp(opt, grpname) == 0) |
| 94 | break; |
| 95 | } |
| 96 | if (!opt) |
| 97 | return (0); |
| 98 | /* |
| 99 | * Ensure that the filesystem is mounted. |
| 100 | */ |
| 101 | if (statfs(fs->fs_file, &sfb) != 0 || |
| 102 | strcmp(fs->fs_file, sfb.f_mntonname)) { |
| 103 | return (0); |
| 104 | } |
| 105 | if (cp) { |
| 106 | strlcpy(qfnamep, cp, qfbufsize); |
| 107 | } else { |
| 108 | (void)snprintf(qfnamep, qfbufsize, "%s/%s.%s", fs->fs_file, |
| 109 | QUOTAFILENAME, qfextension[type]); |
| 110 | } |
| 111 | return (1); |
| 112 | } |
| 113 | |
| 114 | struct quotafile * |
| 115 | quota_open(struct fstab *fs, int quotatype, int openflags) |