112597Ssam #ifndef lint 2*12699Ssam static char sccsid[] = "@(#)fstab.c 4.3 (Berkeley) 05/24/83"; 312597Ssam #endif 412597Ssam 52010Swnj #include <fstab.h> 62010Swnj #include <stdio.h> 72010Swnj #include <ctype.h> 82010Swnj 912597Ssam static struct fstab fs; 1012597Ssam static char line[BUFSIZ+1]; 1112597Ssam static FILE *fs_file = 0; 122010Swnj 1312597Ssam static char * 1412597Ssam fsskip(p) 1512597Ssam register char *p; 162010Swnj { 1712597Ssam 1812597Ssam while (*p && *p != ':') 1912597Ssam ++p; 2012597Ssam if (*p) 2112597Ssam *p++ = 0; 2212597Ssam return (p); 232010Swnj } 2412597Ssam 2512597Ssam static char * 2612597Ssam fsdigit(backp, string, end) 2712597Ssam int *backp; 2812597Ssam char *string, end; 292010Swnj { 3012597Ssam register int value = 0; 3112597Ssam register char *cp; 3212597Ssam 3312597Ssam for (cp = string; *cp && isdigit(*cp); cp++) { 342010Swnj value *= 10; 352010Swnj value += *cp - '0'; 362010Swnj } 3712597Ssam if (*cp == '\0') 38*12699Ssam return ((char *)0); 392010Swnj *backp = value; 4012597Ssam while (*cp && *cp != end) 412010Swnj cp++; 4212597Ssam if (*cp == '\0') 43*12699Ssam return ((char *)0); 4412597Ssam return (cp+1); 452010Swnj } 462010Swnj 4712597Ssam static 4812597Ssam fstabscan(fs) 4912597Ssam struct fstab *fs; 502010Swnj { 5112597Ssam register char *cp; 5212597Ssam 5312597Ssam cp = fgets(line, 256, fs_file); 5412597Ssam if (cp == NULL) 5512597Ssam return (EOF); 5612597Ssam fs->fs_spec = cp; 5712597Ssam cp = fsskip(cp); 5812597Ssam fs->fs_file = cp; 5912597Ssam cp = fsskip(cp); 6012597Ssam fs->fs_type = cp; 6112597Ssam cp = fsskip(cp); 6212597Ssam cp = fsdigit(&fs->fs_freq, cp, ':'); 6312597Ssam if (cp == 0) 64*12699Ssam return (3); 6512597Ssam cp = fsdigit(&fs->fs_passno, cp, '\n'); 6612597Ssam if (cp == 0) 67*12699Ssam return (4); 68*12699Ssam return (5); 692010Swnj } 702010Swnj 7112597Ssam setfsent() 722010Swnj { 7312597Ssam 742010Swnj if (fs_file) 752010Swnj endfsent(); 7612597Ssam if ((fs_file = fopen(FSTAB, "r")) == NULL){ 772010Swnj fs_file = 0; 7812597Ssam return (0); 792010Swnj } 8012597Ssam return (1); 812010Swnj } 822010Swnj 8312597Ssam endfsent() 842010Swnj { 8512597Ssam 8612597Ssam if (fs_file) 872010Swnj fclose(fs_file); 8812597Ssam return (1); 892010Swnj } 902010Swnj 9112597Ssam struct fstab * 9212597Ssam getfsent() 932010Swnj { 9412597Ssam int nfields; 952010Swnj 9612597Ssam if ((fs_file == 0) && (setfsent() == 0)) 97*12699Ssam return ((struct fstab *)0); 982010Swnj nfields = fstabscan(&fs); 99*12699Ssam if (nfields == EOF || nfields != 5) 100*12699Ssam return ((struct fstab *)0); 10112597Ssam return (&fs); 1022010Swnj } 10312597Ssam 10412597Ssam struct fstab * 10512597Ssam getfsspec(name) 10612597Ssam char *name; 1072010Swnj { 10812597Ssam register struct fstab *fsp; 10912597Ssam 1102010Swnj if (setfsent() == 0) /* start from the beginning */ 111*12699Ssam return ((struct fstab *)0); 11212597Ssam while((fsp = getfsent()) != 0) 11312597Ssam if (strcmp(fsp->fs_spec, name) == 0) 11412597Ssam return (fsp); 115*12699Ssam return ((struct fstab *)0); 1162010Swnj } 11712597Ssam 11812597Ssam struct fstab * 11912597Ssam getfsfile(name) 12012597Ssam char *name; 1212010Swnj { 12212597Ssam register struct fstab *fsp; 12312597Ssam 1242010Swnj if (setfsent() == 0) /* start from the beginning */ 125*12699Ssam return ((struct fstab *)0); 12612597Ssam while ((fsp = getfsent()) != 0) 12712597Ssam if (strcmp(fsp->fs_file, name) == 0) 12812597Ssam return (fsp); 129*12699Ssam return ((struct fstab *)0); 1302010Swnj } 131*12699Ssam 132*12699Ssam struct fstab * 133*12699Ssam getfstype(type) 134*12699Ssam char *type; 135*12699Ssam { 136*12699Ssam register struct fstab *fs; 137*12699Ssam 138*12699Ssam if (setfsent() == 0) 139*12699Ssam return ((struct fstab *)0); 140*12699Ssam while ((fs = getfsent()) != 0) 141*12699Ssam if (strcmp(fs->fs_type, type) == 0) 142*12699Ssam return (fs); 143*12699Ssam return ((struct fstab *)0); 144*12699Ssam } 145