1 /* 2 * Copyright (c) 1980, 1988 Regents of the University of California. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms are permitted 6 * provided that the above copyright notice and this paragraph are 7 * duplicated in all such forms and that any documentation, 8 * advertising materials, and other materials related to such 9 * distribution and use acknowledge that the software was developed 10 * by the University of California, Berkeley. The name of the 11 * University may not be used to endorse or promote products derived 12 * from this software without specific prior written permission. 13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 16 */ 17 18 #if defined(LIBC_SCCS) && !defined(lint) 19 static char sccsid[] = "@(#)fstab.c 5.5 (Berkeley) 11/14/88"; 20 #endif /* LIBC_SCCS and not lint */ 21 22 #include <fstab.h> 23 #include <stdio.h> 24 25 static FILE *_fs_fp; 26 static struct fstab _fs_fstab; 27 28 static 29 fstabscan() 30 { 31 register char *cp; 32 #define MAXLINELENGTH 100 33 static char line[MAXLINELENGTH]; 34 char *fgets(), *strsep(); 35 36 for (;;) { 37 if (!(cp = fgets(line, sizeof(line), _fs_fp))) 38 return(0); 39 _fs_fstab.fs_spec = strsep(cp, ":\n"); 40 _fs_fstab.fs_file = strsep((char *)NULL, ":\n"); 41 _fs_fstab.fs_type = strsep((char *)NULL, ":\n"); 42 if (_fs_fstab.fs_type && strcmp(_fs_fstab.fs_type, FSTAB_XX)) { 43 if (!(cp = strsep((char *)NULL, ":\n"))) 44 continue; 45 _fs_fstab.fs_freq = atoi(cp); 46 if (!(cp = strsep((char *)NULL, ":\n"))) 47 continue; 48 _fs_fstab.fs_passno = atoi(cp); 49 return(1); 50 } 51 } 52 /* NOTREACHED */ 53 } 54 55 struct fstab * 56 getfsent() 57 { 58 if (!_fs_fp && !setfsent() || !fstabscan()) 59 return((struct fstab *)NULL); 60 return(&_fs_fstab); 61 } 62 63 struct fstab * 64 getfsspec(name) 65 register char *name; 66 { 67 if (setfsent()) 68 while (fstabscan()) 69 if (!strcmp(_fs_fstab.fs_spec, name)) 70 return(&_fs_fstab); 71 return((struct fstab *)NULL); 72 } 73 74 struct fstab * 75 getfsfile(name) 76 register char *name; 77 { 78 if (setfsent()) 79 while (fstabscan()) 80 if (!strcmp(_fs_fstab.fs_file, name)) 81 return(&_fs_fstab); 82 return((struct fstab *)NULL); 83 } 84 85 setfsent() 86 { 87 if (_fs_fp) { 88 rewind(_fs_fp); 89 return(1); 90 } 91 return((_fs_fp = fopen(FSTAB, "r")) != NULL); 92 } 93 94 void 95 endfsent() 96 { 97 if (_fs_fp) { 98 (void)fclose(_fs_fp); 99 _fs_fp = NULL; 100 } 101 } 102