Operation Record: Configure fuse development environment and fuse Development specification test in ubuntu16.04.1

Source: Internet
Author: User
Tags assert goto strcmp

1, using SSH client, landing ubuntu

Ssh-p 2206 [email protected]

2, download the fuse source code, compile, install (current working directory is ~)

wget Https://github.com/libfuse/libfuse/releases/download/fuse-3.0.0rc3/fuse-3.0.0rc3.tar.gztar XVF FUSE-3.0.0RC3.TAR.GZCD fuse-3.0.0rc3/./configuremake-j8make Installdepmodmodprobe Fuse

3. Test whether the EXAMPLE\HELLO_LL can work properly

CD Example/./hello_ll--help./hello_ll/mntmountcd/mntlscat hellocdumount/mnt
    • For EXAMPLE\HELLO_LL.C, make the change test:


1, in the root directory to create more than one file, the node number is set to 5, the name is Frombyte, the content is the text "Http://www.datahf.net"

The changes are as follows:

/*  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  #0static  const char *inode5_str =  "http://www.datahf.net!\n"; Static const char  *inode5_name =  "Frombyte";//change endstatic int hello_stat (Fuse_ino_t ino ,  struct stat *stbuf) {stbuf->st_ino = ino;switch  (INO)  {case 1: STBUF-&GT;ST_MODE&NBSP;=&NBSP;S_IFDIR&NBSP;|&NBSP;0755;STBUF-&GT;ST_NLINK&NBSP;=&NBSP;2;BREAK;CASE&NBSP;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,     &NBSP;STRUCT&NBSP;FUSE_FILE_INFO&NBSP;*FI) {struct stat stbuf; (void)  fi;memset (&stbuf,  0, sizeof (STBUF));if  (Hello_stat (ino, &stbuf)  == -1) Fuse_reply_err (req,  ENOENT); elsefuse_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,  &AMP;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,&NBSP;&AMP;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 &NBSP;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)); Elsereturn fuse_reply_buf (req, null, 0);} Static void hello_ll_readdir (Fuse_req_t req, fuse_ino_t ino, size_t size, &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;OFF_T&NBSP;OFF,&NBSP;STRUCT&NBSP;FUSE_FILE_INFO&NBSP;*FI) {(void)  fi;if   (ino != 1) Fuse_reply_err (Req, enotdir); Else {struct dirbuf b;memset (&b ,  0, sizeof (b));d Irbuf_add (req, &b,  ".",  1);d irbuf_add (req, &b,  "..." ,  1);d Irbuf_add (req, &b, hello_name, 2);         //change1        dirbuf_add (Req, &b, inode5_name, &NBSP;5);         //endreply_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&NBSP;*FI) {    //change1//if  (ino != 2) &NBSP;&NBSP;&Nbsp; if  (  (ino !=2)  &&  (ino != 5)  )      //endfuse_reply_err (Req, eisdir);else if  ((fi->flags & 3)  != O _rdonly) Fuse_reply_err (req, eacces); Elsefuse_reply_open (REQ,&NBSP;FI);} Static void hello_ll_read (Fuse_req_t req, fuse_ino_t ino, size_t size, &NBSP;&NBSP;OFF_T&NBSP;OFF,&NBSP;STRUCT&NBSP;FUSE_FILE_INFO&NBSP;*FI) {(void)  fi;    / /change1//assert (INO&NBSP;==&NBSP;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;    &nbsP;   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,&NBSP;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); ELSERET&NBSP;=&NBSP;FUSE_SESSION_LOOP_MT (SE,&NBSP;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;}

Results test:

CD ~/fuse-3.0.0rc3/example/make./hello_ll/mntll-i/mntcat/mnt/frombyte umount/mnt

2. To be Continued

This article is from the "Zhang Yu (Data Recovery)" blog, please be sure to keep this source http://zhangyu.blog.51cto.com/197148/1881032

Operation Record: Configure fuse development environment and fuse Development specification test in ubuntu16.04.1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.