storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/pkg/mountinfo/mountinfo_windows.go (about)

     1  //go:build windows
     2  // +build windows
     3  
     4  /*
     5   * MinIO Cloud Storage, (C) 2018 MinIO, Inc.
     6   *
     7   * Licensed under the Apache License, Version 2.0 (the "License");
     8   * you may not use this file except in compliance with the License.
     9   * You may obtain a copy of the License at
    10   *
    11   *     http://www.apache.org/licenses/LICENSE-2.0
    12   *
    13   * Unless required by applicable law or agreed to in writing, software
    14   * distributed under the License is distributed on an "AS IS" BASIS,
    15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    16   * See the License for the specific language governing permissions and
    17   * limitations under the License.
    18   */
    19  
    20  package mountinfo
    21  
    22  import (
    23  	"path/filepath"
    24  	"sync"
    25  
    26  	"golang.org/x/sys/windows"
    27  )
    28  
    29  // CheckCrossDevice - check if any input path has multiple sub-mounts.
    30  // this is a dummy function and returns nil for now.
    31  func CheckCrossDevice(paths []string) error {
    32  	return nil
    33  }
    34  
    35  // mountPointCache contains results of IsLikelyMountPoint
    36  var mountPointCache sync.Map
    37  
    38  // IsLikelyMountPoint determines if a directory is a mountpoint.
    39  func IsLikelyMountPoint(path string) bool {
    40  	path = filepath.Dir(path)
    41  	if v, ok := mountPointCache.Load(path); ok {
    42  		return v.(bool)
    43  	}
    44  	wpath, _ := windows.UTF16PtrFromString(path)
    45  	wvolume := make([]uint16, len(path)+1)
    46  
    47  	if err := windows.GetVolumePathName(wpath, &wvolume[0], uint32(len(wvolume))); err != nil {
    48  		mountPointCache.Store(path, false)
    49  		return false
    50  	}
    51  
    52  	switch windows.GetDriveType(&wvolume[0]) {
    53  	case windows.DRIVE_FIXED, windows.DRIVE_REMOVABLE, windows.DRIVE_REMOTE, windows.DRIVE_RAMDISK:
    54  		// Recognize "fixed", "removable", "remote" and "ramdisk" drives as proper drives
    55  		// which can be treated as an actual mount-point, rest can be ignored.
    56  		// https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getdrivetypew
    57  		mountPointCache.Store(path, true)
    58  		return true
    59  	}
    60  	mountPointCache.Store(path, false)
    61  	return false
    62  }