// Mounted checks if the given path is mounted as the fs type
//Solaris supports only ZFS for now
489396
func Mounted(fsType FsMagic, mountPath string) (bool, error) {

	cs := C.CString(filepath.Dir(mountPath))
	defer C.free(unsafe.Pointer(cs))
	buf := C.getstatfs(cs)
	defer C.free(unsafe.Pointer(buf))

	// on Solaris buf.f_basetype contains ['z', 'f', 's', 0 ... ]
	if (buf.f_basetype[0] != 122) || (buf.f_basetype[1] != 102) || (buf.f_basetype[2] != 115) ||
		(buf.f_basetype[3] != 0) {
		logrus.Debugf("[zfs] no zfs dataset found for rootdir '%s'", mountPath)
		return false, ErrPrerequisites
	}

	return true, nil
}
520793
func (v *View) Mount(dom *js.Object) {
	v.dom = dom
	v.events.OffloadDOM()
	v.events.LoadDOM(dom)
	v.Send(true)
	atomic.StoreInt32(&v.loaded, 1)
}
935187
func (f *Folder) addMount(path []string, dest string) error {
	if len(path) < 1 {
		return errors.Errorf("Path must not be empty")
	}
	name := path[0]
	if len(path) == 1 {
		f.Folders[name] = newMount(name, dest)
		return nil
	}
	next := f.getFolder(name)
	return next.addMount(path[1:], dest)
}
1110760
func (m *Mount) Mount(target string) error {
	if m.Type != "windows-layer" {
		return errors.Errorf("invalid windows mount type: '%s'", m.Type)
	}

	home, layerID := filepath.Split(m.Source)

	parentLayerPaths, err := m.GetParentPaths()
	if err != nil {
		return err
	}

	var di = hcsshim.DriverInfo{
		HomeDir: home,
	}

	if err = hcsshim.ActivateLayer(di, layerID); err != nil {
		return errors.Wrapf(err, "failed to activate layer %s", m.Source)
	}
	defer func() {
		if err != nil {
			hcsshim.DeactivateLayer(di, layerID)
		}
	}()

	if err = hcsshim.PrepareLayer(di, layerID, parentLayerPaths); err != nil {
		return errors.Wrapf(err, "failed to prepare layer %s", m.Source)
	}
	return nil
}
145488
func mount(pendingMounts ...Mounter) {
	for _, mounter := range pendingMounts {
		if mounter == nil {
			continue
		}
		if c, ok := mounter.(Component); ok {
			if c.Context().mounted {
				continue
			}
			c.Context().mounted = true
			c.Context().unmounted = false
		}
		mounter.Mount()
	}
}
1192091
func (c *client) Mount(
	ctx types.Context,
	deviceName, mountPoint string,
	opts *types.DeviceMountOpts) error {

	if c.isController() {
		return utils.NewUnsupportedForClientTypeError(
			c.clientType, "Mount")
	}

	if lsxSO, _ := c.Supported(ctx, opts.Opts); !lsxSO.Mount() {
		return errExecutorNotSupported
	}

	ctx = context.RequireTX(ctx.Join(c.ctx))

	serviceName, ok := context.ServiceName(ctx)
	if !ok {
		return goof.New("missing service name")
	}

	si, err := c.getServiceInfo(serviceName)
	if err != nil {
		return err
	}
	driverName := si.Driver.Name

	// create the executor
	d, err := c.getExecutor(ctx, driverName)
	if err != nil {
		return err
	}

	dd, ok := d.(types.StorageExecutorWithMount)
	if !ok {
		return types.ErrNotImplemented
	}

	if err := dd.Mount(ctx, deviceName, mountPoint, opts); err != nil {
		return err
	}

	ctx.Debug("xli mount success")
	return nil
}
909752
func Mount(ipfs *core.IpfsNode, mountpoint string) (mount.Mount, error) {
	cfg, err := ipfs.Repo.Config()
	if err != nil {
		return nil, err
	}
	allow_other := cfg.Mounts.FuseAllowOther
	fsys := NewFileSystem(ipfs)
	return mount.NewMount(ipfs.Process, fsys, mountpoint, allow_other)
}
116542
func (m *Mounter) Mount(fs VFS, point string) error {
	point = path.Clean(point)
	if point == "." || point == "" {
		point = "/"
	}
	if point == "/" {
		if len(m.points) > 0 {
			return fmt.Errorf("%s is already mounted at /", m.points[0])
		}
		m.points = append(m.points, &mountPoint{point, fs})
		return nil
	}
	stat, err := m.Stat(point)
	if err != nil {
		return err
	}
	if !stat.IsDir() {
		return fmt.Errorf("%s is not a directory", point)
	}
	m.points = append(m.points, &mountPoint{point, fs})
	return nil
}
755720
func Mount(driver Driver, remotePath, localPath string) error {
	// check if the driver is installed
	if err := driver.Installed(); err != nil {
		return err
	}

	// validate that the remote path
	if ok := func(remotePath string) bool {
		parts := strings.Split(remotePath, ":")
		if len(parts) != 2 {
			return false
		}

		ip := net.ParseIP(parts[0])
		if ip == nil {
			return false
		}

		dest := filepath.Clean(parts[1])
		return dest != "/" && filepath.IsAbs(dest)
	}(remotePath); !ok {
		return ErrMalformedNFSMountpoint
	}

	var mountInfo proc.NFSMountInfo
	mountError := driver.Info(localPath, &mountInfo)

	needsReMount := false

	if mountError == nil {
		// we need to check for a stale NFS mount
		if staleNFSCheck(localPath) {
			glog.Infof("Detected stale NFS mount, re-mounting %s", localPath)
			//unmount and re-mount
			needsReMount = true
			if err := driver.Unmount(localPath); err != nil {
				glog.Errorf("Error while unmounting %s: %s", localPath, err)
				return err
			}

		}
	}

	if mountError == proc.ErrMountPointNotFound || needsReMount {
		// the mountpoint is not found so try to mount
		glog.Infof("Creating new mount for %s -> %s", remotePath, localPath)
		if err := os.MkdirAll(localPath, 0775); err != nil {
			return err
		}
		if err := driver.Mount(remotePath, localPath, time.Second*30); err != nil {
			glog.Errorf("Error while creating mount point for %s -> %s: %s", remotePath, localPath, err)
			return err
		}

		// get the mount point
		mountError = driver.Info(localPath, &mountInfo)
	}

	if mountError != nil {
		// we should have a mount point by now or bust
		glog.Errorf("Could not get volume info for %s (mounting from %s): %s", localPath, remotePath, mountError)
		return mountError
	}

	// validate mount info
	glog.Infof("Mount Info: %+v", mountInfo)
	verr := validation.NewValidationError()
	verr.Add(validation.StringsEqual(remotePath, mountInfo.RemotePath, ""))
	verr.Add(validation.StringsEqual("nfs4", mountInfo.FSType, fmt.Sprintf("%s not mounted nfs4, %s instead", mountInfo.LocalPath, mountInfo.FSType)))

	if verr.HasError() {
		// the mountpoint is stale or wrong, so unmount
		glog.Warningf("Stale mount point at %s (mounting %s)", localPath, remotePath)
		if err := driver.Unmount(localPath); err != nil {
			glog.Errorf("Could not unmount %s: %s", localPath, err)
		}
		return verr
	}

	return nil
}
80676
func Mount(cfg *MountCfg) error {
	err := syscall.Mount("overlay", cfg.Dest, "overlay", 0, cfg.Opts())
	if err != nil {
		const text = "error mounting overlay with options '%s' and dest '%s'"
		return errwrap.Wrap(fmt.Errorf(text, cfg.Opts(), cfg.Dest), err)
	}

	return nil
}
133973
func Mount(ipfs *core.IpfsNode, ipnsmp, ipfsmp string) (mount.Mount, error) {
	cfg, err := ipfs.Repo.Config()
	if err != nil {
		return nil, err
	}

	allow_other := cfg.Mounts.FuseAllowOther

	fsys, err := NewFileSystem(ipfs, ipfs.PrivateKey, ipfsmp, ipnsmp)
	if err != nil {
		return nil, err
	}

	return mount.NewMount(ipfs.Process(), fsys, ipnsmp, allow_other)
}
260187
func (c *Core) remount(ctx context.Context, src, dst string) error {
	ns, err := namespace.FromContext(ctx)
	if err != nil {
		return err
	}

	// Ensure we end the path in a slash
	if !strings.HasSuffix(src, "/") {
		src += "/"
	}
	if !strings.HasSuffix(dst, "/") {
		dst += "/"
	}

	// Prevent protected paths from being remounted
	for _, p := range protectedMounts {
		if strings.HasPrefix(src, p) {
			return fmt.Errorf("cannot remount %q", src)
		}
	}

	// Verify exact match of the route
	srcMatch := c.router.MatchingMountEntry(ctx, src)
	if srcMatch == nil {
		return fmt.Errorf("no matching mount at %q", src)
	}
	if srcMatch.NamespaceID != ns.ID {
		return fmt.Errorf("source mount in a different namespace than request")
	}

	if err := verifyNamespace(c, ns, &MountEntry{Path: dst}); err != nil {
		return err
	}

	if match := c.router.MatchingMount(ctx, dst); match != "" {
		return fmt.Errorf("existing mount at %q", match)
	}

	// Mark the entry as tainted
	if err := c.taintMountEntry(ctx, src, true); err != nil {
		return err
	}

	// Taint the router path to prevent routing
	if err := c.router.Taint(ctx, src); err != nil {
		return err
	}

	if !c.IsDRSecondary() {
		// Invoke the rollback manager a final time
		rCtx := namespace.ContextWithNamespace(c.activeContext, ns)
		if err := c.rollback.Rollback(rCtx, src); err != nil {
			return err
		}

		entry := c.router.MatchingMountEntry(ctx, src)
		if entry == nil {
			return fmt.Errorf("no matching mount at %q", src)
		}

		// Revoke all the dynamic keys
		if err := c.expiration.RevokePrefix(rCtx, src, true); err != nil {
			return err
		}
	}

	c.mountsLock.Lock()
	var entry *MountEntry
	for _, mountEntry := range c.mounts.Entries {
		if mountEntry.Path == src && mountEntry.NamespaceID == ns.ID {
			entry = mountEntry
			entry.Path = dst
			entry.Tainted = false
			break
		}
	}

	if entry == nil {
		c.mountsLock.Unlock()
		c.logger.Error("failed to find entry in mounts table")
		return logical.CodedError(500, "failed to find entry in mounts table")
	}

	// Update the mount table
	if err := c.persistMounts(ctx, c.mounts, &entry.Local); err != nil {
		entry.Path = src
		entry.Tainted = true
		c.mountsLock.Unlock()
		if err == logical.ErrReadOnly && c.perfStandby {
			return err
		}

		c.logger.Error("failed to update mounts table", "error", err)
		return logical.CodedError(500, "failed to update mounts table")
	}
	c.mountsLock.Unlock()

	// Remount the backend
	if err := c.router.Remount(ctx, src, dst); err != nil {
		return err
	}

	// Un-taint the path
	if err := c.router.Untaint(ctx, dst); err != nil {
		return err
	}

	if c.logger.IsInfo() {
		c.logger.Info("successful remount", "old_path", src, "new_path", dst)
	}
	return nil
}
171628
func mount(source, destination, fsType string, flags int, options string) error {
	var absSource string

	// Log before validation. This is useful to debug cases where the gRPC
	// protocol version being used by the client is out-of-sync with the
	// agents version. gRPC message members are strictly ordered, so it's
	// quite possible that if the protocol changes, the client may
	// try to pass a valid mountpoint, but the gRPC layer may change that
	// through the member ordering to be a mount *option* for example.
	agentLog.WithFields(logrus.Fields{
		"mount-source":      source,
		"mount-destination": destination,
		"mount-fstype":      fsType,
		"mount-flags":       flags,
		"mount-options":     options,
	}).Debug()

	if source == "" {
		return fmt.Errorf("need mount source")
	}

	if destination == "" {
		return fmt.Errorf("need mount destination")
	}

	if fsType == "" {
		return fmt.Errorf("need mount FS type")
	}

	var err error
	switch fsType {
	case type9pFs, typeVirtioFS:
		if err = createDestinationDir(destination); err != nil {
			return err
		}
		absSource = source
	case typeTmpFs:
		absSource = source
	default:
		absSource, err = filepath.EvalSymlinks(source)
		if err != nil {
			return grpcStatus.Errorf(codes.Internal, "Could not resolve symlink for source %v", source)
		}

		if err = ensureDestinationExists(absSource, destination, fsType); err != nil {
			return grpcStatus.Errorf(codes.Internal, "Could not create destination mount point: %v: %v",
				destination, err)
		}
	}

	if err = syscall.Mount(absSource, destination,
		fsType, uintptr(flags), options); err != nil {
		return grpcStatus.Errorf(codes.Internal, "Could not mount %v to %v: %v",
			absSource, destination, err)
	}

	return nil
}
1242140
func (f *Folder) AddMount(name, path string) error {
	return f.addMount(strings.Split(name, sep), path)
}
367562
func (v *localVolume) Mount(id string) (string, error) {
	v.m.Lock()
	defer v.m.Unlock()
	if v.opts != nil {
		if !v.active.mounted {
			if err := v.mount(); err != nil {
				return "", errdefs.System(err)
			}
			v.active.mounted = true
		}
		v.active.count++
	}
	return v.path, nil
}
487146
func (s *Action) MountAdd(ctx context.Context, c *cli.Context) error {
	alias := c.Args().Get(0)
	localPath := c.Args().Get(1)
	if alias == "" {
		return ExitError(ctx, ExitUsage, nil, "usage: %s mounts add <alias> [local path]", s.Name)
	}

	if localPath == "" {
		localPath = config.PwStoreDir(alias)
	}

	keys := make([]string, 0, 1)
	if k := c.String("init"); k != "" {
		keys = append(keys, k)
	}

	if s.Store.Exists(ctx, alias) {
		out.Yellow(ctx, "WARNING: shadowing %s entry", alias)
	}

	if err := s.Store.AddMount(ctx, alias, localPath, keys...); err != nil {
		switch e := errors.Cause(err).(type) {
		case root.AlreadyMountedError:
			out.Print(ctx, "Store is already mounted")
			return nil
		case root.NotInitializedError:
			out.Print(ctx, "Mount %s is not yet initialized. Initializing ...", e.Alias())
			if err := s.init(ctx, e.Alias(), e.Path()); err != nil {
				return ExitError(ctx, ExitUnknown, err, "failed to add mount '%s': failed to initialize store: %s", e.Alias(), err)
			}
		default:
			return ExitError(ctx, ExitMount, err, "failed to add mount '%s' to '%s': %s", alias, localPath, err)
		}
	}

	if err := s.cfg.Save(); err != nil {
		return ExitError(ctx, ExitConfig, err, "failed to save config: %s", err)
	}

	out.Green(ctx, "Mounted %s as %s", alias, localPath)
	return nil
}
174077
func mountStorage(storage pb.Storage) error {
	flags, options, err := parseMountFlagsAndOptions(storage.Options)
	if err != nil {
		return err
	}

	return mount(storage.Source, storage.MountPoint, storage.Fstype, flags, options)
}