fuse的mount机制 2 -系统调用mount
经过上一篇的分析,目前已经知道mount函数最终进入到mount.c 中的 int fuse_kern_mount(const char *mountpoint, struct fuse_args *args)
而主题函数进入到fuse.c中的 fuse_new_common
这两个函数都会在helper.c中的fuse_setup_common中返回,返回后进入helper.c的 fuse_daemonize 。fuse_daemonize使用 foreground参数也即-f参数。
如果-f参数为真,则进入fuse_daemonize的循环体,否则fuse_daemonize直接返回,然后fuse_setup_common也返回到fuse_main_common,进入fuse_loop_mt循环。
本篇主要研究fuse_kern_mount函数。
1. 该函数调用栈:
fuse_setup_common->
fuse_mount_common(const char *mountpoint,struct fuse_args *args) ->
fuse_mount_compat25(const char *mountpoint, struct fuse_args *args) ->
fuse_kern_mount(const char *mountpoint, struct fuse_args *args)
2. mountpoint就是命令行提供的目录参数。args也是根据命令行的参数生成的,struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
#define FUSE_ARGS_INIT(argc, argv) { argc, argv, 0 }
在fuse_opt.h
struct fuse_args {
/** Argument count */
int argc;
/** Argument vector. NULL terminated */
char **argv;
/** Is 'argv' allocated? */
int allocated;
};
也在fuse_opt.h
注意,在fuse_setup_common中,将命令行的参数进行了规整,处理出mountpoint和args。mountpoint是挂载点的全路径字符串. 如果命令行是./ssfs dir1 -f , args含有两个字符串,第一个字符串是 ./ssfs,第二个字符串是-osubtype=ssfs
3. fuse_kern_mount首先构建struct mount_opts mo;
struct mount_opts {
int allow_other;
int allow_root;
int ishelp;
int flags;
int nonempty;
int auto_unmount;
int blkdev;
char *fsname;
char *subtype;
char *subtype_opt;
char *mtab_opts;
char *fusermount_opts;
char *kernel_opts;
};
然后调用 fuse_mount_sys(mountpoint, &mo, mnt_opts);函数,这里因为 mo->auto_unmount为真,该函数将返回-2,即fallback to fusermount ,
转而调用fuse_mount_fusermount,这里会调用第一个,并返回3.
fuse_mount_fusermount(mountpoint, &mo, tmp_opts, 1);
注意:fuse_mount_sys中主要是open了/dev/fuse以及使用了mount系统调用。 fuse_mount_fusermount中主要使用 socketpair系统调用。
注意2:fuse_mount_fusermount使用了fork,然后子线程做了一系列操作后_exit了。一个重要操作是 exec_fusermount(argv); argv里包含mountpint以及mount程序名即fusermount。
static void exec_fusermount(const char *argv[])
{
execv(FUSERMOUNT_DIR "/" FUSERMOUNT_PROG, (char **) argv);
execvp(FUSERMOUNT_PROG, (char **) argv);
}
FUSERMOUNT_DIR打印字符串显示的是 /usr/local/bin
FUSERMOUNT_DIR "/" FUSERMOUNT_PROG打印字符串显示的是/usr/local/bin/fusermount
原来c语言里将几个字符串直接放在一起就是连起来!
从这里看来,mount函数最终调用了 fusermount程序,一个自带main函数的程序。该程序的源代码就是 util目录下的fusermount.c
注意:后入如果需要打印到屏幕,需要在fuse_mount_fusermount注销掉改变sdio的代码。
4. fusermount.c最终调用了系统调用mount。
调用栈:
fusermount.c:main ->
mount_fuse(const char *mnt, const char *opts) ->
do_mount(const char *mnt, char **typep, mode_t rootmode,
int fd, const char *opts, const char *dev, char **sourcep, char **mnt_optsp, off_t rootsize) ->
mount(source, mnt, type, flags, optbuf).
在mount_fuse向do_mount传递mnt参数之前,调用了check_perm函数,该函数使用chdir将当前的工作路径改为mnt,然后使用"."即当前路径作为mnt。
后面的几个函数均使用"."作为mnt。
问题:自己写的程序按照上述的方式使用root调用mount,会出现errno=22即EINVAL source had an invalid superblock. 那么,为什么fuse就可以这样掉用mount呢?
经验证,在fuse的mount调用中,可以随意改变source,type,flags变量。改变source和type有时会反映到mount列表,有时却不会。
也可以随便改变mnt变量,但是必须是一个存在可访问的路径,改变mnt变量不会反映到mount列表。
注意:貌似这里的mount返回了-1,errno为19表示filesystemtype not configured in the kernel. 但是不影响程序正确执行,而且,strace监测不到这个mount。继续发现,只要type里设置了fuse或fuse.xx就返回0,source可随意设置。 strace追踪不到的原因是mount在fork的子程序里运行的。
如果使用strace -f可以追中到子进程的mount,然而结果显示Operation not permitted。
使用sudo的话,实际运行的mount代码是fuse_mount_sys函数里的。
fuse的mount机制 2 -系统调用mount的更多相关文章
- fuse的mount机制-流程及参数
在bbfs中,传递的参数有两个目录,fuse将一个目录挂载在另一个目录下. 在ssfs中,传递的参数只有一个目录(传递两个目录fuse会出错). 问题:那么fuse的mount机制到底需要几个目录参数 ...
- mount机制3-/etc/mtab
这次查看fuse_mount_sys函数的执行过程,理解mount的各个阶段. 这个函数能够执行的前提是命令行使用root账户. 1. 首先,该函数仍然是主要使用 mount(const char * ...
- linux系统调用mount全过程分析【转】
本文转载自:https://blog.csdn.net/skyflying2012/article/details/9748133 系统调用本身是软中断,使用系统调用,内核也陷入内核态,异常处理,找到 ...
- [mount]linux 挂载时 mount: wrong fs type, bad option, bad superblock on /dev/sdb
原因:挂载时未格式化,使用的文件系统格式不对 解决方案:格式化 sudo mkfs -t ext4 /dev/sdb 再挂载 sudo mount /dev/sdb /xxx/ 用df -h检查,发现 ...
- Linux文件系统的设计
总论: linux的文件系统设计非常优秀,总的来讲有两大部分,第一部分就是树形的组织结构,第二部分就是vfs,树形的组织结构组织了文件系统的表象,用户非常方便的使用,而vfs是文件系统的实现机理,它处 ...
- linux文件系统调用(1)---mount
术语表: struct mount:挂载点 struct mountpoint:挂载点节点 struct vfsmount:挂载项 源文件系统:用户将要挂载的文件系统 目的文件系统:挂载源文件系统的文 ...
- mount源码分析 【转】
转自:http://blog.chinaunix.net/uid-10769062-id-3230811.html Busybox- 在util-linux/mount.c的line:1609行首先映 ...
- mount
产品,平台,RS6000, pseries 软件版本, aix 当NFS在NFS客户端加载时,系统会问是使用 soft-mount 还是hard-mount, 它们之间有什么区别? 它们的区别在于当发 ...
- mount nfs的可选参数
mount nfs的可选参数:HARD mount和SOFT MOUNT:HARD:NFS CLIENT会不断的尝试与SERVER的连接(在后台,不会给出任何提示信息,在LINUX下有的版本仍然会给出 ...
随机推荐
- 在 IntelliJ IDEA 中为自己设计的类库生成 JavaDoc
因为某个项目需要,为团队其他兄弟姐妹开发了一个 XML 分析处理器,并将其设计为一个类库,提供相应的 API 接口.为了方便大家的使用,需要生成对应的 JavaDoc 帮助文档,就像 JavaSE 标 ...
- hdu 4849
简单题,公式计算+最短路.注意点:注意1 取模,2 数组开到n*n+n. #include<iostream> #include<queue> using namespace ...
- (3)Swing常用组件
JTextField-文本框 继承自javax.swing.text.JTextComponent类
- Python使用eval强制转换字符串为字典时报错:File "<string>", line 1, in <module> NameError: name 'nan' is not defined
文本中保存的内容为: { 'QQQ': [0.067, 0.167, 0.2, 0.033, 0.233, 0.267, 0.1, 0.133], 'TTT': [0.5, 0.375, 0.25, ...
- 转:CEF嵌入到单文档mfc
1.下载: http://www.magpcss.net/cef_downloads/下载cef binary 1.1364.1123 windows.zip(可能要FQ,百度goagent教程,最好 ...
- OllyDBG找到按钮的处理函数
最近系统有点慢,就想优化一下,于是下了个XX大师.结果要注册才行,看来可以用来练练手了.OD一下,靠还加了壳,偶就是用一下,就不脱你了.开始在弹出窗口MessageBoxA下断,伊,结果不是用的这个函 ...
- Wide & Deep Learning Model
Generalized linear models with nonlinear feature transformations (特征工程 + 线性模型) are widely used for l ...
- 79.iOS 设备的UI规范和iOS各控件默认高度
iOS设备的UI 规范 iPhone界面尺寸 iPhone图标尺寸 iPad的设计尺寸 iPad图标尺寸 iPhone设备尺寸分辨率比例 iPhone各设备 launch image iOS 各种控件 ...
- Java基础 笔记(四)
泛型: 泛型:通过<数据额类型>来接受一种引用数据类型.作用在编译时.使用检查 加入集合的对象是否属于该类型,从而把执行时的问题转换为编译时异常.提高程序的安全性 避免抛出 ClassCa ...
- 安卓自带下拉刷新SwipeRefreshLayout加入上拉刷新功能
在项目里面要用到刷新库.曾经都是使用第三方的.只是看到官方出了 SwipeRefreshLayout之后就用SwipeRefreshLayout.可是不知道什么原因官方SwipeRefreshL ...