go.mondoo.com/cnquery@v0.0.0-20231005093811-59568235f6ea/providers/os/connection/snapshot/mount_linux.go (about)

     1  // Copyright (c) Mondoo, Inc.
     2  // SPDX-License-Identifier: BUSL-1.1
     3  
     4  package snapshot
     5  
     6  import (
     7  	"strings"
     8  	"syscall"
     9  
    10  	"github.com/rs/zerolog/log"
    11  	"golang.org/x/sys/unix"
    12  )
    13  
    14  func Mount(attachedFS string, scanDir string, fsType string, opts []string) error {
    15  	if err := unix.Mount(attachedFS, scanDir, fsType, syscall.MS_MGC_VAL, strings.Join(opts, ",")); err != nil && err != unix.EBUSY {
    16  		log.Error().Err(err).Str("attached-fs", attachedFS).Str("scan-dir", scanDir).Str("fs-type", fsType).Str("opts", strings.Join(opts, ",")).Msg("failed to mount dir")
    17  		return err
    18  	}
    19  	return nil
    20  }
    21  
    22  func Unmount(scanDir string) error {
    23  	if err := unix.Unmount(scanDir, unix.MNT_DETACH); err != nil && err != unix.EBUSY {
    24  		log.Error().Err(err).Msg("failed to unmount dir")
    25  		return err
    26  	}
    27  	return nil
    28  }