// Ensure mount point on which path is mounted, is shared.
437608
func ensureShared(path string, mountInfos []*dockermounts.Info) error {
	sourceMount, optionalOpts, err := getSourceMount(path, mountInfos)
	if err != nil {
		return err
	}

	// Make sure source mount point is shared.
	optsSplit := strings.Split(optionalOpts, " ")
	for _, opt := range optsSplit {
		if strings.HasPrefix(opt, "shared:") {
			return nil
		}
	}

	return fmt.Errorf("path %q is mounted on %q but it is not a shared mount", path, sourceMount)
}
248172
func Mounted(mountpoint string) (bool, error) {
	var mntpointSt unix.Stat_t
	if err := unix.Stat(mountpoint, &mntpointSt); err != nil {
		if os.IsNotExist(err) {
			return false, nil
		}
		return false, err
	}
	var parentSt unix.Stat_t
	if err := unix.Stat(filepath.Join(mountpoint, ".."), &parentSt); err != nil {
		return false, err
	}
	return mntpointSt.Dev != parentSt.Dev, nil
}
693374
func EnsurePath(path string, dir bool) error {
	if !dir {
		path = filepath.Dir(path)
	}
	return os.MkdirAll(path, 0755)
}
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
}
252067
func (c *Client) Mount(source, destination string) error {
	return nfsMount(&nfs.NFSDriver{}, path.Join(c.exportedPath, source), destination)
}
296343
func validateMounts(mounts []api.Mount) error {
	mountMap := make(map[string]bool)
	for _, mount := range mounts {
		if _, exists := mountMap[mount.Target]; exists {
			return status.Errorf(codes.InvalidArgument, "ContainerSpec: duplicate mount point: %s", mount.Target)
		}
		mountMap[mount.Target] = true
	}

	return nil
}
507692
func findIntelRdtMountpointDir() (string, error) {
	f, err := os.Open("/proc/self/mountinfo")
	if err != nil {
		return "", err
	}
	defer f.Close()

	s := bufio.NewScanner(f)
	for s.Scan() {
		text := s.Text()
		fields := strings.Split(text, " ")
		// Safe as mountinfo encodes mountpoints with spaces as \040.
		index := strings.Index(text, " - ")
		postSeparatorFields := strings.Fields(text[index+3:])
		numPostFields := len(postSeparatorFields)

		// This is an error as we can't detect if the mount is for "Intel RDT"
		if numPostFields == 0 {
			return "", fmt.Errorf("Found no fields post '-' in %q", text)
		}

		if postSeparatorFields[0] == "resctrl" {
			// Check that the mount is properly formatted.
			if numPostFields < 3 {
				return "", fmt.Errorf("Error found less than 3 fields post '-' in %q", text)
			}

			// Check if MBA Software Controller is enabled through mount option "-o mba_MBps"
			if strings.Contains(postSeparatorFields[2], "mba_MBps") {
				isMbaScEnabled = true
			}

			return fields[4], nil
		}
	}
	if err := s.Err(); err != nil {
		return "", err
	}

	return "", NewNotFoundError("Intel RDT")
}
266815
func getSourceMount(source string) (string, string, error) {
	// Ensure any symlinks are resolved.
	sourcePath, err := filepath.EvalSymlinks(source)
	if err != nil {
		return "", "", err
	}

	mi, err := mount.GetMounts(mount.ParentsFilter(sourcePath))
	if err != nil {
		return "", "", err
	}
	if len(mi) < 1 {
		return "", "", fmt.Errorf("Can't find mount point of %s", source)
	}

	// find the longest mount point
	var idx, maxlen int
	for i := range mi {
		if len(mi[i].Mountpoint) > maxlen {
			maxlen = len(mi[i].Mountpoint)
			idx = i
		}
	}
	return mi[idx].Mountpoint, mi[idx].Optional, nil
}
43516
func (c *NodeupModelContext) EnsureDirectory(path string) error {
	st, err := os.Stat(path)
	if err != nil {
		if os.IsNotExist(err) {
			return os.MkdirAll(path, 0755)
		}

		return err
	}

	if !st.IsDir() {
		return fmt.Errorf("path: %s already exists but is not a directory", path)
	}

	return nil
}
627001
func ValidateMountpoints(wmp map[string]types.MountPoint) results {
	r := results{}
	// TODO(jonboulle): verify actual source
	for _, mp := range wmp {
		if err := checkMount(mp.Path, mp.ReadOnly); err != nil {
			r = append(r, err)
		}
	}
	return r
}
1279010
func (r *Store) AddMount(ctx context.Context, alias, path string, keys ...string) error {
	if err := r.addMount(ctx, alias, path, nil, keys...); err != nil {
		return errors.Wrapf(err, "failed to add mount")
	}

	// check for duplicate mounts
	return r.checkMounts()
}
1133103
func MountPoints() (map[string]*MountPoint, error) {
	mp := make(map[string]*MountPoint, 0)
	var current *MountPoint
	err := ParseSimpleProcFile(
		MountProcFile,
		nil,
		func(line int, index int, elm string) error {
			switch index {
			case 0:
				current = new(MountPoint)
				current.Dev = elm
			case 1:
				if len(elm) > 0 && elm[0] != '/' {
					return fmt.Errorf(
						"Invalid path on lin %d of file %s: %s",
						line, MountProcFile, elm)
				}
				current.Path = elm
				mp[elm] = current
			case 2:
				current.Fstype = elm
			case 3:
				current.Options = elm
			case 4:
				n, err := strconv.ParseUint(elm, 10, 32)
				if err != nil {
					return fmt.Errorf(
						"Error parsing column %d on line %d of file %s: %s",
						index, line, MountProcFile, elm)
				}
				current.Dump = int(n)
			case 5:
				n, err := strconv.ParseUint(elm, 10, 32)
				if err != nil {
					return fmt.Errorf(
						"Error parsing column %d on line %d of file %s: %s",
						index, line, MountProcFile, elm)
				}
				current.Fsck = int(n)
			default:
				return fmt.Errorf(
					"Too many colums on line %d of file %s",
					line, MountProcFile)
			}
			return nil
		})
	if err != nil {
		return nil, err
	}
	return mp, nil
}
266496
func (m *Mounter) HasMounts(sourcePath string) int {
	m.Lock()
	defer m.Unlock()

	v, ok := m.mounts[sourcePath]
	if !ok {
		return 0
	}
	return len(v.Mountpoint)
}
1107344
func safeOpenSubPath(mounter mount.Interface, subpath Subpath) (int, error) {
	if !mount.PathWithinBase(subpath.Path, subpath.VolumePath) {
		return -1, fmt.Errorf("subpath %q not within volume path %q", subpath.Path, subpath.VolumePath)
	}
	fd, err := doSafeOpen(subpath.Path, subpath.VolumePath)
	if err != nil {
		return -1, fmt.Errorf("error opening subpath %v: %v", subpath.Path, err)
	}
	return fd, nil
}
856433
func (c *Core) mount(ctx context.Context, entry *MountEntry) error {
	// Ensure we end the path in a slash
	if !strings.HasSuffix(entry.Path, "/") {
		entry.Path += "/"
	}

	// Prevent protected paths from being mounted
	for _, p := range protectedMounts {
		if strings.HasPrefix(entry.Path, p) && entry.namespace == nil {
			return logical.CodedError(403, fmt.Sprintf("cannot mount %q", entry.Path))
		}
	}

	// Do not allow more than one instance of a singleton mount
	for _, p := range singletonMounts {
		if entry.Type == p {
			return logical.CodedError(403, fmt.Sprintf("mount type of %q is not mountable", entry.Type))
		}
	}
	return c.mountInternal(ctx, entry, MountTableUpdateStorage)
}
893309
func (mount *MountInfo) IsMounted() bool {
	ret := C.ceph_is_mounted(mount.mount)
	return ret == 1
}
925431
func Mount(r mountRunner, source string, target string, c *MountConfig) error {
	if err := Unmount(r, target); err != nil {
		return errors.Wrap(err, "umount")
	}

	cmd := fmt.Sprintf("sudo mkdir -m %o -p %s && %s", c.Mode, target, mntCmd(source, target, c))
	glog.Infof("Will run: %s", cmd)
	out, err := r.CombinedOutput(cmd)
	glog.Infof("mount err=%s, out=%s", err, out)
	if err != nil {
		return errors.Wrap(err, out)
	}
	return nil
}