sysinfo.texi 44 KB

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