// PathIsDevice uses FileInfo returned from os.Stat to check if path refers
// to a device.
774589
func (m *execMounter) PathIsDevice(pathname string) (bool, error) {
	return m.wrappedMounter.PathIsDevice(pathname)
}
708166
func (d *driver) NextDevice(
	ctx types.Context,
	opts types.Store) (string, error) {
	return fcUtils.NextDevice(ctx, opts)
}
304203
func (w *wrapper) Device(id protocol.DeviceID) (DeviceConfiguration, bool) {
	w.mut.Lock()
	defer w.mut.Unlock()
	for _, device := range w.cfg.Devices {
		if device.DeviceID == id {
			return device.Copy(), true
		}
	}
	return DeviceConfiguration{}, false
}
277587
func BlockDeviceDiscard(path string) error {
	file, err := os.OpenFile(path, os.O_RDWR, 0)
	if err != nil {
		return err
	}
	defer file.Close()

	size, err := GetBlockDeviceSize(file)
	if err != nil {
		return err
	}

	if err := ioctlBlkDiscard(file.Fd(), 0, size); err != nil {
		return err
	}

	// Without this sometimes the remove of the device that happens after
	// discard fails with EBUSY.
	unix.Sync()

	return nil
}
215866
func convertStructDevice(in *Device) *proto.DetectedDevice {
	if in == nil {
		return nil
	}

	return &proto.DetectedDevice{
		ID:                in.ID,
		Healthy:           in.Healthy,
		HealthDescription: in.HealthDesc,
		HwLocality:        convertStructDeviceLocality(in.HwLocality),
	}
}
67031
func inode(path string) (uint64, error) {
	stat, err := os.Stat(path)
	if err != nil {
		return 0, err
	}
	if st, ok := stat.Sys().(*syscall.Stat_t); ok {
		return uint64(st.Ino), nil
	}
	return 0, fmt.Errorf("could not determine file inode")
}
1327902
func getDeviceInfo(mode os.FileMode, rdev uint64) (kind rune, major uint64, minor uint64, err error) {
	kind = 'b'

	if mode&os.ModeCharDevice != 0 {
		kind = 'c'
	}

	major = (rdev >> 8) & 0xfff
	minor = (rdev & 0xff) | ((rdev >> 12) & 0xfff00)

	return
}
540111
func (c *iscsiDiskUnmapper) TearDownDevice(mapPath, _ string) error {
	err := c.manager.DetachBlockISCSIDisk(*c, mapPath)
	if err != nil {
		return fmt.Errorf("iscsi: failed to detach disk: %s\nError: %v", mapPath, err)
	}
	klog.V(4).Infof("iscsi: %q is unmounted, deleting the directory", mapPath)
	err = os.RemoveAll(mapPath)
	if err != nil {
		return fmt.Errorf("iscsi: failed to delete the directory: %s\nError: %v", mapPath, err)
	}
	klog.V(4).Infof("iscsi: successfully detached disk: %s", mapPath)
	return nil
}
718130
func (d *DeviceMapperDriver) writeDeviceInfo(deviceHash string, devInfo devInfo) error {
	devInfoPath := d.deviceInfoPath(deviceHash)
	fs, err := os.Stat(devInfoPath)
	if err != nil {
		glog.Errorf("Could not stat file %s: %s", devInfoPath, err)
		return err
	}
	data, err := json.Marshal(devInfo)
	if err != nil {
		glog.Errorf("Could not marshal info for device %s: %s", deviceHash, err)
		return err
	}
	if err := atomicfile.WriteFile(devInfoPath, data, fs.Mode()); err != nil {
		glog.Errorf("Could not update info for device %s: %s", deviceHash, err)
		return err
	}
	// Clear the cached device info for the set
	d.invalidateDeviceInfo(deviceHash)
	return nil
}
901609
func isDeviceOpened(deviceToDetach AttachedVolume, mounter mount.Interface) (bool, error) {
	isDevicePath, devicePathErr := mounter.PathIsDevice(deviceToDetach.DevicePath)
	var deviceOpened bool
	var deviceOpenedErr error
	if !isDevicePath && devicePathErr == nil ||
		(devicePathErr != nil && strings.Contains(devicePathErr.Error(), "does not exist")) {
		// not a device path or path doesn't exist
		//TODO: refer to #36092
		klog.V(3).Infof("The path isn't device path or doesn't exist. Skip checking device path: %s", deviceToDetach.DevicePath)
		deviceOpened = false
	} else if devicePathErr != nil {
		return false, deviceToDetach.GenerateErrorDetailed("PathIsDevice failed", devicePathErr)
	} else {
		deviceOpened, deviceOpenedErr = mounter.DeviceOpened(deviceToDetach.DevicePath)
		if deviceOpenedErr != nil {
			return false, deviceToDetach.GenerateErrorDetailed("DeviceOpened failed", deviceOpenedErr)
		}
	}
	return deviceOpened, nil
}
103135
func (devices *DeviceSet) registerDevice(id int, hash string, size uint64, transactionID uint64) (*devInfo, error) {
	logrus.Debugf("devmapper: registerDevice(%v, %v)", id, hash)
	info := &devInfo{
		Hash:          hash,
		DeviceID:      id,
		Size:          size,
		TransactionID: transactionID,
		Initialized:   false,
		devices:       devices,
	}

	devices.Devices[hash] = info

	if err := devices.saveMetadata(info); err != nil {
		// Try to remove unused device
		delete(devices.Devices, hash)
		return nil, err
	}

	return info, nil
}
469090
func findDeviceForPath(path string, io IoUtil) (string, error) {
	devicePath, err := io.EvalSymlinks(path)
	if err != nil {
		return "", err
	}
	// if path /dev/hdX split into "", "dev", "hdX" then we will
	// return just the last part
	parts := strings.Split(devicePath, "/")
	if len(parts) == 3 && strings.HasPrefix(parts[1], "dev") {
		return parts[2], nil
	}
	return "", errors.New("Illegal path for device " + devicePath)
}
264791
func (addr *Address) Device() (*LinkLayerDevice, error) {
	return addr.machineProxy().LinkLayerDevice(addr.doc.DeviceName)
}
248108
func DeviceAlias(path string) string {
	return filepath.Join(deviceAliasDir, filepath.Clean(path))
}
127371
func (d *DeviceMapperDriver) readDeviceInfo(deviceHash string, devInfo *devInfo) error {
	fh, err := os.Open(d.deviceInfoPath(deviceHash))
	if err != nil {
		glog.Errorf("Could not read device info for %s: %s", deviceHash, err)
		return err
	}
	defer fh.Close()
	if err := json.NewDecoder(fh).Decode(devInfo); err != nil {
		glog.Errorf("Could not decode device info for %s: %s", deviceHash, err)
		return err
	}
	return nil
}
312409
func (s *Job) SetDevice(v *Device) *Job {
	s.Device = v
	return s
}
990022
func PathIsDir(path string) (isDir bool, err error) {
	fi, err := os.Stat(path)
	if err != nil {
		return false, err
	}
	return fi.IsDir(), nil
}