func (me *memNode) Open(flags uint32, context *fuse.Context) (fuseFile fuse.File, code fuse.Status) { if flags&fuse.O_ANYWRITE != 0 { return nil, fuse.EPERM } return fuse.NewReadOnlyFile(me.file.Data()), fuse.OK }
func (me *ProcFs) Open(name string, flags uint32, context *fuse.Context) (fuse.File, fuse.Status) { p := me.LoopbackFileSystem.GetPath(name) content, err := ioutil.ReadFile(p) if err == nil { return fuse.NewReadOnlyFile(content), fuse.OK } return nil, fuse.OsErrorToErrno(err) }
func (me *HelloFs) Open(name string, flags uint32) (file fuse.File, code fuse.Status) { if name != "file.txt" { return nil, fuse.ENOENT } if flags&fuse.O_ANYWRITE != 0 { return nil, fuse.EPERM } return fuse.NewReadOnlyFile([]byte(name)), fuse.OK }
func (me *MemTreeFileSystem) Open(name string, flags uint32, context *fuse.Context) (fuseFile fuse.File, code fuse.Status) { if flags&fuse.O_ANYWRITE != 0 { return nil, fuse.EPERM } // TODO - should complain if it is a directory. _, file := me.tree.Lookup(name) if file == nil { return nil, fuse.ENOENT } return fuse.NewReadOnlyFile(file.Data()), fuse.OK }
func (me *AutoUnionFs) Open(path string, flags uint32) (fuse.File, fuse.Status) { if path == filepath.Join(_STATUS, _VERSION) { if flags&fuse.O_ANYWRITE != 0 { return nil, fuse.EPERM } return fuse.NewReadOnlyFile([]byte(fuse.Version())), fuse.OK } if path == filepath.Join(_CONFIG, _SCAN_CONFIG) { if flags&fuse.O_ANYWRITE != 0 { me.updateKnownFses() } return fuse.NewDevNullFile(), fuse.OK } return nil, fuse.ENOENT }
func (me *RpcFs) Open(name string, flags uint32, context *fuse.Context) (fuse.File, fuse.Status) { if flags&fuse.O_ANYWRITE != 0 { return nil, fuse.EPERM } a := me.getFileAttr(name) if a == nil { return nil, fuse.ENOENT } if !a.Status.Ok() { return nil, a.Status } if contents := me.cache.ContentsIfLoaded(a.Hash); contents != nil { return &fuse.WithFlags{ File: fuse.NewReadOnlyFile(contents), FuseFlags: fuse.FOPEN_KEEP_CACHE, }, fuse.OK } p := me.cache.Path(a.Hash) if _, err := os.Lstat(p); fuse.OsErrorToErrno(err) == fuse.ENOENT { log.Printf("Fetching contents for file %s: %x", name, a.Hash) err = me.FetchHash(a.FileInfo.Size, a.Hash) // should return something else? if err != nil { return nil, fuse.ENOENT } } f, err := os.Open(p) if err != nil { return nil, fuse.OsErrorToErrno(err) } return &fuse.WithFlags{ File: &rpcFsFile{ fuse.LoopbackFile{File: f}, *a.FileInfo, }, FuseFlags: fuse.FOPEN_KEEP_CACHE, }, fuse.OK }
func (me *MultiZipFs) Open(name string, flags uint32) (file fuse.File, code fuse.Status) { if 0 != flags&uint32(fuse.O_ANYWRITE) { return nil, fuse.EPERM } dir, basename := filepath.Split(name) if dir == CONFIG_PREFIX { me.lock.RLock() defer me.lock.RUnlock() orig, ok := me.dirZipFileMap[basename] if !ok { return nil, fuse.ENOENT } return fuse.NewReadOnlyFile([]byte(orig)), fuse.OK } return nil, fuse.ENOENT }
func openFile(fs fuse.FileSystem, name string) (result *openResponse) { result = &openResponse{} flags := uint32(os.O_RDONLY) f, code := fs.Open(name, flags) if !code.Ok() { result.Status = code return } defer f.Release() defer f.Flush() buf := bytes.NewBuffer(nil) input := fuse.ReadIn{ Offset: 0, Size: 128 * (1 << 10), Flags: flags, } bp := fuse.NewGcBufferPool() for { data, status := f.Read(&input, bp) buf.Write(data) if !status.Ok() { result.Status = status return } if len(data) < int(input.Size) { break } input.Offset += uint64(len(data)) } result.File = fuse.NewReadOnlyFile(buf.Bytes()) return }