blob: e6c44d6366a591d2c3568793e2fec03e228ecd54 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001@node System Management, System Configuration, Users and Groups, Top
2@c %MENU% Controlling the system and getting information about it
3@chapter System Management
4
5This chapter describes facilities for controlling the system that
6underlies a process (including the operating system and hardware) and
7for getting information about it. Anyone can generally use the
8informational facilities, but usually only a properly privileged process
9can make changes.
10
11
12@menu
13* Host Identification:: Determining the name of the machine.
14* Platform Type:: Determining operating system and basic
15 machine type
16* Filesystem Handling:: Controlling/querying mounts
17* System Parameters:: Getting and setting various system parameters
18@end menu
19
20To get information on parameters of the system that are built into the
21system, such as the maximum length of a filename, @ref{System
22Configuration}.
23
24@node Host Identification
25@section Host Identification
26
27This section explains how to identify the particular system on which your
28program is running. First, let's review the various ways computer systems
29are named, which is a little complicated because of the history of the
30development of the Internet.
31
32Every Unix system (also known as a host) has a host name, whether it's
33connected to a network or not. In its simplest form, as used before
34computer networks were an issue, it's just a word like @samp{chicken}.
35@cindex host name
36
37But any system attached to the Internet or any network like it conforms
38to a more rigorous naming convention as part of the Domain Name System
39(DNS). In DNS, every host name is composed of two parts:
40@cindex DNS
41@cindex Domain Name System
42
43@enumerate
44@item
45hostname
46@cindex hostname
47@item
48domain name
49@cindex domain name
50@end enumerate
51
52You will note that ``hostname'' looks a lot like ``host name'', but is
53not the same thing, and that people often incorrectly refer to entire
54host names as ``domain names.''
55
56In DNS, the full host name is properly called the FQDN (Fully Qualified
57Domain Name) and consists of the hostname, then a period, then the
58domain name. The domain name itself usually has multiple components
59separated by periods. So for example, a system's hostname may be
60@samp{chicken} and its domain name might be @samp{ai.mit.edu}, so
61its FQDN (which is its host name) is @samp{chicken.ai.mit.edu}.
62@cindex FQDN
63
64Adding to the confusion, though, is that DNS is not the only name space
65in which a computer needs to be known. Another name space is the
66NIS (aka YP) name space. For NIS purposes, there is another domain
67name, which is called the NIS domain name or the YP domain name. It
68need not have anything to do with the DNS domain name.
69@cindex YP
70@cindex NIS
71@cindex NIS domain name
72@cindex YP domain name
73
74Confusing things even more is the fact that in DNS, it is possible for
75multiple FQDNs to refer to the same system. However, there is always
76exactly one of them that is the true host name, and it is called the
77canonical FQDN.
78
79In some contexts, the host name is called a ``node name.''
80
81For more information on DNS host naming, see @ref{Host Names}.
82
83@pindex hostname
84@pindex hostid
85@pindex unistd.h
86Prototypes for these functions appear in @file{unistd.h}.
87
88The programs @code{hostname}, @code{hostid}, and @code{domainname} work
89by calling these functions.
90
91@comment unistd.h
92@comment BSD
93@deftypefun int gethostname (char *@var{name}, size_t @var{size})
94@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
95@c Direct syscall on unix; implemented in terms of uname on posix and of
96@c hurd_get_host_config on hurd.
97This function returns the host name of the system on which it is called,
98in the array @var{name}. The @var{size} argument specifies the size of
99this array, in bytes. Note that this is @emph{not} the DNS hostname.
100If the system participates in DNS, this is the FQDN (see above).
101
102The return value is @code{0} on success and @code{-1} on failure. In
103@theglibc{}, @code{gethostname} fails if @var{size} is not large
104enough; then you can try again with a larger array. The following
105@code{errno} error condition is defined for this function:
106
107@table @code
108@item ENAMETOOLONG
109The @var{size} argument is less than the size of the host name plus one.
110@end table
111
112@pindex sys/param.h
113On some systems, there is a symbol for the maximum possible host name
114length: @code{MAXHOSTNAMELEN}. It is defined in @file{sys/param.h}.
115But you can't count on this to exist, so it is cleaner to handle
116failure and try again.
117
118@code{gethostname} stores the beginning of the host name in @var{name}
119even if the host name won't entirely fit. For some purposes, a
120truncated host name is good enough. If it is, you can ignore the
121error code.
122@end deftypefun
123
124@comment unistd.h
125@comment BSD
126@deftypefun int sethostname (const char *@var{name}, size_t @var{length})
127@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
128@c Direct syscall on unix; implemented in terms of hurd_set_host_config
129@c on hurd.
130The @code{sethostname} function sets the host name of the system that
131calls it to @var{name}, a string with length @var{length}. Only
132privileged processes are permitted to do this.
133
134Usually @code{sethostname} gets called just once, at system boot time.
135Often, the program that calls it sets it to the value it finds in the
136file @code{/etc/hostname}.
137@cindex /etc/hostname
138
139Be sure to set the host name to the full host name, not just the DNS
140hostname (see above).
141
142The return value is @code{0} on success and @code{-1} on failure.
143The following @code{errno} error condition is defined for this function:
144
145@table @code
146@item EPERM
147This process cannot set the host name because it is not privileged.
148@end table
149@end deftypefun
150
151@comment unistd.h
152@comment ???
153@deftypefun int getdomainnname (char *@var{name}, size_t @var{length})
154@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
155@c Syscalls uname, then strlen and memcpy.
156@cindex NIS domain name
157@cindex YP domain name
158
159@code{getdomainname} returns the NIS (aka YP) domain name of the system
160on which it is called. Note that this is not the more popular DNS
161domain name. Get that with @code{gethostname}.
162
163The specifics of this function are analogous to @code{gethostname}, above.
164
165@end deftypefun
166
167@comment unistd.h
168@comment ???
169@deftypefun int setdomainname (const char *@var{name}, size_t @var{length})
170@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
171@c Direct syscall.
172@cindex NIS domain name
173@cindex YP domain name
174
175@code{getdomainname} sets the NIS (aka YP) domain name of the system
176on which it is called. Note that this is not the more popular DNS
177domain name. Set that with @code{sethostname}.
178
179The specifics of this function are analogous to @code{sethostname}, above.
180
181@end deftypefun
182
183@comment unistd.h
184@comment BSD
185@deftypefun {long int} gethostid (void)
186@safety{@prelim{}@mtsafe{@mtshostid{} @mtsenv{} @mtslocale{}}@asunsafe{@ascudlopen{} @ascuplugin{} @asucorrupt{} @ascuheap{} @asulock{}}@acunsafe{@aculock{} @acucorrupt{} @acsmem{} @acsfd{}}}
187@c On HURD, calls _hurd_get_host_config and strtol. On Linux, open
188@c HOSTIDFILE, reads an int32_t and closes; if that fails, it calls
189@c gethostname and gethostbyname_r to use the h_addr.
190This function returns the ``host ID'' of the machine the program is
191running on. By convention, this is usually the primary Internet IP address
192of that machine, converted to a @w{@code{long int}}. However, on some
193systems it is a meaningless but unique number which is hard-coded for
194each machine.
195
196This is not widely used. It arose in BSD 4.2, but was dropped in BSD 4.4.
197It is not required by POSIX.
198
199The proper way to query the IP address is to use @code{gethostbyname}
200on the results of @code{gethostname}. For more information on IP addresses,
201@xref{Host Addresses}.
202@end deftypefun
203
204@comment unistd.h
205@comment BSD
206@deftypefun int sethostid (long int @var{id})
207@safety{@prelim{}@mtunsafe{@mtasuconst{:@mtshostid{}}}@asunsafe{}@acunsafe{@acucorrupt{} @acsfd{}}}
208The @code{sethostid} function sets the ``host ID'' of the host machine
209to @var{id}. Only privileged processes are permitted to do this. Usually
210it happens just once, at system boot time.
211
212The proper way to establish the primary IP address of a system
213is to configure the IP address resolver to associate that IP address with
214the system's host name as returned by @code{gethostname}. For example,
215put a record for the system in @file{/etc/hosts}.
216
217See @code{gethostid} above for more information on host ids.
218
219The return value is @code{0} on success and @code{-1} on failure.
220The following @code{errno} error conditions are defined for this function:
221
222@table @code
223@item EPERM
224This process cannot set the host name because it is not privileged.
225
226@item ENOSYS
227The operating system does not support setting the host ID. On some
228systems, the host ID is a meaningless but unique number hard-coded for
229each machine.
230@end table
231@end deftypefun
232
233@node Platform Type
234@section Platform Type Identification
235
236You can use the @code{uname} function to find out some information about
237the type of computer your program is running on. This function and the
238associated data type are declared in the header file
239@file{sys/utsname.h}.
240@pindex sys/utsname.h
241
242As a bonus, @code{uname} also gives some information identifying the
243particular system your program is running on. This is the same information
244which you can get with functions targeted to this purpose described in
245@ref{Host Identification}.
246
247
248@comment sys/utsname.h
249@comment POSIX.1
250@deftp {Data Type} {struct utsname}
251The @code{utsname} structure is used to hold information returned
252by the @code{uname} function. It has the following members:
253
254@table @code
255@item char sysname[]
256This is the name of the operating system in use.
257
258@item char release[]
259This is the current release level of the operating system implementation.
260
261@item char version[]
262This is the current version level within the release of the operating
263system.
264
265@item char machine[]
266This is a description of the type of hardware that is in use.
267
268Some systems provide a mechanism to interrogate the kernel directly for
269this information. On systems without such a mechanism, @theglibc{}
270fills in this field based on the configuration name that was
271specified when building and installing the library.
272
273GNU uses a three-part name to describe a system configuration; the three
274parts are @var{cpu}, @var{manufacturer} and @var{system-type}, and they
275are separated with dashes. Any possible combination of three names is
276potentially meaningful, but most such combinations are meaningless in
277practice and even the meaningful ones are not necessarily supported by
278any particular GNU program.
279
280Since the value in @code{machine} is supposed to describe just the
281hardware, it consists of the first two parts of the configuration name:
282@samp{@var{cpu}-@var{manufacturer}}. For example, it might be one of these:
283
284@quotation
285@code{"sparc-sun"},
286@code{"i386-@var{anything}"},
287@code{"m68k-hp"},
288@code{"m68k-sony"},
289@code{"m68k-sun"},
290@code{"mips-dec"}
291@end quotation
292
293@item char nodename[]
294This is the host name of this particular computer. In @theglibc{},
295the value is the same as that returned by @code{gethostname};
296see @ref{Host Identification}.
297
298@ gethostname() is implemented with a call to uname().
299
300@item char domainname[]
301This is the NIS or YP domain name. It is the same value returned by
302@code{getdomainname}; see @ref{Host Identification}. This element
303is a relatively recent invention and use of it is not as portable as
304use of the rest of the structure.
305
306@c getdomainname() is implemented with a call to uname().
307
308@end table
309@end deftp
310
311@comment sys/utsname.h
312@comment POSIX.1
313@deftypefun int uname (struct utsname *@var{info})
314@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
315@c Direct syscall on unix; the posix fallback is to call gethostname and
316@c then fills in the other fields with constants; on HURD, it calls
317@c proc_uname and then gethostname.
318The @code{uname} function fills in the structure pointed to by
319@var{info} with information about the operating system and host machine.
320A non-negative value indicates that the data was successfully stored.
321
322@code{-1} as the value indicates an error. The only error possible is
323@code{EFAULT}, which we normally don't mention as it is always a
324possibility.
325@end deftypefun
326
327
328@node Filesystem Handling
329@section Controlling and Querying Mounts
330
331All files are in filesystems, and before you can access any file, its
332filesystem must be mounted. Because of Unix's concept of
333@emph{Everything is a file}, mounting of filesystems is central to doing
334almost anything. This section explains how to find out what filesystems
335are currently mounted and what filesystems are available for mounting,
336and how to change what is mounted.
337
338The classic filesystem is the contents of a disk drive. The concept is
339considerably more abstract, though, and lots of things other than disk
340drives can be mounted.
341
342Some block devices don't correspond to traditional devices like disk
343drives. For example, a loop device is a block device whose driver uses
344a regular file in another filesystem as its medium. So if that regular
345file contains appropriate data for a filesystem, you can by mounting the
346loop device essentially mount a regular file.
347
348Some filesystems aren't based on a device of any kind. The ``proc''
349filesystem, for example, contains files whose data is made up by the
350filesystem driver on the fly whenever you ask for it. And when you
351write to it, the data you write causes changes in the system. No data
352gets stored.
353
354@c It would be good to mention NFS mounts here.
355
356@menu
357* Mount Information:: What is or could be mounted?
358* Mount-Unmount-Remount:: Controlling what is mounted and how
359@end menu
360
361@node Mount Information, Mount-Unmount-Remount, , Filesystem Handling
362@subsection Mount Information
363
364For some programs it is desirable and necessary to access information
365about whether a certain filesystem is mounted and, if it is, where, or
366simply to get lists of all the available filesystems. @Theglibc{}
367provides some functions to retrieve this information portably.
368
369Traditionally Unix systems have a file named @file{/etc/fstab} which
370describes all possibly mounted filesystems. The @code{mount} program
371uses this file to mount at startup time of the system all the
372necessary filesystems. The information about all the filesystems
373actually mounted is normally kept in a file named either
374@file{/var/run/mtab} or @file{/etc/mtab}. Both files share the same
375syntax and it is crucial that this syntax is followed all the time.
376Therefore it is best to never directly write the files. The functions
377described in this section can do this and they also provide the
378functionality to convert the external textual representation to the
379internal representation.
380
381Note that the @file{fstab} and @file{mtab} files are maintained on a
382system by @emph{convention}. It is possible for the files not to exist
383or not to be consistent with what is really mounted or available to
384mount, if the system's administration policy allows it. But programs
385that mount and unmount filesystems typically maintain and use these
386files as described herein.
387
388@vindex _PATH_FSTAB
389@vindex _PATH_MNTTAB
390@vindex _PATH_MOUNTED
391@vindex FSTAB
392@vindex MNTTAB
393@vindex MOUNTED
394The filenames given above should never be used directly. The portable
395way to handle these file is to use the macro @code{_PATH_FSTAB},
396defined in @file{fstab.h}, or @code{_PATH_MNTTAB}, defined in
397@file{mntent.h} and @file{paths.h}, for @file{fstab}; and the macro
398@code{_PATH_MOUNTED}, also defined in @file{mntent.h} and
399@file{paths.h}, for @file{mtab}. There are also two alternate macro
400names @code{FSTAB}, @code{MNTTAB}, and @code{MOUNTED} defined but
401these names are deprecated and kept only for backward compatibility.
402The names @code{_PATH_MNTTAB} and @code{_PATH_MOUNTED} should always be used.
403
404@menu
405* fstab:: The @file{fstab} file
406* mtab:: The @file{mtab} file
407* Other Mount Information:: Other (non-libc) sources of mount information
408@end menu
409
410@node fstab
411@subsubsection The @file{fstab} file
412
413The internal representation for entries of the file is @w{@code{struct
414fstab}}, defined in @file{fstab.h}.
415
416@comment fstab.h
417@comment BSD
418@deftp {Data Type} {struct fstab}
419This structure is used with the @code{getfsent}, @code{getfsspec}, and
420@code{getfsfile} functions.
421
422@table @code
423@item char *fs_spec
424This element describes the device from which the filesystem is mounted.
425Normally this is the name of a special device, such as a hard disk
426partition, but it could also be a more or less generic string. For
427@dfn{NFS} it would be a hostname and directory name combination.
428
429Even though the element is not declared @code{const} it shouldn't be
430modified. The missing @code{const} has historic reasons, since this
431function predates @w{ISO C}. The same is true for the other string
432elements of this structure.
433
434@item char *fs_file
435This describes the mount point on the local system. I.e., accessing any
436file in this filesystem has implicitly or explicitly this string as a
437prefix.
438
439@item char *fs_vfstype
440This is the type of the filesystem. Depending on what the underlying
441kernel understands it can be any string.
442
443@item char *fs_mntops
444This is a string containing options passed to the kernel with the
445@code{mount} call. Again, this can be almost anything. There can be
446more than one option, separated from the others by a comma. Each option
447consists of a name and an optional value part, introduced by an @code{=}
448character.
449
450If the value of this element must be processed it should ideally be done
451using the @code{getsubopt} function; see @ref{Suboptions}.
452
453@item const char *fs_type
454This name is poorly chosen. This element points to a string (possibly
455in the @code{fs_mntops} string) which describes the modes with which the
456filesystem is mounted. @file{fstab} defines five macros to describe the
457possible values:
458
459@vtable @code
460@item FSTAB_RW
461The filesystems gets mounted with read and write enabled.
462@item FSTAB_RQ
463The filesystems gets mounted with read and write enabled. Write access
464is restricted by quotas.
465@item FSTAB_RO
466The filesystem gets mounted read-only.
467@item FSTAB_SW
468This is not a real filesystem, it is a swap device.
469@item FSTAB_XX
470This entry from the @file{fstab} file is totally ignored.
471@end vtable
472
473Testing for equality with these value must happen using @code{strcmp}
474since these are all strings. Comparing the pointer will probably always
475fail.
476
477@item int fs_freq
478This element describes the dump frequency in days.
479
480@item int fs_passno
481This element describes the pass number on parallel dumps. It is closely
482related to the @code{dump} utility used on Unix systems.
483@end table
484@end deftp
485
486
487To read the entire content of the of the @file{fstab} file @theglibc{}
488contains a set of three functions which are designed in the usual way.
489
490@comment fstab.h
491@comment BSD
492@deftypefun int setfsent (void)
493@safety{@prelim{}@mtunsafe{@mtasurace{:fsent}}@asunsafe{@ascuheap{} @asucorrupt{} @asulock{}}@acunsafe{@acucorrupt{} @aculock{} @acsmem{} @acsfd{}}}
494@c setfsent @mtasurace:fsent @ascuheap @asucorrupt @asulock @acucorrupt @aculock @acsmem @acsfd
495@c fstab_init(1) @mtasurace:fsent @ascuheap @asucorrupt @asulock @acucorrupt @aculock @acsmem @acsfd
496@c malloc dup @ascuheap @acsmem
497@c rewind dup @asucorrupt @acucorrupt [no @aculock]
498@c setmntent dup @ascuheap @asulock @acsmem @acsfd @aculock
499This function makes sure that the internal read pointer for the
500@file{fstab} file is at the beginning of the file. This is done by
501either opening the file or resetting the read pointer.
502
503Since the file handle is internal to the libc this function is not
504thread-safe.
505
506This function returns a non-zero value if the operation was successful
507and the @code{getfs*} functions can be used to read the entries of the
508file.
509@end deftypefun
510
511@comment fstab.h
512@comment BSD
513@deftypefun void endfsent (void)
514@safety{@prelim{}@mtunsafe{@mtasurace{:fsent}}@asunsafe{@ascuheap{} @asucorrupt{} @asulock{}}@acunsafe{@acucorrupt{} @aculock{} @acsmem{} @acsfd{}}}
515@c endfsent @mtasurace:fsent @ascuheap @asucorrupt @asulock @acucorrupt @aculock @acsmem @acsfd
516@c endmntent dup @ascuheap @asulock @aculock @acsmem @acsfd
517This function makes sure that all resources acquired by a prior call to
518@code{setfsent} (explicitly or implicitly by calling @code{getfsent}) are
519freed.
520@end deftypefun
521
522@comment fstab.h
523@comment BSD
524@deftypefun {struct fstab *} getfsent (void)
525@safety{@prelim{}@mtunsafe{@mtasurace{:fsent} @mtslocale{}}@asunsafe{@asucorrupt{} @ascuheap{} @asulock{}}@acunsafe{@acucorrupt{} @aculock{} @acsmem{}}}
526@c getfsent @mtasurace:fsent @mtslocale @asucorrupt @ascuheap @asulock @acucorrupt @aculock @acsmem
527@c fstab_init(0) dup @mtasurace:fsent @ascuheap @asucorrupt @asulock @acucorrupt @aculock @acsmem @acsfd
528@c fstab_fetch @mtasurace:fsent @mtslocale @asucorrupt @ascuheap @acucorrupt @aculock @acsmem
529@c getmntent_r dup @mtslocale @asucorrupt @ascuheap @acucorrupt @aculock @acsmem
530@c fstab_convert @mtasurace:fsent
531@c hasmntopt dup ok
532This function returns the next entry of the @file{fstab} file. If this
533is the first call to any of the functions handling @file{fstab} since
534program start or the last call of @code{endfsent}, the file will be
535opened.
536
537The function returns a pointer to a variable of type @code{struct
538fstab}. This variable is shared by all threads and therefore this
539function is not thread-safe. If an error occurred @code{getfsent}
540returns a @code{NULL} pointer.
541@end deftypefun
542
543@comment fstab.h
544@comment BSD
545@deftypefun {struct fstab *} getfsspec (const char *@var{name})
546@safety{@prelim{}@mtunsafe{@mtasurace{:fsent} @mtslocale{}}@asunsafe{@asucorrupt{} @ascuheap{} @asulock{}}@acunsafe{@acucorrupt{} @aculock{} @acsmem{}}}
547@c getffsspec @mtasurace:fsent @mtslocale @asucorrupt @ascuheap @asulock @acucorrupt @aculock @acsmem
548@c fstab_init(1) dup @mtasurace:fsent @ascuheap @asucorrupt @asulock @acucorrupt @aculock @acsmem @acsfd
549@c fstab_fetch dup @mtasurace:fsent @mtslocale @asucorrupt @ascuheap @acucorrupt @aculock @acsmem
550@c strcmp dup ok
551@c fstab_convert dup @mtasurace:fsent
552This function returns the next entry of the @file{fstab} file which has
553a string equal to @var{name} pointed to by the @code{fs_spec} element.
554Since there is normally exactly one entry for each special device it
555makes no sense to call this function more than once for the same
556argument. If this is the first call to any of the functions handling
557@file{fstab} since program start or the last call of @code{endfsent},
558the file will be opened.
559
560The function returns a pointer to a variable of type @code{struct
561fstab}. This variable is shared by all threads and therefore this
562function is not thread-safe. If an error occurred @code{getfsent}
563returns a @code{NULL} pointer.
564@end deftypefun
565
566@comment fstab.h
567@comment BSD
568@deftypefun {struct fstab *} getfsfile (const char *@var{name})
569@safety{@prelim{}@mtunsafe{@mtasurace{:fsent} @mtslocale{}}@asunsafe{@asucorrupt{} @ascuheap{} @asulock{}}@acunsafe{@acucorrupt{} @aculock{} @acsmem{}}}
570@c getffsfile @mtasurace:fsent @mtslocale @asucorrupt @ascuheap @asulock @acucorrupt @aculock @acsmem
571@c fstab_init(1) dup @mtasurace:fsent @ascuheap @asucorrupt @asulock @acucorrupt @aculock @acsmem @acsfd
572@c fstab_fetch dup @mtasurace:fsent @mtslocale @asucorrupt @ascuheap @acucorrupt @aculock @acsmem
573@c strcmp dup ok
574@c fstab_convert dup @mtasurace:fsent
575This function returns the next entry of the @file{fstab} file which has
576a string equal to @var{name} pointed to by the @code{fs_file} element.
577Since there is normally exactly one entry for each mount point it
578makes no sense to call this function more than once for the same
579argument. If this is the first call to any of the functions handling
580@file{fstab} since program start or the last call of @code{endfsent},
581the file will be opened.
582
583The function returns a pointer to a variable of type @code{struct
584fstab}. This variable is shared by all threads and therefore this
585function is not thread-safe. If an error occurred @code{getfsent}
586returns a @code{NULL} pointer.
587@end deftypefun
588
589
590@node mtab
591@subsubsection The @file{mtab} file
592The following functions and data structure access the @file{mtab} file.
593
594@comment mntent.h
595@comment BSD
596@deftp {Data Type} {struct mntent}
597This structure is used with the @code{getmntent}, @code{getmntent_t},
598@code{addmntent}, and @code{hasmntopt} functions.
599
600@table @code
601@item char *mnt_fsname
602This element contains a pointer to a string describing the name of the
603special device from which the filesystem is mounted. It corresponds to
604the @code{fs_spec} element in @code{struct fstab}.
605
606@item char *mnt_dir
607This element points to a string describing the mount point of the
608filesystem. It corresponds to the @code{fs_file} element in
609@code{struct fstab}.
610
611@item char *mnt_type
612@code{mnt_type} describes the filesystem type and is therefore
613equivalent to @code{fs_vfstype} in @code{struct fstab}. @file{mntent.h}
614defines a few symbolic names for some of the values this string can have.
615But since the kernel can support arbitrary filesystems it does not
616make much sense to give them symbolic names. If one knows the symbol
617name one also knows the filesystem name. Nevertheless here follows the
618list of the symbols provided in @file{mntent.h}.
619
620@vtable @code
621@item MNTTYPE_IGNORE
622This symbol expands to @code{"ignore"}. The value is sometime used in
623@file{fstab} files to make sure entries are not used without removing them.
624@item MNTTYPE_NFS
625Expands to @code{"nfs"}. Using this macro sometimes could make sense
626since it names the default NFS implementation, in case both version 2
627and 3 are supported.
628@item MNTTYPE_SWAP
629This symbol expands to @code{"swap"}. It names the special @file{fstab}
630entry which names one of the possibly multiple swap partitions.
631@end vtable
632
633@item char *mnt_opts
634The element contains a string describing the options used while mounting
635the filesystem. As for the equivalent element @code{fs_mntops} of
636@code{struct fstab} it is best to use the function @code{getsubopt}
637(@pxref{Suboptions}) to access the parts of this string.
638
639The @file{mntent.h} file defines a number of macros with string values
640which correspond to some of the options understood by the kernel. There
641might be many more options which are possible so it doesn't make much sense
642to rely on these macros but to be consistent here is the list:
643
644@vtable @code
645@item MNTOPT_DEFAULTS
646Expands to @code{"defaults"}. This option should be used alone since it
647indicates all values for the customizable values are chosen to be the
648default.
649@item MNTOPT_RO
650Expands to @code{"ro"}. See the @code{FSTAB_RO} value, it means the
651filesystem is mounted read-only.
652@item MNTOPT_RW
653Expand to @code{"rw"}. See the @code{FSTAB_RW} value, it means the
654filesystem is mounted with read and write permissions.
655@item MNTOPT_SUID
656Expands to @code{"suid"}. This means that the SUID bit (@pxref{How
657Change Persona}) is respected when a program from the filesystem is
658started.
659@item MNTOPT_NOSUID
660Expands to @code{"nosuid"}. This is the opposite of @code{MNTOPT_SUID},
661the SUID bit for all files from the filesystem is ignored.
662@item MNTOPT_NOAUTO
663Expands to @code{"noauto"}. At startup time the @code{mount} program
664will ignore this entry if it is started with the @code{-a} option to
665mount all filesystems mentioned in the @file{fstab} file.
666@end vtable
667
668As for the @code{FSTAB_*} entries introduced above it is important to
669use @code{strcmp} to check for equality.
670
671@item mnt_freq
672This elements corresponds to @code{fs_freq} and also specifies the
673frequency in days in which dumps are made.
674
675@item mnt_passno
676This element is equivalent to @code{fs_passno} with the same meaning
677which is uninteresting for all programs beside @code{dump}.
678@end table
679@end deftp
680
681For accessing the @file{mtab} file there is again a set of three
682functions to access all entries in a row. Unlike the functions to
683handle @file{fstab} these functions do not access a fixed file and there
684is even a thread safe variant of the get function. Beside this @theglibc
685contains functions to alter the file and test for specific options.
686
687@comment mntent.h
688@comment BSD
689@deftypefun {FILE *} setmntent (const char *@var{file}, const char *@var{mode})
690@safety{@prelim{}@mtsafe{}@asunsafe{@ascuheap{} @asulock{}}@acunsafe{@acsmem{} @acsfd{} @aculock{}}}
691@c setmntent @ascuheap @asulock @acsmem @acsfd @aculock
692@c strlen dup ok
693@c mempcpy dup ok
694@c memcpy dup ok
695@c fopen dup @ascuheap @asulock @acsmem @acsfd @aculock
696@c fsetlocking dup ok [no @mtasurace:stream @asulock: exclusive stream]
697The @code{setmntent} function prepares the file named @var{FILE} which
698must be in the format of a @file{fstab} and @file{mtab} file for the
699upcoming processing through the other functions of the family. The
700@var{mode} parameter can be chosen in the way the @var{opentype}
701parameter for @code{fopen} (@pxref{Opening Streams}) can be chosen. If
702the file is opened for writing the file is also allowed to be empty.
703
704If the file was successfully opened @code{setmntent} returns a file
705descriptor for future use. Otherwise the return value is @code{NULL}
706and @code{errno} is set accordingly.
707@end deftypefun
708
709@comment mntent.h
710@comment BSD
711@deftypefun int endmntent (FILE *@var{stream})
712@safety{@prelim{}@mtsafe{}@asunsafe{@ascuheap{} @asulock{}}@acunsafe{@aculock{} @acsmem{} @acsfd{}}}
713@c endmntent @ascuheap @asulock @aculock @acsmem @acsfd
714@c fclose dup @ascuheap @asulock @aculock @acsmem @acsfd
715This function takes for the @var{stream} parameter a file handle which
716previously was returned from the @code{setmntent} call.
717@code{endmntent} closes the stream and frees all resources.
718
719The return value is @math{1} unless an error occurred in which case it
720is @math{0}.
721@end deftypefun
722
723@comment mntent.h
724@comment BSD
725@deftypefun {struct mntent *} getmntent (FILE *@var{stream})
726@safety{@prelim{}@mtunsafe{@mtasurace{:mntentbuf} @mtslocale{}}@asunsafe{@asucorrupt{} @ascuheap{} @asuinit{}}@acunsafe{@acuinit{} @acucorrupt{} @aculock{} @acsmem{}}}
727@c getmntent @mtasurace:mntentbuf @mtslocale @asucorrupt @ascuheap @asuinit @acuinit @acucorrupt @aculock @acsmem
728@c libc_once @ascuheap @asuinit @acuinit @acsmem
729@c allocate @ascuheap @acsmem
730@c malloc dup @ascuheap @acsmem
731@c getmntent_r dup @mtslocale @asucorrupt @ascuheap @acucorrupt @aculock @acsmem
732The @code{getmntent} function takes as the parameter a file handle
733previously returned by successful call to @code{setmntent}. It returns
734a pointer to a static variable of type @code{struct mntent} which is
735filled with the information from the next entry from the file currently
736read.
737
738The file format used prescribes the use of spaces or tab characters to
739separate the fields. This makes it harder to use name containing one
740of these characters (e.g., mount points using spaces). Therefore
741these characters are encoded in the files and the @code{getmntent}
742function takes care of the decoding while reading the entries back in.
743@code{'\040'} is used to encode a space character, @code{'\011'} to
744encode a tab character, @code{'\012'} to encode a newline character,
745and @code{'\\'} to encode a backslash.
746
747If there was an error or the end of the file is reached the return value
748is @code{NULL}.
749
750This function is not thread-safe since all calls to this function return
751a pointer to the same static variable. @code{getmntent_r} should be
752used in situations where multiple threads access the file.
753@end deftypefun
754
755@comment mntent.h
756@comment BSD
757@deftypefun {struct mntent *} getmntent_r (FILE *@var{stream}, struct mntent *@var{result}, char *@var{buffer}, int @var{bufsize})
758@safety{@prelim{}@mtsafe{@mtslocale{}}@asunsafe{@asucorrupt{} @ascuheap{}}@acunsafe{@acucorrupt{} @aculock{} @acsmem{}}}
759@c getmntent_r @mtslocale @asucorrupt @ascuheap @acucorrupt @aculock @acsmem
760@c flockfile dup @aculock
761@c fgets_unlocked dup @asucorrupt @acucorrupt [locked, so no @mtsrace:stream]
762@c funlockfile dup @aculock
763@c strchr dup ok
764@c strspn dup ok
765@c strsep dup ok
766@c decode_name ok
767@c sscanf dup @mtslocale @ascuheap @acsmem
768The @code{getmntent_r} function is the reentrant variant of
769@code{getmntent}. It also returns the next entry from the file and
770returns a pointer. The actual variable the values are stored in is not
771static, though. Instead the function stores the values in the variable
772pointed to by the @var{result} parameter. Additional information (e.g.,
773the strings pointed to by the elements of the result) are kept in the
774buffer of size @var{bufsize} pointed to by @var{buffer}.
775
776Escaped characters (space, tab, backslash) are converted back in the
777same way as it happens for @code{getmentent}.
778
779The function returns a @code{NULL} pointer in error cases. Errors could be:
780@itemize @bullet
781@item
782error while reading the file,
783@item
784end of file reached,
785@item
786@var{bufsize} is too small for reading a complete new entry.
787@end itemize
788@end deftypefun
789
790@comment mntent.h
791@comment BSD
792@deftypefun int addmntent (FILE *@var{stream}, const struct mntent *@var{mnt})
793@safety{@prelim{}@mtsafe{@mtsrace{:stream} @mtslocale{}}@asunsafe{@asucorrupt{}}@acunsafe{@acucorrupt{}}}
794@c addmntent @mtasurace:stream @mtslocale @asucorrupt @acucorrupt
795@c fseek dup @asucorrupt @acucorrupt [no @aculock]
796@c encode_name ok
797@c fprintf dup @mtslocale @asucorrupt @acucorrupt [no @ascuheap @acsmem, no @aculock]
798@c fflush dup @asucorrupt @acucorrupt [no @aculock]
799The @code{addmntent} function allows adding a new entry to the file
800previously opened with @code{setmntent}. The new entries are always
801appended. I.e., even if the position of the file descriptor is not at
802the end of the file this function does not overwrite an existing entry
803following the current position.
804
805The implication of this is that to remove an entry from a file one has
806to create a new file while leaving out the entry to be removed and after
807closing the file remove the old one and rename the new file to the
808chosen name.
809
810This function takes care of spaces and tab characters in the names to be
811written to the file. It converts them and the backslash character into
812the format describe in the @code{getmntent} description above.
813
814This function returns @math{0} in case the operation was successful.
815Otherwise the return value is @math{1} and @code{errno} is set
816appropriately.
817@end deftypefun
818
819@comment mntent.h
820@comment BSD
821@deftypefun {char *} hasmntopt (const struct mntent *@var{mnt}, const char *@var{opt})
822@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
823@c hasmntopt ok
824@c strlen dup ok
825@c strstr dup ok
826@c strchr dup ok
827This function can be used to check whether the string pointed to by the
828@code{mnt_opts} element of the variable pointed to by @var{mnt} contains
829the option @var{opt}. If this is true a pointer to the beginning of the
830option in the @code{mnt_opts} element is returned. If no such option
831exists the function returns @code{NULL}.
832
833This function is useful to test whether a specific option is present but
834when all options have to be processed one is better off with using the
835@code{getsubopt} function to iterate over all options in the string.
836@end deftypefun
837
838@node Other Mount Information
839@subsubsection Other (Non-libc) Sources of Mount Information
840
841On a system with a Linux kernel and the @code{proc} filesystem, you can
842get information on currently mounted filesystems from the file
843@file{mounts} in the @code{proc} filesystem. Its format is similar to
844that of the @file{mtab} file, but represents what is truly mounted
845without relying on facilities outside the kernel to keep @file{mtab} up
846to date.
847
848
849@node Mount-Unmount-Remount, , Mount Information, Filesystem Handling
850@subsection Mount, Unmount, Remount
851
852This section describes the functions for mounting, unmounting, and
853remounting filesystems.
854
855Only the superuser can mount, unmount, or remount a filesystem.
856
857These functions do not access the @file{fstab} and @file{mtab} files. You
858should maintain and use these separately. @xref{Mount Information}.
859
860The symbols in this section are declared in @file{sys/mount.h}.
861
862@comment sys/mount.h
863@comment SVID, BSD
864@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})
865@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
866@c Direct syscall.
867
868@code{mount} mounts or remounts a filesystem. The two operations are
869quite different and are merged rather unnaturally into this one function.
870The @code{MS_REMOUNT} option, explained below, determines whether
871@code{mount} mounts or remounts.
872
873For a mount, the filesystem on the block device represented by the
874device special file named @var{special_file} gets mounted over the mount
875point @var{dir}. This means that the directory @var{dir} (along with any
876files in it) is no longer visible; in its place (and still with the name
877@var{dir}) is the root directory of the filesystem on the device.
878
879As an exception, if the filesystem type (see below) is one which is not
880based on a device (e.g. ``proc''), @code{mount} instantiates a
881filesystem and mounts it over @var{dir} and ignores @var{special_file}.
882
883For a remount, @var{dir} specifies the mount point where the filesystem
884to be remounted is (and remains) mounted and @var{special_file} is
885ignored. Remounting a filesystem means changing the options that control
886operations on the filesystem while it is mounted. It does not mean
887unmounting and mounting again.
888
889For a mount, you must identify the type of the filesystem as
890@var{fstype}. This type tells the kernel how to access the filesystem
891and can be thought of as the name of a filesystem driver. The
892acceptable values are system dependent. On a system with a Linux kernel
893and the @code{proc} filesystem, the list of possible values is in the
894file @file{filesystems} in the @code{proc} filesystem (e.g. type
895@kbd{cat /proc/filesystems} to see the list). With a Linux kernel, the
896types of filesystems that @code{mount} can mount, and their type names,
897depends on what filesystem drivers are configured into the kernel or
898loaded as loadable kernel modules. An example of a common value for
899@var{fstype} is @code{ext2}.
900
901For a remount, @code{mount} ignores @var{fstype}.
902
903@c This is traditionally called "rwflag" for historical reasons.
904@c No point in confusing people today, though.
905@var{options} specifies a variety of options that apply until the
906filesystem is unmounted or remounted. The precise meaning of an option
907depends on the filesystem and with some filesystems, an option may have
908no effect at all. Furthermore, for some filesystems, some of these
909options (but never @code{MS_RDONLY}) can be overridden for individual
910file accesses via @code{ioctl}.
911
912@var{options} is a bit string with bit fields defined using the
913following mask and masked value macros:
914
915@table @code
916@item MS_MGC_MASK
917This multibit field contains a magic number. If it does not have the value
918@code{MS_MGC_VAL}, @code{mount} assumes all the following bits are zero and
919the @var{data} argument is a null string, regardless of their actual values.
920
921@item MS_REMOUNT
922This bit on means to remount the filesystem. Off means to mount it.
923@c There is a mask MS_RMT_MASK in mount.h that says only two of the options
924@c can be reset by remount. But the Linux kernel has its own version of
925@c MS_RMT_MASK that says they all can be reset. As far as I can tell,
926@c libc just passes the arguments straight through to the kernel.
927
928@item MS_RDONLY
929This bit on specifies that no writing to the filesystem shall be allowed
930while it is mounted. This cannot be overridden by @code{ioctl}. This
931option is available on nearly all filesystems.
932
933@item S_IMMUTABLE
934This bit on specifies that no writing to the files in the filesystem
935shall be allowed while it is mounted. This can be overridden for a
936particular file access by a properly privileged call to @code{ioctl}.
937This option is a relatively new invention and is not available on many
938filesystems.
939
940@item S_APPEND
941This bit on specifies that the only file writing that shall be allowed
942while the filesystem is mounted is appending. Some filesystems allow
943this to be overridden for a particular process by a properly privileged
944call to @code{ioctl}. This is a relatively new invention and is not
945available on many filesystems.
946
947@item MS_NOSUID
948This bit on specifies that Setuid and Setgid permissions on files in the
949filesystem shall be ignored while it is mounted.
950
951@item MS_NOEXEC
952This bit on specifies that no files in the filesystem shall be executed
953while the filesystem is mounted.
954
955@item MS_NODEV
956This bit on specifies that no device special files in the filesystem
957shall be accessible while the filesystem is mounted.
958
959@item MS_SYNCHRONOUS
960This bit on specifies that all writes to the filesystem while it is
961mounted shall be synchronous; i.e., data shall be synced before each
962write completes rather than held in the buffer cache.
963
964@item MS_MANDLOCK
965This bit on specifies that mandatory locks on files shall be permitted while
966the filesystem is mounted.
967
968@item MS_NOATIME
969This bit on specifies that access times of files shall not be updated when
970the files are accessed while the filesystem is mounted.
971
972@item MS_NODIRATIME
973This bit on specifies that access times of directories shall not be updated
974when the directories are accessed while the filesystem in mounted.
975
976@c there is also S_QUOTA Linux fs.h (mount.h still uses its former name
977@c S_WRITE), but I can't see what it does. Turns on quotas, I guess.
978
979@end table
980
981Any bits not covered by the above masks should be set off; otherwise,
982results are undefined.
983
984The meaning of @var{data} depends on the filesystem type and is controlled
985entirely by the filesystem driver in the kernel.
986
987Example:
988
989@smallexample
990@group
991#include <sys/mount.h>
992
993mount("/dev/hdb", "/cdrom", MS_MGC_VAL | MS_RDONLY | MS_NOSUID, "");
994
995mount("/dev/hda2", "/mnt", MS_MGC_VAL | MS_REMOUNT, "");
996
997@end group
998@end smallexample
999
1000Appropriate arguments for @code{mount} are conventionally recorded in
1001the @file{fstab} table. @xref{Mount Information}.
1002
1003The return value is zero if the mount or remount is successful. Otherwise,
1004it is @code{-1} and @code{errno} is set appropriately. The values of
1005@code{errno} are filesystem dependent, but here is a general list:
1006
1007@table @code
1008@item EPERM
1009The process is not superuser.
1010@item ENODEV
1011The file system type @var{fstype} is not known to the kernel.
1012@item ENOTBLK
1013The file @var{dev} is not a block device special file.
1014@item EBUSY
1015
1016@itemize @bullet
1017
1018@item
1019The device is already mounted.
1020
1021@item
1022The mount point is busy. (E.g. it is some process' working directory or
1023has a filesystem mounted on it already).
1024
1025@item
1026The request is to remount read-only, but there are files open for write.
1027@end itemize
1028
1029@item EINVAL
1030@itemize @bullet
1031
1032@item
1033A remount was attempted, but there is no filesystem mounted over the
1034specified mount point.
1035
1036@item
1037The supposed filesystem has an invalid superblock.
1038
1039@end itemize
1040
1041@item EACCES
1042@itemize @bullet
1043
1044@item
1045The filesystem is inherently read-only (possibly due to a switch on the
1046device) and the process attempted to mount it read/write (by setting the
1047@code{MS_RDONLY} bit off).
1048
1049@item
1050@var{special_file} or @var{dir} is not accessible due to file permissions.
1051
1052@item
1053@var{special_file} is not accessible because it is in a filesystem that is
1054mounted with the @code{MS_NODEV} option.
1055
1056@end itemize
1057
1058@item EM_FILE
1059The table of dummy devices is full. @code{mount} needs to create a
1060dummy device (aka ``unnamed'' device) if the filesystem being mounted is
1061not one that uses a device.
1062
1063@end table
1064
1065@end deftypefun
1066
1067
1068@comment sys/mount.h
1069@comment GNU
1070@deftypefun {int} umount2 (const char *@var{file}, int @var{flags})
1071@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
1072@c Direct syscall.
1073
1074@code{umount2} unmounts a filesystem.
1075
1076You can identify the filesystem to unmount either by the device special
1077file that contains the filesystem or by the mount point. The effect is
1078the same. Specify either as the string @var{file}.
1079
1080@var{flags} contains the one-bit field identified by the following
1081mask macro:
1082
1083@table @code
1084
1085@item MNT_FORCE
1086This bit on means to force the unmounting even if the filesystem is
1087busy, by making it unbusy first. If the bit is off and the filesystem is
1088busy, @code{umount2} fails with @code{errno} = @code{EBUSY}. Depending
1089on the filesystem, this may override all, some, or no busy conditions.
1090
1091@end table
1092
1093All other bits in @var{flags} should be set to zero; otherwise, the result
1094is undefined.
1095
1096Example:
1097
1098@smallexample
1099@group
1100#include <sys/mount.h>
1101
1102umount2("/mnt", MNT_FORCE);
1103
1104umount2("/dev/hdd1", 0);
1105
1106@end group
1107@end smallexample
1108
1109After the filesystem is unmounted, the directory that was the mount point
1110is visible, as are any files in it.
1111
1112As part of unmounting, @code{umount2} syncs the filesystem.
1113
1114If the unmounting is successful, the return value is zero. Otherwise, it
1115is @code{-1} and @code{errno} is set accordingly:
1116
1117@table @code
1118@item EPERM
1119The process is not superuser.
1120@item EBUSY
1121The filesystem cannot be unmounted because it is busy. E.g. it contains
1122a directory that is some process's working directory or a file that some
1123process has open. With some filesystems in some cases, you can avoid
1124this failure with the @code{MNT_FORCE} option.
1125
1126@item EINVAL
1127@var{file} validly refers to a file, but that file is neither a mount
1128point nor a device special file of a currently mounted filesystem.
1129
1130@end table
1131
1132This function is not available on all systems.
1133@end deftypefun
1134
1135@comment sys/mount.h
1136@comment SVID, GNU
1137@deftypefun {int} umount (const char *@var{file})
1138@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
1139@c Direct syscall or wrapper for umount2.
1140
1141@code{umount} does the same thing as @code{umount2} with @var{flags} set
1142to zeroes. It is more widely available than @code{umount2} but since it
1143lacks the possibility to forcefully unmount a filesystem is deprecated
1144when @code{umount2} is also available.
1145@end deftypefun
1146
1147
1148
1149@node System Parameters
1150@section System Parameters
1151
1152This section describes the @code{sysctl} function, which gets and sets
1153a variety of system parameters.
1154
1155The symbols used in this section are declared in the file @file{sys/sysctl.h}.
1156
1157@comment sys/sysctl.h
1158@comment BSD
1159@deftypefun int sysctl (int *@var{names}, int @var{nlen}, void *@var{oldval}, size_t *@var{oldlenp}, void *@var{newval}, size_t @var{newlen})
1160@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
1161@c Direct syscall, Linux only.
1162
1163@code{sysctl} gets or sets a specified system parameter. There are so
1164many of these parameters that it is not practical to list them all here,
1165but here are some examples:
1166
1167@itemize @bullet
1168@item network domain name
1169@item paging parameters
1170@item network Address Resolution Protocol timeout time
1171@item maximum number of files that may be open
1172@item root filesystem device
1173@item when kernel was built
1174@end itemize
1175
1176The set of available parameters depends on the kernel configuration and
1177can change while the system is running, particularly when you load and
1178unload loadable kernel modules.
1179
1180The system parameters with which @code{syslog} is concerned are arranged
1181in a hierarchical structure like a hierarchical filesystem. To identify
1182a particular parameter, you specify a path through the structure in a
1183way analogous to specifying the pathname of a file. Each component of
1184the path is specified by an integer and each of these integers has a
1185macro defined for it by @file{sys/sysctl.h}. @var{names} is the path, in
1186the form of an array of integers. Each component of the path is one
1187element of the array, in order. @var{nlen} is the number of components
1188in the path.
1189
1190For example, the first component of the path for all the paging
1191parameters is the value @code{CTL_VM}. For the free page thresholds, the
1192second component of the path is @code{VM_FREEPG}. So to get the free
1193page threshold values, make @var{names} an array containing the two
1194elements @code{CTL_VM} and @code{VM_FREEPG} and make @var{nlen} = 2.
1195
1196
1197The format of the value of a parameter depends on the parameter.
1198Sometimes it is an integer; sometimes it is an ASCII string; sometimes
1199it is an elaborate structure. In the case of the free page thresholds
1200used in the example above, the parameter value is a structure containing
1201several integers.
1202
1203In any case, you identify a place to return the parameter's value with
1204@var{oldval} and specify the amount of storage available at that
1205location as *@var{oldlenp}. *@var{oldlenp} does double duty because it
1206is also the output location that contains the actual length of the
1207returned value.
1208
1209If you don't want the parameter value returned, specify a null pointer
1210for @var{oldval}.
1211
1212To set the parameter, specify the address and length of the new value
1213as @var{newval} and @var{newlen}. If you don't want to set the parameter,
1214specify a null pointer as @var{newval}.
1215
1216If you get and set a parameter in the same @code{sysctl} call, the value
1217returned is the value of the parameter before it was set.
1218
1219Each system parameter has a set of permissions similar to the
1220permissions for a file (including the permissions on directories in its
1221path) that determine whether you may get or set it. For the purposes of
1222these permissions, every parameter is considered to be owned by the
1223superuser and Group 0 so processes with that effective uid or gid may
1224have more access to system parameters. Unlike with files, the superuser
1225does not invariably have full permission to all system parameters, because
1226some of them are designed not to be changed ever.
1227
1228
1229@code{sysctl} returns a zero return value if it succeeds. Otherwise, it
1230returns @code{-1} and sets @code{errno} appropriately. Besides the
1231failures that apply to all system calls, the following are the
1232@code{errno} codes for all possible failures:
1233
1234@table @code
1235@item EPERM
1236The process is not permitted to access one of the components of the
1237path of the system parameter or is not permitted to access the system parameter
1238itself in the way (read or write) that it requested.
1239@c There is some indication in the Linux 2.2 code that the code is trying to
1240@c return EACCES here, but the EACCES value never actually makes it to the
1241@c user.
1242@item ENOTDIR
1243There is no system parameter corresponding to @var{name}.
1244@item EFAULT
1245@var{oldval} is not null, which means the process wanted to read the parameter,
1246but *@var{oldlenp} is zero, so there is no place to return it.
1247@item EINVAL
1248@itemize @bullet
1249@item
1250The process attempted to set a system parameter to a value that is not valid
1251for that parameter.
1252@item
1253The space provided for the return of the system parameter is not the right
1254size for that parameter.
1255@end itemize
1256@item ENOMEM
1257This value may be returned instead of the more correct @code{EINVAL} in some
1258cases where the space provided for the return of the system parameter is too
1259small.
1260
1261@end table
1262
1263@end deftypefun
1264
1265If you have a Linux kernel with the @code{proc} filesystem, you can get
1266and set most of the same parameters by reading and writing to files in
1267the @code{sys} directory of the @code{proc} filesystem. In the @code{sys}
1268directory, the directory structure represents the hierarchical structure
1269of the parameters. E.g. you can display the free page thresholds with
1270@smallexample
1271cat /proc/sys/vm/freepages
1272@end smallexample
1273@c In Linux, the sysctl() and /proc instances of the parameter are created
1274@c together. The proc filesystem accesses the same data structure as
1275@c sysctl(), which has special fields in it for /proc. But it is still
1276@c possible to create a sysctl-only parameter.
1277
1278Some more traditional and more widely available, though less general,
1279@glibcadj{} functions for getting and setting some of the same system
1280parameters are:
1281
1282@itemize @bullet
1283@item
1284@code{getdomainname}, @code{setdomainname}
1285@item
1286@code{gethostname}, @code{sethostname} (@xref{Host Identification}.)
1287@item
1288@code{uname} (@xref{Platform Type}.)
1289@item
1290@code{bdflush}
1291@end itemize