// Open implements the billy.Filesystem interface for RootFS.
193821
func (rfs *RootFS) Open(filename string) (f billy.File, err error) {
	if !rootWrappedNodeNames[filename] {
		// In particular, this FS doesn't let you open the folderlist
		// directories or anything in them.
		return nil, os.ErrNotExist
	}

	switch filename {
	case StatusFileName:
		return &wrappedReadFile{
			name: StatusFileName,
			reader: func(ctx context.Context) ([]byte, time.Time, error) {
				return GetEncodedStatus(ctx, rfs.config)
			},
			log: rfs.log,
		}, nil
	default:
		panic(fmt.Sprintf("Name %s was in map, but not in switch", filename))
	}
}
1171509
func (f *FS) open(ctx context.Context, oc *openContext, ps []string) (dokan.File, dokan.CreateStatus, error) {
	f.vlog.CLogf(ctx, libkb.VLog1, "FS Open: %q", ps)
	psl := len(ps)
	switch {
	case psl < 1:
		return nil, 0, dokan.ErrObjectNameNotFound
	case psl == 1 && ps[0] == ``:
		return oc.returnDirNoCleanup(f.root)

		// This section is equivalent to
		// handleCommonSpecialFile in libfuse.
	case libkbfs.ErrorFile == ps[psl-1]:
		return oc.returnFileNoCleanup(NewErrorFile(f))
	case libfs.MetricsFileName == ps[psl-1]:
		return oc.returnFileNoCleanup(NewMetricsFile(f))
		// TODO: Make the two cases below available from any
		// directory.
	case libfs.ProfileListDirName == ps[0]:
		return (ProfileList{fs: f}).open(ctx, oc, ps[1:])
	case libfs.ResetCachesFileName == ps[0]:
		return oc.returnFileNoCleanup(&ResetCachesFile{fs: f.root.private.fs})

		// This section is equivalent to
		// handleNonTLFSpecialFile in libfuse.
		//
		// TODO: Make the two cases below available from any
		// non-TLF directory.
	case libfs.StatusFileName == ps[0]:
		return oc.returnFileNoCleanup(NewNonTLFStatusFile(f.root.private.fs))
	case libfs.HumanErrorFileName == ps[0], libfs.HumanNoLoginFileName == ps[0]:
		return oc.returnFileNoCleanup(&SpecialReadFile{
			read: f.remoteStatus.NewSpecialReadFunc,
			fs:   f})

	case libfs.EnableAutoJournalsFileName == ps[0]:
		return oc.returnFileNoCleanup(&JournalControlFile{
			folder: &Folder{fs: f}, // fake Folder for logging, etc.
			action: libfs.JournalEnableAuto,
		})
	case libfs.DisableAutoJournalsFileName == ps[0]:
		return oc.returnFileNoCleanup(&JournalControlFile{
			folder: &Folder{fs: f}, // fake Folder for logging, etc.
			action: libfs.JournalDisableAuto,
		})
	case libfs.EnableBlockPrefetchingFileName == ps[0]:
		return oc.returnFileNoCleanup(&PrefetchFile{
			fs:     f,
			enable: true,
		})
	case libfs.DisableBlockPrefetchingFileName == ps[0]:
		return oc.returnFileNoCleanup(&PrefetchFile{
			fs:     f,
			enable: false,
		})

	case libfs.EditHistoryName == ps[0]:
		return oc.returnFileNoCleanup(NewUserEditHistoryFile(&Folder{fs: f}))

	case ".kbfs_unmount" == ps[0]:
		f.log.CDebugf(ctx, "Exiting due to .kbfs_unmount")
		logger.Shutdown()
		os.Exit(0)
	case ".kbfs_number_of_handles" == ps[0]:
		x := stringReadFile(strconv.Itoa(int(oc.fi.NumberOfFileHandles())))
		return oc.returnFileNoCleanup(x)
	// TODO
	// Unfortunately sometimes we end up in this case while using
	// reparse points.
	case strings.ToUpper(PublicName) == ps[0]:
		oc.isUppercasePath = true
		fallthrough
	case PublicName == ps[0]:
		// Refuse private directories while we are in a a generic error state.
		if f.remoteStatus.ExtraFileName() == libfs.HumanErrorFileName {
			f.log.CWarningf(ctx, "Refusing access to public directory while errors are present!")
			return nil, 0, dokan.ErrAccessDenied
		}
		return f.root.public.open(ctx, oc, ps[1:])
	case strings.ToUpper(PrivateName) == ps[0]:
		oc.isUppercasePath = true
		fallthrough
	case PrivateName == ps[0]:
		// Refuse private directories while we are in a error state.
		if f.remoteStatus.ExtraFileName() != "" {
			f.log.CWarningf(ctx, "Refusing access to private directory while errors are present!")
			return nil, 0, dokan.ErrAccessDenied
		}
		return f.root.private.open(ctx, oc, ps[1:])
	case strings.ToUpper(TeamName) == ps[0]:
		oc.isUppercasePath = true
		fallthrough
	case TeamName == ps[0]:
		// Refuse team directories while we are in a error state.
		if f.remoteStatus.ExtraFileName() != "" {
			f.log.CWarningf(ctx, "Refusing access to team directory while errors are present!")
			return nil, 0, dokan.ErrAccessDenied
		}
		return f.root.team.open(ctx, oc, ps[1:])
	}
	return nil, 0, dokan.ErrObjectNameNotFound
}
466165
func (i *item) Open() (io.ReadCloser, error) {
	return os.Open(i.path)
}
1193232
func (h *fs) Open(filename string) (io.ReadCloser, error) {
	return os.Open(filename)
}
1001911
func (m *ProcessManager) Open(u *url.URL, mode int32) (hgfs.File, error) {
	info, err := m.Stat(u)
	if err != nil {
		return nil, err
	}

	pinfo, ok := info.(*ProcessFile)

	if !ok {
		return nil, os.ErrNotExist // fall through to default os.Open
	}

	switch path.Base(u.Path) {
	case "stdin":
		if mode != hgfs.OpenModeWriteOnly {
			return nil, vix.Error(vix.InvalidArg)
		}
	case "stdout", "stderr":
		if mode != hgfs.OpenModeReadOnly {
			return nil, vix.Error(vix.InvalidArg)
		}
	}

	return pinfo, nil
}
1252509
func (fs onlyfilesFS) Open(name string) (http.File, error) {
	f, err := fs.fs.Open(name)
	if err != nil {
		return nil, err
	}
	return neuteredReaddirFile{f}, nil
}
256521
func (tlf *TLF) Open(ctx context.Context, req *fuse.OpenRequest,
	resp *fuse.OpenResponse) (fs.Handle, error) {
	// Explicitly load the directory when a TLF is opened, because
	// some OSX programs like ls have a bug that doesn't report errors
	// on a ReadDirAll.
	_, _, err := tlf.loadDirAllowNonexistent(ctx)
	if err != nil {
		return nil, err
	}
	return tlf, nil
}
454648
func (w *SSTFileWriter) Open(path string) error {
	var (
		cErr  *C.char
		cPath = C.CString(path)
	)
	defer C.free(unsafe.Pointer(cPath))
	C.rocksdb_sstfilewriter_open(w.c, cPath, &cErr)
	if cErr != nil {
		defer C.free(unsafe.Pointer(cErr))
		return errors.New(C.GoString(cErr))
	}
	return nil
}
1020536
func (s *Server) Open() error {
	opts := stand.GetDefaultOptions()
	opts.StoreType = stores.TypeFile
	opts.ID = ServerName
	opts.FilestoreDir = s.config.FilestoreDir
	server, err := stand.RunServerWithOpts(opts, nil)
	if err != nil {
		return err
	}

	s.Server = server

	return nil
}
789333
func (hfs httpFileSystem) Open(filename string) (entry http.File, err error) {
	hfs.fs.log.CDebugf(
		hfs.fs.ctx, "hfs.Open %s", filename)
	defer func() {
		hfs.fs.deferLog.CDebugf(hfs.fs.ctx, "hfs.Open done: %+v", err)
		if err != nil {
			err = translateErr(err)
		}
	}()

	n, ei, err := hfs.fs.lookupOrCreateEntry(filename, os.O_RDONLY, 0600)
	if err != nil {
		return fileOrDir{}, err
	}

	if ei.Type.IsFile() {
		return fileOrDir{
			file: &File{
				fs:       hfs.fs,
				filename: n.GetBasename(),
				node:     n,
				readOnly: true,
				offset:   0,
			},
			ei: ei,
		}, nil
	}
	return fileOrDir{
		dir: &dir{
			fs:      hfs.fs,
			dirname: n.GetBasename(),
			node:    n,
		},
		ei: ei,
	}, nil
}
195742
func (b *Backend) open() error {
	if b.f != nil {
		return nil
	}
	if err := os.MkdirAll(filepath.Dir(b.path), b.mode); err != nil {
		return err
	}

	var err error
	b.f, err = os.OpenFile(b.path, os.O_APPEND|os.O_WRONLY|os.O_CREATE, b.mode)
	if err != nil {
		return err
	}

	// Change the file mode in case the log file already existed. We special
	// case /dev/null since we can't chmod it and bypass if the mode is zero
	switch b.path {
	case "/dev/null":
	default:
		if b.mode != 0 {
			err = os.Chmod(b.path, b.mode)
			if err != nil {
				return err
			}
		}
	}

	return nil
}
791751
func (fs DefaultFsEval) Open(path string) (*os.File, error) {
	return os.Open(path)
}
1235147
func Open(filename string) (rc *ReadCloser, err error) {
	fp, err := os.Open(filename)
	if err != nil {
		return nil, err
	}

	if strings.HasSuffix(filename, ".gz") {
		r := &ReadCloser{
			fp:     fp,
			isGzip: true,
			isOpen: true,
		}
		r.gz, err = gzip.NewReader(fp)
		if err != nil {
			fp.Close()
			return nil, err
		}
		r.r = r.gz
		runtime.SetFinalizer(r, (*ReadCloser).Close)
		return r, nil
	}

	if strings.HasSuffix(filename, ".bz2") {
		r := &ReadCloser{
			fp:      fp,
			r:       bzip2.NewReader(fp),
			isBzip2: true,
			isOpen:  true,
		}
		runtime.SetFinalizer(r, (*ReadCloser).Close)
		return r, nil
	}

	r := &ReadCloser{
		fp:      fp,
		r:       fp,
		isOpen:  true,
	}
	runtime.SetFinalizer(r, (*ReadCloser).Close)
	return r, nil
}
117350
func (fs *FileSystem) Open(name string) (http.File, error) {
	fs.mutex.RLock()
	defer fs.mutex.RUnlock()

	name = path.Clean(filepath.ToSlash(name))
	if path.IsAbs(name) {
		name = name[1:]
		if name == "" {
			name = "."
		}
	}

	parts := strings.Split(name, "/")
	n := fs.root
	for _, p := range parts {
		if p == "." {
			continue
		} else {
			c, ok := n.children[p]
			if !ok {
				if fs.Fallback {
					return os.Open(name)
				}
				return nil, os.ErrNotExist
			}

			n = c
		}
	}

	if n.stat.IsDir() {
		files := []os.FileInfo{}
		names := make([]string, 0, len(n.children))

		for name := range n.children {
			names = append(names, name)
		}

		sort.Strings(names)

		for _, name := range names {
			files = append(files, n.children[name].stat)
		}

		return newDir(n.stat, files), nil
	} else {
		return newFile(n.data, n.stat), nil
	}
}
970246
func (d Datastore) Open(ctx context.Context, name string) (*DatastoreFile, error) {
	return &DatastoreFile{
		d:      d,
		name:   name,
		length: -1,
		ctx:    ctx,
	}, nil
}
1308079
func (t *tOps) open(f *tFile) (ch *cache.Handle, err error) {
	ch = t.cache.Get(0, uint64(f.fd.Num), func() (size int, value cache.Value) {
		var r storage.Reader
		r, err = t.s.stor.Open(f.fd)
		if err != nil {
			return 0, nil
		}

		var bcache *cache.NamespaceGetter
		if t.bcache != nil {
			bcache = &cache.NamespaceGetter{Cache: t.bcache, NS: uint64(f.fd.Num)}
		}

		var tr *table.Reader
		tr, err = table.NewReader(r, f.size, f.fd, bcache, t.bpool, t.s.o.Options)
		if err != nil {
			r.Close()
			return 0, nil
		}
		return 1, tr

	})
	if ch == nil && err == nil {
		err = ErrClosed
	}
	return
}
957300
func (d Dir) Open(name string) (http.File, error) {
	f, err := d.dir.Open(name)
	if err != nil {
		f, err = os.Open(d.Default)
		if err != nil {
			return nil, err
		}
		return f, nil
	}
	return f, err
}