// GetDeviceInfo returns the type, major, and minor numbers of a device.
// Kind is 'b' or 'c' for block and character devices, respectively.
// This does not follow symlinks.
762447
func GetDeviceInfo(path string) (kind rune, major uint64, minor uint64, err error) {
	d, err := os.Lstat(path)
	if err != nil {
		return
	}
	mode := d.Mode()

	if mode&os.ModeDevice == 0 {
		err = fmt.Errorf("not a device: %s", path)
		return
	}
	stat_t, ok := d.Sys().(*syscall.Stat_t)
	if !ok {
		err = fmt.Errorf("cannot determine device number")
		return
	}
	return getDeviceInfo(mode, stat_t.Rdev)
}
1347271
func (c *Client) GetDeviceByLabel(label string) (common.Device, error) {
	devices, _ := c.GetDevices()
	for _, dev := range devices {
		res, err := dev.GetLabel()
		if err == nil && res == label {
			return dev, nil
		}
	}

	var timeout <-chan time.Time
	if c.timeout > 0 {
		timeout = time.After(c.timeout)
	} else {
		timeout = make(<-chan time.Time)
	}

	sub := c.protocol.Subscribe()
	defer func() {
		if err := sub.Close(); err != nil {
			common.Log.Warnf("Failed closing device subscription: %+v", err)
		}
	}()
	events := sub.Events()

	for {
		select {
		case event, ok := <-events:
			if !ok {
				return nil, common.ErrClosed
			}
			switch event := event.(type) {
			case common.EventNewDevice:
				l, err := event.Device.GetLabel()
				if err != nil {
					return nil, err
				}
				if l == label {
					return event.Device, nil
				}
			}
		case <-timeout:
			return nil, common.ErrNotFound
		}
	}
}
1052926
func getDeviceResources(deviceGroupStats []*api.DeviceGroupStats) []string {
	statsSummaryMap := buildDeviceStatsSummaryMap(deviceGroupStats)

	result := make([]string, 0, len(statsSummaryMap))
	for id, stats := range statsSummaryMap {
		result = append(result, id+"|"+stats.String())
	}

	sort.Strings(result)

	return result
}
1006824
func (_m *DBClient) GetDevicesWithLabel(l string) ([]models.Device, error) {
	ret := _m.Called(l)

	var r0 []models.Device
	if rf, ok := ret.Get(0).(func(string) []models.Device); ok {
		r0 = rf(l)
	} else {
		if ret.Get(0) != nil {
			r0 = ret.Get(0).([]models.Device)
		}
	}

	var r1 error
	if rf, ok := ret.Get(1).(func(string) error); ok {
		r1 = rf(l)
	} else {
		r1 = ret.Error(1)
	}

	return r0, r1
}
832500
func (vm VirtualMachine) FindDevice(p func(Device) bool, types ...BusType) bool {
	return vm.walkDevices(p, types...)
}
285579
func (mounter *Mounter) GetDeviceNameFromMount(mountPath, pluginMountDir string) (string, error) {
	return getDeviceNameFromMount(mounter, mountPath, pluginMountDir)
}
961855
func (r Hardware_Component_Model) GetType() (resp string, err error) {
	err = r.Session.DoRequest("SoftLayer_Hardware_Component_Model", "getType", nil, &r.Options, &resp)
	return
}
1182476
func pathDeviceType(path string) (deviceType, error) {
	fi, err := os.Stat(path)
	if err != nil {
		return modeUnsupported, err
	}
	switch mode := fi.Mode(); {
	case mode&os.ModeDevice != 0:
		return modeBlock, nil
	case mode.IsRegular():
		return modeFile, nil
	default:
		return modeUnsupported, nil
	}
}
1123173
func GetInfoWithDeferred(name string) (*Info, error) {
	task, err := TaskCreateNamed(deviceInfo, name)
	if task == nil {
		return nil, err
	}
	if err := task.run(); err != nil {
		return nil, err
	}
	return task.getInfoWithDeferred()
}
1270160
func (ispr iscsiDevicePathResolver) getDevicePaths(devices []string, shouldExist bool) ([]string, error) {
	var paths []string
	for _, device := range devices {
		exist, err := regexp.MatchString("-part1", device)
		if err != nil {
			return paths, bosherr.WrapError(err, "There is a problem with your regexp: '-part1'. That is used to find existing device")
		}
		if exist == shouldExist {
			matchedPath := path.Join("/dev/mapper", strings.Split(strings.Fields(device)[0], "-")[0])
			ispr.logger.Debug(ispr.logTag, "path in device list: '%+v'", matchedPath)
			paths = append(paths, matchedPath)
		}
	}

	return paths, nil
}
1365032
func (e *Kex2Provisioner) rememberDeviceInfo(jw *jsonw.Wrapper) error {
	name, err := jw.AtPath("body.device.name").GetString()
	if err != nil {
		return err
	}
	e.provisioneeDeviceName = name

	dtype, err := jw.AtPath("body.device.type").GetString()
	if err != nil {
		return err
	}
	e.provisioneeDeviceType = dtype

	return nil
}
988237
func (c *Client) GetDevices() (devices []common.Device, err error) {
	return c.protocol.GetDevices()
}
1286135
func (os *OpenStack) GetDevicePath(volumeID string) string {
	devicePath := os.GetDevicePathBySerialID(volumeID)

	if devicePath == "" {
		devicePath = os.getDevicePathFromInstanceMetadata(volumeID)
	}

	if devicePath == "" {
		klog.Warningf("Failed to find device for the volumeID: %q", volumeID)
	}

	return devicePath
}
1244220
func (mc MongoClient) GetAllDeviceReports() ([]contract.DeviceReport, error) {
	return mc.getDeviceReports(bson.M{})
}
171812
func DefaultInputDevice() (*DeviceInfo, error) {
	devs, err := Devices()
	if err != nil {
		return nil, err
	}
	i := C.Pa_GetDefaultInputDevice()
	if i < 0 {
		return nil, newError(C.PaError(i))
	}
	return devs[i], nil
}
201017
func (c *Client) GetDeviceServiceByName(n string) (contract.DeviceService, error) {
	conn := c.Pool.Get()
	defer conn.Close()

	var d contract.DeviceService
	err := getObjectByHash(conn, db.DeviceService+":name", n, unmarshalDeviceService, &d)
	return d, err
}
1316095
func InterfaceInfoFromDevices(nics map[string]device) ([]network.InterfaceInfo, error) {
	interfaces := make([]network.InterfaceInfo, len(nics))
	var i int
	for name, device := range nics {
		iInfo := network.InterfaceInfo{
			InterfaceName:       name,
			ParentInterfaceName: device["parent"],
			MACAddress:          device["hwaddr"],
			ConfigType:          network.ConfigDHCP,
		}
		if device["mtu"] != "" {
			mtu, err := strconv.Atoi(device["mtu"])
			if err != nil {
				return nil, errors.Annotate(err, "parsing device MTU")
			}
			iInfo.MTU = mtu
		}

		interfaces[i] = iInfo
		i++
	}

	sortInterfacesByName(interfaces)
	return interfaces, nil
}