summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormdodd <mdodd@FreeBSD.org>2003-04-07 12:55:00 +0000
committermdodd <mdodd@FreeBSD.org>2003-04-07 12:55:00 +0000
commit7c43f96140c9e0208ae1f650102cab1a120e7295 (patch)
treef0f3737571d3ceb5573b076eebbe87546958dfd0
parent86b0c078f70abab5140a11d0a13440d83cdce13d (diff)
downloadFreeBSD-src-7c43f96140c9e0208ae1f650102cab1a120e7295.zip
FreeBSD-src-7c43f96140c9e0208ae1f650102cab1a120e7295.tar.gz
- Add setfstab() and getfstab().
- Use the environment variable 'PATH_FSTAB' if set rather than the hardcoded '/etc/fstab' (fstab.h:_PATH_FSTAB)
-rw-r--r--include/fstab.h2
-rw-r--r--lib/libc/gen/Makefile.inc3
-rw-r--r--lib/libc/gen/fstab.c41
-rw-r--r--lib/libc/gen/getfsent.331
4 files changed, 73 insertions, 4 deletions
diff --git a/include/fstab.h b/include/fstab.h
index a269d42..cae9172 100644
--- a/include/fstab.h
+++ b/include/fstab.h
@@ -75,6 +75,8 @@ struct fstab *getfsspec(const char *);
struct fstab *getfsfile(const char *);
int setfsent(void);
void endfsent(void);
+void setfstab(const char *);
+const char *getfstab(void);
__END_DECLS
#endif /* !_FSTAB_H_ */
diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc
index 9507023..d83f526 100644
--- a/lib/libc/gen/Makefile.inc
+++ b/lib/libc/gen/Makefile.inc
@@ -84,7 +84,8 @@ MLINKS+=getcwd.3 getwd.3
MLINKS+=getcontext.3 setcontext.3
MLINKS+=getdomainname.3 setdomainname.3
MLINKS+=getfsent.3 endfsent.3 getfsent.3 getfsfile.3 getfsent.3 getfsspec.3 \
- getfsent.3 getfstype.3 getfsent.3 setfsent.3
+ getfsent.3 getfstype.3 getfsent.3 setfsent.3 \
+ getfsent.3 setfstab.3 getfsent.3 getfstab.3
MLINKS+=getgrent.3 endgrent.3 getgrent.3 getgrgid.3 getgrent.3 getgrnam.3 \
getgrent.3 setgrent.3 getgrent.3 setgroupent.3
MLINKS+=gethostname.3 sethostname.3
diff --git a/lib/libc/gen/fstab.c b/lib/libc/gen/fstab.c
index dce191d..beeb700 100644
--- a/lib/libc/gen/fstab.c
+++ b/lib/libc/gen/fstab.c
@@ -54,11 +54,40 @@ __FBSDID("$FreeBSD$");
static FILE *_fs_fp;
static struct fstab _fs_fstab;
static int LineNo = 0;
+static char *path_fstab;
+static char fstab_path[PATH_MAX];
+static int fsp_set = 0;
static void error(int);
static void fixfsfile(void);
static int fstabscan(void);
+void
+setfstab(const char *file)
+{
+
+ if (file == NULL) {
+ path_fstab = _PATH_FSTAB;
+ } else {
+ strncpy(fstab_path, file, PATH_MAX);
+ fstab_path[PATH_MAX - 1] = '\0';
+ path_fstab = fstab_path;
+ }
+ fsp_set = 1;
+
+ return;
+}
+
+const char *
+getfstab (void)
+{
+
+ if (fsp_set)
+ return (path_fstab);
+ else
+ return (_PATH_FSTAB);
+}
+
static void
fixfsfile()
{
@@ -226,7 +255,13 @@ setfsent()
LineNo = 0;
return(1);
}
- if ((_fs_fp = fopen(_PATH_FSTAB, "r")) != NULL) {
+ if (fsp_set == 0) {
+ if (issetugid())
+ setfstab(NULL);
+ else
+ setfstab(getenv("PATH_FSTAB"));
+ }
+ if ((_fs_fp = fopen(path_fstab, "r")) != NULL) {
LineNo = 0;
return(1);
}
@@ -241,6 +276,8 @@ endfsent()
(void)fclose(_fs_fp);
_fs_fp = NULL;
}
+
+ fsp_set = 0;
}
static void
@@ -251,7 +288,7 @@ error(err)
char num[30];
(void)_write(STDERR_FILENO, "fstab: ", 7);
- (void)_write(STDERR_FILENO, _PATH_FSTAB, sizeof(_PATH_FSTAB) - 1);
+ (void)_write(STDERR_FILENO, path_fstab, strlen(path_fstab));
(void)_write(STDERR_FILENO, ":", 1);
sprintf(num, "%d: ", LineNo);
(void)_write(STDERR_FILENO, num, strlen(num));
diff --git a/lib/libc/gen/getfsent.3 b/lib/libc/gen/getfsent.3
index 06def9d..bbf2151 100644
--- a/lib/libc/gen/getfsent.3
+++ b/lib/libc/gen/getfsent.3
@@ -56,6 +56,10 @@
.Fn setfsent void
.Ft void
.Fn endfsent void
+.Ft void
+.Fn setfstab "const char *file"
+.Ft const char *
+.Fn getfstab void
.Sh DESCRIPTION
The
.Fn getfsent ,
@@ -94,6 +98,18 @@ function
closes the file.
.Pp
The
+.Fn setfstab
+function sets the file to be used by subsequent operations.
+The value set by
+.Fn setfstab
+does not persist across calls to
+.Fn endfsent
+.Pp
+The
+.Fn getfstab
+function returns the name of the file that that will be used.
+.Pp
+The
.Fn getfsspec
and
.Fn getfsfile
@@ -128,6 +144,13 @@ The
.Fn endfsent
function
returns nothing.
+.Sh ENVIRONMENT
+.Bl -tag -width PATH_FSTAB
+.It Pa PATH_FSTAB
+If the environment variable
+.Pa PATH_FSTAB
+is set all operations are performed against the specified file.
+.El
.Sh FILES
.Bl -tag -width /etc/fstab -compact
.It Pa /etc/fstab
@@ -146,7 +169,13 @@ the
and
.Fn setfsent
functions appeared in
-.Bx 4.3 .
+.Bx 4.3 ;
+the
+.Fn setfstab
+and
+.Fn getfstab
+functions appeared in
+.Fx 5.1.
.Sh BUGS
These functions use static data storage;
if the data is needed for future use, it should be
OpenPOWER on IntegriCloud