首页 > 编程知识 正文

陆毅简介,fuseeho是什么意思

时间:2023-05-06 18:38:27 阅读:113882 作者:2105

译文: 3358 www.Linux.org/threads/fuse.6211 /

译文:

安全(thefilesysteminuserspace,简称fuse )是Kernel的一个奇怪部分,允许普通用户创建和使用自己的文件系统,而无需修改Kernel或获得根权限。 FUSE使用的文件系统是“虚拟文件系统”,但不是所有虚拟文件系统都使用FUSE。 位于USE的代码Kernel中,但文件系统位于User Space中。 但是,典型的文件系统存在于Kernel中。

使用FUSE,用户可以创建、修改或临时使用特殊的文件系统。 另外,如gvfs(gnomevirtualfilesystem )那样,程序可以与本地文件一样访问远程文件系统,或者通过FUSE访问远程文件系统等另外,在撰写本文时,Linux Kernel还不支持本机exFAT/FAT64 ),但用户可以使用FUSE装载exFAT/FAT64文件系统。 但是,FUSE可能需要安装其他支持包才能运行这些文件系统。 例如,如果用户需要使用上述exFAT,则必须安装扩展了fuse (fuse的驱动程序包)的exfat-fuse '软件包。 下图是更多的FUSE扩展包。

FUSE项目位于http://fuse.sourceforge.net/,是一个谁都可以获得和使用的、稳定、安全、可靠的开源项目。 但是,使用“真正的”文件系统可以提高效率。 FUSE与操作系统(如Solaris、FreeBSD、Darwin、GNU/Hurd、OS X和OpenSolaris )兼容。 虽然某些操作系统不支持FUSE,但NetBSD使用PUFFS,Windows可以使用来自FUSE的替代品,如使用“Fuse4Win '”。

use不仅用于装载虚拟文件系统,还用于“真”文件系统,如ZFS和exFAT。 FUSE还可以装载ISO、CD和压缩文件(zip、gzip、tar等)。 use还扩展到了网络文件系统,如HTTP-FS和aptfs(aptrepos )。 FUSE可用于传输Apple设备(如iPod和iPhone )上的文件。 更令人惊讶的是,FUSE还可以通过mp3fs将FLAC转换为mp3。

用户可以实现自己的文件系统,而无需修改Kernel。 用户文件系统是用类似的方法开发的。 如果用户希望使用Ruby实现虚拟文件系统,则需要“ruby-fusefs”包。 许多语言提供FUSE绑定,如Perl、Python、C/C和C#。 完整的语言绑定列表: http://SourceForge.net/apps/mediawiki/fuse/index.PHP? title=语言绑定。

如果使用FUSE,则这些虚拟文件系统没有格式化。 相反,用户必须初始化这些文件系统,并将其挂载到用户有权访问的空目录中。

现在,我们应该了解FUSE的很多知识,并说明它是如何工作的。 FUSE是Linux的中介(Mediaor )模块,位于FUSE文件系统和Linux Kernel的VFS之间。 VFS只能由管理员用户或进程访问。 因为用户可以访问FUSE,FUSE可以访问VFS,所以权限系统允许任何用户使用FUSE。 对FUSE本身来说,代码包含结构变量,并包含FUSE的函数指针,许多进程可能会到达该函数指针。

简单的FUSE结构变量代码:

struct fuse _ operations { int (* mknod ) ) const char *,mode_t,dev_t ); int(*getdir ) ) const char *,fuse_dirh_t,fuse_dirfil_t ); int(*mkdir ) ) const char *,mode_t ); int(*rmdir ) )常数char * ); int(*readlink ) ) const char *、char *、size_t ); int(*symlink ) ) const char *,const char *; int(*unlink ) ) const char * ); int(*rename ) )常数char *,常数char *; int(*link ) )常数char *,常数char *; int(*chmod ) ) const char *,mode_t ); int(*chown ) ) const char *,uid_t,gid_t ); int(*truncate ) ) const char *,off_t ); int(*utime ) ) const char *,struct utimbuf * ); int(*open ) ) const char *,struct fuse_file_info *; int(*read ) ) const char *、char *、size_t、off_t、struct fuse_file_info *; int(*write ) ) const char *,const char

*, size_t, off_t,struct fuse_file_info *); int (*statfs) (const char *, struct statfs *); int (*flush) (const char *, struct fuse_file_info *); int (*release) (const char *, struct fuse_file_info *); int (*fsync) (const char *, int, struct fuse_file_info *); int (*getattr) (const char *, struct stat *); int (*setxattr) (const char *, const char *, const char *, size_t, int); int (*getxattr) (const char *, const char *, char *, size_t); int (*listxattr) (const char *, char *, size_t); int (*removexattr) (const char *, const char *);};

所以,如果一个进程使用FUSE执行Write操作,则文件系统执行write()的代码。

下面列一下使用FUSE需要的工作:

导入头文件:所有的C/C++头文件,以及其它语言的支持库;

声明变量:任何被大量使用的变量应该放在源程序的显眼位置,让开发者容易找到并修改;

系统调用声明:以“fuse_operations"声明的系统调用及相关参数;

系统调用函数:实现需要的系统调用,如open(), read(), write()及其它特性;

Main函数:显然,如果基于C/C++实现,main函数必不可少。

一旦文件系统”运行“起来,FUSE会作为中介,与Kernel进行通信。

下面的例子来自于http://fuse.sourceforge.net/helloworld.html:

/* FUSE: Filesystem in Userspace Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu> This program can be distributed under the terms of the GNU GPL. See the file COPYING. gcc -Wall hello.c `pkg-config fuse --cflags --libs` -o hello*/#define FUSE_USE_VERSION 26#include <fuse.h>#include <stdio.h>#include <string.h>#include <errno.h>#include <fcntl.h>static const char *hello_str = "Hello World!n";static const char *hello_path = "/hello";static int hello_getattr(const char *path, struct stat *stbuf){ int res = 0; memset(stbuf, 0, sizeof(struct stat)); if (strcmp(path, "/") == 0) { stbuf->st_mode = S_IFDIR | 0755; stbuf->st_nlink = 2; } else if (strcmp(path, hello_path) == 0) { stbuf->st_mode = S_IFREG | 0444; stbuf->st_nlink = 1; stbuf->st_size = strlen(hello_str); } else res = -ENOENT; return res;}static int hello_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi){ (void) offset; (void) fi; if (strcmp(path, "/") != 0) return -ENOENT; filler(buf, ".", NULL, 0); filler(buf, "..", NULL, 0); filler(buf, hello_path + 1, NULL, 0); return 0;}static int hello_open(const char *path, struct fuse_file_info *fi){ if (strcmp(path, hello_path) != 0) return -ENOENT; if ((fi->flags & 3) != O_RDONLY) return -EACCES; return 0;}static int hello_read(const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi){ size_t len; (void) fi; if(strcmp(path, hello_path) != 0) return -ENOENT; len = strlen(hello_str); if (offset < len) { if (offset + size > len) size = len - offset; memcpy(buf, hello_str + offset, size); } else size = 0; return size;}static struct fuse_operations hello_oper = { .getattr = hello_getattr, .readdir = hello_readdir, .open = hello_open, .read = hello_read,};int main(int argc, char *argv[]){ return fuse_main(argc, argv, &hello_oper, NULL);}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。