Blame manual/sysinfo.texi

Packit Service 82fcde
@node System Management, System Configuration, Users and Groups, Top
Packit Service 82fcde
@c %MENU% Controlling the system and getting information about it
Packit Service 82fcde
@chapter System Management
Packit Service 82fcde
Packit Service 82fcde
This chapter describes facilities for controlling the system that
Packit Service 82fcde
underlies a process (including the operating system and hardware) and
Packit Service 82fcde
for getting information about it.  Anyone can generally use the
Packit Service 82fcde
informational facilities, but usually only a properly privileged process
Packit Service 82fcde
can make changes.
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@menu
Packit Service 82fcde
* Host Identification::         Determining the name of the machine.
Packit Service 82fcde
* Platform Type::               Determining operating system and basic
Packit Service 82fcde
                                  machine type
Packit Service 82fcde
* Filesystem Handling::         Controlling/querying mounts
Packit Service 82fcde
* System Parameters::           Getting and setting various system parameters
Packit Service 82fcde
@end menu
Packit Service 82fcde
Packit Service 82fcde
To get information on parameters of the system that are built into the
Packit Service 82fcde
system, such as the maximum length of a filename, @ref{System
Packit Service 82fcde
Configuration}.
Packit Service 82fcde
Packit Service 82fcde
@node Host Identification
Packit Service 82fcde
@section Host Identification
Packit Service 82fcde
Packit Service 82fcde
This section explains how to identify the particular system on which your
Packit Service 82fcde
program is running.  First, let's review the various ways computer systems
Packit Service 82fcde
are named, which is a little complicated because of the history of the
Packit Service 82fcde
development of the Internet.
Packit Service 82fcde
Packit Service 82fcde
Every Unix system (also known as a host) has a host name, whether it's
Packit Service 82fcde
connected to a network or not.  In its simplest form, as used before
Packit Service 82fcde
computer networks were an issue, it's just a word like @samp{chicken}.
Packit Service 82fcde
@cindex host name
Packit Service 82fcde
Packit Service 82fcde
But any system attached to the Internet or any network like it conforms
Packit Service 82fcde
to a more rigorous naming convention as part of the Domain Name System
Packit Service 82fcde
(DNS).  In the DNS, every host name is composed of two parts:
Packit Service 82fcde
@cindex DNS
Packit Service 82fcde
@cindex Domain Name System
Packit Service 82fcde
Packit Service 82fcde
@enumerate
Packit Service 82fcde
@item
Packit Service 82fcde
hostname
Packit Service 82fcde
@cindex hostname
Packit Service 82fcde
@item
Packit Service 82fcde
domain name
Packit Service 82fcde
@cindex domain name
Packit Service 82fcde
@end enumerate
Packit Service 82fcde
Packit Service 82fcde
You will note that ``hostname'' looks a lot like ``host name'', but is
Packit Service 82fcde
not the same thing, and that people often incorrectly refer to entire
Packit Service 82fcde
host names as ``domain names.''
Packit Service 82fcde
Packit Service 82fcde
In the DNS, the full host name is properly called the FQDN (Fully Qualified
Packit Service 82fcde
Domain Name) and consists of the hostname, then a period, then the
Packit Service 82fcde
domain name.  The domain name itself usually has multiple components
Packit Service 82fcde
separated by periods.  So for example, a system's hostname may be
Packit Service 82fcde
@samp{chicken} and its domain name might be @samp{ai.mit.edu}, so
Packit Service 82fcde
its FQDN (which is its host name) is @samp{chicken.ai.mit.edu}.
Packit Service 82fcde
@cindex FQDN
Packit Service 82fcde
Packit Service 82fcde
Adding to the confusion, though, is that the DNS is not the only name space
Packit Service 82fcde
in which a computer needs to be known.  Another name space is the
Packit Service 82fcde
NIS (aka YP) name space.  For NIS purposes, there is another domain
Packit Service 82fcde
name, which is called the NIS domain name or the YP domain name.  It
Packit Service 82fcde
need not have anything to do with the DNS domain name.
Packit Service 82fcde
@cindex YP
Packit Service 82fcde
@cindex NIS
Packit Service 82fcde
@cindex NIS domain name
Packit Service 82fcde
@cindex YP domain name
Packit Service 82fcde
Packit Service 82fcde
Confusing things even more is the fact that in the DNS, it is possible for
Packit Service 82fcde
multiple FQDNs to refer to the same system.  However, there is always
Packit Service 82fcde
exactly one of them that is the true host name, and it is called the
Packit Service 82fcde
canonical FQDN.
Packit Service 82fcde
Packit Service 82fcde
In some contexts, the host name is called a ``node name.''
Packit Service 82fcde
Packit Service 82fcde
For more information on DNS host naming, see @ref{Host Names}.
Packit Service 82fcde
Packit Service 82fcde
@pindex hostname
Packit Service 82fcde
@pindex hostid
Packit Service 82fcde
@pindex unistd.h
Packit Service 82fcde
Prototypes for these functions appear in @file{unistd.h}.
Packit Service 82fcde
Packit Service 82fcde
The programs @code{hostname}, @code{hostid}, and @code{domainname} work
Packit Service 82fcde
by calling these functions.
Packit Service 82fcde
Packit Service 82fcde
@deftypefun int gethostname (char *@var{name}, size_t @var{size})
Packit Service 82fcde
@standards{BSD, unistd.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
@c Direct syscall on unix; implemented in terms of uname on posix and of
Packit Service 82fcde
@c hurd_get_host_config on hurd.
Packit Service 82fcde
This function returns the host name of the system on which it is called,
Packit Service 82fcde
in the array @var{name}.  The @var{size} argument specifies the size of
Packit Service 82fcde
this array, in bytes.  Note that this is @emph{not} the DNS hostname.
Packit Service 82fcde
If the system participates in the DNS, this is the FQDN (see above).
Packit Service 82fcde
Packit Service 82fcde
The return value is @code{0} on success and @code{-1} on failure.  In
Packit Service 82fcde
@theglibc{}, @code{gethostname} fails if @var{size} is not large
Packit Service 82fcde
enough; then you can try again with a larger array.  The following
Packit Service 82fcde
@code{errno} error condition is defined for this function:
Packit Service 82fcde
Packit Service 82fcde
@table @code
Packit Service 82fcde
@item ENAMETOOLONG
Packit Service 82fcde
The @var{size} argument is less than the size of the host name plus one.
Packit Service 82fcde
@end table
Packit Service 82fcde
Packit Service 82fcde
@pindex sys/param.h
Packit Service 82fcde
On some systems, there is a symbol for the maximum possible host name
Packit Service 82fcde
length: @code{MAXHOSTNAMELEN}.  It is defined in @file{sys/param.h}.
Packit Service 82fcde
But you can't count on this to exist, so it is cleaner to handle
Packit Service 82fcde
failure and try again.
Packit Service 82fcde
Packit Service 82fcde
@code{gethostname} stores the beginning of the host name in @var{name}
Packit Service 82fcde
even if the host name won't entirely fit.  For some purposes, a
Packit Service 82fcde
truncated host name is good enough.  If it is, you can ignore the
Packit Service 82fcde
error code.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun int sethostname (const char *@var{name}, size_t @var{length})
Packit Service 82fcde
@standards{BSD, unistd.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
@c Direct syscall on unix; implemented in terms of hurd_set_host_config
Packit Service 82fcde
@c on hurd.
Packit Service 82fcde
The @code{sethostname} function sets the host name of the system that
Packit Service 82fcde
calls it to @var{name}, a string with length @var{length}.  Only
Packit Service 82fcde
privileged processes are permitted to do this.
Packit Service 82fcde
Packit Service 82fcde
Usually @code{sethostname} gets called just once, at system boot time.
Packit Service 82fcde
Often, the program that calls it sets it to the value it finds in the
Packit Service 82fcde
file @code{/etc/hostname}.
Packit Service 82fcde
@cindex /etc/hostname
Packit Service 82fcde
Packit Service 82fcde
Be sure to set the host name to the full host name, not just the DNS
Packit Service 82fcde
hostname (see above).
Packit Service 82fcde
Packit Service 82fcde
The return value is @code{0} on success and @code{-1} on failure.
Packit Service 82fcde
The following @code{errno} error condition is defined for this function:
Packit Service 82fcde
Packit Service 82fcde
@table @code
Packit Service 82fcde
@item EPERM
Packit Service 82fcde
This process cannot set the host name because it is not privileged.
Packit Service 82fcde
@end table
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun int getdomainnname (char *@var{name}, size_t @var{length})
Packit Service 82fcde
@standards{???, unistd.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
@c Syscalls uname, then strlen and memcpy.
Packit Service 82fcde
@cindex NIS domain name
Packit Service 82fcde
@cindex YP domain name
Packit Service 82fcde
Packit Service 82fcde
@code{getdomainname} returns the NIS (aka YP) domain name of the system
Packit Service 82fcde
on which it is called.  Note that this is not the more popular DNS
Packit Service 82fcde
domain name.  Get that with @code{gethostname}.
Packit Service 82fcde
Packit Service 82fcde
The specifics of this function are analogous to @code{gethostname}, above.
Packit Service 82fcde
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun int setdomainname (const char *@var{name}, size_t @var{length})
Packit Service 82fcde
@standards{???, unistd.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
@c Direct syscall.
Packit Service 82fcde
@cindex NIS domain name
Packit Service 82fcde
@cindex YP domain name
Packit Service 82fcde
Packit Service 82fcde
@code{setdomainname} sets the NIS (aka YP) domain name of the system
Packit Service 82fcde
on which it is called.  Note that this is not the more popular DNS
Packit Service 82fcde
domain name.  Set that with @code{sethostname}.
Packit Service 82fcde
Packit Service 82fcde
The specifics of this function are analogous to @code{sethostname}, above.
Packit Service 82fcde
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun {long int} gethostid (void)
Packit Service 82fcde
@standards{BSD, unistd.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{@mtshostid{} @mtsenv{} @mtslocale{}}@asunsafe{@ascudlopen{} @ascuplugin{} @asucorrupt{} @ascuheap{} @asulock{}}@acunsafe{@aculock{} @acucorrupt{} @acsmem{} @acsfd{}}}
Packit Service 82fcde
@c On HURD, calls _hurd_get_host_config and strtol.  On Linux, open
Packit Service 82fcde
@c HOSTIDFILE, reads an int32_t and closes; if that fails, it calls
Packit Service 82fcde
@c gethostname and gethostbyname_r to use the h_addr.
Packit Service 82fcde
This function returns the ``host ID'' of the machine the program is
Packit Service 82fcde
running on.  By convention, this is usually the primary Internet IP address
Packit Service 82fcde
of that machine, converted to a @w{@code{long int}}.  However, on some
Packit Service 82fcde
systems it is a meaningless but unique number which is hard-coded for
Packit Service 82fcde
each machine.
Packit Service 82fcde
Packit Service 82fcde
This is not widely used.  It arose in BSD 4.2, but was dropped in BSD 4.4.
Packit Service 82fcde
It is not required by POSIX.
Packit Service 82fcde
Packit Service 82fcde
The proper way to query the IP address is to use @code{gethostbyname}
Packit Service 82fcde
on the results of @code{gethostname}.  For more information on IP addresses,
Packit Service 82fcde
@xref{Host Addresses}.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun int sethostid (long int @var{id})
Packit Service 82fcde
@standards{BSD, unistd.h}
Packit Service 82fcde
@safety{@prelim{}@mtunsafe{@mtasuconst{:@mtshostid{}}}@asunsafe{}@acunsafe{@acucorrupt{} @acsfd{}}}
Packit Service 82fcde
The @code{sethostid} function sets the ``host ID'' of the host machine
Packit Service 82fcde
to @var{id}.  Only privileged processes are permitted to do this.  Usually
Packit Service 82fcde
it happens just once, at system boot time.
Packit Service 82fcde
Packit Service 82fcde
The proper way to establish the primary IP address of a system
Packit Service 82fcde
is to configure the IP address resolver to associate that IP address with
Packit Service 82fcde
the system's host name as returned by @code{gethostname}.  For example,
Packit Service 82fcde
put a record for the system in @file{/etc/hosts}.
Packit Service 82fcde
Packit Service 82fcde
See @code{gethostid} above for more information on host ids.
Packit Service 82fcde
Packit Service 82fcde
The return value is @code{0} on success and @code{-1} on failure.
Packit Service 82fcde
The following @code{errno} error conditions are defined for this function:
Packit Service 82fcde
Packit Service 82fcde
@table @code
Packit Service 82fcde
@item EPERM
Packit Service 82fcde
This process cannot set the host name because it is not privileged.
Packit Service 82fcde
Packit Service 82fcde
@item ENOSYS
Packit Service 82fcde
The operating system does not support setting the host ID.  On some
Packit Service 82fcde
systems, the host ID is a meaningless but unique number hard-coded for
Packit Service 82fcde
each machine.
Packit Service 82fcde
@end table
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@node Platform Type
Packit Service 82fcde
@section Platform Type Identification
Packit Service 82fcde
Packit Service 82fcde
You can use the @code{uname} function to find out some information about
Packit Service 82fcde
the type of computer your program is running on.  This function and the
Packit Service 82fcde
associated data type are declared in the header file
Packit Service 82fcde
@file{sys/utsname.h}.
Packit Service 82fcde
@pindex sys/utsname.h
Packit Service 82fcde
Packit Service 82fcde
As a bonus, @code{uname} also gives some information identifying the
Packit Service 82fcde
particular system your program is running on.  This is the same information
Packit Service 82fcde
which you can get with functions targeted to this purpose described in
Packit Service 82fcde
@ref{Host Identification}.
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@deftp {Data Type} {struct utsname}
Packit Service 82fcde
@standards{POSIX.1, sys/utsname.h}
Packit Service 82fcde
The @code{utsname} structure is used to hold information returned
Packit Service 82fcde
by the @code{uname} function.  It has the following members:
Packit Service 82fcde
Packit Service 82fcde
@table @code
Packit Service 82fcde
@item char sysname[]
Packit Service 82fcde
This is the name of the operating system in use.
Packit Service 82fcde
Packit Service 82fcde
@item char release[]
Packit Service 82fcde
This is the current release level of the operating system implementation.
Packit Service 82fcde
Packit Service 82fcde
@item char version[]
Packit Service 82fcde
This is the current version level within the release of the operating
Packit Service 82fcde
system.
Packit Service 82fcde
Packit Service 82fcde
@item char machine[]
Packit Service 82fcde
This is a description of the type of hardware that is in use.
Packit Service 82fcde
Packit Service 82fcde
Some systems provide a mechanism to interrogate the kernel directly for
Packit Service 82fcde
this information.  On systems without such a mechanism, @theglibc{}
Packit Service 82fcde
fills in this field based on the configuration name that was
Packit Service 82fcde
specified when building and installing the library.
Packit Service 82fcde
Packit Service 82fcde
GNU uses a three-part name to describe a system configuration; the three
Packit Service 82fcde
parts are @var{cpu}, @var{manufacturer} and @var{system-type}, and they
Packit Service 82fcde
are separated with dashes.  Any possible combination of three names is
Packit Service 82fcde
potentially meaningful, but most such combinations are meaningless in
Packit Service 82fcde
practice and even the meaningful ones are not necessarily supported by
Packit Service 82fcde
any particular GNU program.
Packit Service 82fcde
Packit Service 82fcde
Since the value in @code{machine} is supposed to describe just the
Packit Service 82fcde
hardware, it consists of the first two parts of the configuration name:
Packit Service 82fcde
@samp{@var{cpu}-@var{manufacturer}}.  For example, it might be one of these:
Packit Service 82fcde
Packit Service 82fcde
@quotation
Packit Service 82fcde
@code{"sparc-sun"},
Packit Service 82fcde
@code{"i386-@var{anything}"},
Packit Service 82fcde
@code{"m68k-hp"},
Packit Service 82fcde
@code{"m68k-sony"},
Packit Service 82fcde
@code{"m68k-sun"},
Packit Service 82fcde
@code{"mips-dec"}
Packit Service 82fcde
@end quotation
Packit Service 82fcde
Packit Service 82fcde
@item char nodename[]
Packit Service 82fcde
This is the host name of this particular computer.  In @theglibc{},
Packit Service 82fcde
the value is the same as that returned by @code{gethostname};
Packit Service 82fcde
see @ref{Host Identification}.
Packit Service 82fcde
Packit Service 82fcde
@code{gethostname} is implemented with a call to @code{uname}.
Packit Service 82fcde
Packit Service 82fcde
@item char domainname[]
Packit Service 82fcde
This is the NIS or YP domain name.  It is the same value returned by
Packit Service 82fcde
@code{getdomainname}; see @ref{Host Identification}.  This element
Packit Service 82fcde
is a relatively recent invention and use of it is not as portable as
Packit Service 82fcde
use of the rest of the structure.
Packit Service 82fcde
Packit Service 82fcde
@c getdomainname() is implemented with a call to uname().
Packit Service 82fcde
Packit Service 82fcde
@end table
Packit Service 82fcde
@end deftp
Packit Service 82fcde
Packit Service 82fcde
@deftypefun int uname (struct utsname *@var{info})
Packit Service 82fcde
@standards{POSIX.1, sys/utsname.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
@c Direct syscall on unix; the posix fallback is to call gethostname and
Packit Service 82fcde
@c then fills in the other fields with constants; on HURD, it calls
Packit Service 82fcde
@c proc_uname and then gethostname.
Packit Service 82fcde
The @code{uname} function fills in the structure pointed to by
Packit Service 82fcde
@var{info} with information about the operating system and host machine.
Packit Service 82fcde
A non-negative return value indicates that the data was successfully stored.
Packit Service 82fcde
Packit Service 82fcde
@code{-1} as the return value indicates an error.  The only error possible is
Packit Service 82fcde
@code{EFAULT}, which we normally don't mention as it is always a
Packit Service 82fcde
possibility.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@node Filesystem Handling
Packit Service 82fcde
@section Controlling and Querying Mounts
Packit Service 82fcde
Packit Service 82fcde
All files are in filesystems, and before you can access any file, its
Packit Service 82fcde
filesystem must be mounted.  Because of Unix's concept of
Packit Service 82fcde
@emph{Everything is a file}, mounting of filesystems is central to doing
Packit Service 82fcde
almost anything.  This section explains how to find out what filesystems
Packit Service 82fcde
are currently mounted and what filesystems are available for mounting,
Packit Service 82fcde
and how to change what is mounted.
Packit Service 82fcde
Packit Service 82fcde
The classic filesystem is the contents of a disk drive.  The concept is
Packit Service 82fcde
considerably more abstract, though, and lots of things other than disk
Packit Service 82fcde
drives can be mounted.
Packit Service 82fcde
Packit Service 82fcde
Some block devices don't correspond to traditional devices like disk
Packit Service 82fcde
drives.  For example, a loop device is a block device whose driver uses
Packit Service 82fcde
a regular file in another filesystem as its medium.  So if that regular
Packit Service 82fcde
file contains appropriate data for a filesystem, you can by mounting the
Packit Service 82fcde
loop device essentially mount a regular file.
Packit Service 82fcde
Packit Service 82fcde
Some filesystems aren't based on a device of any kind.  The ``proc''
Packit Service 82fcde
filesystem, for example, contains files whose data is made up by the
Packit Service 82fcde
filesystem driver on the fly whenever you ask for it.  And when you
Packit Service 82fcde
write to it, the data you write causes changes in the system.  No data
Packit Service 82fcde
gets stored.
Packit Service 82fcde
Packit Service 82fcde
@c It would be good to mention NFS mounts here.
Packit Service 82fcde
Packit Service 82fcde
@menu
Packit Service 82fcde
* Mount Information::           What is or could be mounted?
Packit Service 82fcde
* Mount-Unmount-Remount::       Controlling what is mounted and how
Packit Service 82fcde
@end menu
Packit Service 82fcde
Packit Service 82fcde
@node Mount Information, Mount-Unmount-Remount, , Filesystem Handling
Packit Service 82fcde
@subsection Mount Information
Packit Service 82fcde
Packit Service 82fcde
For some programs it is desirable and necessary to access information
Packit Service 82fcde
about whether a certain filesystem is mounted and, if it is, where, or
Packit Service 82fcde
simply to get lists of all the available filesystems.  @Theglibc{}
Packit Service 82fcde
provides some functions to retrieve this information portably.
Packit Service 82fcde
Packit Service 82fcde
Traditionally Unix systems have a file named @file{/etc/fstab} which
Packit Service 82fcde
describes all possibly mounted filesystems.  The @code{mount} program
Packit Service 82fcde
uses this file to mount at startup time of the system all the
Packit Service 82fcde
necessary filesystems.  The information about all the filesystems
Packit Service 82fcde
actually mounted is normally kept in a file named either
Packit Service 82fcde
@file{/var/run/mtab} or @file{/etc/mtab}.  Both files share the same
Packit Service 82fcde
syntax and it is crucial that this syntax is followed all the time.
Packit Service 82fcde
Therefore it is best to never directly write to the files.  The functions
Packit Service 82fcde
described in this section can do this and they also provide the
Packit Service 82fcde
functionality to convert the external textual representation to the
Packit Service 82fcde
internal representation.
Packit Service 82fcde
Packit Service 82fcde
Note that the @file{fstab} and @file{mtab} files are maintained on a
Packit Service 82fcde
system by @emph{convention}.  It is possible for the files not to exist
Packit Service 82fcde
or not to be consistent with what is really mounted or available to
Packit Service 82fcde
mount, if the system's administration policy allows it.  But programs
Packit Service 82fcde
that mount and unmount filesystems typically maintain and use these
Packit Service 82fcde
files as described herein.
Packit Service 82fcde
Packit Service 82fcde
@vindex _PATH_FSTAB
Packit Service 82fcde
@vindex _PATH_MNTTAB
Packit Service 82fcde
@vindex _PATH_MOUNTED
Packit Service 82fcde
@vindex FSTAB
Packit Service 82fcde
@vindex MNTTAB
Packit Service 82fcde
@vindex MOUNTED
Packit Service 82fcde
The filenames given above should never be used directly.  The portable
Packit Service 82fcde
way to handle these files is to use the macros @code{_PATH_FSTAB},
Packit Service 82fcde
defined in @file{fstab.h}, or @code{_PATH_MNTTAB}, defined in
Packit Service 82fcde
@file{mntent.h} and @file{paths.h}, for @file{fstab}; and the macro
Packit Service 82fcde
@code{_PATH_MOUNTED}, also defined in @file{mntent.h} and
Packit Service 82fcde
@file{paths.h}, for @file{mtab}.  There are also two alternate macro
Packit Service 82fcde
names @code{FSTAB}, @code{MNTTAB}, and @code{MOUNTED} defined but
Packit Service 82fcde
these names are deprecated and kept only for backward compatibility.
Packit Service 82fcde
The names @code{_PATH_MNTTAB} and @code{_PATH_MOUNTED} should always be used.
Packit Service 82fcde
Packit Service 82fcde
@menu
Packit Service 82fcde
* fstab::                       The @file{fstab} file
Packit Service 82fcde
* mtab::                        The @file{mtab} file
Packit Service 82fcde
* Other Mount Information::     Other (non-libc) sources of mount information
Packit Service 82fcde
@end menu
Packit Service 82fcde
Packit Service 82fcde
@node fstab
Packit Service 82fcde
@subsubsection The @file{fstab} file
Packit Service 82fcde
Packit Service 82fcde
The internal representation for entries of the file is @w{@code{struct
Packit Service 82fcde
fstab}}, defined in @file{fstab.h}.
Packit Service 82fcde
Packit Service 82fcde
@deftp {Data Type} {struct fstab}
Packit Service 82fcde
@standards{BSD, fstab.h}
Packit Service 82fcde
This structure is used with the @code{getfsent}, @code{getfsspec}, and
Packit Service 82fcde
@code{getfsfile} functions.
Packit Service 82fcde
Packit Service 82fcde
@table @code
Packit Service 82fcde
@item char *fs_spec
Packit Service 82fcde
This element describes the device from which the filesystem is mounted.
Packit Service 82fcde
Normally this is the name of a special device, such as a hard disk
Packit Service 82fcde
partition, but it could also be a more or less generic string.  For
Packit Service 82fcde
@dfn{NFS} it would be a hostname and directory name combination.
Packit Service 82fcde
Packit Service 82fcde
Even though the element is not declared @code{const} it shouldn't be
Packit Service 82fcde
modified.  The missing @code{const} has historic reasons, since this
Packit Service 82fcde
function predates @w{ISO C}.  The same is true for the other string
Packit Service 82fcde
elements of this structure.
Packit Service 82fcde
Packit Service 82fcde
@item char *fs_file
Packit Service 82fcde
This describes the mount point on the local system.  I.e., accessing any
Packit Service 82fcde
file in this filesystem has implicitly or explicitly this string as a
Packit Service 82fcde
prefix.
Packit Service 82fcde
Packit Service 82fcde
@item char *fs_vfstype
Packit Service 82fcde
This is the type of the filesystem.  Depending on what the underlying
Packit Service 82fcde
kernel understands it can be any string.
Packit Service 82fcde
Packit Service 82fcde
@item char *fs_mntops
Packit Service 82fcde
This is a string containing options passed to the kernel with the
Packit Service 82fcde
@code{mount} call.  Again, this can be almost anything.  There can be
Packit Service 82fcde
more than one option, separated from the others by a comma.  Each option
Packit Service 82fcde
consists of a name and an optional value part, introduced by an @code{=}
Packit Service 82fcde
character.
Packit Service 82fcde
Packit Service 82fcde
If the value of this element must be processed it should ideally be done
Packit Service 82fcde
using the @code{getsubopt} function; see @ref{Suboptions}.
Packit Service 82fcde
Packit Service 82fcde
@item const char *fs_type
Packit Service 82fcde
This name is poorly chosen.  This element points to a string (possibly
Packit Service 82fcde
in the @code{fs_mntops} string) which describes the modes with which the
Packit Service 82fcde
filesystem is mounted.  @file{fstab} defines five macros to describe the
Packit Service 82fcde
possible values:
Packit Service 82fcde
Packit Service 82fcde
@vtable @code
Packit Service 82fcde
@item FSTAB_RW
Packit Service 82fcde
The filesystem gets mounted with read and write enabled.
Packit Service 82fcde
@item FSTAB_RQ
Packit Service 82fcde
The filesystem gets mounted with read and write enabled.  Write access
Packit Service 82fcde
is restricted by quotas.
Packit Service 82fcde
@item FSTAB_RO
Packit Service 82fcde
The filesystem gets mounted read-only.
Packit Service 82fcde
@item FSTAB_SW
Packit Service 82fcde
This is not a real filesystem, it is a swap device.
Packit Service 82fcde
@item FSTAB_XX
Packit Service 82fcde
This entry from the @file{fstab} file is totally ignored.
Packit Service 82fcde
@end vtable
Packit Service 82fcde
Packit Service 82fcde
Testing for equality with these values must happen using @code{strcmp}
Packit Service 82fcde
since these are all strings.  Comparing the pointer will probably always
Packit Service 82fcde
fail.
Packit Service 82fcde
Packit Service 82fcde
@item int fs_freq
Packit Service 82fcde
This element describes the dump frequency in days.
Packit Service 82fcde
Packit Service 82fcde
@item int fs_passno
Packit Service 82fcde
This element describes the pass number on parallel dumps.  It is closely
Packit Service 82fcde
related to the @code{dump} utility used on Unix systems.
Packit Service 82fcde
@end table
Packit Service 82fcde
@end deftp
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
To read the entire content of the of the @file{fstab} file @theglibc{}
Packit Service 82fcde
contains a set of three functions which are designed in the usual way.
Packit Service 82fcde
Packit Service 82fcde
@deftypefun int setfsent (void)
Packit Service 82fcde
@standards{BSD, fstab.h}
Packit Service 82fcde
@safety{@prelim{}@mtunsafe{@mtasurace{:fsent}}@asunsafe{@ascuheap{} @asucorrupt{} @asulock{}}@acunsafe{@acucorrupt{} @aculock{} @acsmem{} @acsfd{}}}
Packit Service 82fcde
@c setfsent @mtasurace:fsent @ascuheap @asucorrupt @asulock @acucorrupt @aculock @acsmem @acsfd
Packit Service 82fcde
@c  fstab_init(1) @mtasurace:fsent @ascuheap @asucorrupt @asulock @acucorrupt @aculock @acsmem @acsfd
Packit Service 82fcde
@c   malloc dup @ascuheap @acsmem
Packit Service 82fcde
@c   rewind dup @asucorrupt @acucorrupt [no @aculock]
Packit Service 82fcde
@c   setmntent dup @ascuheap @asulock @acsmem @acsfd @aculock
Packit Service 82fcde
This function makes sure that the internal read pointer for the
Packit Service 82fcde
@file{fstab} file is at the beginning of the file.  This is done by
Packit Service 82fcde
either opening the file or resetting the read pointer.
Packit Service 82fcde
Packit Service 82fcde
Since the file handle is internal to the libc this function is not
Packit Service 82fcde
thread-safe.
Packit Service 82fcde
Packit Service 82fcde
This function returns a non-zero value if the operation was successful
Packit Service 82fcde
and the @code{getfs*} functions can be used to read the entries of the
Packit Service 82fcde
file.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun void endfsent (void)
Packit Service 82fcde
@standards{BSD, fstab.h}
Packit Service 82fcde
@safety{@prelim{}@mtunsafe{@mtasurace{:fsent}}@asunsafe{@ascuheap{} @asucorrupt{} @asulock{}}@acunsafe{@acucorrupt{} @aculock{} @acsmem{} @acsfd{}}}
Packit Service 82fcde
@c endfsent @mtasurace:fsent @ascuheap @asucorrupt @asulock @acucorrupt @aculock @acsmem @acsfd
Packit Service 82fcde
@c  endmntent dup @ascuheap @asulock @aculock @acsmem @acsfd
Packit Service 82fcde
This function makes sure that all resources acquired by a prior call to
Packit Service 82fcde
@code{setfsent} (explicitly or implicitly by calling @code{getfsent}) are
Packit Service 82fcde
freed.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun {struct fstab *} getfsent (void)
Packit Service 82fcde
@standards{BSD, fstab.h}
Packit Service 82fcde
@safety{@prelim{}@mtunsafe{@mtasurace{:fsent} @mtslocale{}}@asunsafe{@asucorrupt{} @ascuheap{} @asulock{}}@acunsafe{@acucorrupt{} @aculock{} @acsmem{}}}
Packit Service 82fcde
@c getfsent @mtasurace:fsent @mtslocale @asucorrupt @ascuheap @asulock @acucorrupt @aculock @acsmem
Packit Service 82fcde
@c  fstab_init(0) dup @mtasurace:fsent @ascuheap @asucorrupt @asulock @acucorrupt @aculock @acsmem @acsfd
Packit Service 82fcde
@c  fstab_fetch @mtasurace:fsent @mtslocale @asucorrupt @ascuheap @acucorrupt @aculock @acsmem
Packit Service 82fcde
@c   getmntent_r dup @mtslocale @asucorrupt @ascuheap @acucorrupt @aculock @acsmem
Packit Service 82fcde
@c  fstab_convert @mtasurace:fsent
Packit Service 82fcde
@c   hasmntopt dup ok
Packit Service 82fcde
This function returns the next entry of the @file{fstab} file.  If this
Packit Service 82fcde
is the first call to any of the functions handling @file{fstab} since
Packit Service 82fcde
program start or the last call of @code{endfsent}, the file will be
Packit Service 82fcde
opened.
Packit Service 82fcde
Packit Service 82fcde
The function returns a pointer to a variable of type @code{struct
Packit Service 82fcde
fstab}.  This variable is shared by all threads and therefore this
Packit Service 82fcde
function is not thread-safe.  If an error occurred @code{getfsent}
Packit Service 82fcde
returns a @code{NULL} pointer.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun {struct fstab *} getfsspec (const char *@var{name})
Packit Service 82fcde
@standards{BSD, fstab.h}
Packit Service 82fcde
@safety{@prelim{}@mtunsafe{@mtasurace{:fsent} @mtslocale{}}@asunsafe{@asucorrupt{} @ascuheap{} @asulock{}}@acunsafe{@acucorrupt{} @aculock{} @acsmem{}}}
Packit Service 82fcde
@c getffsspec @mtasurace:fsent @mtslocale @asucorrupt @ascuheap @asulock @acucorrupt @aculock @acsmem
Packit Service 82fcde
@c  fstab_init(1) dup @mtasurace:fsent @ascuheap @asucorrupt @asulock @acucorrupt @aculock @acsmem @acsfd
Packit Service 82fcde
@c  fstab_fetch dup @mtasurace:fsent @mtslocale @asucorrupt @ascuheap @acucorrupt @aculock @acsmem
Packit Service 82fcde
@c  strcmp dup ok
Packit Service 82fcde
@c  fstab_convert dup @mtasurace:fsent
Packit Service 82fcde
This function returns the next entry of the @file{fstab} file which has
Packit Service 82fcde
a string equal to @var{name} pointed to by the @code{fs_spec} element.
Packit Service 82fcde
Since there is normally exactly one entry for each special device it
Packit Service 82fcde
makes no sense to call this function more than once for the same
Packit Service 82fcde
argument.  If this is the first call to any of the functions handling
Packit Service 82fcde
@file{fstab} since program start or the last call of @code{endfsent},
Packit Service 82fcde
the file will be opened.
Packit Service 82fcde
Packit Service 82fcde
The function returns a pointer to a variable of type @code{struct
Packit Service 82fcde
fstab}.  This variable is shared by all threads and therefore this
Packit Service 82fcde
function is not thread-safe.  If an error occurred @code{getfsent}
Packit Service 82fcde
returns a @code{NULL} pointer.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun {struct fstab *} getfsfile (const char *@var{name})
Packit Service 82fcde
@standards{BSD, fstab.h}
Packit Service 82fcde
@safety{@prelim{}@mtunsafe{@mtasurace{:fsent} @mtslocale{}}@asunsafe{@asucorrupt{} @ascuheap{} @asulock{}}@acunsafe{@acucorrupt{} @aculock{} @acsmem{}}}
Packit Service 82fcde
@c getffsfile @mtasurace:fsent @mtslocale @asucorrupt @ascuheap @asulock @acucorrupt @aculock @acsmem
Packit Service 82fcde
@c  fstab_init(1) dup @mtasurace:fsent @ascuheap @asucorrupt @asulock @acucorrupt @aculock @acsmem @acsfd
Packit Service 82fcde
@c  fstab_fetch dup @mtasurace:fsent @mtslocale @asucorrupt @ascuheap @acucorrupt @aculock @acsmem
Packit Service 82fcde
@c  strcmp dup ok
Packit Service 82fcde
@c  fstab_convert dup @mtasurace:fsent
Packit Service 82fcde
This function returns the next entry of the @file{fstab} file which has
Packit Service 82fcde
a string equal to @var{name} pointed to by the @code{fs_file} element.
Packit Service 82fcde
Since there is normally exactly one entry for each mount point it
Packit Service 82fcde
makes no sense to call this function more than once for the same
Packit Service 82fcde
argument.  If this is the first call to any of the functions handling
Packit Service 82fcde
@file{fstab} since program start or the last call of @code{endfsent},
Packit Service 82fcde
the file will be opened.
Packit Service 82fcde
Packit Service 82fcde
The function returns a pointer to a variable of type @code{struct
Packit Service 82fcde
fstab}.  This variable is shared by all threads and therefore this
Packit Service 82fcde
function is not thread-safe.  If an error occurred @code{getfsent}
Packit Service 82fcde
returns a @code{NULL} pointer.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@node mtab
Packit Service 82fcde
@subsubsection The @file{mtab} file
Packit Service 82fcde
The following functions and data structure access the @file{mtab} file.
Packit Service 82fcde
Packit Service 82fcde
@deftp {Data Type} {struct mntent}
Packit Service 82fcde
@standards{BSD, mntent.h}
Packit Service 82fcde
This structure is used with the @code{getmntent}, @code{getmntent_r},
Packit Service 82fcde
@code{addmntent}, and @code{hasmntopt} functions.
Packit Service 82fcde
Packit Service 82fcde
@table @code
Packit Service 82fcde
@item char *mnt_fsname
Packit Service 82fcde
This element contains a pointer to a string describing the name of the
Packit Service 82fcde
special device from which the filesystem is mounted.  It corresponds to
Packit Service 82fcde
the @code{fs_spec} element in @code{struct fstab}.
Packit Service 82fcde
Packit Service 82fcde
@item char *mnt_dir
Packit Service 82fcde
This element points to a string describing the mount point of the
Packit Service 82fcde
filesystem.  It corresponds to the @code{fs_file} element in
Packit Service 82fcde
@code{struct fstab}.
Packit Service 82fcde
Packit Service 82fcde
@item char *mnt_type
Packit Service 82fcde
@code{mnt_type} describes the filesystem type and is therefore
Packit Service 82fcde
equivalent to @code{fs_vfstype} in @code{struct fstab}.  @file{mntent.h}
Packit Service 82fcde
defines a few symbolic names for some of the values this string can have.
Packit Service 82fcde
But since the kernel can support arbitrary filesystems it does not
Packit Service 82fcde
make much sense to give them symbolic names.  If one knows the symbol
Packit Service 82fcde
name one also knows the filesystem name.  Nevertheless here follows the
Packit Service 82fcde
list of the symbols provided in @file{mntent.h}.
Packit Service 82fcde
Packit Service 82fcde
@vtable @code
Packit Service 82fcde
@item MNTTYPE_IGNORE
Packit Service 82fcde
This symbol expands to @code{"ignore"}.  The value is sometimes used in
Packit Service 82fcde
@file{fstab} files to make sure entries are not used without removing them.
Packit Service 82fcde
@item MNTTYPE_NFS
Packit Service 82fcde
Expands to @code{"nfs"}.  Using this macro sometimes could make sense
Packit Service 82fcde
since it names the default NFS implementation, in case both version 2
Packit Service 82fcde
and 3 are supported.
Packit Service 82fcde
@item MNTTYPE_SWAP
Packit Service 82fcde
This symbol expands to @code{"swap"}.  It names the special @file{fstab}
Packit Service 82fcde
entry which names one of the possibly multiple swap partitions.
Packit Service 82fcde
@end vtable
Packit Service 82fcde
Packit Service 82fcde
@item char *mnt_opts
Packit Service 82fcde
The element contains a string describing the options used while mounting
Packit Service 82fcde
the filesystem.  As for the equivalent element @code{fs_mntops} of
Packit Service 82fcde
@code{struct fstab} it is best to use the function @code{getsubopt}
Packit Service 82fcde
(@pxref{Suboptions}) to access the parts of this string.
Packit Service 82fcde
Packit Service 82fcde
The @file{mntent.h} file defines a number of macros with string values
Packit Service 82fcde
which correspond to some of the options understood by the kernel.  There
Packit Service 82fcde
might be many more options which are possible so it doesn't make much sense
Packit Service 82fcde
to rely on these macros but to be consistent here is the list:
Packit Service 82fcde
Packit Service 82fcde
@vtable @code
Packit Service 82fcde
@item MNTOPT_DEFAULTS
Packit Service 82fcde
Expands to @code{"defaults"}.  This option should be used alone since it
Packit Service 82fcde
indicates all values for the customizable values are chosen to be the
Packit Service 82fcde
default.
Packit Service 82fcde
@item MNTOPT_RO
Packit Service 82fcde
Expands to @code{"ro"}.  See the @code{FSTAB_RO} value, it means the
Packit Service 82fcde
filesystem is mounted read-only.
Packit Service 82fcde
@item MNTOPT_RW
Packit Service 82fcde
Expands to @code{"rw"}.  See the @code{FSTAB_RW} value, it means the
Packit Service 82fcde
filesystem is mounted with read and write permissions.
Packit Service 82fcde
@item MNTOPT_SUID
Packit Service 82fcde
Expands to @code{"suid"}.  This means that the SUID bit (@pxref{How
Packit Service 82fcde
Change Persona}) is respected when a program from the filesystem is
Packit Service 82fcde
started.
Packit Service 82fcde
@item MNTOPT_NOSUID
Packit Service 82fcde
Expands to @code{"nosuid"}.  This is the opposite of @code{MNTOPT_SUID},
Packit Service 82fcde
the SUID bit for all files from the filesystem is ignored.
Packit Service 82fcde
@item MNTOPT_NOAUTO
Packit Service 82fcde
Expands to @code{"noauto"}.  At startup time the @code{mount} program
Packit Service 82fcde
will ignore this entry if it is started with the @code{-a} option to
Packit Service 82fcde
mount all filesystems mentioned in the @file{fstab} file.
Packit Service 82fcde
@end vtable
Packit Service 82fcde
Packit Service 82fcde
As for the @code{FSTAB_*} entries introduced above it is important to
Packit Service 82fcde
use @code{strcmp} to check for equality.
Packit Service 82fcde
Packit Service 82fcde
@item mnt_freq
Packit Service 82fcde
This elements corresponds to @code{fs_freq} and also specifies the
Packit Service 82fcde
frequency in days in which dumps are made.
Packit Service 82fcde
Packit Service 82fcde
@item mnt_passno
Packit Service 82fcde
This element is equivalent to @code{fs_passno} with the same meaning
Packit Service 82fcde
which is uninteresting for all programs beside @code{dump}.
Packit Service 82fcde
@end table
Packit Service 82fcde
@end deftp
Packit Service 82fcde
Packit Service 82fcde
For accessing the @file{mtab} file there is again a set of three
Packit Service 82fcde
functions to access all entries in a row.  Unlike the functions to
Packit Service 82fcde
handle @file{fstab} these functions do not access a fixed file and there
Packit Service 82fcde
is even a thread safe variant of the get function.  Besides this @theglibc{}
Packit Service 82fcde
contains functions to alter the file and test for specific options.
Packit Service 82fcde
Packit Service 82fcde
@deftypefun {FILE *} setmntent (const char *@var{file}, const char *@var{mode})
Packit Service 82fcde
@standards{BSD, mntent.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@asunsafe{@ascuheap{} @asulock{}}@acunsafe{@acsmem{} @acsfd{} @aculock{}}}
Packit Service 82fcde
@c setmntent @ascuheap @asulock @acsmem @acsfd @aculock
Packit Service 82fcde
@c  strlen dup ok
Packit Service 82fcde
@c  mempcpy dup ok
Packit Service 82fcde
@c  memcpy dup ok
Packit Service 82fcde
@c  fopen dup @ascuheap @asulock @acsmem @acsfd @aculock
Packit Service 82fcde
@c  fsetlocking dup ok [no @mtasurace:stream @asulock: exclusive stream]
Packit Service 82fcde
The @code{setmntent} function prepares the file named @var{FILE} which
Packit Service 82fcde
must be in the format of a @file{fstab} and @file{mtab} file for the
Packit Service 82fcde
upcoming processing through the other functions of the family.  The
Packit Service 82fcde
@var{mode} parameter can be chosen in the way the @var{opentype}
Packit Service 82fcde
parameter for @code{fopen} (@pxref{Opening Streams}) can be chosen.  If
Packit Service 82fcde
the file is opened for writing the file is also allowed to be empty.
Packit Service 82fcde
Packit Service 82fcde
If the file was successfully opened @code{setmntent} returns a file
Packit Service 82fcde
handle for future use.  Otherwise the return value is @code{NULL}
Packit Service 82fcde
and @code{errno} is set accordingly.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun int endmntent (FILE *@var{stream})
Packit Service 82fcde
@standards{BSD, mntent.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@asunsafe{@ascuheap{} @asulock{}}@acunsafe{@aculock{} @acsmem{} @acsfd{}}}
Packit Service 82fcde
@c endmntent @ascuheap @asulock @aculock @acsmem @acsfd
Packit Service 82fcde
@c  fclose dup @ascuheap @asulock @aculock @acsmem @acsfd
Packit Service 82fcde
This function takes for the @var{stream} parameter a file handle which
Packit Service 82fcde
previously was returned from the @code{setmntent} call.
Packit Service 82fcde
@code{endmntent} closes the stream and frees all resources.
Packit Service 82fcde
Packit Service 82fcde
The return value is @math{1} unless an error occurred in which case it
Packit Service 82fcde
is @math{0}.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun {struct mntent *} getmntent (FILE *@var{stream})
Packit Service 82fcde
@standards{BSD, mntent.h}
Packit Service 82fcde
@safety{@prelim{}@mtunsafe{@mtasurace{:mntentbuf} @mtslocale{}}@asunsafe{@asucorrupt{} @ascuheap{} @asuinit{}}@acunsafe{@acuinit{} @acucorrupt{} @aculock{} @acsmem{}}}
Packit Service 82fcde
@c getmntent @mtasurace:mntentbuf @mtslocale @asucorrupt @ascuheap @asuinit @acuinit @acucorrupt @aculock @acsmem
Packit Service 82fcde
@c  libc_once @ascuheap @asuinit @acuinit @acsmem
Packit Service 82fcde
@c   allocate @ascuheap @acsmem
Packit Service 82fcde
@c    malloc dup @ascuheap @acsmem
Packit Service 82fcde
@c  getmntent_r dup @mtslocale @asucorrupt @ascuheap @acucorrupt @aculock @acsmem
Packit Service 82fcde
The @code{getmntent} function takes as the parameter a file handle
Packit Service 82fcde
previously returned by a successful call to @code{setmntent}.  It returns
Packit Service 82fcde
a pointer to a static variable of type @code{struct mntent} which is
Packit Service 82fcde
filled with the information from the next entry from the file currently
Packit Service 82fcde
read.
Packit Service 82fcde
Packit Service 82fcde
The file format used prescribes the use of spaces or tab characters to
Packit Service 82fcde
separate the fields.  This makes it harder to use names containing one
Packit Service 82fcde
of these characters (e.g., mount points using spaces).  Therefore
Packit Service 82fcde
these characters are encoded in the files and the @code{getmntent}
Packit Service 82fcde
function takes care of the decoding while reading the entries back in.
Packit Service 82fcde
@code{'\040'} is used to encode a space character, @code{'\011'} to
Packit Service 82fcde
encode a tab character, @code{'\012'} to encode a newline character,
Packit Service 82fcde
and @code{'\\'} to encode a backslash.
Packit Service 82fcde
Packit Service 82fcde
If there was an error or the end of the file is reached the return value
Packit Service 82fcde
is @code{NULL}.
Packit Service 82fcde
Packit Service 82fcde
This function is not thread-safe since all calls to this function return
Packit Service 82fcde
a pointer to the same static variable.  @code{getmntent_r} should be
Packit Service 82fcde
used in situations where multiple threads access the file.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun {struct mntent *} getmntent_r (FILE *@var{stream}, struct mntent *@var{result}, char *@var{buffer}, int @var{bufsize})
Packit Service 82fcde
@standards{BSD, mntent.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{@mtslocale{}}@asunsafe{@asucorrupt{} @ascuheap{}}@acunsafe{@acucorrupt{} @aculock{} @acsmem{}}}
Packit Service 82fcde
@c getmntent_r @mtslocale @asucorrupt @ascuheap @acucorrupt @aculock @acsmem
Packit Service 82fcde
@c  flockfile dup @aculock
Packit Service 82fcde
@c  fgets_unlocked dup @asucorrupt @acucorrupt [locked, so no @mtsrace:stream]
Packit Service 82fcde
@c  funlockfile dup @aculock
Packit Service 82fcde
@c  strchr dup ok
Packit Service 82fcde
@c  strspn dup ok
Packit Service 82fcde
@c  strsep dup ok
Packit Service 82fcde
@c  decode_name ok
Packit Service 82fcde
@c  sscanf dup @mtslocale @ascuheap @acsmem
Packit Service 82fcde
The @code{getmntent_r} function is the reentrant variant of
Packit Service 82fcde
@code{getmntent}.  It also returns the next entry from the file and
Packit Service 82fcde
returns a pointer.  The actual variable the values are stored in is not
Packit Service 82fcde
static, though.  Instead the function stores the values in the variable
Packit Service 82fcde
pointed to by the @var{result} parameter.  Additional information (e.g.,
Packit Service 82fcde
the strings pointed to by the elements of the result) are kept in the
Packit Service 82fcde
buffer of size @var{bufsize} pointed to by @var{buffer}.
Packit Service 82fcde
Packit Service 82fcde
Escaped characters (space, tab, backslash) are converted back in the
Packit Service 82fcde
same way as it happens for @code{getmentent}.
Packit Service 82fcde
Packit Service 82fcde
The function returns a @code{NULL} pointer in error cases.  Errors could be:
Packit Service 82fcde
@itemize @bullet
Packit Service 82fcde
@item
Packit Service 82fcde
error while reading the file,
Packit Service 82fcde
@item
Packit Service 82fcde
end of file reached,
Packit Service 82fcde
@item
Packit Service 82fcde
@var{bufsize} is too small for reading a complete new entry.
Packit Service 82fcde
@end itemize
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun int addmntent (FILE *@var{stream}, const struct mntent *@var{mnt})
Packit Service 82fcde
@standards{BSD, mntent.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{@mtsrace{:stream} @mtslocale{}}@asunsafe{@asucorrupt{}}@acunsafe{@acucorrupt{}}}
Packit Service 82fcde
@c addmntent @mtasurace:stream @mtslocale @asucorrupt @acucorrupt
Packit Service 82fcde
@c  fseek dup @asucorrupt @acucorrupt [no @aculock]
Packit Service 82fcde
@c  encode_name ok
Packit Service 82fcde
@c  fprintf dup @mtslocale @asucorrupt @acucorrupt [no @ascuheap @acsmem, no @aculock]
Packit Service 82fcde
@c  fflush dup @asucorrupt @acucorrupt [no @aculock]
Packit Service 82fcde
The @code{addmntent} function allows adding a new entry to the file
Packit Service 82fcde
previously opened with @code{setmntent}.  The new entries are always
Packit Service 82fcde
appended.  I.e., even if the position of the file descriptor is not at
Packit Service 82fcde
the end of the file this function does not overwrite an existing entry
Packit Service 82fcde
following the current position.
Packit Service 82fcde
Packit Service 82fcde
The implication of this is that to remove an entry from a file one has
Packit Service 82fcde
to create a new file while leaving out the entry to be removed and after
Packit Service 82fcde
closing the file remove the old one and rename the new file to the
Packit Service 82fcde
chosen name.
Packit Service 82fcde
Packit Service 82fcde
This function takes care of spaces and tab characters in the names to be
Packit Service 82fcde
written to the file.  It converts them and the backslash character into
Packit Service 82fcde
the format described in the @code{getmntent} description above.
Packit Service 82fcde
Packit Service 82fcde
This function returns @math{0} in case the operation was successful.
Packit Service 82fcde
Otherwise the return value is @math{1} and @code{errno} is set
Packit Service 82fcde
appropriately.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun {char *} hasmntopt (const struct mntent *@var{mnt}, const char *@var{opt})
Packit Service 82fcde
@standards{BSD, mntent.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
@c hasmntopt ok
Packit Service 82fcde
@c  strlen dup ok
Packit Service 82fcde
@c  strstr dup ok
Packit Service 82fcde
@c  strchr dup ok
Packit Service 82fcde
This function can be used to check whether the string pointed to by the
Packit Service 82fcde
@code{mnt_opts} element of the variable pointed to by @var{mnt} contains
Packit Service 82fcde
the option @var{opt}.  If this is true a pointer to the beginning of the
Packit Service 82fcde
option in the @code{mnt_opts} element is returned.  If no such option
Packit Service 82fcde
exists the function returns @code{NULL}.
Packit Service 82fcde
Packit Service 82fcde
This function is useful to test whether a specific option is present but
Packit Service 82fcde
when all options have to be processed one is better off with using the
Packit Service 82fcde
@code{getsubopt} function to iterate over all options in the string.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@node Other Mount Information
Packit Service 82fcde
@subsubsection Other (Non-libc) Sources of Mount Information
Packit Service 82fcde
Packit Service 82fcde
On a system with a Linux kernel and the @code{proc} filesystem, you can
Packit Service 82fcde
get information on currently mounted filesystems from the file
Packit Service 82fcde
@file{mounts} in the @code{proc} filesystem.  Its format is similar to
Packit Service 82fcde
that of the @file{mtab} file, but represents what is truly mounted
Packit Service 82fcde
without relying on facilities outside the kernel to keep @file{mtab} up
Packit Service 82fcde
to date.
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@node Mount-Unmount-Remount, , Mount Information, Filesystem Handling
Packit Service 82fcde
@subsection Mount, Unmount, Remount
Packit Service 82fcde
Packit Service 82fcde
This section describes the functions for mounting, unmounting, and
Packit Service 82fcde
remounting filesystems.
Packit Service 82fcde
Packit Service 82fcde
Only the superuser can mount, unmount, or remount a filesystem.
Packit Service 82fcde
Packit Service 82fcde
These functions do not access the @file{fstab} and @file{mtab} files.  You
Packit Service 82fcde
should maintain and use these separately.  @xref{Mount Information}.
Packit Service 82fcde
Packit Service 82fcde
The symbols in this section are declared in @file{sys/mount.h}.
Packit Service 82fcde
Packit Service 82fcde
@deftypefun {int} mount (const char *@var{special_file}, const char *@var{dir}, const char *@var{fstype}, unsigned long int @var{options}, const void *@var{data})
Packit Service 82fcde
@standards{SVID, sys/mount.h}
Packit Service 82fcde
@standards{BSD, sys/mount.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
@c Direct syscall.
Packit Service 82fcde
Packit Service 82fcde
@code{mount} mounts or remounts a filesystem.  The two operations are
Packit Service 82fcde
quite different and are merged rather unnaturally into this one function.
Packit Service 82fcde
The @code{MS_REMOUNT} option, explained below, determines whether
Packit Service 82fcde
@code{mount} mounts or remounts.
Packit Service 82fcde
Packit Service 82fcde
For a mount, the filesystem on the block device represented by the
Packit Service 82fcde
device special file named @var{special_file} gets mounted over the mount
Packit Service 82fcde
point @var{dir}.  This means that the directory @var{dir} (along with any
Packit Service 82fcde
files in it) is no longer visible; in its place (and still with the name
Packit Service 82fcde
@var{dir}) is the root directory of the filesystem on the device.
Packit Service 82fcde
Packit Service 82fcde
As an exception, if the filesystem type (see below) is one which is not
Packit Service 82fcde
based on a device (e.g. ``proc''), @code{mount} instantiates a
Packit Service 82fcde
filesystem and mounts it over @var{dir} and ignores @var{special_file}.
Packit Service 82fcde
Packit Service 82fcde
For a remount, @var{dir} specifies the mount point where the filesystem
Packit Service 82fcde
to be remounted is (and remains) mounted and @var{special_file} is
Packit Service 82fcde
ignored.  Remounting a filesystem means changing the options that control
Packit Service 82fcde
operations on the filesystem while it is mounted.  It does not mean
Packit Service 82fcde
unmounting and mounting again.
Packit Service 82fcde
Packit Service 82fcde
For a mount, you must identify the type of the filesystem with
Packit Service 82fcde
@var{fstype}.  This type tells the kernel how to access the filesystem
Packit Service 82fcde
and can be thought of as the name of a filesystem driver.  The
Packit Service 82fcde
acceptable values are system dependent.  On a system with a Linux kernel
Packit Service 82fcde
and the @code{proc} filesystem, the list of possible values is in the
Packit Service 82fcde
file @file{filesystems} in the @code{proc} filesystem (e.g. type
Packit Service 82fcde
@kbd{cat /proc/filesystems} to see the list).  With a Linux kernel, the
Packit Service 82fcde
types of filesystems that @code{mount} can mount, and their type names,
Packit Service 82fcde
depends on what filesystem drivers are configured into the kernel or
Packit Service 82fcde
loaded as loadable kernel modules.  An example of a common value for
Packit Service 82fcde
@var{fstype} is @code{ext2}.
Packit Service 82fcde
Packit Service 82fcde
For a remount, @code{mount} ignores @var{fstype}.
Packit Service 82fcde
Packit Service 82fcde
@c This is traditionally called "rwflag" for historical reasons.
Packit Service 82fcde
@c No point in confusing people today, though.
Packit Service 82fcde
@var{options} specifies a variety of options that apply until the
Packit Service 82fcde
filesystem is unmounted or remounted.  The precise meaning of an option
Packit Service 82fcde
depends on the filesystem and with some filesystems, an option may have
Packit Service 82fcde
no effect at all.  Furthermore, for some filesystems, some of these
Packit Service 82fcde
options (but never @code{MS_RDONLY}) can be overridden for individual
Packit Service 82fcde
file accesses via @code{ioctl}.
Packit Service 82fcde
Packit Service 82fcde
@var{options} is a bit string with bit fields defined using the
Packit Service 82fcde
following mask and masked value macros:
Packit Service 82fcde
Packit Service 82fcde
@vtable @code
Packit Service 82fcde
@item MS_MGC_MASK
Packit Service 82fcde
This multibit field contains a magic number.  If it does not have the value
Packit Service 82fcde
@code{MS_MGC_VAL}, @code{mount} assumes all the following bits are zero and
Packit Service 82fcde
the @var{data} argument is a null string, regardless of their actual values.
Packit Service 82fcde
Packit Service 82fcde
@item MS_REMOUNT
Packit Service 82fcde
This bit on means to remount the filesystem.  Off means to mount it.
Packit Service 82fcde
@c There is a mask MS_RMT_MASK in mount.h that says only two of the options
Packit Service 82fcde
@c can be reset by remount.  But the Linux kernel has its own version of
Packit Service 82fcde
@c MS_RMT_MASK that says they all can be reset.  As far as I can tell,
Packit Service 82fcde
@c libc just passes the arguments straight through to the kernel.
Packit Service 82fcde
Packit Service 82fcde
@item MS_RDONLY
Packit Service 82fcde
This bit on specifies that no writing to the filesystem shall be allowed
Packit Service 82fcde
while it is mounted.  This cannot be overridden by @code{ioctl}.  This
Packit Service 82fcde
option is available on nearly all filesystems.
Packit Service 82fcde
Packit Service 82fcde
@item MS_NOSUID
Packit Service 82fcde
This bit on specifies that Setuid and Setgid permissions on files in the
Packit Service 82fcde
filesystem shall be ignored while it is mounted.
Packit Service 82fcde
Packit Service 82fcde
@item MS_NOEXEC
Packit Service 82fcde
This bit on specifies that no files in the filesystem shall be executed
Packit Service 82fcde
while the filesystem is mounted.
Packit Service 82fcde
Packit Service 82fcde
@item MS_NODEV
Packit Service 82fcde
This bit on specifies that no device special files in the filesystem
Packit Service 82fcde
shall be accessible while the filesystem is mounted.
Packit Service 82fcde
Packit Service 82fcde
@item MS_SYNCHRONOUS
Packit Service 82fcde
This bit on specifies that all writes to the filesystem while it is
Packit Service 82fcde
mounted shall be synchronous; i.e., data shall be synced before each
Packit Service 82fcde
write completes rather than held in the buffer cache.
Packit Service 82fcde
Packit Service 82fcde
@item MS_MANDLOCK
Packit Service 82fcde
This bit on specifies that mandatory locks on files shall be permitted while
Packit Service 82fcde
the filesystem is mounted.
Packit Service 82fcde
Packit Service 82fcde
@item MS_NOATIME
Packit Service 82fcde
This bit on specifies that access times of files shall not be updated when
Packit Service 82fcde
the files are accessed while the filesystem is mounted.
Packit Service 82fcde
Packit Service 82fcde
@item MS_NODIRATIME
Packit Service 82fcde
This bit on specifies that access times of directories shall not be updated
Packit Service 82fcde
when the directories are accessed while the filesystem in mounted.
Packit Service 82fcde
Packit Service 82fcde
@c there is also S_QUOTA Linux fs.h (mount.h still uses its former name
Packit Service 82fcde
@c S_WRITE), but I can't see what it does.  Turns on quotas, I guess.
Packit Service 82fcde
Packit Service 82fcde
@end vtable
Packit Service 82fcde
Packit Service 82fcde
Any bits not covered by the above masks should be set off; otherwise,
Packit Service 82fcde
results are undefined.
Packit Service 82fcde
Packit Service 82fcde
The meaning of @var{data} depends on the filesystem type and is controlled
Packit Service 82fcde
entirely by the filesystem driver in the kernel.
Packit Service 82fcde
Packit Service 82fcde
Example:
Packit Service 82fcde
Packit Service 82fcde
@smallexample
Packit Service 82fcde
@group
Packit Service 82fcde
#include <sys/mount.h>
Packit Service 82fcde
Packit Service 82fcde
mount("/dev/hdb", "/cdrom", MS_MGC_VAL | MS_RDONLY | MS_NOSUID, "");
Packit Service 82fcde
Packit Service 82fcde
mount("/dev/hda2", "/mnt", MS_MGC_VAL | MS_REMOUNT, "");
Packit Service 82fcde
Packit Service 82fcde
@end group
Packit Service 82fcde
@end smallexample
Packit Service 82fcde
Packit Service 82fcde
Appropriate arguments for @code{mount} are conventionally recorded in
Packit Service 82fcde
the @file{fstab} table.  @xref{Mount Information}.
Packit Service 82fcde
Packit Service 82fcde
The return value is zero if the mount or remount is successful.  Otherwise,
Packit Service 82fcde
it is @code{-1} and @code{errno} is set appropriately.  The values of
Packit Service 82fcde
@code{errno} are filesystem dependent, but here is a general list:
Packit Service 82fcde
Packit Service 82fcde
@table @code
Packit Service 82fcde
@item EPERM
Packit Service 82fcde
The process is not superuser.
Packit Service 82fcde
@item ENODEV
Packit Service 82fcde
The file system type @var{fstype} is not known to the kernel.
Packit Service 82fcde
@item ENOTBLK
Packit Service 82fcde
The file @var{dev} is not a block device special file.
Packit Service 82fcde
@item EBUSY
Packit Service 82fcde
Packit Service 82fcde
@itemize @bullet
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
The device is already mounted.
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
The mount point is busy.  (E.g. it is some process' working directory or
Packit Service 82fcde
has a filesystem mounted on it already).
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
The request is to remount read-only, but there are files open for writing.
Packit Service 82fcde
@end itemize
Packit Service 82fcde
Packit Service 82fcde
@item EINVAL
Packit Service 82fcde
@itemize @bullet
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
A remount was attempted, but there is no filesystem mounted over the
Packit Service 82fcde
specified mount point.
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
The supposed filesystem has an invalid superblock.
Packit Service 82fcde
Packit Service 82fcde
@end itemize
Packit Service 82fcde
Packit Service 82fcde
@item EACCES
Packit Service 82fcde
@itemize @bullet
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
The filesystem is inherently read-only (possibly due to a switch on the
Packit Service 82fcde
device) and the process attempted to mount it read/write (by setting the
Packit Service 82fcde
@code{MS_RDONLY} bit off).
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
@var{special_file} or @var{dir} is not accessible due to file permissions.
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
@var{special_file} is not accessible because it is in a filesystem that is
Packit Service 82fcde
mounted with the @code{MS_NODEV} option.
Packit Service 82fcde
Packit Service 82fcde
@end itemize
Packit Service 82fcde
Packit Service 82fcde
@item EM_FILE
Packit Service 82fcde
The table of dummy devices is full.  @code{mount} needs to create a
Packit Service 82fcde
dummy device (aka ``unnamed'' device) if the filesystem being mounted is
Packit Service 82fcde
not one that uses a device.
Packit Service 82fcde
Packit Service 82fcde
@end table
Packit Service 82fcde
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@deftypefun {int} umount2 (const char *@var{file}, int @var{flags})
Packit Service 82fcde
@standards{GNU, sys/mount.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
@c Direct syscall.
Packit Service 82fcde
Packit Service 82fcde
@code{umount2} unmounts a filesystem.
Packit Service 82fcde
Packit Service 82fcde
You can identify the filesystem to unmount either by the device special
Packit Service 82fcde
file that contains the filesystem or by the mount point.  The effect is
Packit Service 82fcde
the same.  Specify either as the string @var{file}.
Packit Service 82fcde
Packit Service 82fcde
@var{flags} contains the one-bit field identified by the following
Packit Service 82fcde
mask macro:
Packit Service 82fcde
Packit Service 82fcde
@vtable @code
Packit Service 82fcde
Packit Service 82fcde
@item MNT_FORCE
Packit Service 82fcde
This bit on means to force the unmounting even if the filesystem is
Packit Service 82fcde
busy, by making it unbusy first.  If the bit is off and the filesystem is
Packit Service 82fcde
busy, @code{umount2} fails with @code{errno} = @code{EBUSY}.  Depending
Packit Service 82fcde
on the filesystem, this may override all, some, or no busy conditions.
Packit Service 82fcde
Packit Service 82fcde
@end vtable
Packit Service 82fcde
Packit Service 82fcde
All other bits in @var{flags} should be set to zero; otherwise, the result
Packit Service 82fcde
is undefined.
Packit Service 82fcde
Packit Service 82fcde
Example:
Packit Service 82fcde
Packit Service 82fcde
@smallexample
Packit Service 82fcde
@group
Packit Service 82fcde
#include <sys/mount.h>
Packit Service 82fcde
Packit Service 82fcde
umount2("/mnt", MNT_FORCE);
Packit Service 82fcde
Packit Service 82fcde
umount2("/dev/hdd1", 0);
Packit Service 82fcde
Packit Service 82fcde
@end group
Packit Service 82fcde
@end smallexample
Packit Service 82fcde
Packit Service 82fcde
After the filesystem is unmounted, the directory that was the mount point
Packit Service 82fcde
is visible, as are any files in it.
Packit Service 82fcde
Packit Service 82fcde
As part of unmounting, @code{umount2} syncs the filesystem.
Packit Service 82fcde
Packit Service 82fcde
If the unmounting is successful, the return value is zero.  Otherwise, it
Packit Service 82fcde
is @code{-1} and @code{errno} is set accordingly:
Packit Service 82fcde
Packit Service 82fcde
@table @code
Packit Service 82fcde
@item EPERM
Packit Service 82fcde
The process is not superuser.
Packit Service 82fcde
@item EBUSY
Packit Service 82fcde
The filesystem cannot be unmounted because it is busy.  E.g. it contains
Packit Service 82fcde
a directory that is some process's working directory or a file that some
Packit Service 82fcde
process has open.  With some filesystems in some cases, you can avoid
Packit Service 82fcde
this failure with the @code{MNT_FORCE} option.
Packit Service 82fcde
Packit Service 82fcde
@item EINVAL
Packit Service 82fcde
@var{file} validly refers to a file, but that file is neither a mount
Packit Service 82fcde
point nor a device special file of a currently mounted filesystem.
Packit Service 82fcde
Packit Service 82fcde
@end table
Packit Service 82fcde
Packit Service 82fcde
This function is not available on all systems.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
@deftypefun {int} umount (const char *@var{file})
Packit Service 82fcde
@standards{SVID, sys/mount.h}
Packit Service 82fcde
@standards{GNU, sys/mount.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
@c Direct syscall or wrapper for umount2.
Packit Service 82fcde
Packit Service 82fcde
@code{umount} does the same thing as @code{umount2} with @var{flags} set
Packit Service 82fcde
to zeroes.  It is more widely available than @code{umount2} but since it
Packit Service 82fcde
lacks the possibility to forcefully unmount a filesystem is deprecated
Packit Service 82fcde
when @code{umount2} is also available.
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@node System Parameters
Packit Service 82fcde
@section System Parameters
Packit Service 82fcde
Packit Service 82fcde
This section describes the @code{sysctl} function, which gets and sets
Packit Service 82fcde
a variety of system parameters.
Packit Service 82fcde
Packit Service 82fcde
The symbols used in this section are declared in the file @file{sys/sysctl.h}.
Packit Service 82fcde
Packit Service 82fcde
@deftypefun int sysctl (int *@var{names}, int @var{nlen}, void *@var{oldval}, size_t *@var{oldlenp}, void *@var{newval}, size_t @var{newlen})
Packit Service 82fcde
@standards{BSD, sys/sysctl.h}
Packit Service 82fcde
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
@c Direct syscall, Linux only.
Packit Service 82fcde
Packit Service 82fcde
@code{sysctl} gets or sets a specified system parameter.  There are so
Packit Service 82fcde
many of these parameters that it is not practical to list them all here,
Packit Service 82fcde
but here are some examples:
Packit Service 82fcde
Packit Service 82fcde
@itemize @bullet
Packit Service 82fcde
@item network domain name
Packit Service 82fcde
@item paging parameters
Packit Service 82fcde
@item network Address Resolution Protocol timeout time
Packit Service 82fcde
@item maximum number of files that may be open
Packit Service 82fcde
@item root filesystem device
Packit Service 82fcde
@item when kernel was built
Packit Service 82fcde
@end itemize
Packit Service 82fcde
Packit Service 82fcde
The set of available parameters depends on the kernel configuration and
Packit Service 82fcde
can change while the system is running, particularly when you load and
Packit Service 82fcde
unload loadable kernel modules.
Packit Service 82fcde
Packit Service 82fcde
The system parameters with which @code{sysctl} is concerned are arranged
Packit Service 82fcde
in a hierarchical structure like a hierarchical filesystem.  To identify
Packit Service 82fcde
a particular parameter, you specify a path through the structure in a
Packit Service 82fcde
way analogous to specifying the pathname of a file.  Each component of
Packit Service 82fcde
the path is specified by an integer and each of these integers has a
Packit Service 82fcde
macro defined for it by @file{sys/sysctl.h}.  @var{names} is the path, in
Packit Service 82fcde
the form of an array of integers.  Each component of the path is one
Packit Service 82fcde
element of the array, in order.  @var{nlen} is the number of components
Packit Service 82fcde
in the path.
Packit Service 82fcde
Packit Service 82fcde
For example, the first component of the path for all the paging
Packit Service 82fcde
parameters is the value @code{CTL_VM}.  For the free page thresholds, the
Packit Service 82fcde
second component of the path is @code{VM_FREEPG}.  So to get the free
Packit Service 82fcde
page threshold values, make @var{names} an array containing the two
Packit Service 82fcde
elements @code{CTL_VM} and @code{VM_FREEPG} and make @var{nlen} = 2.
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
The format of the value of a parameter depends on the parameter.
Packit Service 82fcde
Sometimes it is an integer; sometimes it is an ASCII string; sometimes
Packit Service 82fcde
it is an elaborate structure.  In the case of the free page thresholds
Packit Service 82fcde
used in the example above, the parameter value is a structure containing
Packit Service 82fcde
several integers.
Packit Service 82fcde
Packit Service 82fcde
In any case, you identify a place to return the parameter's value with
Packit Service 82fcde
@var{oldval} and specify the amount of storage available at that
Packit Service 82fcde
location as *@var{oldlenp}.  *@var{oldlenp} does double duty because it
Packit Service 82fcde
is also the output location that contains the actual length of the
Packit Service 82fcde
returned value.
Packit Service 82fcde
Packit Service 82fcde
If you don't want the parameter value returned, specify a null pointer
Packit Service 82fcde
for @var{oldval}.
Packit Service 82fcde
Packit Service 82fcde
To set the parameter, specify the address and length of the new value
Packit Service 82fcde
as @var{newval} and @var{newlen}.  If you don't want to set the parameter,
Packit Service 82fcde
specify a null pointer as @var{newval}.
Packit Service 82fcde
Packit Service 82fcde
If you get and set a parameter in the same @code{sysctl} call, the value
Packit Service 82fcde
returned is the value of the parameter before it was set.
Packit Service 82fcde
Packit Service 82fcde
Each system parameter has a set of permissions similar to the
Packit Service 82fcde
permissions for a file (including the permissions on directories in its
Packit Service 82fcde
path) that determine whether you may get or set it.  For the purposes of
Packit Service 82fcde
these permissions, every parameter is considered to be owned by the
Packit Service 82fcde
superuser and Group 0 so processes with that effective uid or gid may
Packit Service 82fcde
have more access to system parameters.  Unlike with files, the superuser
Packit Service 82fcde
does not invariably have full permission to all system parameters, because
Packit Service 82fcde
some of them are designed not to be changed ever.
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@code{sysctl} returns a zero return value if it succeeds.  Otherwise, it
Packit Service 82fcde
returns @code{-1} and sets @code{errno} appropriately.  Besides the
Packit Service 82fcde
failures that apply to all system calls, the following are the
Packit Service 82fcde
@code{errno} codes for all possible failures:
Packit Service 82fcde
Packit Service 82fcde
@table @code
Packit Service 82fcde
@item EPERM
Packit Service 82fcde
The process is not permitted to access one of the components of the
Packit Service 82fcde
path of the system parameter or is not permitted to access the system parameter
Packit Service 82fcde
itself in the way (read or write) that it requested.
Packit Service 82fcde
@c There is some indication in the Linux 2.2 code that the code is trying to
Packit Service 82fcde
@c return EACCES here, but the EACCES value never actually makes it to the
Packit Service 82fcde
@c user.
Packit Service 82fcde
@item ENOTDIR
Packit Service 82fcde
There is no system parameter corresponding to @var{name}.
Packit Service 82fcde
@item EFAULT
Packit Service 82fcde
@var{oldval} is not null, which means the process wanted to read the parameter,
Packit Service 82fcde
but *@var{oldlenp} is zero, so there is no place to return it.
Packit Service 82fcde
@item EINVAL
Packit Service 82fcde
@itemize @bullet
Packit Service 82fcde
@item
Packit Service 82fcde
The process attempted to set a system parameter to a value that is not valid
Packit Service 82fcde
for that parameter.
Packit Service 82fcde
@item
Packit Service 82fcde
The space provided for the return of the system parameter is not the right
Packit Service 82fcde
size for that parameter.
Packit Service 82fcde
@end itemize
Packit Service 82fcde
@item ENOMEM
Packit Service 82fcde
This value may be returned instead of the more correct @code{EINVAL} in some
Packit Service 82fcde
cases where the space provided for the return of the system parameter is too
Packit Service 82fcde
small.
Packit Service 82fcde
Packit Service 82fcde
@end table
Packit Service 82fcde
Packit Service 82fcde
@end deftypefun
Packit Service 82fcde
Packit Service 82fcde
If you have a Linux kernel with the @code{proc} filesystem, you can get
Packit Service 82fcde
and set most of the same parameters by reading and writing to files in
Packit Service 82fcde
the @code{sys} directory of the @code{proc} filesystem.  In the @code{sys}
Packit Service 82fcde
directory, the directory structure represents the hierarchical structure
Packit Service 82fcde
of the parameters.  E.g. you can display the free page thresholds with
Packit Service 82fcde
@smallexample
Packit Service 82fcde
cat /proc/sys/vm/freepages
Packit Service 82fcde
@end smallexample
Packit Service 82fcde
@c In Linux, the sysctl() and /proc instances of the parameter are created
Packit Service 82fcde
@c together.  The proc filesystem accesses the same data structure as
Packit Service 82fcde
@c sysctl(), which has special fields in it for /proc.  But it is still
Packit Service 82fcde
@c possible to create a sysctl-only parameter.
Packit Service 82fcde
Packit Service 82fcde
Some more traditional and more widely available, though less general,
Packit Service 82fcde
@glibcadj{} functions for getting and setting some of the same system
Packit Service 82fcde
parameters are:
Packit Service 82fcde
Packit Service 82fcde
@itemize @bullet
Packit Service 82fcde
@item
Packit Service 82fcde
@code{getdomainname}, @code{setdomainname}
Packit Service 82fcde
@item
Packit Service 82fcde
@code{gethostname}, @code{sethostname} (@xref{Host Identification}.)
Packit Service 82fcde
@item
Packit Service 82fcde
@code{uname} (@xref{Platform Type}.)
Packit Service 82fcde
@end itemize