This is libc.info, produced by makeinfo version 4.0 from libc.texinfo.

INFO-DIR-SECTION GNU libraries
START-INFO-DIR-ENTRY
* Libc: (libc).                 C library.
END-INFO-DIR-ENTRY

   This file documents the GNU C library.

   This is Edition 0.09 DRAFT, last updated 28 Aug 1999, of `The GNU C
Library Reference Manual', for Version 2.2 Beta.

   Copyright (C) 1993, '94, '95, '96, '97, '98, '99 Free Software
Foundation, Inc.

   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 also
that the section entitled "GNU Library General Public License" is
included exactly as in the original, and provided that the entire
resulting derived work is distributed under the terms of a permission
notice identical to this one.

   Permission is granted to copy and distribute translations of this
manual into another language, under the above conditions for modified
versions, except that the text of the translation of the section
entitled "GNU Library General Public License" must be approved for
accuracy by the Foundation.


File: libc.info,  Node: Host Identification,  Next: Platform Type,  Up: System Management

Host Identification
===================

   This section explains how to identify the particular system on which
your program is running.  First, let's review the various ways computer
systems are named, which is a little complicated because of the history
of the development of the Internet.

   Every Unix system (also known as a host) has a host name, whether
it's connected to a network or not.  In its simplest form, as used
before computer networks were an issue, it's just a word like `chicken'.

   But any system attached to the Internet or any network like it
conforms to a more rigorous naming convention as part of the Domain
Name System (DNS).  In DNS, every host name is composed of two parts:

  1. hostname

  2. domain name

   You will note that "hostname" looks a lot like "host name", but is
not the same thing, and that people often incorrectly refer to entire
host names as "domain names."

   In DNS, the full host name is properly called the FQDN (Fully
Qualified Domain Name) and consists of the hostname, then a period,
then the domain name.  The domain name itself usually has multiple
components separated by periods.  So for example, a system's hostname
may be `chicken' and its domain name might be `ai.mit.edu', so its FQDN
(which is its host name) is `chicken.ai.mit.edu'.

   Adding to the confusion, though, is that DNS is not the only name
space in which a computer needs to be known.  Another name space is the
NIS (aka YP) name space.  For NIS purposes, there is another domain
name, which is called the NIS domain name or the YP domain name.  It
need not have anything to do with the DNS domain name.

   Confusing things even more is the fact that in DNS, it is possible
for multiple FQDNs to refer to the same system.  However, there is
always exactly one of them that is the true host name, and it is called
the canonical FQDN.

   In some contexts, the host name is called a "node name."

   For more information on DNS host naming, *Note Host Names::.

   Prototypes for these functions appear in `unistd.h'.

   The programs `hostname', `hostid', and `domainname' work by calling
these functions.

 - Function: int gethostname (char *NAME, size_t SIZE)
     This function returns the host name of the system on which it is
     called, in the array NAME.  The SIZE argument specifies the size of
     this array, in bytes.  Note that this is _not_ the DNS hostname.
     If the system participates in DNS, this is the FQDN (see above).

     The return value is `0' on success and `-1' on failure.  In the
     GNU C library, `gethostname' fails if SIZE is not large enough;
     then you can try again with a larger array.  The following `errno'
     error condition is defined for this function:

    `ENAMETOOLONG'
          The SIZE argument is less than the size of the host name plus
          one.

     On some systems, there is a symbol for the maximum possible host
     name length: `MAXHOSTNAMELEN'.  It is defined in `sys/param.h'.
     But you can't count on this to exist, so it is cleaner to handle
     failure and try again.

     `gethostname' stores the beginning of the host name in NAME even
     if the host name won't entirely fit.  For some purposes, a
     truncated host name is good enough.  If it is, you can ignore the
     error code.

 - Function: int sethostname (const char *NAME, size_t LENGTH)
     The `sethostname' function sets the host name of the system that
     calls it to NAME, a string with length LENGTH.  Only privileged
     processes are permitted to do this.

     Usually `sethostname' gets called just once, at system boot time.
     Often, the program that calls it sets it to the value it finds in
     the file `/etc/hostname'.

     Be sure to set the host name to the full host name, not just the
     DNS hostname (see above).

     The return value is `0' on success and `-1' on failure.  The
     following `errno' error condition is defined for this function:

    `EPERM'
          This process cannot set the host name because it is not
          privileged.

 - Function: int getdomainnname (char *NAME, size_t LENGTH)
     `getdomainname' returns the NIS (aka YP) domain name of the system
     on which it is called.  Note that this is not the more popular DNS
     domain name.  Get that with `gethostname'.

     The specifics of this function are analogous to `gethostname',
     above.


 - Function: int setdomainname (const char *NAME, size_t LENGTH)
     `getdomainname' sets the NIS (aka YP) domain name of the system on
     which it is called.  Note that this is not the more popular DNS
     domain name.  Set that with `sethostname'.

     The specifics of this function are analogous to `sethostname',
     above.


 - Function: long int gethostid (void)
     This function returns the "host ID" of the machine the program is
     running on.  By convention, this is usually the primary Internet
     IP address of that machine, converted to a `long int'.  However,
     on some systems it is a meaningless but unique number which is
     hard-coded for each machine.

     This is not widely used.  It arose in BSD 4.2, but was dropped in
     BSD 4.4.  It is not required by POSIX.

     The proper way to query the IP address is to use `gethostbyname'
     on the results of `gethostname'.  For more information on IP
     addresses, *Note Host Addresses::.

 - Function: int sethostid (long int ID)
     The `sethostid' function sets the "host ID" of the host machine to
     ID.  Only privileged processes are permitted to do this.  Usually
     it happens just once, at system boot time.

     The proper way to establish the primary IP address of a system is
     to configure the IP address resolver to associate that IP address
     with the system's host name as returned by `gethostname'.  For
     example, put a record for the system in `/etc/hosts'.

     See `gethostid' above for more information on host ids.

     The return value is `0' on success and `-1' on failure.  The
     following `errno' error conditions are defined for this function:

    `EPERM'
          This process cannot set the host name because it is not
          privileged.

    `ENOSYS'
          The operating system does not support setting the host ID.
          On some systems, the host ID is a meaningless but unique
          number hard-coded for each machine.


File: libc.info,  Node: Platform Type,  Next: Filesystem Handling,  Prev: Host Identification,  Up: System Management

Platform Type Identification
============================

   You can use the `uname' function to find out some information about
the type of computer your program is running on.  This function and the
associated data type are declared in the header file `sys/utsname.h'.

   As a bonus, `uname' also gives some information identifying the
particular system your program is running on.  This is the same
information which you can get with functions targetted to this purpose
described in *Note Host Identification::.

 - Data Type: struct utsname
     The `utsname' structure is used to hold information returned by
     the `uname' function.  It has the following members:

    `char sysname[]'
          This is the name of the operating system in use.

    `char release[]'
          This is the current release level of the operating system
          implementation.

    `char version[]'
          This is the current version level within the release of the
          operating system.

    `char machine[]'
          This is a description of the type of hardware that is in use.

          Some systems provide a mechanism to interrogate the kernel
          directly for this information.  On systems without such a
          mechanism, the GNU C library fills in this field based on the
          configuration name that was specified when building and
          installing the library.

          GNU uses a three-part name to describe a system
          configuration; the three parts are CPU, MANUFACTURER and
          SYSTEM-TYPE, and they are separated with dashes.  Any
          possible combination of three names is potentially
          meaningful, but most such combinations are meaningless in
          practice and even the meaningful ones are not necessarily
          supported by any particular GNU program.

          Since the value in `machine' is supposed to describe just the
          hardware, it consists of the first two parts of the
          configuration name: `CPU-MANUFACTURER'.  For example, it
          might be one of these:

               `"sparc-sun"', `"i386-ANYTHING"', `"m68k-hp"',
               `"m68k-sony"', `"m68k-sun"', `"mips-dec"'

    `char nodename[]'
          This is the host name of this particular computer.  In the
          GNU C library, the value is the same as that returned by
          `gethostname'; see *Note Host Identification::.

          gethostname() is implemented with a call to uname().

    `char domainname[]'
          This is the NIS or YP domain name.  It is the same value
          returned by `getdomainname'; see *Note Host Identification::.
          This element is a relatively recent invention and use of it
          is not as portable as use of the rest of the structure.


 - Function: int uname (struct utsname *INFO)
     The `uname' function fills in the structure pointed to by INFO
     with information about the operating system and host machine.  A
     non-negative value indicates that the data was successfully stored.

     `-1' as the value indicates an error.  The only error possible is
     `EFAULT', which we normally don't mention as it is always a
     possibility.


File: libc.info,  Node: Filesystem Handling,  Next: System Parameters,  Prev: Platform Type,  Up: System Management

Controlling and Querying Mounts
===============================

   All files are in filesystems, and before you can access any file, its
filesystem must be mounted.  Because of Unix's concept of _Everything
is a file_, mounting of filesystems is central to doing almost
anything.  This section explains how to find out what filesystems are
currently mounted and what filesystems are available for mounting, and
how to change what is mounted.

   The classic filesystem is the contents of a disk drive.  The concept
is considerably more abstract, though, and lots of things other than
disk drives can be mounted.

   Some block devices don't correspond to traditional devices like disk
drives.  For example, a loop device is a block device whose driver uses
a regular file in another filesystem as its medium.  So if that regular
file contains appropriate data for a filesystem, you can by mounting the
loop device essentially mount a regular file.

   Some filesystems aren't based on a device of any kind.  The "proc"
filesystem, for example, contains files whose data is made up by the
filesystem driver on the fly whenever you ask for it.  And when you
write to it, the data you write causes changes in the system.  No data
gets stored.

* Menu:

* Mount Information::           What is or could be mounted?
* Mount-Unmount-Remount::       Controlling what is mounted and how


File: libc.info,  Node: Mount Information,  Next: Mount-Unmount-Remount,  Up: Filesystem Handling

Mount Information
-----------------

   For some programs it is desirable and necessary to access information
about whether a certain filesystem is mounted and, if it is, where, or
simply to get lists of all the available filesystems.  The GNU libc
provides some functions to retrieve this information portably.

   Traditionally Unix systems have a file named `/etc/fstab' which
describes all possibly mounted filesystems.  The `mount' program uses
this file to mount at startup time of the system all the necessary
filesystems.  The information about all the filesystems actually mounted
is normally kept in a file named `/etc/mtab'.  Both files share the
same syntax and it is crucial that this syntax is followed all the
time.  Therefore it is best to never directly write the files.  The
functions described in this section can do this and they also provide
the functionality to convert the external textual representation to the
internal representation.

   Note that the `fstab' and `mtab' files are maintained on a system by
_convention_.  It is possible for the files not to exist or not to be
consistent with what is really mounted or available to mount, if the
system's administration policy allows it.  But programs that mount and
unmount filesystems typically maintain and use these files as described
herein.

   The filenames given above should never be used directly.  The
portable way to handle these file is to use the macros `_PATH_FSTAB',
defined in `fstab.h' and `_PATH_MNTTAB', defined in `mntent.h',
respectively.  There are also two alternate macro names `FSTAB' and
`_PATH_MOUNTED' defined but both names are deprecated and kept only for
backward compatibility.  The two former names should always be used.

* Menu:

* fstab::                       The `fstab' file
* mtab::                        The `mtab' file
* Other Mount Information::     Other (non-libc) sources of mount information


File: libc.info,  Node: fstab,  Next: mtab,  Up: Mount Information

The `fstab' file
................

   The internal representation for entries of the file is
`struct fstab', defined in `fstab.h'.

 - Data Type: struct fstab
     This structure is used with the `getfsent', `getfsspec', and
     `getfsfile' functions.

    `char *fs_spec'
          This element describes the device from which the filesystem
          is mounted.  Normally this is the name of a special device,
          such as a hard disk partition, but it could also be a more or
          less generic string.  For "NFS" it would be a hostname and
          directory name combination.

          Even though the element is not declared `const' it shouldn't
          be modified.  The missing `const' has historic reasons, since
          this function predates ISO C.  The same is true for the other
          string elements of this structure.

    `char *fs_file'
          This describes the mount point on the local system.  I.e.,
          accessing any file in this filesystem has implicitly or
          explicitly this string as a prefix.

    `char *fs_vfstype'
          This is the type of the filesystem.  Depending on what the
          underlying kernel understands it can be any string.

    `char *fs_mntops'
          This is a string containing options passed to the kernel with
          the `mount' call.  Again, this can be almost anything.  There
          can be more than one option, separated from the others by a
          comma.  Each option consists of a name and an optional value
          part, introduced by an `=' character.

          If the value of this element must be processed it should
          ideally be done using the `getsubopt' function; see *Note
          Suboptions::.

    `const char *fs_type'
          This name is poorly chosen.  This element points to a string
          (possibly in the `fs_mntops' string) which describes the
          modes with which the filesystem is mounted.  `fstab' defines
          five macros to describe the possible values:

         `FSTAB_RW'
               The filesystems gets mounted with read and write enabled.

         `FSTAB_RQ'
               The filesystems gets mounted with read and write
               enabled.  Write access is restricted by quotas.

         `FSTAB_RO'
               The filesystem gets mounted read-only.

         `FSTAB_SW'
               This is not a real filesystem, it is a swap device.

         `FSTAB_XX'
               This entry from the `fstab' file is totally ignored.

          Testing for equality with these value must happen using
          `strcmp' since these are all strings.  Comparing the pointer
          will probably always fail.

    `int fs_freq'
          This element describes the dump frequency in days.

    `int fs_passno'
          This element describes the pass number on parallel dumps.  It
          is closely related to the `dump' utility used on Unix systems.

   To read the entire content of the of the `fstab' file the GNU libc
contains a set of three functions which are designed in the usual way.

 - Function: int setfsent (void)
     This function makes sure that the internal read pointer for the
     `fstab' file is at the beginning of the file.  This is done by
     either opening the file or resetting the read pointer.

     Since the file handle is internal to the libc this function is not
     thread-safe.

     This function returns a non-zero value if the operation was
     successful and the `getfs*' functions can be used to read the
     entries of the file.

 - Function: void endfsent (void)
     This function makes sure that all resources acquired by a prior
     call to `setfsent' (explicitly or implicitly by calling
     `getfsent') are freed.

 - Function: struct fstab * getfsent (void)
     This function returns the next entry of the `fstab' file.  If this
     is the first call to any of the functions handling `fstab' since
     program start or the last call of `endfsent', the file will be
     opened.

     The function returns a pointer to a variable of type `struct
     fstab'.  This variable is shared by all threads and therefore this
     function is not thread-safe.  If an error occurred `getfsent'
     returns a `NULL' pointer.

 - Function: struct fstab * getfsspec (const char *NAME)
     This function returns the next entry of the `fstab' file which has
     a string equal to NAME pointed to by the `fs_spec' element.  Since
     there is normally exactly one entry for each special device it
     makes no sense to call this function more than once for the same
     argument.  If this is the first call to any of the functions
     handling `fstab' since program start or the last call of
     `endfsent', the file will be opened.

     The function returns a pointer to a variable of type `struct
     fstab'.  This variable is shared by all threads and therefore this
     function is not thread-safe.  If an error occurred `getfsent'
     returns a `NULL' pointer.

 - Function: struct fstab * getfsfile (const char *NAME)
     This function returns the next entry of the `fstab' file which has
     a string equal to NAME pointed to by the `fs_file' element.  Since
     there is normally exactly one entry for each mount point it makes
     no sense to call this function more than once for the same
     argument.  If this is the first call to any of the functions
     handling `fstab' since program start or the last call of
     `endfsent', the file will be opened.

     The function returns a pointer to a variable of type `struct
     fstab'.  This variable is shared by all threads and therefore this
     function is not thread-safe.  If an error occurred `getfsent'
     returns a `NULL' pointer.


File: libc.info,  Node: mtab,  Next: Other Mount Information,  Prev: fstab,  Up: Mount Information

The `mtab' file
...............

   The following functions and data structure access the `mtab' file.

 - Data Type: struct mntent
     This structure is used with the `getmntent', `getmntent_t',
     `addmntent', and `hasmntopt' functions.

    `char *mnt_fsname'
          This element contains a pointer to a string describing the
          name of the special device from which the filesystem is
          mounted.  It corresponds to the `fs_spec' element in `struct
          fstab'.

    `char *mnt_dir'
          This element points to a string describing the mount point of
          the filesystem.  It corresponds to the `fs_file' element in
          `struct fstab'.

    `char *mnt_type'
          `mnt_type' describes the filesystem type and is therefore
          equivalent to `fs_vfstype' in `struct fstab'.  `mntent.h'
          defines a few symbolic names for some of the values this
          string can have.  But since the kernel can support arbitrary
          filesystems it does not make much sense to give them symbolic
          names.  If one knows the symbol name one also knows the
          filesystem name.  Nevertheless here follows the list of the
          symbols provided in `mntent.h'.

         `MNTTYPE_IGNORE'
               This symbol expands to `"ignore"'.  The value is
               sometime used in `fstab' files to make sure entries are
               not used without removing them.

         `MNTTYPE_NFS'
               Expands to `"nfs"'.  Using this macro sometimes could
               make sense since it names the default NFS
               implementation, in case both version 2 and 3 are
               supported.

         `MNTTYPE_SWAP'
               This symbol expands to `"swap"'.  It names the special
               `fstab' entry which names one of the possibly multiple
               swap partitions.

    `char *mnt_opts'
          The element contains a string describing the options used
          while mounting the filesystem.  As for the equivalent element
          `fs_mntops' of `struct fstab' it is best to use the function
          `getsubopt' (*note Suboptions::) to access the parts of this
          string.

          The `mntent.h' file defines a number of macros with string
          values which correspond to some of the options understood by
          the kernel.  There might be many more options which are
          possible so it doesn't make much sense to rely on these
          macros but to be consistent here is the list:

         `MNTOPT_DEFAULTS'
               Expands to `"defaults"'.  This option should be used
               alone since it indicates all values for the customizable
               values are chosen to be the default.

         `MNTOPT_RO'
               Expands to `"ro"'.  See the `FSTAB_RO' value, it means
               the filesystem is mounted read-only.

         `MNTOPT_RW'
               Expand to `"rw"'.  See the `FSTAB_RW' value, it means the
               filesystem is mounted with read and write permissions.

         `MNTOPT_SUID'
               Expands to `"suid"'.  This means that the SUID bit
               (*note How Change Persona::) is respected when a program
               from the filesystem is started.

         `MNTOPT_NOSUID'
               Expands to `"nosuid"'.  This is the opposite of
               `MNTOPT_SUID', the SUID bit for all files from the
               filesystem is ignored.

         `MNTOPT_NOAUTO'
               Expands to `"noauto"'.  At startup time the `mount'
               program will ignore this entry if it is started with the
               `-a' option to mount all filesystems mentioned in the
               `fstab' file.

          As for the `FSTAB_*' entries introduced above it is important
          to use `strcmp' to check for equality.

    `mnt_freq'
          This elements corresponds to `fs_freq' and also specifies the
          frequency in days in which dumps are made.

    `mnt_passno'
          This element is equivalent to `fs_passno' with the same
          meaning which is uninteresting for all programs beside `dump'.

   For accessing the `mtab' file there is again a set of three
functions to access all entries in a row.  Unlike the functions to
handle `fstab' these functions do not access a fixed file and there is
even a thread safe variant of the get function.  Beside this the GNU
libc contains functions to alter the file and test for specific options.

 - Function: FILE * setmntent (const char *FILE, const char *MODE)
     The `setmntent' function prepares the file named FILE which must
     be in the format of a `fstab' and `mtab' file for the upcoming
     processing through the other functions of the family.  The MODE
     parameter can be chosen in the way the OPENTYPE parameter for
     `fopen' (*note Opening Streams::) can be chosen.  If the file is
     opened for writing the file is also allowed to be empty.

     If the file was successfully opened `setmntent' returns a file
     descriptor for future use.  Otherwise the return value is `NULL'
     and `errno' is set accordingly.

 - Function: int endmntent (FILE *STREAM)
     This function takes for the STREAM parameter a file handle which
     previously was returned from the `setmntent' call.  `endmntent'
     closes the stream and frees all resources.

     The return value is 1 unless an error occurred in which case it is
     0.

 - Function: struct mntent * getmntent (FILE *STREAM)
     The `getmntent' function takes as the parameter a file handle
     previously returned by successful call to `setmntent'.  It returns
     a pointer to a static variable of type `struct mntent' which is
     filled with the information from the next entry from the file
     currently read.

     The file format used prescribes the use of spaces or tab
     characters to separate the fields.  This makes it harder to use
     name containing one of these characters (e.g., mount points using
     spaces).  Therefore these characters are encoded in the files and
     the `getmntent' function takes care of the decoding while reading
     the entries back in.  `'\040'' is used to encode a space
     character, `'\012'' to encode a tab character and `'\\'' to encode
     a backslash.

     If there was an error or the end of the file is reached the return
     value is `NULL'.

     This function is not thread-safe since all calls to this function
     return a pointer to the same static variable.  `getmntent_r'
     should be used in situations where multiple threads access the
     file.

 - Function: struct mntent * getmntent_r (FILE *STREAM, struct mentent
          *RESULT, char *BUFFER, int BUFSIZE)
     The `getmntent_r' function is the reentrant variant of
     `getmntent'.  It also returns the next entry from the file and
     returns a pointer.  The actual variable the values are stored in
     is not static, though.  Instead the function stores the values in
     the variable pointed to by the RESULT parameter.  Additional
     information (e.g., the strings pointed to by the elements of the
     result) are kept in the buffer of size BUFSIZE pointed to by
     BUFFER.

     Escaped characters (space, tab, backslash) are converted back in
     the same way as it happens for `getmentent'.

     The function returns a `NULL' pointer in error cases.  Errors
     could be:
        * error while reading the file,

        * end of file reached,

        * BUFSIZE is too small for reading a complete new entry.

 - Function: int addmntent (FILE *STREAM, const struct mntent *MNT)
     The `addmntent' function allows adding a new entry to the file
     previously opened with `setmntent'.  The new entries are always
     appended.  I.e., even if the position of the file descriptor is
     not at the end of the file this function does not overwrite an
     existing entry following the current position.

     The implication of this is that to remove an entry from a file one
     has to create a new file while leaving out the entry to be removed
     and after closing the file remove the old one and rename the new
     file to the chosen name.

     This function takes care of spaces and tab characters in the names
     to be written to the file.  It converts them and the backslash
     character into the format describe in the `getmntent' description
     above.

     This function returns 0 in case the operation was successful.
     Otherwise the return value is 1 and `errno' is set appropriately.

 - Function: char * hasmntopt (const struct mntent *MNT, const char
          *OPT)
     This function can be used to check whether the string pointed to
     by the `mnt_opts' element of the variable pointed to by MNT
     contains the option OPT.  If this is true a pointer to the
     beginning of the option in the `mnt_opts' element is returned.  If
     no such option exists the function returns `NULL'.

     This function is useful to test whether a specific option is
     present but when all options have to be processed one is better
     off with using the `getsubopt' function to iterate over all
     options in the string.


File: libc.info,  Node: Other Mount Information,  Prev: mtab,  Up: Mount Information

Other (Non-libc) Sources of Mount Information
.............................................

   On a system with a Linux kernel and the `proc' filesystem, you can
get information on currently mounted filesystems from the file `mounts'
in the `proc' filesystem.  Its format is similar to that of the `mtab'
file, but represents what is truly mounted without relying on
facilities outside the kernel to keep `mtab' up to date.


File: libc.info,  Node: Mount-Unmount-Remount,  Prev: Mount Information,  Up: Filesystem Handling

Mount, Unmount, Remount
-----------------------

   This section describes the functions for mounting, unmounting, and
remounting filesystems.

   Only the superuser can mount, unmount, or remount a filesystem.

   These functions do not access the `fstab' and `mtab' files.  You
should maintain and use these separately.  *Note Mount Information::.

   The symbols in this section are declared in `sys/mount.h'.

 - Function: int mount (const char *SPECIAL_FILE, const char *DIR,
          const char *FSTYPE, unsigned long int OPTIONS, const void
          *DATA)
     `mount' mounts or remounts a filesystem.  The two operations are
     quite different and are merged rather unnnaturally into this one
     function.  The `MS_REMOUNT' option, explained below, determines
     whether `mount' mounts or remounts.

     For a mount, the filesystem on the block device represented by the
     device special file named SPECIAL_FILE gets mounted over the mount
     point DIR.  This means that the directory DIR (along with any
     files in it) is no longer visible; in its place (and still with
     the name DIR) is the root directory of the filesystem on the
     device.

     As an exception, if the filesystem type (see below) is one which
     is not based on a device (e.g. "proc"), `mount' instantiates a
     filesystem and mounts it over DIR and ignores SPECIAL_FILE.

     For a remount, DIR specifies the mount point where the filesystem
     to be remounted is (and remains) mounted and SPECIAL_FILE is
     ignored.  Remounting a filesystem means changing the options that
     control operations on the filesystem while it is mounted.  It does
     not mean unmounting and mounting again.

     For a mount, you must identify the type of the filesystem as
     FSTYPE.  This type tells the kernel how to access the filesystem
     and can be thought of as the name of a filesystem driver.  The
     acceptable values are system dependent.  On a system with a Linux
     kernel and the `proc' filesystem, the list of possible values is
     in the file `filesystems' in the `proc' filesystem (e.g. type `cat
     /proc/filesystems' to see the list).  With a Linux kernel, the
     types of filesystems that `mount' can mount, and their type names,
     depends on what filesystem drivers are configured into the kernel
     or loaded as loadable kernel modules.  An example of a common
     value for FSTYPE is `ext2'.

     For a remount, `mount' ignores FSTYPE.

     OPTIONS specifies a variety of options that apply until the
     filesystem is unmounted or remounted.  The precise meaning of an
     option depends on the filesystem and with some filesystems, an
     option may have no effect at all.  Furthermore, for some
     filesystems, some of these options (but never `MS_RDONLY') can be
     overridden for individual file accesses via `ioctl'.

     OPTIONS is a bit string with bit fields defined using the
     following mask and masked value macros:

    `MS_MGC_MASK'
          This multibit field contains a magic number.  If it does not
          have the value `MS_MGC_VAL', `mount' assumes all the
          following bits are zero and the DATA argument is a null
          string, regardless of their actual values.

    `MS_REMOUNT'
          This bit on means to remount the filesystem.  Off means to
          mount it.

    `MS_RDONLY'
          This bit on specifies that no writing to the filesystem shall
          be allowed while it is mounted.  This cannot be overridden by
          `ioctl'.  This option is available on nearly all filesystems.

    `S_IMMUTABLE'
          This bit on specifies that no writing to the files in the
          filesystem shall be allowed while it is mounted.  This can be
          overridden for a particular file access by a properly
          privileged call to `ioctl'.  This option is a relatively new
          invention and is not available on many filesystems.

    `S_APPEND'
          This bit on specifies that the only file writing that shall
          be allowed while the filesystem is mounted is appending.
          Some filesystems allow this to be overridden for a particular
          process by a properly privileged call to `ioctl'.  This is a
          relatively new invention and is not available on many
          filesystems.

    `MS_NOSUID'
          This bit on specifies that Setuid and Setgid permissions on
          files in the filesystem shall be ignored while it is mounted.

    `MS_NOEXEC'
          This bit on specifies that no files in the filesystem shall
          be executed while the filesystem is mounted.

    `MS_NODEV'
          This bit on specifies that no device special files in the
          filesystem shall be accessible while the filesystem is
          mounted.

    `MS_SYNCHRONOUS'
          This bit on specifies that all writes to the filesystem while
          it is mounted shall be synchronous; i.e. data shall be synced
          before each write completes rather than held in the buffer
          cache.

    `MS_MANDLOCK'
          This bit on specifies that mandatory locks on files shall be
          permitted while the filesystem is mounted.

    `MS_NOATIME'
          This bit on specifies that access times of files shall not be
          updated when the files are accessed while the filesystem is
          mounted.

    `MS_NODIRATIME'
          This bit on specifies that access times of directories shall
          not be updated when the directories are accessed while the
          filesystem in mounted.

     Any bits not covered by the above masks should be set off;
     otherwise, results are undefined.

     The meaning of DATA depends on the filesystem type and is
     controlled entirely by the filesystem driver in the kernel.

     Example:

          #include <sys/mount.h>
          
          mount("/dev/hdb", "/cdrom", MS_MGC_VAL | MS_RDONLY | MS_NOSUID, "");
          
          mount("/dev/hda2", "/mnt", MS_MGC_VAL | MS_REMOUNT, "");

     Appropriate arguments for `mount' are conventionally recorded in
     the `fstab' table.  *Note Mount Information::.

     The return value is zero if the mount or remount is successful.
     Otherwise, it is `-1' and `errno' is set appropriately.  The
     values of `errno' are filesystem dependent, but here is a general
     list:

    `EPERM'
          The process is not superuser.

    `ENODEV'
          The file system type FSTYPE is not known to the kernel.

    `ENOTBLK'
          The file DEV is not a block device special file.

    `EBUSY'
             * The device is already mounted.

             * The mount point is busy.  (E.g. it is some process'
               working directory or has a filesystem mounted on it
               already).

             * The request is to remount read-only, but there are files
               open for write.

    `EINVAL'
             * A remount was attempted, but there is no filesystem
               mounted over the specified mount point.

             * The supposed filesystem has an invalid superblock.


    `EACCESS'
             * The filesystem is inherently read-only (possibly due to
               a switch on the device) and the process attempted to
               mount it read/write (by setting the `MS_RDONLY' bit off).

             * SPECIAL_FILE or DIR is not accessible due to file
               permissions.

             * SPECIAL_FILE is not accessible because it is in a
               filesystem that is mounted with the `MS_NODEV' option.


    `EM_FILE'
          The table of dummy devices is full.  `mount' needs to create a
          dummy device (aka "unnamed" device) if the filesystem being
          mounted is not one that uses a device.


 - Function: int umount2 (const char *FILE, int FLAGS)
     `umount2' unmounts a filesystem.

     You can identify the filesystem to unmount either by the device
     special file that contains the filesystem or by the mount point.
     The effect is the same.  Specify either as the string FILE.

     FLAGS contains the one-bit field identified by the following mask
     macro:

    `MNT_FORCE'
          This bit on means to force the unmounting even if the
          filesystem is busy, by making it unbusy first.  If the bit is
          off and the filesystem is busy, `umount2' fails with `errno'
          = `EBUSY'.  Depending on the filesystem, this may override
          all, some, or no busy conditions.

     All other bits in FLAGS should be set to zero; otherwise, the
     result is undefined.

     Example:

          #include <sys/mount.h>
          
          umount2("/mnt", MNT_FORCE);
          
          umount2("/dev/hdd1", 0);

     After the filesystem is unmounted, the directory that was the
     mount point is visible, as are any files in it.

     As part of unmounting, `umount2' syncs the filesystem.

     If the unmounting is successful, the return value is zero.
     Otherwise, it is `-1' and `errno' is set accordingly:

    `EPERM'
          The process is not superuser.

    `EBUSY'
          The filesystem cannot be unmounted because it is busy.  E.g.
          it contains a directory that is some process's working
          directory or a file that some process has open.  With some
          filesystems in some cases, you can avoid this failure with
          the `MNT_FORCE' option.

    `EINVAL'
          FILE validly refers to a file, but that file is neither a
          mount point nor a device special file of a currently mounted
          filesystem.

     This function is not available on all systems.

 - Function: int umount (const char *FILE)
     `umount' does the same thing as `umount2' with FLAGS set to
     zeroes.  It is more widely available than `umount2' but since it
     lacks the possibility to forcefully unmount a filesystem is
     deprecated when `umount2' is also available.


File: libc.info,  Node: System Parameters,  Prev: Filesystem Handling,  Up: System Management

System Parameters
=================

   This section describes the `sysctl' function, which gets and sets a
variety of system parameters.

   The symbols used in this section are declared in the file `sysctl.h'.

 - Function: int sysctl (int *NAMES, int NLEN, void *OLDVAL,
     size_t *OLDLENP, void *NEWVAL, size_t NEWLEN)

     `sysctl' gets or sets a specified system parameter.  There are so
     many of these parameters that it is not practical to list them all
     here, but here are some examples:

        * network domain name

        * paging parameters

        * network Address Resolution Protocol timeout time

        * maximum number of files that may be open

        * root filesystem device

        * when kernel was built

     The set of available parameters depends on the kernel
     configuration and can change while the system is running,
     particularly when you load and unload loadable kernel modules.

     The system parameters with which `syslog' is concerned are arranged
     in a hierarchical structure like a hierarchical filesystem.  To
     identify a particular parameter, you specify a path through the
     structure in a way analogous to specifying the pathname of a file.
     Each component of the path is specified by an integer and each of
     these integers has a macro defined for it by `sysctl.h'.  NAMES is
     the path, in the form of an array of integers.  Each component of
     the path is one element of the array, in order.  NLEN is the
     number of components in the path.

     For example, the first component of the path for all the paging
     parameters is the value `CTL_VM'.  For the free page thresholds,
     the second component of the path is `VM_FREEPG'.  So to get the
     free page threshold values, make NAMES an array containing the two
     elements `CTL_VM' and `VM_FREEPG' and make NLEN = 2.

     The format of the value of a parameter depends on the parameter.
     Sometimes it is an integer; sometimes it is an ASCII string;
     sometimes it is an elaborate structure.  In the case of the free
     page thresholds used in the example above, the parameter value is
     a structure containing several integers.

     In any case, you identify a place to return the parameter's value
     with OLDVAL and specify the amount of storage available at that
     location as *OLDLENP.  *OLDLENP does double duty because it is
     also the output location that contains the actual length of the
     returned value.

     If you don't want the parameter value returned, specify a null
     pointer for OLDVAL.

     To set the parameter, specify the address and length of the new
     value as NEWVAL and NEWLEN.  If you don't want to set the
     parameter, specify a null pointer as NEWVAL.

     If you get and set a parameter in the same `sysctl' call, the value
     returned is the value of the parameter before it was set.

     Each system parameter has a set of permissions similar to the
     permissions for a file (including the permissions on directories
     in its path) that determine whether you may get or set it.  For
     the purposes of these permissions, every parameter is considered
     to be owned by the superuser and Group 0 so processes with that
     effective uid or gid may have more access to system parameters.
     Unlike with files, the superuser does not invariably have full
     permission to all system parameters, because some of them are
     designed not to be changed ever.

     `sysctl' returns a zero return value if it succeeds.  Otherwise, it
     returns `-1' and sets `errno' appropriately.  Besides the failures
     that apply to all system calls, the following are the `errno'
     codes for all possible failures:

    `EPERM'
          The process is not permitted to access one of the components
          of the path of the system parameter or is not permitted to
          access the system parameter itself in the way (read or write)
          that it requested.

    `ENOTDIR'
          There is no system parameter corresponding to NAME.

    `EFAULT'
          OLDVAL is not null, which means the process wanted to read
          the parameter, but *OLDLENP is zero, so there is no place to
          return it.

    `EINVAL'
             * The process attempted to set a system parameter to a
               value that is not valid for that parameter.

             * The space provided for the return of the system
               parameter is not the right size for that parameter.

    `ENOMEM'
          This value may be returned instead of the more correct
          `EINVAL' in some cases where the space provided for the
          return of the system parameter is too small.


   If you have a Linux kernel with the `proc' filesystem, you can get
and set most of the same parameters by reading and writing to files in
the `sys' directory of the `proc' filesystem.  In the `sys' directory,
the directory structure represents the hierarchical structure of the
parameters.  E.g. you can display the free page thresholds with
     cat /proc/sys/vm/freepages

   Some more traditional and more widely available, though less general,
GNU C library functions for getting and setting some of the same system
parameters are:

   * `getdomainname', `setdomainname'

   * `gethostname', `sethostname' (*Note Host Identification::.)

   * `uname' (*Note Platform Type::.)

   * `bdflush'


File: libc.info,  Node: System Configuration,  Next: Cryptographic Functions,  Prev: System Management,  Up: Top

System Configuration Parameters
*******************************

   The functions and macros listed in this chapter give information
about configuration parameters of the operating system--for example,
capacity limits, presence of optional POSIX features, and the default
path for executable files (*note String Parameters::).

* Menu:

* General Limits::           Constants and functions that describe
				various process-related limits that have
				one uniform value for any given machine.
* System Options::           Optional POSIX features.
* Version Supported::        Version numbers of POSIX.1 and POSIX.2.
* Sysconf::                  Getting specific configuration values
                                of general limits and system options.
* Minimums::                 Minimum values for general limits.

* Limits for Files::         Size limitations that pertain to individual files.
                                These can vary between file systems
                                or even from file to file.
* Options for Files::        Optional features that some files may support.
* File Minimums::            Minimum values for file limits.
* Pathconf::                 Getting the limit values for a particular file.

* Utility Limits::           Capacity limits of some POSIX.2 utility programs.
* Utility Minimums::         Minimum allowable values of those limits.

* String Parameters::        Getting the default search path.


File: libc.info,  Node: General Limits,  Next: System Options,  Up: System Configuration

General Capacity Limits
=======================

   The POSIX.1 and POSIX.2 standards specify a number of parameters that
describe capacity limitations of the system.  These limits can be fixed
constants for a given operating system, or they can vary from machine to
machine.  For example, some limit values may be configurable by the
system administrator, either at run time or by rebuilding the kernel,
and this should not require recompiling application programs.

   Each of the following limit parameters has a macro that is defined in
`limits.h' only if the system has a fixed, uniform limit for the
parameter in question.  If the system allows different file systems or
files to have different limits, then the macro is undefined; use
`sysconf' to find out the limit that applies at a particular time on a
particular machine.  *Note Sysconf::.

   Each of these parameters also has another macro, with a name starting
with `_POSIX', which gives the lowest value that the limit is allowed
to have on _any_ POSIX system.  *Note Minimums::.

 - Macro: int ARG_MAX
     If defined, the unvarying maximum combined length of the ARGV and
     ENVIRON arguments that can be passed to the `exec' functions.

 - Macro: int CHILD_MAX
     If defined, the unvarying maximum number of processes that can
     exist with the same real user ID at any one time.  In BSD and GNU,
     this is controlled by the `RLIMIT_NPROC' resource limit; *note
     Limits on Resources::.

 - Macro: int OPEN_MAX
     If defined, the unvarying maximum number of files that a single
     process can have open simultaneously.  In BSD and GNU, this is
     controlled by the `RLIMIT_NOFILE' resource limit; *note Limits on
     Resources::.

 - Macro: int STREAM_MAX
     If defined, the unvarying maximum number of streams that a single
     process can have open simultaneously.  *Note Opening Streams::.

 - Macro: int TZNAME_MAX
     If defined, the unvarying maximum length of a time zone name.
     *Note Time Zone Functions::.

   These limit macros are always defined in `limits.h'.

 - Macro: int NGROUPS_MAX
     The maximum number of supplementary group IDs that one process can
     have.

     The value of this macro is actually a lower bound for the maximum.
     That is, you can count on being able to have that many
     supplementary group IDs, but a particular machine might let you
     have even more.  You can use `sysconf' to see whether a particular
     machine will let you have more (*note Sysconf::).

 - Macro: int SSIZE_MAX
     The largest value that can fit in an object of type `ssize_t'.
     Effectively, this is the limit on the number of bytes that can be
     read or written in a single operation.

     This macro is defined in all POSIX systems because this limit is
     never configurable.

 - Macro: int RE_DUP_MAX
     The largest number of repetitions you are guaranteed is allowed in
     the construct `\{MIN,MAX\}' in a regular expression.

     The value of this macro is actually a lower bound for the maximum.
     That is, you can count on being able to have that many
     repetitions, but a particular machine might let you have even
     more.  You can use `sysconf' to see whether a particular machine
     will let you have more (*note Sysconf::).  And even the value that
     `sysconf' tells you is just a lower bound--larger values might
     work.

     This macro is defined in all POSIX.2 systems, because POSIX.2 says
     it should always be defined even if there is no specific imposed
     limit.

