mount, umount -装载和卸载文件系统

内容简介

#include

int mount(const char *source, const char *target, const char *filesystemtype, unsigned longmountflags, const void *data);

int umount(const char *target);

int umount2(const char *target, intflags);

描述

mount() attaches the filesystem specified bysource(which is often a device name, but can also be a directory name or a dummy) to the directory specified bytarget.

umount() and umount2() remove the attachment of the (topmost) filesystem mounted on target.

Appropriate privilege (Linux: the CAP_SYS_ADMIN capability) is required to mount and unmount filesystems.

Since Linux 2.4 a single filesystem can be visible at multiple mount points, and multiple mounts can be stacked on the same mount point.

Values for the filesystemtype argument supported by the kernel are listed in/proc/filesystems (like "minix", "ext2", "msdos", "proc", "nfs", "iso9660" etc.). Further types may become available when the appropriate modules are loaded.

The mountflags argument may have the magic number 0xC0ED (MS_MGC_VAL) in the top 16 bits (this was required in kernel versions prior to 2.4, but is no longer required and ignored if specified), and various mount flags (as defined in for libc4 and libc5 and in for glibc2) in the low order 16 bits:

标签

描述

MS_BIND

(Linux 2.4 onwards) Perform a bind mount, making a file or a directory subtree visible at another point within a file system. Bind mounts may cross file system boundaries and spanchroot(2) jails. The filesystemtype, mountflags, and dataarguments are ignored.

MS_DIRSYNC (since Linux 2.5.19)

Make directory changes on this file system synchronous. (This property can be obtained for individual directories or subtrees using chattr(8).)

MS_MANDLOCK

Permit mandatory locking on files in this file system. (Mandatory locking must still be enabled on a per-file basis, as described infcntl(2).)

MS_MOVE

Move a subtree. source specifies an existing mount point andtarget specifies the new location. The move is atomic: at no point is the subtree unmounted. The filesystemtype, mountflags, and data arguments are ignored.

MS_NOATIME

Do not update access times for (all types of) files on this file system.

MS_NODEV

Do not allow access to devices (special files) on this file system.

MS_NODIRATIME

Do not update access times for directories on this file system.

MS_NOEXEC

Do not allow programs to be executed from this file system.

MS_NOSUID

Do not honour set-user-ID and set-group-ID bits when executing programs from this file system.

MS_RDONLY

Mount file system read-only.

MS_REMOUNT

Remount an existing mount. This is allows you to change themountflags and data of an existing mount without having to unmount and remount the file system. source and target should be the same values specified in the initial mount() call;filesystemtype is ignored.

The following mountflags can be changed: MS_RDONLY,MS_SYNCHRONOUS, MS_MANDLOCK; before kernel 2.6.16, the following could also be changed: MS_NOATIME andMS_NODIRATIME; and, additionally, before kernel 2.4, the following could also be changed: MS_NOSUID, MS_NODEV,MS_NOEXEC.

MS_SYNCHRONOUS

Make writes on this file system synchronous (as though theO_SYNC flag to open(2) was specified for all file opens to this file system).

From Linux 2.4 onwards, the MS_NODEV, MS_NOEXEC, and MS_NOSUID flags are settable on a per-mount-point basis. From kernel 2.6.16 onwards, MS_NOATIME andMS_NODIRATIME are also settable on a per-mount-point basis.

The data argument is interpreted by the different file systems. Typically it is a string of comma-separated options understood by this file system. See mount(8) for details of the options available for each filesystem type.

Linux 2.1.116 added the umount2() system call, which, like umount(), unmounts a target, but allows additional flags controlling the behaviour of the operation:

MNT_FORCE (since Linux 2.1.116)

Force unmount even if busy. (Only for NFS mounts.)

MNT_DETACH (since Linux 2.4.11)

Perform a lazy unmount: make the mount point unavailable for new accesses, and actually perform the unmount when the mount point ceases to be busy.

MNT_EXPIRE (since Linux 2.6.8)

Mark the mount point as expired. If a mount point is not currently in use, then an initial call to umount2() with this flag fails with the error EAGAIN, but marks the mount point as expired. The mount point remains expired as long as it isn’t accessed by any process. A second umount2() call specifyingMNT_EXPIRE unmounts an expired mount point. This flag cannot be specified with either MNT_FORCE or MNT_DETACH.

返回值

On success, zero is returned. On error, -1 is returned, anderrnois set appropriately.

错误

下面给出的误差值,导致文件系统类型无关的错误。每个文件系统类型可能有自己特殊的错误和自己的特殊行为。详情请参阅内核源代码。

标签

描述

EACCES

A component of a path was not searchable. (See alsopath_resolution(2).) Or, mounting a read-only filesystem was attempted without giving the MS_RDONLY flag. Or, the block device source is located on a filesystem mounted with theMS_NODEV option.

EAGAIN

A call to umount2() specifying MNT_EXPIRE successfully marked an unbusy file system as expired.

EBUSY

source is already mounted. Or, it cannot be remounted read-only, because it still holds files open for writing. Or, it cannot be mounted on target because target is still busy (it is the working directory of some task, the mount point of another device, has open files, etc.). Or, it could not be unmounted because it is busy.

EFAULT

One of the pointer arguments points outside the user address space.

EINVAL

source had an invalid superblock. Or, a remount (MS_REMOUNT) was attempted, but source was not already mounted on target. Or, a move (MS_MOVE) was attempted, butsource was not a mount point, or was ’/’. Or, an unmount was attempted, but target was not a mount point. Or, umount2() was called with MNT_EXPIRE and either MNT_DETACH orMNT_FORCE.

ELOOP

Too many link encountered during pathname resolution. Or, a move was attempted, while target is a descendant of source.

EMFILE

(In case no block device is required:) Table of dummy devices is full.

ENAMETOOLONG

A pathname was longer than MAXPATHLEN.

ENODEV

filesystemtype not configured in the kernel.

ENOENT

A pathname was empty or had a nonexistent component.

ENOMEM

The kernel could not allocate a free page to copy filenames or data into.

ENOTBLK

source is not a block device (and a device was required).

ENOTDIR

The second argument, or a prefix of the first argument, is not a directory.

ENXIO

The major number of the block device source is out of range.

EPERM

The caller does not have the required privileges.

遵循于

这些功能是Linux特有的,应在拟移植的程序不能使用。

历史

The originalumount() function was called asumount(device)and would return ENOTBLK when called with something other than a block device. In Linux 0.98p4 a callumount(dir)was added, in order to support anonymous devices. In Linux 2.3.99-pre7 the callumount(device)was removed, leaving onlyumount(dir)(since now devices can be mounted in more than one place, so specifying the device does not suffice).

The original MS_SYNC flag was renamed MS_SYNCHRONOUS in 1.1.69 when a different MS_SYNC was added to .

Before Linux 2.4 an attempt to execute a set-user-ID or set-group-ID program on a filesystem mounted with MS_NOSUID would fail with EPERM. Since Linux 2.4 the set-user-ID and set-group-ID bits are just silently ignored in this case.

另请参阅

¥ 我要打赏

纠错/补充

收藏

加QQ群啦,易百教程官方技术学习群

注意:建议每个人选自己的技术方向加群,同一个QQ最多限加 3 个群。

linux mount_nodev函数,mount()函数 Unix/Linux相关推荐

  1. linux c++ 程序运行时间,总结UNIX/LINUX下C++程序计时的方法

    前言 良好的计时器可帮助程序开发人员确定程序的性能瓶颈,或对不同算法进行性能比较.但要精确测量程序的运行时间并不容易,因为进程切换.中断.共享的多用户.网络流量.高速缓存访问及转移预测等因素都会对程序 ...

  2. linux下启动tlq命令,UNIX/LINUX命令

    1 如何查看磁盘使用情况 查看磁盘空间 df -k 可以看出磁盘空间使用情况.以及分区或者逻辑卷的挂载目录等. $ df -k Filesystem 1024-blocks Free %Used Iu ...

  3. linux下 远程桌面连接,Unix/Linux下通过远程桌面连接Windows OS

    不知Microsoft出于什么考虑,在Windows XP中只允许一个Session通过远程桌面连接,如果一台XP为管理工作站,只有它能够访问后端的SAN Switch或存储系统,那么多人将无法同时使 ...

  4. linux中ftok的作用,Unix/Linux编程之ftok函数用法

    linux 中ftok函数的用法 1.函数作用: 系统建立IPC通讯(如消息队列.共享内存时)必须指定一个ID值.通常情况下,该id值通过ftok函数得到 2.函数原型: #include #incl ...

  5. windows下的linux工具,Windows下的Unix/Linux工具集:UnxUtils

    最近用dos命令多了些,感觉方便得多,对付一些老机器特别有效~只是可惜dos命令功效有限,如果能使用到linux系统上类似grep,sed,cat这样命令就完美了~ 果然和想得差不多,网上还真有&qu ...

  6. Unit 3: Unix/Linux File System 3.1 Unix/Linux File System Sleuthkit and Autopsy

    >> Now let's learn and practice a well-known open source forensic analysis tool called Sleuth ...

  7. linux退出脚本命令,【Unix/Linux.Shell Script】退出状态,exit命令

    每一条命令,不管是内置,shell函数,还是外部的,当它退出时,都会返回一个小的整数值给引用它的程序,这是程序的退出状态. 在shell下执行程序时,有许多方式可以取出程序的退出状态. 退出状态值 以 ...

  8. Linux学习:简单基础的Linux系统命令

    Linux操作系统介绍     肯.汤普逊 丹尼斯.里奇     美国 贝尔实验室     1970-1973     BCPL->new B->C->UNIX系统->Mini ...

  9. linux 网卡驱动编译安装包,linux网卡驱动程序的编译与安装

    一般来说,目前新版的Linux预设可以支持的网络卡芯片组数量已经很完备了,很多网络卡芯片都已经被支持, 例如RLT 8139芯片( RealTek 8139 )的网络卡所以使用者可以很轻易的设定好他们 ...

最新文章

  1. npc寻路问题 c++_《原神》游戏中最懒的NPC出现了,她要玩家找一朵甜甜花
  2. matlab optimvar
  3. 微信内置浏览器的JsAPI(WeixinJSBridge续)[转载]
  4. 网络相关的一些基本的命令的使用(ping、ifconfig、route、netstat)---Linux学习笔记
  5. 在FSM模型中使用两态数据类型
  6. 层次分析法matlab_建模开讲课程回放2:层次分析法及其MATLAB
  7. win 二进制门安装mysql_MySQL5.7 windows二进制安装
  8. Java程序员,上班那点事儿
  9. 案例学习BlazeDS+Spring之五InSync03强类型
  10. Android中导入Unity项目,界面点击事件失去焦点问题
  11. 微信小程序文件大小限制
  12. LimeSurvey 安装
  13. win7 安装 python3.8.10
  14. 永洪报表工具_报表工具对比选型系列用例——过程计算
  15. 武汉大学计算机系就业方向如何,武汉大学有什么王牌专业?它们的就业在哪些方向?...
  16. 乒乓球比赛赛程_这家律所再次摘得业余乒乓球赛事冠军,为何结缘乒乓?
  17. 好嗨哟!OneOS 图形组件显示自己喜欢的图片
  18. matlab scop的波形图怎么标注,matlab_simulink_示波器_scope图片属性设置.doc
  19. mysql密码认证插件_关于mysql:无法加载身份验证插件’caching_sha2_password’
  20. 必应每日一图php,自建必应每日一图API接口

热门文章

  1. java run 方法_java线程中的run()方法能有几个啊?
  2. power bi 创建空表_使用Power BI创建足球热图
  3. 查询sql执行计划_使用SQL执行计划进行查询性能调整
  4. nginx静态资源 性能_如何欺骗生产环境资源以进行性能调整
  5. 如何下载和安装SQL Server数据库实验助手(DEA)
  6. 未能找到存储过程sp__sp_WhoIsActive存储过程概述
  7. 官网改版项目问题总结
  8. SSM框架的基本概念
  9. hive join on 条件 与 where 条件区别
  10. NodeJS仿WebApi路由