man-pages/man2/umount.2.html
2021-03-31 01:06:50 +01:00

337 lines
7.5 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of UMOUNT</TITLE>
</HEAD><BODY>
<H1>UMOUNT</H1>
Section: Linux Programmer's Manual (2)<BR>Updated: 2017-09-15<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
umount, umount2 - unmount filesystem
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<PRE>
<B>#include &lt;<A HREF="file:///usr/include/sys/mount.h">sys/mount.h</A>&gt;</B>
<B>int umount(const char *</B><I>target</I><B>);</B>
<B>int umount2(const char *</B><I>target</I><B>, int </B><I>flags</I><B>);</B>
</PRE>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
<B>umount</B>()
and
<B>umount2</B>()
remove the attachment of the (topmost) filesystem mounted on
<I>target</I>.
<P>
Appropriate privilege (Linux: the
<B>CAP_SYS_ADMIN</B>
capability) is required to unmount filesystems.
<P>
Linux 2.1.116 added the
<B>umount2</B>()
system call, which, like
<B>umount</B>(),
unmounts a target, but allows additional
<I>flags</I>
controlling the behavior of the operation:
<DL COMPACT>
<DT id="1"><B>MNT_FORCE</B> (since Linux 2.1.116)
<DD>
Ask the filesystem to abort pending requests before attempting the
unmount.
This may allow the unmount to complete without waiting
for an inaccessible server, but could cause data loss.
If, after aborting requests,
some processes still have active references to the filesystem,
the unmount will still fail.
As at Linux 4.12,
<B>MNT_FORCE</B>
is supported only on the following filesystems:
9p (since Linux 2.6.16),
ceph (since Linux 2.6.34),
cifs (since Linux 2.6.12),
fuse (since Linux 2.6.16),
lustre (since Linux 3.11),
and NFS (since Linux 2.1.116).
<DT id="2"><B>MNT_DETACH</B> (since Linux 2.4.11)
<DD>
Perform a lazy unmount: make the mount point unavailable for new
accesses, immediately disconnect the filesystem and all filesystems
mounted below it from each other and from the mount table, and
actually perform the unmount when the mount point ceases to be busy.
<DT id="3"><B>MNT_EXPIRE</B> (since Linux 2.6.8)
<DD>
Mark the mount point as expired.
If a mount point is not currently in use, then an initial call to
<B>umount2</B>()
with this flag fails with the error
<B>EAGAIN</B>,
but marks the mount point as expired.
The mount point remains expired as long as it isn't accessed
by any process.
A second
<B>umount2</B>()
call specifying
<B>MNT_EXPIRE</B>
unmounts an expired mount point.
This flag cannot be specified with either
<B>MNT_FORCE</B>
or
<B>MNT_DETACH</B>.
<DT id="4"><B>UMOUNT_NOFOLLOW</B> (since Linux 2.6.34)
<DD>
Don't dereference
<I>target</I>
if it is a symbolic link.
This flag allows security problems to be avoided in set-user-ID-<I>root</I>
programs that allow unprivileged users to unmount filesystems.
</DL>
<A NAME="lbAE">&nbsp;</A>
<H2>RETURN VALUE</H2>
On success, zero is returned.
On error, -1 is returned, and
<I>errno</I>
is set appropriately.
<A NAME="lbAF">&nbsp;</A>
<H2>ERRORS</H2>
The error values given below result from filesystem type independent
errors.
Each filesystem type may have its own special errors and its
own special behavior.
See the Linux kernel source code for details.
<DL COMPACT>
<DT id="5"><B>EAGAIN</B>
<DD>
A call to
<B>umount2</B>()
specifying
<B>MNT_EXPIRE</B>
successfully marked an unbusy filesystem as expired.
<DT id="6"><B>EBUSY</B>
<DD>
<I>target</I>
could not be unmounted because it is busy.
<DT id="7"><B>EFAULT</B>
<DD>
<I>target</I>
points outside the user address space.
<DT id="8"><B>EINVAL</B>
<DD>
<I>target</I>
is not a mount point.
<DT id="9"><B>EINVAL</B>
<DD>
<B>umount2</B>()
was called with
<B>MNT_EXPIRE</B>
and either
<B>MNT_DETACH</B>
or
<B>MNT_FORCE</B>.
<DT id="10"><B>EINVAL</B> (since Linux 2.6.34)
<DD>
<B>umount2</B>()
was called with an invalid flag value in
<I>flags</I>.
<DT id="11"><B>ENAMETOOLONG</B>
<DD>
A pathname was longer than
<B>MAXPATHLEN</B>.
<DT id="12"><B>ENOENT</B>
<DD>
A pathname was empty or had a nonexistent component.
<DT id="13"><B>ENOMEM</B>
<DD>
The kernel could not allocate a free page to copy filenames or data into.
<DT id="14"><B>EPERM</B>
<DD>
The caller does not have the required privileges.
</DL>
<A NAME="lbAG">&nbsp;</A>
<H2>VERSIONS</H2>
<B>MNT_DETACH</B>
and
<B>MNT_EXPIRE</B>
are available in glibc since version 2.11.
<A NAME="lbAH">&nbsp;</A>
<H2>CONFORMING TO</H2>
These functions are Linux-specific and should not be used in
programs intended to be portable.
<A NAME="lbAI">&nbsp;</A>
<H2>NOTES</H2>
<A NAME="lbAJ">&nbsp;</A>
<H3>umount() and shared mount points</H3>
Shared mount points cause any mount activity on a mount point, including
<B>umount</B>()
operations, to be forwarded to every shared mount point in the
peer group and every slave mount of that peer group.
This means that
<B>umount</B>()
of any peer in a set of shared mounts will cause all of its
peers to be unmounted and all of their slaves to be unmounted as well.
<P>
This propagation of unmount activity can be particularly surprising
on systems where every mount point is shared by default.
On such systems,
recursively bind mounting the root directory of the filesystem
onto a subdirectory and then later unmounting that subdirectory with
<B>MNT_DETACH</B>
will cause every mount in the mount namespace to be lazily unmounted.
<P>
To ensure
<B>umount</B>()
does not propagate in this fashion,
the mount point may be remounted using a
<B>mount</B>()
call with a
<I>mount_flags</I>
argument that includes both
<B>MS_REC</B>
and
<B>MS_PRIVATE</B>
prior to
<B>umount</B>()
being called.
<A NAME="lbAK">&nbsp;</A>
<H3>Historical details</H3>
The original
<B>umount</B>()
function was called as <I>umount(device)</I> and would return
<B>ENOTBLK</B>
when called with something other than a block device.
In Linux 0.98p4, a call <I>umount(dir)</I> was added, in order to
support anonymous devices.
In Linux 2.3.99-pre7, the call <I>umount(device)</I> was removed,
leaving only <I>umount(dir)</I> (since now devices can be mounted
in more than one place, so specifying the device does not suffice).
<A NAME="lbAL">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?2+mount">mount</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?7+mount_namespaces">mount_namespaces</A></B>(7),
<B><A HREF="/cgi-bin/man/man2html?7+path_resolution">path_resolution</A></B>(7),
<B><A HREF="/cgi-bin/man/man2html?8+mount">mount</A></B>(8),
<B><A HREF="/cgi-bin/man/man2html?8+umount">umount</A></B>(8)
<A NAME="lbAM">&nbsp;</A>
<H2>COLOPHON</H2>
This page is part of release 5.05 of the Linux
<I>man-pages</I>
project.
A description of the project,
information about reporting bugs,
and the latest version of this page,
can be found at
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="15"><A HREF="#lbAB">NAME</A><DD>
<DT id="16"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="17"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="18"><A HREF="#lbAE">RETURN VALUE</A><DD>
<DT id="19"><A HREF="#lbAF">ERRORS</A><DD>
<DT id="20"><A HREF="#lbAG">VERSIONS</A><DD>
<DT id="21"><A HREF="#lbAH">CONFORMING TO</A><DD>
<DT id="22"><A HREF="#lbAI">NOTES</A><DD>
<DL>
<DT id="23"><A HREF="#lbAJ">umount() and shared mount points</A><DD>
<DT id="24"><A HREF="#lbAK">Historical details</A><DD>
</DL>
<DT id="25"><A HREF="#lbAL">SEE ALSO</A><DD>
<DT id="26"><A HREF="#lbAM">COLOPHON</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:35 GMT, March 31, 2021
</BODY>
</HTML>