操作记录:在ubuntu16.04.1配置fuse开发环境及fuse开发规范测试
1、使用ssh客户端,登陆ubuntu ssh-p2206root@127.0.0.1 2、下载fuse源码,进行编译,安装(当前工作目录为~) wgethttps://github.com/libfuse/libfuse/releases/download/fuse-3.0.0rc3/fuse-3.0.0rc3.tar.gz tarxvffuse-3.0.0rc3.tar.gz cdfuse-3.0.0rc3/ ./configure make-j8 makeinstall depmod modprobefuse 3、测试example\hello_ll是否能正常工作 cdexample/ ./hello_ll--help ./hello_ll/mnt mount cd/mnt ls cathello cd umount/mnt 针对example\hello_ll.c,进行改动测试: 1、在根目录下多创建一个文件出来,节点号定为5,名称为frombyte,内容为文本"http://www.datahf.net" 改动如下: /* FUSE:FilesysteminUserspace Copyright(C)2001-2007MiklosSzeredi<miklos@szeredi.hu> ThisprogramcanbedistributedunderthetermsoftheGNUGPL. SeethefileCOPYING. */ /**@file * *minimalexamplefilesystemusinglow-levelAPI * *Compilewith: * *gcc-Wallhello_ll.c`pkg-configfuse3--cflags--libs`-ohello_ll * *##Sourcecode## *\includehello_ll.c */ #defineFUSE_USE_VERSION30 #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> staticconstchar*hello_str="HelloWorld!\n"; staticconstchar*hello_name="hello"; //change1#0 staticconstchar*inode5_str="http://www.datahf.net!\n"; staticconstchar*inode5_name="frombyte"; //changeend staticinthello_stat(fuse_ino_tino,structstat*stbuf) { stbuf->st_ino=ino; switch(ino){ case1: stbuf->st_mode=S_IFDIR|0755; stbuf->st_nlink=2; break; case2: stbuf->st_mode=S_IFREG|0444; stbuf->st_nlink=1; stbuf->st_size=strlen(hello_str); break; //change1#1 case5: stbuf->st_mode=S_IFREG|0444; stbuf->st_nlink=1; stbuf->st_size=strlen(inode5_str); break; //change1end default: return-1; } return0; } staticvoidhello_ll_getattr(fuse_req_treq,fuse_ino_tino, structfuse_file_info*fi) { structstatstbuf; (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); } staticvoidhello_ll_lookup(fuse_req_treq,fuse_ino_tparent,constchar*name) { structfuse_entry_parame; //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); elseif(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); } elseif(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); //change1end } structdirbuf{ char*p; size_tsize; }; staticvoiddirbuf_add(fuse_req_treq,structdirbuf*b,constchar*name, fuse_ino_tino) { structstatstbuf; size_toldsize=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); } #definemin(x,y)((x)<(y)?(x):(y)) staticintreply_buf_limited(fuse_req_treq,constchar*buf,size_tbufsize, off_toff,size_tmaxsize) { if(off<bufsize) returnfuse_reply_buf(req,buf+off, min(bufsize-off,maxsize)); else returnfuse_reply_buf(req,NULL,0); } staticvoidhello_ll_readdir(fuse_req_treq,fuse_ino_tino,size_tsize, off_toff,structfuse_file_info*fi) { (void)fi; if(ino!=1) fuse_reply_err(req,ENOTDIR); else{ structdirbufb; 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); } } staticvoidhello_ll_open(fuse_req_treq,fuse_ino_tino, structfuse_file_info*fi) { //change1 //if(ino!=2) if((ino!=2)&&(ino!=5)) //end fuse_reply_err(req,EISDIR); elseif((fi->flags&3)!=O_RDONLY) fuse_reply_err(req,EACCES); else fuse_reply_open(req,fi); } staticvoidhello_ll_read(fuse_req_treq,fuse_ino_tino,size_tsize, off_toff,structfuse_file_info*fi) { (void)fi; //change1 //assert(ino==2); //reply_buf_limited(req,hello_str,strlen(hello_str),off,size); switch(ino){ case2: reply_buf_limited(req,hello_str,strlen(hello_str),off,size); break; case5: reply_buf_limited(req,inode5_str,strlen(inode5_str),off,size); break; default: ; } //end } staticstructfuse_lowlevel_opshello_ll_oper={ .lookup =hello_ll_lookup, .getattr =hello_ll_getattr, .readdir =hello_ll_readdir, .open =hello_ll_open, .read =hello_ll_read, }; intmain(intargc,char*argv[]) { structfuse_argsargs=FUSE_ARGS_INIT(argc,argv); structfuse_session*se; structfuse_cmdline_optsopts; intret=-1; if(fuse_parse_cmdline(&args,&opts)!=0) return1; if(opts.show_help){ printf("usage:%s[options]<mountpoint>\n\n",argv[0]); fuse_cmdline_help(); fuse_lowlevel_help(); ret=0; gotoerr_out1; }elseif(opts.show_version){ printf("FUSElibraryversion%s\n",fuse_pkgversion()); fuse_lowlevel_version(); ret=0; gotoerr_out1; } se=fuse_session_new(&args,&hello_ll_oper, sizeof(hello_ll_oper),NULL); if(se==NULL) gotoerr_out1; if(fuse_set_signal_handlers(se)!=0) gotoerr_out2; if(fuse_session_mount(se,opts.mountpoint)!=0) gotoerr_out3; fuse_daemonize(opts.foreground); /*Blockuntilctrl+corfusermount-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); returnret?1:0; } 结果测试: cd~/fuse-3.0.0rc3/example/ make ./hello_ll/mnt ll-i/mnt cat/mnt/frombyte umount/mnt 2、增加目录、增加二进制文件测试: /* FUSE:FilesysteminUserspace Copyright(C)2001-2007MiklosSzeredi<miklos@szeredi.hu> ThisprogramcanbedistributedunderthetermsoftheGNUGPL. SeethefileCOPYING. */ /**@file * *minimalexamplefilesystemusinglow-levelAPI * *Compilewith: * *gcc-Wallhello_ll.c`pkg-configfuse3--cflags--libs`-ohello_ll * *##Sourcecode## *\includehello_ll.c */ #defineFUSE_USE_VERSION30 #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> staticconstchar*hello_str="HelloWorld!\n"; staticconstchar*hello_name="hello"; //change1#0 staticconstchar*inode5_str="http://www.datahf.net!\n"; staticconstchar*inode5_name="frombyte"; staticconstchar*inode3_name="frombyte.dir"; staticconstchar*inode6_name="inode6.img"; //changeend staticinthello_stat(fuse_ino_tino,structstat*stbuf) { stbuf->st_ino=ino; switch(ino){ case1: stbuf->st_mode=S_IFDIR|0755; stbuf->st_nlink=3; break; case2: stbuf->st_mode=S_IFREG|0444; stbuf->st_nlink=1; stbuf->st_size=strlen(hello_str); break; //change1#1 case3: stbuf->st_mode=S_IFDIR|0755; stbuf->st_nlink=2; break; case5: stbuf->st_mode=S_IFREG|0444; stbuf->st_nlink=1; stbuf->st_size=strlen(inode5_str); break; case6: stbuf->st_mode=S_IFREG|0444; stbuf->st_nlink=1; stbuf->st_size=1024*1024*1024; break; //change1end default: return-1; } return0; } staticvoidhello_ll_getattr(fuse_req_treq,fuse_ino_tino, structfuse_file_info*fi) { structstatstbuf; (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); } staticvoidhello_ll_lookup(fuse_req_treq,fuse_ino_tparent,constchar*name) { structfuse_entry_parame; //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); }*/ switch(parent){ case1: 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); } elseif(strcmp(name,inode3_name)==0){ memset(&e,0,sizeof(e)); e.ino=3; 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); break; case3: 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); } elseif(strcmp(name,inode6_name)==0){ memset(&e,0,sizeof(e)); e.ino=6; 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); break; default: fuse_reply_err(req,ENOENT); break; } //change1end } structdirbuf{ char*p; size_tsize; }; staticvoiddirbuf_add(fuse_req_treq,structdirbuf*b,constchar*name, fuse_ino_tino) { structstatstbuf; size_toldsize=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); } #definemin(x,y)((x)<(y)?(x):(y)) staticintreply_buf_limited(fuse_req_treq,constchar*buf,size_tbufsize, off_toff,size_tmaxsize) { if(off<bufsize) returnfuse_reply_buf(req,buf+off, min(bufsize-off,maxsize)); else returnfuse_reply_buf(req,NULL,0); } staticvoidhello_ll_readdir(fuse_req_treq,fuse_ino_tino,size_tsize, off_toff,structfuse_file_info*fi) { (void)fi; /* if(ino!=1) fuse_reply_err(req,ENOTDIR); else{*/ structdirbufb; switch(ino){ case1: 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,inode3_name,3); //end reply_buf_limited(req,b.p,b.size,off,size); free(b.p); break; case3: memset(&b,0,sizeof(b)); dirbuf_add(req,&b,".",3); dirbuf_add(req,&b,"..",1); dirbuf_add(req,&b,inode5_name,5); dirbuf_add(req,&b,inode6_name,6); reply_buf_limited(req,b.p,b.size,off,size); free(b.p); break; default: fuse_reply_err(req,ENOTDIR); break; } //} } staticvoidhello_ll_open(fuse_req_treq,fuse_ino_tino, structfuse_file_info*fi) { //change1 //if(ino!=2) switch(ino) { case2:case5:case6: if((fi->flags&3)!=O_RDONLY) fuse_reply_err(req,EACCES); else fuse_reply_open(req,fi); break; default: fuse_reply_err(req,EISDIR); break; } } staticvoidhello_ll_read(fuse_req_treq,fuse_ino_tino,size_tsize, off_toff,structfuse_file_info*fi) { (void)fi; char*tbuf; //change1 //assert(ino==2); //reply_buf_limited(req,hello_str,strlen(hello_str),off,size); switch(ino){ case2: reply_buf_limited(req,hello_str,strlen(hello_str),off,size); break; case5: reply_buf_limited(req,inode5_str,strlen(inode5_str),off,size); break; case6: tbuf=(char*)malloc(size); for(inti=0;i<size/sizeof(int);i++) ((int*)tbuf)[i]=size; fuse_reply_buf(req,tbuf,size); free(tbuf); default: ; } //end } staticstructfuse_lowlevel_opshello_ll_oper={ .lookup =hello_ll_lookup, .getattr =hello_ll_getattr, .readdir =hello_ll_readdir, .open =hello_ll_open, .read =hello_ll_read, }; intmain(intargc,char*argv[]) { structfuse_argsargs=FUSE_ARGS_INIT(argc,argv); structfuse_session*se; structfuse_cmdline_optsopts; intret=-1; if(fuse_parse_cmdline(&args,&opts)!=0) return1; if(opts.show_help){ printf("usage:%s[options]<mountpoint>\n\n",argv[0]); fuse_cmdline_help(); fuse_lowlevel_help(); ret=0; gotoerr_out1; }elseif(opts.show_version){ printf("FUSElibraryversion%s\n",fuse_pkgversion()); fuse_lowlevel_version(); ret=0; gotoerr_out1; } se=fuse_session_new(&args,&hello_ll_oper, sizeof(hello_ll_oper),NULL); if(se==NULL) gotoerr_out1; if(fuse_set_signal_handlers(se)!=0) gotoerr_out2; if(fuse_session_mount(se,opts.mountpoint)!=0) gotoerr_out3; fuse_daemonize(opts.foreground); /*Blockuntilctrl+corfusermount-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); returnret?1:0; } 3、fuse的根节点号是1,在源码中是以常量的方式定义的,本来想改成变量,估计工作量和稳定性会有麻烦,变通处理吧。 4、修改代码,实现自定义文件生成 /* FUSE:FilesysteminUserspace Copyright(C)2001-2007MiklosSzeredi<miklos@szeredi.hu> ThisprogramcanbedistributedunderthetermsoftheGNUGPL. SeethefileCOPYING. */ /**@file * *minimalexamplefilesystemusinglow-levelAPI * *Compilewith: * *gcc-Wallhello_ll.c`pkg-configfuse3--cflags--libs`-ohello_ll * *##Sourcecode## *\includehello_ll.c */ /*change2: 定义一个idx文件,格式为typedefstructStr_idx{ intlow_off; shorthige_off; shortfileid; }str_idx; 按每8字节一个索引的方式组合某个镜像文件,文件ID为0表示自由,用字符'F'填充。 文件ID为1,表示使用当前目录下的$MFT文件做为数据源进行加工。 测试代码,至少还需补全: 1、配置文件(文件大小、源文件路径等)的参数指定 2、idx结构的准确大小(int,short和机器位长有关系,需修改为与机器位长无关的数据类型) 3、排错:文件打不开 4、排错:文件大小与idx不符 5、排错:文件溢出处理 6、修改缓冲机制,不能先把源文件全读到内存,需要建立缓冲机制,应对读函数,或者简单地用fopen加缓冲处理。 bywww.datahf.net张宇 */ #defineFUSE_USE_VERSION30 #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> #include<string.h> staticconstchar*hello_str="HelloWorld!\n"; staticconstchar*hello_name="hello"; //change1#0 staticconstchar*inode5_str="http://www.datahf.net!\n"; staticconstchar*inode5_name="frombyte"; staticconstchar*inode3_name="frombyte.dir"; staticconstchar*inode6_name="inode6.img"; unsignedchar*databuf; #defineINODE6_SIZE(1024*1024*4) //changeend staticinthello_stat(fuse_ino_tino,structstat*stbuf) { stbuf->st_ino=ino; switch(ino){ case1: stbuf->st_mode=S_IFDIR|0755; stbuf->st_nlink=3; break; case2: stbuf->st_mode=S_IFREG|0444; stbuf->st_nlink=1; stbuf->st_size=strlen(hello_str); break; //change1#1 case3: stbuf->st_mode=S_IFDIR|0755; stbuf->st_nlink=2; break; case5: stbuf->st_mode=S_IFREG|0444; stbuf->st_nlink=1; stbuf->st_size=strlen(inode5_str); break; case6: stbuf->st_mode=S_IFREG|0444; stbuf->st_nlink=1; stbuf->st_size=INODE6_SIZE; break; //change1end default: return-1; } return0; } staticvoidhello_ll_getattr(fuse_req_treq,fuse_ino_tino, structfuse_file_info*fi) { structstatstbuf; (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); } staticvoidhello_ll_lookup(fuse_req_treq,fuse_ino_tparent,constchar*name) { structfuse_entry_parame; //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); }*/ switch(parent){ case1: 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); } elseif(strcmp(name,inode3_name)==0){ memset(&e,0,sizeof(e)); e.ino=3; 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); break; case3: 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); } elseif(strcmp(name,inode6_name)==0){ memset(&e,0,sizeof(e)); e.ino=6; 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); break; default: fuse_reply_err(req,ENOENT); break; } //change1end } structdirbuf{ char*p; size_tsize; }; //change2 typedefstructStr_idx{ intlow_off; shorthige_off; shortfileid; }str_idx; staticvoiddirbuf_add(fuse_req_treq,structdirbuf*b,constchar*name, fuse_ino_tino) { structstatstbuf; size_toldsize=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); } #definemin(x,y)((x)<(y)?(x):(y)) staticintreply_buf_limited(fuse_req_treq,constchar*buf,size_tbufsize, off_toff,size_tmaxsize) { if(off<bufsize) returnfuse_reply_buf(req,buf+off, min(bufsize-off,maxsize)); else returnfuse_reply_buf(req,NULL,0); } staticvoidhello_ll_readdir(fuse_req_treq,fuse_ino_tino,size_tsize, off_toff,structfuse_file_info*fi) { (void)fi; /* if(ino!=1) fuse_reply_err(req,ENOTDIR); else{*/ structdirbufb; switch(ino){ case1: 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,inode3_name,3); //end reply_buf_limited(req,b.p,b.size,off,size); free(b.p); break; case3: memset(&b,0,sizeof(b)); dirbuf_add(req,&b,".",3); dirbuf_add(req,&b,"..",1); dirbuf_add(req,&b,inode5_name,5); dirbuf_add(req,&b,inode6_name,6); reply_buf_limited(req,b.p,b.size,off,size); free(b.p); break; default: fuse_reply_err(req,ENOTDIR); break; } //} } staticvoidhello_ll_open(fuse_req_treq,fuse_ino_tino, structfuse_file_info*fi) { //change1 //if(ino!=2) switch(ino) { case2:case5:case6: if((fi->flags&3)!=O_RDONLY) fuse_reply_err(req,EACCES); else fuse_reply_open(req,fi); break; default: fuse_reply_err(req,EISDIR); break; } } staticvoidhello_ll_read(fuse_req_treq,fuse_ino_tino,size_tsize, off_toff,structfuse_file_info*fi) { (void)fi; //change1 //assert(ino==2); //reply_buf_limited(req,hello_str,strlen(hello_str),off,size); switch(ino){ case2: reply_buf_limited(req,hello_str,strlen(hello_str),off,size); break; case5: reply_buf_limited(req,inode5_str,strlen(inode5_str),off,size); break; case6: fuse_reply_buf(req,databuf+off,size); default: ; } //end } staticstructfuse_lowlevel_opshello_ll_oper={ .lookup =hello_ll_lookup, .getattr =hello_ll_getattr, .readdir =hello_ll_readdir, .open =hello_ll_open, .read =hello_ll_read, }; intmain(intargc,char*argv[]) { structfuse_argsargs=FUSE_ARGS_INIT(argc,argv); structfuse_session*se; structfuse_cmdline_optsopts; intret=-1; if(fuse_parse_cmdline(&args,&opts)!=0) return1; if(opts.show_help){ printf("usage:%s[options]<mountpoint>\n\n",argv[0]); fuse_cmdline_help(); fuse_lowlevel_help(); ret=0; gotoerr_out1; }elseif(opts.show_version){ printf("FUSElibraryversion%s\n",fuse_pkgversion()); fuse_lowlevel_version(); ret=0; gotoerr_out1; } //change2 FILE*f_idx,*f_img; f_idx=fopen("./1.idx","rb"); f_img=fopen("./$MFT","rb"); if((f_idx==-1)||(f_img==-1)) { printf("f_idxis%d\nf_imgis%d\n",f_idx,f_img); gotoerr_out1; } size_ts_idx,s_img; s_idx=512; unsignedcharidx_buf[512]; databuf=NULL; databuf=(char*)malloc(INODE6_SIZE); fread(idx_buf,512,1,f_idx); inti=0; structStr_idx*tidx; tidx=(structStr_idx*)idx_buf; for(i=0;i<4;i++) { if(tidx[i].fileid==0) memset(databuf+i*1024*1024,'F',1024*1024); elseif(tidx[i].fileid==1) { fseek(f_img, tidx[i].low_off*1024*1024+tidx[i].hige_off*1024*1024, SEEK_SET); fread(databuf+i*1024*1024,1024*1024,1,f_img); } else ; printf("#i:%d,%d,%d\n",tidx[i].low_off,tidx[i].hige_off,tidx[i].fileid); } se=fuse_session_new(&args,&hello_ll_oper, sizeof(hello_ll_oper),NULL); if(se==NULL) gotoerr_out1; if(fuse_set_signal_handlers(se)!=0) gotoerr_out2; if(fuse_session_mount(se,opts.mountpoint)!=0) gotoerr_out3; fuse_daemonize(opts.foreground); /*Blockuntilctrl+corfusermount-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); returnret?1:0; } 待续