github.com/openebs/node-disk-manager@v1.9.1-0.20230225014141-4531f06ffa1e/pkg/mount/libmount/filesystem.go (about) 1 /* 2 Copyright 2020 The OpenEBS Authors 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package libmount 18 19 import "strings" 20 21 // Filesystem represents a single filesystem entry in a mount table. 22 type Filesystem struct { 23 tab *MountTab 24 id int 25 source string 26 tagName string 27 tagValue string 28 target string 29 fsType string 30 vfsOpts string 31 fsOpts string 32 } 33 34 type FsFilter func(*Filesystem) bool 35 36 // NewFilesystem returns an empty filesystem 37 func NewFilesystem() *Filesystem { 38 return &Filesystem{} 39 } 40 41 // GetID returns the id of the filesystem 42 func (fs *Filesystem) GetID() int { 43 return fs.id 44 } 45 46 // GetSource returns the source device of the filesystem 47 func (fs *Filesystem) GetSource() string { 48 return fs.source 49 } 50 51 // GetTarget returns the target path of the filesystem 52 func (fs *Filesystem) GetTarget() string { 53 return fs.target 54 } 55 56 // GetVFSOptions returns the vfs options of the filesystem 57 func (fs *Filesystem) GetVFSOptions() string { 58 return fs.vfsOpts 59 } 60 61 // GetFsOptions returns the fs options of the filesystem 62 func (fs *Filesystem) GetFSOptions() string { 63 return fs.fsOpts 64 } 65 66 // SetTag sets the tag for the filesystem 67 func (fs *Filesystem) SetTag(name string, value string) { 68 fs.tagName = name 69 fs.tagValue = value 70 } 71 72 // SetSource sets the source device of the filesystem 73 func (fs *Filesystem) SetSource(src string) { 74 fs.source = src 75 } 76 77 // SetTarget sets the target path of the filesystem 78 func (fs *Filesystem) SetTarget(target string) { 79 fs.target = target 80 } 81 82 // SetFsType sets the filsystem type of the filesystem 83 // Eg: ext4, vfat, etc. 84 func (fs *Filesystem) SetFsType(fsType string) { 85 fs.fsType = fsType 86 } 87 88 // GetMountTable returns a pointer to the mount tab this filesystem 89 // is a part of. nil if the filesystem isn't a part of any mount tab. 90 func (fs *Filesystem) GetMountTable() *MountTab { 91 return fs.tab 92 } 93 94 // SetMountTable sets the mount tab that this filesystem is a part of. 95 // A filesystem can only be a part of a single mount tab. 96 func (fs *Filesystem) SetMountTable(tab *MountTab) { 97 fs.tab = tab 98 } 99 100 // SourceFilter returns a filter that can be used to filter filesystems 101 // by matching the source value. 102 func SourceFilter(source string) FsFilter { 103 return func(f *Filesystem) bool { 104 return f != nil && f.source == source 105 } 106 } 107 108 // TargetFilter returns a filter that can be used to filter filesystems 109 // by matching target values. 110 func TargetFilter(target string) FsFilter { 111 return func(f *Filesystem) bool { 112 return f != nil && f.target == target 113 } 114 } 115 116 // IDFilter returns a filter that can be used to filter filesystems 117 // by matching id values. 118 func IDFilter(id int) FsFilter { 119 return func(f *Filesystem) bool { 120 return f != nil && f.id == id 121 } 122 } 123 124 // TargetContainsFilter returns a filter that can be used to filter filesystems 125 // by checking if the target contains the given substring. 126 func TargetContainsFilter(substr string) FsFilter { 127 return func(f *Filesystem) bool { 128 return f != nil && strings.Contains(f.target, substr) 129 } 130 } 131 132 // SourceContainsFilter returns a filter that can be used to filter filesystems 133 // by checking if the source contains the given substring. 134 func SourceContainsFilter(substr string) FsFilter { 135 return func(f *Filesystem) bool { 136 return f != nil && strings.Contains(f.source, substr) 137 } 138 }