github.com/openebs/node-disk-manager@v1.9.1-0.20230225014141-4531f06ffa1e/pkg/mount/mountinfo.go (about)

     1  /*
     2  Copyright 2019 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 mount
    18  
    19  const (
    20  	// HostMountsFilePath is the default path of
    21  	// the mounts file mounted inside container
    22  	HostMountsFilePath = "/host/proc/1/mounts"
    23  )
    24  
    25  // Identifier is an identifier for the mount probe. It will be a devpath like
    26  // /dev/sda, /dev/sda1 etc
    27  type Identifier struct {
    28  	DevPath string
    29  }
    30  
    31  // DeviceMountAttr is the struct used for returning all available mount related information like
    32  // mount point, filesystem type etc.
    33  // It helps to find mountpoint of a partition/block
    34  type DeviceMountAttr struct {
    35  	DevPath    string   // DevPath of the device/block
    36  	MountPoint []string // MountPoint of the the device/block
    37  	FileSystem string   // FileSystem in the device that is mounted
    38  }
    39  
    40  // DeviceBasicMountInfo gives the mount attributes of a device that is attached. The mount
    41  // attributes include the filesystem type, mountpoint, device path etc. These mount attributes
    42  // are fetched by parsing a mounts file (/proc/1/mounts) and getting the relevant data. If the
    43  // device is not mounted, then the function will return an error.
    44  func (I *Identifier) DeviceBasicMountInfo(mountsFilePath string) (DeviceMountAttr, error) {
    45  	mountUtil := NewMountUtil(mountsFilePath, I.DevPath, "")
    46  	mountAttr, err := mountUtil.getDeviceMountAttr(mountUtil.getMountName)
    47  	return mountAttr, err
    48  }