2004-11-03 13:51:07 +00:00
|
|
|
.\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
|
|
|
|
.\"
|
|
|
|
.\" Permission is granted to make and distribute verbatim copies of this
|
|
|
|
.\" manual provided the copyright notice and this permission notice are
|
|
|
|
.\" preserved on all copies.
|
|
|
|
.\"
|
|
|
|
.\" Permission is granted to copy and distribute modified versions of this
|
|
|
|
.\" manual under the conditions for verbatim copying, provided that the
|
|
|
|
.\" entire resulting derived work is distributed under the terms of a
|
|
|
|
.\" permission notice identical to this one.
|
|
|
|
.\"
|
|
|
|
.\" Since the Linux kernel and libraries are constantly changing, this
|
|
|
|
.\" manual page may be incorrect or out-of-date. The author(s) assume no
|
|
|
|
.\" responsibility for errors or omissions, or for damages resulting from
|
|
|
|
.\" the use of the information contained herein. The author(s) may not
|
|
|
|
.\" have taken the same level of care in the production of this manual,
|
|
|
|
.\" which is licensed free of charge, as they might when working
|
|
|
|
.\" professionally.
|
|
|
|
.\"
|
|
|
|
.\" Formatted or processed versions of this manual, if unaccompanied by
|
|
|
|
.\" the source, must acknowledge the copyright and authors of this work.
|
|
|
|
.\"
|
|
|
|
.\" References consulted:
|
|
|
|
.\" Linux libc source code
|
|
|
|
.\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
|
|
|
|
.\" 386BSD man pages
|
|
|
|
.\" Modified Sat Jul 24 21:46:57 1993 by Rik Faith (faith@cs.unc.edu)
|
|
|
|
.\" Modified 961109, 031115, aeb
|
|
|
|
.\"
|
|
|
|
.TH GETMNTENT 3 2003-11-15 "" "Linux Programmer's Manual"
|
|
|
|
.SH NAME
|
|
|
|
getmntent, setmntent, addmntent, endmntent, hasmntopt,
|
|
|
|
getmntent_r \- get file system descriptor file entry
|
|
|
|
.SH SYNOPSIS
|
|
|
|
.nf
|
|
|
|
.B #include <stdio.h>
|
|
|
|
.B #include <mntent.h>
|
|
|
|
.sp
|
|
|
|
.BI "FILE *setmntent(const char *" filename ", const char *" type );
|
|
|
|
.sp
|
|
|
|
.BI "struct mntent *getmntent(FILE *" fp );
|
|
|
|
.sp
|
|
|
|
.BI "int addmntent(FILE *" fp ", const struct mntent *" mnt );
|
|
|
|
.sp
|
|
|
|
.BI "int endmntent(FILE *" fp );
|
|
|
|
.sp
|
|
|
|
.BI "char *hasmntopt(const struct mntent *" mnt ", const char *" opt );
|
|
|
|
.sp
|
|
|
|
/* GNU extension */
|
2006-05-31 22:16:55 +00:00
|
|
|
.BR "#define _GNU_SOURCE" " /* or _SVID_SOURCE or _BSD_SOURCE */"
|
2004-11-03 13:51:07 +00:00
|
|
|
.B #include <mntent.h>
|
|
|
|
.sp
|
|
|
|
.BI "struct mntent *getmntent_r(FILE *" fp ", struct mntent *" mntbuf ,
|
|
|
|
.BI " char *" buf ", int " buflen );
|
|
|
|
.fi
|
|
|
|
.SH DESCRIPTION
|
|
|
|
These routines are used to access the file system description file
|
|
|
|
\fI/etc/fstab\fP and the mounted file system description file
|
|
|
|
\fI/etc/mtab\fP.
|
|
|
|
.PP
|
2005-10-19 07:07:02 +00:00
|
|
|
The \fBsetmntent\fP() function opens the file system description file
|
2004-11-03 13:51:07 +00:00
|
|
|
\fIfp\fP and returns a file pointer which can be used by
|
2005-10-19 07:07:02 +00:00
|
|
|
\fBgetmntent\fP(). The argument \fItype\fP is the type of access
|
2004-11-03 13:51:07 +00:00
|
|
|
required and can take the same values as the \fImode\fP argument of
|
|
|
|
.BR fopen (3).
|
|
|
|
.PP
|
2005-10-19 07:07:02 +00:00
|
|
|
The \fBgetmntent\fP() function reads the next line from the file system
|
2004-11-03 13:51:07 +00:00
|
|
|
description file \fIfp\fP and returns a pointer to a structure
|
|
|
|
containing the broken out fields from a line in the file. The pointer
|
|
|
|
points to a static area of memory which is overwritten by subsequent
|
2005-10-19 07:07:02 +00:00
|
|
|
calls to \fBgetmntent\fP().
|
2004-11-03 13:51:07 +00:00
|
|
|
.PP
|
2005-10-19 07:07:02 +00:00
|
|
|
The \fBaddmntent\fP() function adds the mntent structure \fImnt\fP to
|
2004-11-03 13:51:07 +00:00
|
|
|
the end of the open file \fIfp\fP.
|
|
|
|
.PP
|
2005-10-19 07:07:02 +00:00
|
|
|
The \fBendmntent\fP() function closes the file system description file
|
2004-11-03 13:51:07 +00:00
|
|
|
\fIfp\fP.
|
|
|
|
.PP
|
2005-10-19 07:07:02 +00:00
|
|
|
The \fBhasmntopt\fP() function scans the \fImnt_opts\fP field (see below)
|
2004-11-03 13:51:07 +00:00
|
|
|
of the mntent structure \fImnt\fP for a substring that matches \fIopt\fP.
|
|
|
|
See \fI<mntent.h>\fP and
|
|
|
|
.BR mount (8)
|
|
|
|
for valid mount options.
|
|
|
|
.PP
|
2005-10-19 07:07:02 +00:00
|
|
|
The reentrant \fBgetmntent_r\fP() function is similar to \fBgetmntent\fP(),
|
2004-11-03 13:51:07 +00:00
|
|
|
but stores the struct mount in the provided
|
|
|
|
.RI * mntbuf
|
|
|
|
and stores the strings pointed to by the entries in that struct
|
|
|
|
in the provided array
|
|
|
|
.I buf
|
|
|
|
of size
|
|
|
|
.IR buflen .
|
|
|
|
.PP
|
|
|
|
The \fImntent\fP structure is defined in \fI<mntent.h>\fP as follows:
|
|
|
|
.sp
|
|
|
|
.RS
|
|
|
|
.nf
|
|
|
|
.ne 8
|
|
|
|
.ta 8n 16n 32n
|
|
|
|
struct mntent {
|
|
|
|
char *mnt_fsname; /* name of mounted file system */
|
|
|
|
char *mnt_dir; /* file system path prefix */
|
|
|
|
char *mnt_type; /* mount type (see mntent.h) */
|
|
|
|
char *mnt_opts; /* mount options (see mntent.h) */
|
|
|
|
int mnt_freq; /* dump frequency in days */
|
|
|
|
int mnt_passno; /* pass number on parallel fsck */
|
|
|
|
};
|
|
|
|
.ta
|
|
|
|
.fi
|
|
|
|
.RE
|
|
|
|
|
|
|
|
Since fields in the mtab and fstab files are separated by whitespace,
|
|
|
|
octal escapes are used to represent the four characters space (\e040),
|
|
|
|
tab (\e011), newline (\e012) and backslash (\e134) in those files
|
|
|
|
when they occur in one of the four strings in a mntent structure.
|
2005-10-19 07:07:02 +00:00
|
|
|
The routines \fBaddmntent\fP() and \fBgetmntent\fP() will convert
|
2004-11-03 13:51:07 +00:00
|
|
|
from string representation to escaped representation and back.
|
|
|
|
.SH "RETURN VALUE"
|
2005-10-19 07:07:02 +00:00
|
|
|
The \fBgetmntent\fP() and \fBgetmntent_r\fP() functions return
|
2004-11-03 13:51:07 +00:00
|
|
|
a pointer to the mntent structure or NULL on failure.
|
|
|
|
.PP
|
2005-10-19 07:07:02 +00:00
|
|
|
The \fBaddmntent\fP() function returns 0 on success and 1 on failure.
|
2004-11-03 13:51:07 +00:00
|
|
|
.PP
|
2005-10-19 07:07:02 +00:00
|
|
|
The \fBendmntent\fP() function always returns 1.
|
2004-11-03 13:51:07 +00:00
|
|
|
.PP
|
2005-10-19 07:07:02 +00:00
|
|
|
The \fBhasmntopt\fP() function returns the address of the substring if
|
2004-11-03 13:51:07 +00:00
|
|
|
a match is found and NULL otherwise.
|
|
|
|
.SH FILES
|
|
|
|
.nf
|
|
|
|
/etc/fstab file system description file
|
|
|
|
/etc/mtab mounted file system description file
|
|
|
|
.fi
|
|
|
|
.SH "CONFORMING TO"
|
|
|
|
The non-reentrant functions are from SunOS 4.1.3.
|
|
|
|
A routine
|
2005-10-19 07:07:02 +00:00
|
|
|
.BR getmntent_r ()
|
2006-08-03 13:57:30 +00:00
|
|
|
was introduced in HP-UX 10, but it returns an int.
|
|
|
|
The prototype shown above is glibc-only.
|
2004-11-03 13:51:07 +00:00
|
|
|
LSB deprecates the functions
|
2005-10-19 07:07:02 +00:00
|
|
|
.BR endhostent (),
|
|
|
|
.BR sethostent ()
|
2004-11-03 13:51:07 +00:00
|
|
|
and
|
2005-10-19 07:07:02 +00:00
|
|
|
.BR setmntent ().
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH NOTES
|
2006-01-13 09:39:55 +00:00
|
|
|
System V also has a \fBgetmntent\fP() function but the calling sequence
|
|
|
|
differs, and the returned structure is different. Under System V
|
2004-11-03 13:51:07 +00:00
|
|
|
.I /etc/mnttab
|
|
|
|
is used.
|
2005-10-19 07:07:02 +00:00
|
|
|
4.4BSD and Digital Unix have a routine \fBgetmntinfo\fP(),
|
|
|
|
a wrapper around the system call \fBgetfsstat\fP().
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH "SEE ALSO"
|
|
|
|
.BR fopen (3),
|
|
|
|
.BR fstab (5),
|
|
|
|
.BR mount (8)
|