• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2020 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package mount
16
17import (
18	"fmt"
19)
20
21type MountEntry struct {
22	Source string
23	FSType string
24	Flags  uintptr
25	Data   string
26}
27
28type fakeMounter struct {
29	mountMap map[string]MountEntry //keyed by target
30}
31
32func NewFakeMounter() *fakeMounter {
33	var f fakeMounter
34	f.mountMap = make(map[string]MountEntry)
35	return &f
36}
37
38func (f *fakeMounter) Mount(source string, target string, fstype string, flags uintptr, data string) error {
39	//Using the target as the key prevents more
40	//than one source mapping to the same target
41	f.mountMap[target] = MountEntry{
42		Source: source,
43		FSType: fstype,
44		Flags:  flags,
45		Data:   data,
46	}
47	return nil
48}
49
50func (f *fakeMounter) Unmount(target string, flags int) error {
51	_, ok := f.mountMap[target]
52	if !ok {
53		return fmt.Errorf("Mount %s not found", target)
54	}
55	delete(f.mountMap, target)
56	return nil
57}
58
59func (f *fakeMounter) List() ([]string, error) {
60	var list []string
61	for target, _ := range f.mountMap {
62		list = append(list, target)
63	}
64
65	return list, nil
66}
67