- Add setfstab() and getfstab().
- Use the environment variable 'PATH_FSTAB' if set rather than the hardcoded '/etc/fstab' (fstab.h:_PATH_FSTAB)
This commit is contained in:
parent
a988d6fc74
commit
19637eaabb
@ -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_ */
|
||||
|
@ -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
|
||||
|
@ -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));
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user