func (fs *unionFS) Open(name string, flags uint32, context *fuse.Context) (fuseFile nodefs.File, status fuse.Status) { if name == _DROP_CACHE { if flags&fuse.O_ANYWRITE != 0 { log.Println("Forced cache drop on", fs) fs.DropBranchCache(nil) fs.DropDeletionCache() fs.DropSubFsCaches() fs.nodeFs.ForgetClientInodes() } return nodefs.NewDevNullFile(), fuse.OK } r := fs.getBranch(name) if r.branch < 0 { // This should not happen, as a GetAttr() should have // already verified existence. log.Println("UnionFs: open of non-existent file:", name) return nil, fuse.ENOENT } if flags&fuse.O_ANYWRITE != 0 && r.branch > 0 { code := fs.Promote(name, r, context) if code != fuse.OK { return nil, code } r.branch = 0 now := time.Now() r.attr.SetTimes(nil, &now, nil) fs.branchCache.Set(name, r) } fuseFile, status = fs.fileSystems[r.branch].Open(name, uint32(flags), context) if fuseFile != nil { fuseFile = fs.newUnionFsFile(fuseFile, r.branch) } return fuseFile, status }
func (fs *autoUnionFs) Open(path string, flags uint32, context *fuse.Context) (nodefs.File, fuse.Status) { if path == filepath.Join(_STATUS, _DEBUG) { if flags&fuse.O_ANYWRITE != 0 { return nil, fuse.EPERM } return nodefs.NewDataFile([]byte(fs.DebugData())), fuse.OK } if path == filepath.Join(_STATUS, _VERSION) { if flags&fuse.O_ANYWRITE != 0 { return nil, fuse.EPERM } return nodefs.NewDataFile([]byte(fs.options.Version)), fuse.OK } if path == filepath.Join(_CONFIG, _SCAN_CONFIG) { if flags&fuse.O_ANYWRITE != 0 { fs.updateKnownFses() } return nodefs.NewDevNullFile(), fuse.OK } return nil, fuse.ENOENT }
// Open is a FUSE function where an in-memory open file struct is constructed. func (kwfs KeywhizFs) Open(name string, flags uint32, context *fuse.Context) (nodefs.File, fuse.Status) { kwfs.Debugf("Open called with '%v'", name) var file nodefs.File switch { case name == "", name == ".json", name == ".json/secret": return nil, EISDIR case name == ".version": file = nodefs.NewDataFile([]byte(VERSION)) case name == ".clear_cache": file = nodefs.NewDevNullFile() case name == ".running": file = nodefs.NewDataFile(running()) case name == ".json/secrets": data, ok := kwfs.Client.RawSecretList() if ok { file = nodefs.NewDataFile(data) } case strings.HasPrefix(name, ".json/secret/"): name = name[len(".json/secret/"):] data, ok := kwfs.Client.RawSecret(name) if ok { file = nodefs.NewDataFile(data) kwfs.Infof("Access to %s by uid %d, with gid %d", name, context.Uid, context.Gid) } default: secret, ok := kwfs.Cache.Secret(name) if ok { file = nodefs.NewDataFile(secret.Content) kwfs.Infof("Access to %s by uid %d, with gid %d", name, context.Uid, context.Gid) } } if file != nil { file = nodefs.NewReadOnlyFile(file) return file, fuse.OK } return nil, fuse.ENOENT }