int fuse_loop_mt(struct fuse *f) { if (f == NULL) return -1; return fuse_session_loop_mt(fuse_get_session(f)); }
int fuse_loop_mt_proc(struct fuse *f, fuse_processor_t proc, void *data) { int res; struct procdata pd; struct fuse_session *prevse = fuse_get_session(f); struct fuse_session *se; struct fuse_chan *prevch = fuse_session_next_chan(prevse, NULL); struct fuse_chan *ch; struct fuse_session_ops sop = { .exit = mt_session_exit, .exited = mt_session_exited, .process = mt_session_proc, }; struct fuse_chan_ops cop = { .receive = mt_chan_receive, .send = mt_chan_send, }; pd.f = f; pd.prevch = prevch; pd.prevse = prevse; pd.proc = proc; pd.data = data; se = fuse_session_new(&sop, &pd); if (se == NULL) return -1; ch = fuse_chan_new(&cop, fuse_chan_fd(prevch), sizeof(struct fuse_cmd *), &pd); if (ch == NULL) { fuse_session_destroy(se); return -1; } fuse_session_add_chan(se, ch); res = fuse_session_loop_mt(se); fuse_session_destroy(se); return res; }
int cuse_lowlevel_main(int argc, char *argv[], const struct cuse_info *ci, const struct cuse_lowlevel_ops *clop, void *userdata) { struct fuse_session *se; int multithreaded; int res; se = cuse_lowlevel_setup(argc, argv, ci, clop, &multithreaded, userdata); if (se == NULL) return 1; if (multithreaded) res = fuse_session_loop_mt(se); else res = fuse_session_loop(se); cuse_lowlevel_teardown(se); if (res == -1) return 1; return 0; }
int mainloop(struct fuse_args *args,const char* mp,int mt,int fg) { struct fuse_session *se; struct fuse_chan *ch; struct rlimit rls; int piped[2]; char s; int err; int i; md5ctx ctx; uint8_t md5pass[16]; if (mfsopts.passwordask && mfsopts.password==NULL && mfsopts.md5pass==NULL) { mfsopts.password = getpass("MFS Password:"******"bad md5 definition (md5 should be given as 32 hex digits)\n"); return 1; } p++; if (*p>='0' && *p<='9') { md5pass[i]+=(*p-'0'); } else if (*p>='a' && *p<='f') { md5pass[i]+=(*p-'a'+10); } else if (*p>='A' && *p<='F') { md5pass[i]+=(*p-'A'+10); } else { fprintf(stderr,"bad md5 definition (md5 should be given as 32 hex digits)\n"); return 1; } p++; } if (*p) { fprintf(stderr,"bad md5 definition (md5 should be given as 32 hex digits)\n"); return 1; } memset(mfsopts.md5pass,0,strlen(mfsopts.md5pass)); } if (mfsopts.delayedinit) { fs_init_master_connection(mfsopts.bindhost,mfsopts.masterhost,mfsopts.masterport,mfsopts.meta,mp,mfsopts.subfolder,(mfsopts.password||mfsopts.md5pass)?md5pass:NULL,mfsopts.donotrememberpassword,1); } else { if (fs_init_master_connection(mfsopts.bindhost,mfsopts.masterhost,mfsopts.masterport,mfsopts.meta,mp,mfsopts.subfolder,(mfsopts.password||mfsopts.md5pass)?md5pass:NULL,mfsopts.donotrememberpassword,0)<0) { return 1; } } memset(md5pass,0,16); if (fg==0) { openlog(STR(APPNAME), LOG_PID | LOG_NDELAY , LOG_DAEMON); } else { #if defined(LOG_PERROR) openlog(STR(APPNAME), LOG_PID | LOG_NDELAY | LOG_PERROR, LOG_USER); #else openlog(STR(APPNAME), LOG_PID | LOG_NDELAY, LOG_USER); #endif } i = mfsopts.nofile; while (1) { rls.rlim_cur = i; rls.rlim_max = i; if (setrlimit(RLIMIT_NOFILE,&rls)<0) { i /= 2; if (i<1000) { break; } } else { break; } } if (i != (int)(mfsopts.nofile)) { fprintf(stderr,"can't set open file limit to %d\n",mfsopts.nofile); if (i>=1000) { fprintf(stderr,"open file limit set to: %d\n",i); } } setpriority(PRIO_PROCESS,getpid(),mfsopts.nice); #ifdef MFS_USE_MEMLOCK if (mfsopts.memlock) { rls.rlim_cur = RLIM_INFINITY; rls.rlim_max = RLIM_INFINITY; if (setrlimit(RLIMIT_MEMLOCK,&rls)<0) { mfsopts.memlock=0; } } #endif piped[0] = piped[1] = -1; if (fg==0) { if (pipe(piped)<0) { fprintf(stderr,"pipe error\n"); return 1; } err = fork(); if (err<0) { fprintf(stderr,"fork error\n"); return 1; } else if (err>0) { close(piped[1]); err = read(piped[0],&s,1); if (err==0) { s=1; } return s; } close(piped[0]); s=1; } #ifdef MFS_USE_MEMLOCK if (mfsopts.memlock) { if (mlockall(MCL_CURRENT|MCL_FUTURE)==0) { syslog(LOG_NOTICE,"process memory was successfully locked in RAM"); } } #endif /* glibc malloc tuning */ #ifdef MFS_USE_MALLOPT if (mfsopts.limitarenas) { if (!getenv("MALLOC_ARENA_MAX")) { syslog(LOG_NOTICE,"setting glibc malloc arena max to 8"); mallopt(M_ARENA_MAX, mfsopts.limitarenas); } if (!getenv("MALLOC_ARENA_TEST")) { syslog(LOG_NOTICE,"setting glibc malloc arena test to 1"); mallopt(M_ARENA_TEST, 1); } } else { syslog(LOG_NOTICE,"setting glibc malloc arenas turned off"); } #endif /* glibc malloc tuning */ syslog(LOG_NOTICE,"monotonic clock function: %s",monotonic_method()); syslog(LOG_NOTICE,"monotonic clock speed: %"PRIu32" ops / 10 mili seconds",monotonic_speed()); conncache_init(200); chunkloc_cache_init(); symlink_cache_init(); negentry_cache_init(mfsopts.negentrycacheto); // dir_cache_init(); fs_init_threads(mfsopts.ioretries); if (masterproxy_init(mfsopts.proxyhost)<0) { fs_term(); // dir_cache_term(); negentry_cache_term(); symlink_cache_term(); chunkloc_cache_term(); return 1; } // fs_term(); // negentry_cache_term(); // symlink_cache_term(); // chunkloc_cache_term(); // return 1; if (mfsopts.meta==0) { csdb_init(); delay_init(); read_data_init(mfsopts.readaheadsize*1024*1024,mfsopts.readaheadleng,mfsopts.readaheadtrigger,mfsopts.ioretries); write_data_init(mfsopts.writecachesize*1024*1024,mfsopts.ioretries); } ch = fuse_mount(mp, args); if (ch==NULL) { fprintf(stderr,"error in fuse_mount\n"); if (piped[1]>=0) { if (write(piped[1],&s,1)!=1) { fprintf(stderr,"pipe write error\n"); } close(piped[1]); } if (mfsopts.meta==0) { write_data_term(); read_data_term(); delay_term(); csdb_term(); } masterproxy_term(); fs_term(); // dir_cache_term(); negentry_cache_term(); symlink_cache_term(); chunkloc_cache_term(); return 1; } if (mfsopts.meta) { mfs_meta_init(mfsopts.debug,mfsopts.entrycacheto,mfsopts.attrcacheto); se = fuse_lowlevel_new(args, &mfs_meta_oper, sizeof(mfs_meta_oper), (void*)piped); } else { mfs_init(mfsopts.debug,mfsopts.keepcache,mfsopts.direntrycacheto,mfsopts.entrycacheto,mfsopts.attrcacheto,mfsopts.xattrcacheto,mfsopts.groupscacheto,mfsopts.mkdircopysgid,mfsopts.sugidclearmode,1,mfsopts.fsyncbeforeclose,mfsopts.noxattrs,mfsopts.noposixlocks,mfsopts.nobsdlocks); //mfsopts.xattraclsupport); se = fuse_lowlevel_new(args, &mfs_oper, sizeof(mfs_oper), (void*)piped); } if (se==NULL) { fuse_unmount(mp,ch); fprintf(stderr,"error in fuse_lowlevel_new\n"); portable_usleep(100000); // time for print other error messages by FUSE if (piped[1]>=0) { if (write(piped[1],&s,1)!=1) { fprintf(stderr,"pipe write error\n"); } close(piped[1]); } if (mfsopts.meta==0) { write_data_term(); read_data_term(); delay_term(); csdb_term(); } masterproxy_term(); fs_term(); // dir_cache_term(); negentry_cache_term(); symlink_cache_term(); chunkloc_cache_term(); return 1; } // fprintf(stderr,"check\n"); fuse_session_add_chan(se, ch); if (fuse_set_signal_handlers(se)<0) { fprintf(stderr,"error in fuse_set_signal_handlers\n"); fuse_session_remove_chan(ch); fuse_session_destroy(se); fuse_unmount(mp,ch); if (piped[1]>=0) { if (write(piped[1],&s,1)!=1) { fprintf(stderr,"pipe write error\n"); } close(piped[1]); } if (mfsopts.meta==0) { write_data_term(); read_data_term(); delay_term(); csdb_term(); } masterproxy_term(); fs_term(); // dir_cache_term(); negentry_cache_term(); symlink_cache_term(); chunkloc_cache_term(); return 1; } if (mfsopts.debug==0 && fg==0) { setsid(); setpgid(0,getpid()); if ((i = open("/dev/null", O_RDWR, 0)) != -1) { (void)dup2(i, STDIN_FILENO); (void)dup2(i, STDOUT_FILENO); (void)dup2(i, STDERR_FILENO); if (i>2) close (i); } } if (mt) { err = fuse_session_loop_mt(se); } else { err = fuse_session_loop(se); } if (err) { if (piped[1]>=0) { if (write(piped[1],&s,1)!=1) { syslog(LOG_ERR,"pipe write error: %s",strerr(errno)); } close(piped[1]); } } fuse_remove_signal_handlers(se); fuse_session_remove_chan(ch); fuse_session_destroy(se); fuse_unmount(mp,ch); if (mfsopts.meta==0) { write_data_term(); read_data_term(); delay_term(); csdb_term(); } masterproxy_term(); fs_term(); // dir_cache_term(); negentry_cache_term(); symlink_cache_term(); chunkloc_cache_term(); return err ? 1 : 0; }
int main(int argc, char **argv) { extern void init_ops(fuse_lowlevel_ops *ops); struct options options; std::memset(&options, 0, sizeof(options)); struct fuse_args args = FUSE_ARGS_INIT(argc, argv); struct fuse_chan *ch; char *mountpoint = NULL; int err = -1; std::string mountPath; unsigned format = 0; int foreground = false; int multithread = false; Pascal::VolumeEntryPointer volume; init_ops(&pascal_ops); // scan the argument list, looking for the name of the disk image. if (fuse_opt_parse(&args, &options ,pascal_options, pascal_option_proc) == -1) exit(1); if (fDiskImage.empty()) { usage(); exit(1); } // default prodos-order disk image. if (options.format) { format = Device::BlockDevice::ImageType(options.format); if (!format) std::fprintf(stderr, "Warning: Unknown image type ``%s''\n", options.format); } try { Device::BlockDevicePointer device; device = Device::BlockDevice::Open(fDiskImage.c_str(), File::ReadOnly, format); if (!device.get()) { std::fprintf(stderr, "Error: Unknown or unsupported device type.\n"); exit(1); } volume = Pascal::VolumeEntry::Open(device); } catch (::Exception &e) { std::fprintf(stderr, "%s\n", e.what()); std::fprintf(stderr, "%s\n", std::strerror(e.error())); return -1; } #ifdef __APPLE__ { // Macfuse supports custom volume names (displayed in Finder) std::string str("-ovolname="); str += volume->name(); fuse_opt_add_arg(&args, str.c_str()); // 512 byte blocksize. fuse_opt_add_arg(&args, "-oiosize=512"); } #endif fuse_opt_add_arg(&args, "-ofsname=PascalFS"); if (!options.readOnly) fuse_opt_add_arg(&args, "-ordonly"); if (options.readWrite) { std::fprintf(stderr, "Warning: write support is not yet enabled.\n"); } if (fuse_parse_cmdline(&args, &mountpoint, &multithread, &foreground) == -1) { usage(); return -1; } #ifdef __APPLE__ if (mountpoint == NULL || *mountpoint == 0) { if (make_mount_dir(volume->name(), mountPath)) mountpoint = (char *)mountPath.c_str(); } #endif if ((ch = fuse_mount(mountpoint, &args)) != NULL) { struct fuse_session* se; std::printf("Mounting ``%s'' on ``%s''\n", volume->name(), mountpoint); se = fuse_lowlevel_new(&args, &pascal_ops, sizeof(pascal_ops), volume.get()); if (se) do { err = fuse_daemonize(foreground); if (err < 0 ) break; err = fuse_set_signal_handlers(se); if (err < 0) break; fuse_session_add_chan(se, ch); if (multithread) err = fuse_session_loop_mt(se); else err = fuse_session_loop(se); fuse_remove_signal_handlers(se); fuse_session_remove_chan(ch); } while (false); if (se) fuse_session_destroy(se); fuse_unmount(mountpoint, ch); } fuse_opt_free_args(&args); #ifdef __APPLE__ if (!mountPath.empty()) rmdir(mountPath.c_str()); #endif return err ? 1 : 0; }