操作记录:在ubuntu16.04.1配置fuse开发环境及fuse开发规范测试

1、使用ssh客户端,登陆ubuntu

ssh -p 2206 [email protected]

2、下载fuse源码,进行编译,安装(当前工作目录为~)

wget https://github.com/libfuse/libfuse/releases/download/fuse-3.0.0rc3/fuse-3.0.0rc3.tar.gz
tar xvf fuse-3.0.0rc3.tar.gz
cd fuse-3.0.0rc3/
./configure
make -j8
make install
depmod
modprobe fuse

3、测试example\hello_ll是否能正常工作

cd example/
./hello_ll --help
./hello_ll /mnt
mount
cd /mnt
ls
cat hello
cd
umount /mnt

  • 针对example\hello_ll.c,进行改动测试:

1、在根目录下多创建一个文件出来,节点号定为5,名称为frombyte,内容为文本"http://www.datahf.net"

改动如下:

/*
  FUSE: Filesystem in Userspace
  Copyright (C) 2001-2007  Miklos Szeredi <[email protected]>

  This program can be distributed under the terms of the GNU GPL.
  See the file COPYING.
*/

/** @file
 *
 * minimal example filesystem using low-level API
 *
 * Compile with:
 *
 *     gcc -Wall hello_ll.c `pkg-config fuse3 --cflags --libs` -o hello_ll
 *
 * ## Source code ##
 * \include hello_ll.c
 */

#define FUSE_USE_VERSION 30

#include <config.h>

#include <fuse_lowlevel.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <assert.h>

static const char *hello_str = "Hello World!\n";
static const char *hello_name = "hello";
//change1 #0
static const char *inode5_str = "http://www.datahf.net!\n";
static const char *inode5_name = "frombyte";
//change end
static int hello_stat(fuse_ino_t ino, struct stat *stbuf)
{
	stbuf->st_ino = ino;
	switch (ino) {
	case 1:
		stbuf->st_mode = S_IFDIR | 0755;
		stbuf->st_nlink = 2;
		break;

	case 2:
		stbuf->st_mode = S_IFREG | 0444;
		stbuf->st_nlink = 1;
		stbuf->st_size = strlen(hello_str);
		break;

//change1  #1
    case 5:
        stbuf->st_mode = S_IFREG | 0444;
        stbuf->st_nlink = 1;
        stbuf->st_size = strlen(inode5_str);
        break;
//change1 end
            
	default:
		return -1;
	}
	return 0;
}

static void hello_ll_getattr(fuse_req_t req, fuse_ino_t ino,
			     struct fuse_file_info *fi)
{
	struct stat stbuf;

	(void) fi;

	memset(&stbuf, 0, sizeof(stbuf));
	if (hello_stat(ino, &stbuf) == -1)
		fuse_reply_err(req, ENOENT);
	else
		fuse_reply_attr(req, &stbuf, 1.0);
}

static void hello_ll_lookup(fuse_req_t req, fuse_ino_t parent, const char *name)
{
	struct fuse_entry_param e;
    //change1  #2
    /*
    if (parent != 1 || strcmp(name, hello_name) != 0)
        fuse_reply_err(req, ENOENT);
    else {
        memset(&e, 0, sizeof(e));
        e.ino = 2;
        e.attr_timeout = 1.0;
        e.entry_timeout = 1.0;
        hello_stat(e.ino, &e.attr);
        
        fuse_reply_entry(req, &e);
    }*/

    if (parent != 1)
		fuse_reply_err(req, ENOENT);
	else if(strcmp(name, hello_name) == 0){
		memset(&e, 0, sizeof(e));
		e.ino = 2;
		e.attr_timeout = 1.0;
		e.entry_timeout = 1.0;
		hello_stat(e.ino, &e.attr);
		fuse_reply_entry(req, &e);
	}
    else if(strcmp(name, inode5_name) == 0){
        memset(&e, 0, sizeof(e));
        e.ino = 5;
        e.attr_timeout = 1.0;
        e.entry_timeout = 1.0;
        hello_stat(e.ino, &e.attr);
        fuse_reply_entry(req, &e);
    }
    else
        fuse_reply_err(req, ENOENT);
    //change1 end
}

struct dirbuf {
	char *p;
	size_t size;
};

static void dirbuf_add(fuse_req_t req, struct dirbuf *b, const char *name,
		       fuse_ino_t ino)
{
	struct stat stbuf;
	size_t oldsize = b->size;
	b->size += fuse_add_direntry(req, NULL, 0, name, NULL, 0);
	b->p = (char *) realloc(b->p, b->size);
	memset(&stbuf, 0, sizeof(stbuf));
	stbuf.st_ino = ino;
	fuse_add_direntry(req, b->p + oldsize, b->size - oldsize, name, &stbuf,
			  b->size);
}

#define min(x, y) ((x) < (y) ? (x) : (y))

static int reply_buf_limited(fuse_req_t req, const char *buf, size_t bufsize,
			     off_t off, size_t maxsize)
{
	if (off < bufsize)
		return fuse_reply_buf(req, buf + off,
				      min(bufsize - off, maxsize));
	else
		return fuse_reply_buf(req, NULL, 0);
}

static void hello_ll_readdir(fuse_req_t req, fuse_ino_t ino, size_t size,
			     off_t off, struct fuse_file_info *fi)
{
	(void) fi;

	if (ino != 1)
		fuse_reply_err(req, ENOTDIR);
	else {
		struct dirbuf b;

		memset(&b, 0, sizeof(b));
		dirbuf_add(req, &b, ".", 1);
		dirbuf_add(req, &b, "..", 1);
		dirbuf_add(req, &b, hello_name, 2);
        //change1
        dirbuf_add(req, &b, inode5_name, 5);
        //end
		reply_buf_limited(req, b.p, b.size, off, size);
		free(b.p);
	}
}

static void hello_ll_open(fuse_req_t req, fuse_ino_t ino,
			  struct fuse_file_info *fi)
{
    //change1
	//if (ino != 2)
    if ( (ino !=2) && (ino != 5) )
    //end
		fuse_reply_err(req, EISDIR);
	else if ((fi->flags & 3) != O_RDONLY)
		fuse_reply_err(req, EACCES);
	else
		fuse_reply_open(req, fi);
}

static void hello_ll_read(fuse_req_t req, fuse_ino_t ino, size_t size,
			  off_t off, struct fuse_file_info *fi)
{
	(void) fi;

    //change1
	//assert(ino == 2);
	//reply_buf_limited(req, hello_str, strlen(hello_str), off, size);
    switch (ino) {
        case 2:
            reply_buf_limited(req, hello_str, strlen(hello_str), off, size);
            break;
        case 5:
            reply_buf_limited(req, inode5_str, strlen(inode5_str), off, size);
            break;
        default:
            ;
    }
    //end
}

static struct fuse_lowlevel_ops hello_ll_oper = {
	.lookup		= hello_ll_lookup,
	.getattr	= hello_ll_getattr,
	.readdir	= hello_ll_readdir,
	.open		= hello_ll_open,
	.read		= hello_ll_read,
};

int main(int argc, char *argv[])
{
	struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
	struct fuse_session *se;
	struct fuse_cmdline_opts opts;
	int ret = -1;

	if (fuse_parse_cmdline(&args, &opts) != 0)
		return 1;
	if (opts.show_help) {
		printf("usage: %s [options] <mountpoint>\n\n", argv[0]);
		fuse_cmdline_help();
		fuse_lowlevel_help();
		ret = 0;
		goto err_out1;
	} else if (opts.show_version) {
		printf("FUSE library version %s\n", fuse_pkgversion());
		fuse_lowlevel_version();
		ret = 0;
		goto err_out1;
	}

	se = fuse_session_new(&args, &hello_ll_oper,
			      sizeof(hello_ll_oper), NULL);
	if (se == NULL)
	    goto err_out1;

	if (fuse_set_signal_handlers(se) != 0)
	    goto err_out2;

	if (fuse_session_mount(se, opts.mountpoint) != 0)
	    goto err_out3;

	fuse_daemonize(opts.foreground);

	/* Block until ctrl+c or fusermount -u */
	if (opts.singlethread)
		ret = fuse_session_loop(se);
	else
		ret = fuse_session_loop_mt(se, opts.clone_fd);

	fuse_session_unmount(se);
err_out3:
	fuse_remove_signal_handlers(se);
err_out2:
	fuse_session_destroy(se);
err_out1:
	free(opts.mountpoint);
	fuse_opt_free_args(&args);

	return ret ? 1 : 0;
}

结果测试:

cd ~/fuse-3.0.0rc3/example/
make
./hello_ll /mnt
ll -i /mnt
cat /mnt/frombyte 
umount /mnt

2、待续

时间: 2024-08-23 14:06:48

操作记录:在ubuntu16.04.1配置fuse开发环境及fuse开发规范测试的相关文章

ubuntu16.04下配置apache2与php

系统版本:ubuntu16.04 命令均在终端中输入,用浏览器测试 //安装apache2命令 sudo apt install apache2 //测试是否安装成功 浏览器地址栏输入"localhost" //安装最新版php命令 sudo apt install php //配置apache2与php命令 sudo apt-get install libapache2-mod-php //重启apache2命令 sudo /etc/init.d/apache2 restart //

Ubuntu16.04 vim 配置自动补全

Ubuntu16.04 vim 配置自动补全 上个月末,ubuntu16.04的消息在各linux论坛算是炸开了锅.对于一直置立于ubuntu下的我,也是蛮期待下一个长期稳定版本的发布.好不容易等到了新版本的发布,刚好那几天请假在家,工作上也没有什么事.对于有跟新症的我,那还等什么呢,那还不赶紧的备份安装. 一直用vim进行c++的编写工作,当然更新系统后少不了进行vim的各种配置.vim的补全功能虽然没有ide的强大,但是安装上youcompleteme后,补全功能也算说的过去. 下边开始进入

Ubuntu16.04安装配置和使用ctags

Ubuntu16.04安装配置和使用ctags by ChrisZZ ctags可以用于在vim中的函数定义跳转.在ubuntu16.04下默认提供的ctags是很老很旧的ctags,快要发霉的版本(5.9~svn20110310-11),快扔掉它,安装universal-ctags吧! 发霉的exuberant-ctags 来,一起看看,默认的ctags是什么情况. 查看apt提供了哪些ctags包 aptitude search ctags 查询结果: v ctags - v ctags:i

Ubuntu16.04.5 配置英伟达NVIDIA 显卡 驱动实现GPU加速

Ubuntu16.04.5 配置英伟达NVIDIA 显卡 驱动实现GPU加速 标签(空格分隔): 运维系列 一:系统环境初始化与系统包准备 二:安装测试步骤 一:系统环境初始化与系统包准备 apt-get update apt-get install vim openssh-server 准备系统所需要的安装包 NVIDIA-Linux-x86_64-440.44.run cuda_10.2.89_440.33.01_linux.run 二:安装测试步骤 1.1 安装Nvidia显卡驱动 1.

基础知识 - 在 Ubuntu 14.04 中配置 Sublime Text 3 的 Golang 开发环境

1.下载 golang 并解压(这里以解压到 $HOME/golang/ 目录为例): http://www.golangtc.com/download 2.创建 GoPath 相关目录(这里以 $HOME/golang/projects/ 目录为例): mkdir ~/golang mkdir ~/golang/projects mkdir ~/golang/projects/3rdparty mkdir ~/golang/projects/3rdparty/bin mkdir ~/golan

操作记录:在ubuntu16.04.1配置qemu-img,qemu-nbd

1.下载ubuntu-16.04.1-server-amd64.iso 2.在vbox中创建虚拟机,设置网络配置为网络地址转换NAT,创建端口转发规则(以便用于ssh): 名称:默认 协议:TCP 主机IP:空 主机端口:2206 子系统IP:空 子系统端口:22 3.正常安装系统,中间选模块时勾选sshd 4.安装后进入shell,修改root密码,懒得每次执行命令都sudo sudo passwd root 5.修改/etc/ssh/sshd_config     PermitRootLog

Ubuntu16.04 安装配置Caffe

Caffe已经是第三次安装配置了,为什么是第三次呢?因为我实在是低估了深度学习对于硬件的要求.第一次我在自己笔记本上配置的单核,CPU only ...  结果是,样例数据跑了4小时,这还怎么玩?第二次在台式机上,因为台式机比较low,I5处理器4核,没有NVIDIA的GPU.我把别人训练好的模型下载下来,然后自己测试,发现真的成功了,心里小激动~ 然而,当我自己训练模型时,我训练7天.....  关键是7天了还在跑..... 心想,我这个穷逼难道要自己掏钱买个服务器?那怎么可能.还好,老师人非

ubuntu16.04下配置JDK 1.8+安装Java EE,并实现最大子数组算法

软工第二次作业: 1.在个人电脑中安装一个集成开发环境(Microsoft Visual Studio.Eclipse或其它工具均可),要求该环境能够提供单元自动测试功能: 2.记录安装过程,并将全部内容发表在博客中: 3.实现最大子数组和算法,并将该段代码上传至Coding.net系统中: 4.自行选择合适的覆盖标准并设计测试用例对该段代码进行测试,并将测试结果发布在博客中,结果以如下表格形式完成. 本文为干货,希望有用,欢迎评论. 由于我的labtop上安装的是ubuntu16.04系统,其

【Caffe】Ubuntu16.04上配置安装caffe(Only CPU)

一.首先看看自己的系统,Ubuntu16.04,cpu,没有Nvidia,没有opencv 二.安装依赖包 安装protobuf,leveldb,snappy,OpenCV,hdf5, protobuf compiler andboost: sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler sudo apt-get

ubuntu16.04 安装配置matlab ,python ,cuda8.0,cudnn,opencv3.1的caffe环境

网络上有很多ubuntu上caffe配置环境的帖子,本人照着其中的许多进行了参考,都出现了或多或少的错误,很多地方也有差异. 于是自己整理了下自己的安装过程,成功进行了测试,跑通了faster-rcnn.配置环境时间为2017.1.4 系统ubuntu16.04 一:显卡驱动的安装: 由于要使用GPU,所以先要查看自己显卡所匹配的显卡驱动,网址:http://www.nvidia.com/Download/index.aspx%3Flang=en-us 选择电脑匹配的显卡驱动,本人电脑显卡为GT