Пример #1
0
/* This function allocates memory from the heap for the property
 * value.  That memory must be later freed by some other code. */
static int udevGetDeviceProperty(struct udev_device *udev_device,
                                 const char *property_key,
                                 char **property_value)
{
    const char *udev_value = NULL;
    int ret = PROPERTY_FOUND;

    udev_value = udev_device_get_property_value(udev_device, property_key);
    if (udev_value == NULL) {
        VIR_DEBUG("udev reports device '%s' does not have property '%s'",
                  udev_device_get_sysname(udev_device), property_key);
        ret = PROPERTY_MISSING;
        goto out;
    }

    /* If this allocation is changed, the comment at the beginning
     * of the function must also be changed. */
    *property_value = strdup(udev_value);
    if (*property_value == NULL) {
        VIR_ERROR(_("Failed to allocate memory for property value for "
                    "property key '%s' on device with sysname '%s'"),
                  property_key, udev_device_get_sysname(udev_device));
        virReportOOMError();
        ret = PROPERTY_ERROR;
        goto out;
    }

    VIR_DEBUG("Found property key '%s' value '%s' "
              "for device with sysname '%s'",
              property_key, *property_value,
              udev_device_get_sysname(udev_device));

out:
    return ret;
}
Пример #2
0
static int manager_process_link(Manager *m, struct udev_device *device) {
        Link *link;
        int r;

        if (streq_ptr(udev_device_get_action(device), "remove")) {
                uint64_t ifindex;

                log_debug("Link removed: %s", udev_device_get_sysname(device));

                ifindex = udev_device_get_ifindex(device);
                link = hashmap_get(m->links, &ifindex);
                if (!link)
                        return 0;

                link_free(link);
        } else {
                log_debug("New link: %s", udev_device_get_sysname(device));

                r = link_add(m, device);
                if (r < 0) {
                        log_error("Could not handle link %s: %s",
                                        udev_device_get_sysname(device),
                                        strerror(-r));
                }
        }

        return 0;
}
Пример #3
0
static int manager_process_link(Manager *m, struct udev_device *device) {
        Link *link;
        int r;

        if (streq_ptr(udev_device_get_action(device), "remove")) {
                uint64_t ifindex;

                log_debug("%s: link removed", udev_device_get_sysname(device));

                ifindex = udev_device_get_ifindex(device);
                link = hashmap_get(m->links, &ifindex);
                if (!link)
                        return 0;

                link_free(link);
        } else {
                r = link_add(m, device, &link);
                if (r < 0) {
                        if (r == -EEXIST)
                                log_debug("%s: link already exists, ignoring",
                                          link->ifname);
                        else
                                log_error("%s: could not handle link: %s",
                                          udev_device_get_sysname(device),
                                          strerror(-r));
                } else
                        log_debug("%s: link (with ifindex %" PRIu64") added",
                                  link->ifname, link->ifindex);
        }

        return 0;
}
Пример #4
0
static int manager_process_link(Manager *m, struct udev_device *device) {
        Link *link = NULL;
        int r;

        assert(m);
        assert(device);

        link_get(m, udev_device_get_ifindex(device), &link);

        if (streq_ptr(udev_device_get_action(device), "remove")) {
                log_debug("%s: link removed", udev_device_get_sysname(device));

                if (link)
                        link_free(link);
        } else {
                if (link) {
                        log_debug("%s: link already exists, ignoring",
                                  link->ifname);
                        return 0;
                }

                r = link_add(m, device, &link);
                if (r < 0) {
                        log_error("%s: could not handle link: %s",
                                  udev_device_get_sysname(device),
                                  strerror(-r));
                } else
                        log_debug("%s: link (with ifindex %" PRIu64") added",
                                  link->ifname, link->ifindex);
        }

        return 0;
}
//Here we can only handle udev events related to plugging and removing entire 
//drives
void pup_cdrom_udev_event(PupVMMonitor *monitor, struct udev_device *dev)
{
	//An optical drive is a block device
	if (g_strcmp0(udev_device_get_subsystem(dev), "block") != 0)
		return;
	g_debug("processing event for %s...\n", udev_device_get_sysname(dev));
	if (pup_drive_test_optical(dev))
	{
		//We are handling it...
		pup_vm_monitor_stop_processing_uevent(monitor);

		const gchar *action = udev_device_get_action(dev);
		g_return_if_fail(action);
		if (strcmp(action, "remove") == 0)
		{
			g_debug("Removing %s", udev_device_get_sysname(dev));
			PupDrive *drv = pup_vm_monitor_lookup_drive
				(monitor, udev_device_get_sysname(dev), FALSE);
			if (drv) pup_vm_monitor_remove_device(monitor, PUP_DEVICE(drv));
			PupVolume *vol = pup_vm_monitor_lookup_volume
				(monitor, udev_device_get_sysname(dev), FALSE);
			if (vol) pup_vm_monitor_remove_device(monitor, PUP_DEVICE(vol));
			
		}
		else
		{
			g_debug("Optical drive, now probing...\n");
			pup_cd_drive_new_from_udev_device(monitor, dev);
		}
	}
	else
		g_debug("Not an optical drive\n");
}
Пример #6
0
static int udevGenerateDeviceName(struct udev_device *device,
                                  virNodeDeviceDefPtr def,
                                  const char *s)
{
    int ret = 0, i = 0;
    virBuffer buf = VIR_BUFFER_INITIALIZER;

    virBufferAsprintf(&buf, "%s_%s",
                      udev_device_get_subsystem(device),
                      udev_device_get_sysname(device));

    if (s != NULL) {
        virBufferAsprintf(&buf, "_%s", s);
    }

    if (virBufferError(&buf)) {
        virBufferFreeAndReset(&buf);
        VIR_ERROR(_("Buffer error when generating device name for device "
                    "with sysname '%s'"), udev_device_get_sysname(device));
        ret = -1;
    }

    def->name = virBufferContentAndReset(&buf);

    for (i = 0; i < strlen(def->name) ; i++) {
        if (!(c_isalnum(*(def->name + i)))) {
            *(def->name + i) = '_';
        }
    }

    return ret;
}
Пример #7
0
/* This function allocates memory from the heap for the property
 * value.  That memory must be later freed by some other code. */
static int udevGetDeviceSysfsAttr(struct udev_device *udev_device,
                                  const char *attr_name,
                                  char **attr_value)
{
    const char *udev_value = NULL;
    int ret = PROPERTY_FOUND;

    udev_value = udev_device_get_sysattr_value(udev_device, attr_name);
    if (udev_value == NULL) {
        VIR_DEBUG("udev reports device '%s' does not have sysfs attr '%s'",
                  udev_device_get_sysname(udev_device), attr_name);
        ret = PROPERTY_MISSING;
        goto out;
    }

    /* If this allocation is changed, the comment at the beginning
     * of the function must also be changed. */
    *attr_value = strdup(udev_value);
    if (*attr_value == NULL) {
        VIR_ERROR(_("Failed to allocate memory for sysfs attribute value for "
                    "sysfs attribute '%s' on device with sysname '%s'"),
                  attr_name, udev_device_get_sysname(udev_device));
        virReportOOMError();
        ret = PROPERTY_ERROR;
        goto out;
    }

    VIR_DEBUG("Found sysfs attribute '%s' value '%s' "
              "for device with sysname '%s'",
              attr_name, *attr_value,
              udev_device_get_sysname(udev_device));

out:
    return ret;
}
Пример #8
0
static struct udev_device *handle_scsi_iscsi(struct udev_device *parent, char **path)
{
	struct udev *udev  = udev_device_get_udev(parent);
	struct udev_device *transportdev;
	struct udev_device *sessiondev = NULL;
	const char *target;
	char *connname;
	struct udev_device *conndev = NULL;
	const char *addr;
	const char *port;

	/* find iscsi session */
	transportdev = parent;
	while (1) {
		transportdev = udev_device_get_parent(transportdev);
		if (transportdev == NULL)
			return NULL;
		if (strncmp(udev_device_get_sysname(transportdev), "session", 7) == 0)
			break;
	}
	if (transportdev == NULL)
		return NULL;

	/* find iscsi session device */
	sessiondev = udev_device_new_from_subsystem_sysname(udev, "iscsi_session", udev_device_get_sysname(transportdev));
	if (sessiondev == NULL)
		return NULL;
	target = udev_device_get_sysattr_value(sessiondev, "targetname");
	if (target == NULL) {
		parent = NULL;
		goto out;
	}

	if (asprintf(&connname, "connection%s:0", udev_device_get_sysnum(transportdev)) < 0) {
		parent = NULL;
		goto out;
	}
	conndev = udev_device_new_from_subsystem_sysname(udev, "iscsi_connection", connname);
	free(connname);
	if (conndev == NULL) {
		parent = NULL;
		goto out;
	}
	addr = udev_device_get_sysattr_value(conndev, "persistent_address");
	port = udev_device_get_sysattr_value(conndev, "persistent_port");
	if (addr == NULL || port == NULL) {
		parent = NULL;
		goto out;
	}

	path_prepend(path, "ip-%s:%s-iscsi-%s-lun-%s", addr, port, target, udev_device_get_sysnum(parent));
out:
	udev_device_unref(sessiondev);
	udev_device_unref(conndev);
	return parent;
}
Пример #9
0
static struct udev_device *handle_scsi_fibre_channel(struct udev_device *parent, char **path)
{
	struct udev *udev  = udev_device_get_udev(parent);
	struct udev_device *targetdev;
	struct udev_device *fcdev = NULL;
	const char *port;
	unsigned int lun;

	targetdev = udev_device_get_parent_with_subsystem_devtype(parent, "scsi", "scsi_target");
	if (targetdev == NULL)
		return NULL;

	fcdev = udev_device_new_from_subsystem_sysname(udev, "fc_transport", udev_device_get_sysname(targetdev));
	if (fcdev == NULL)
		return NULL;
	port = udev_device_get_sysattr_value(fcdev, "port_name");
	if (port == NULL) {
		parent = NULL;
		goto out;
	}

	lun = strtoul(udev_device_get_sysnum(parent), NULL, 10);
	path_prepend(path, "fc-%s:0x%04x%04x00000000", port, lun & 0xffff, (lun >> 16) & 0xffff);
out:
	udev_device_unref(fcdev);
	return parent;
}
Пример #10
0
static gboolean setup_isi_serial(struct modem_info* modem)
{
	struct serial_device_info* info;
	const char *value;

	info = modem->serial;

	if (g_strcmp0(udev_device_get_subsystem(info->dev), "net") != 0)
		return FALSE;

	value = udev_device_get_sysattr_value(info->dev, "type");
	if (g_strcmp0(value, "820") != 0)
		return FALSE;

	/* OK, we want this device to be a modem */
	value = udev_device_get_sysname(info->dev);
	if (value)
		ofono_modem_set_string(modem->modem, "Interface", value);

	value = udev_device_get_property_value(info->dev, "OFONO_ISI_ADDRESS");
	if (value)
		ofono_modem_set_integer(modem->modem, "Address", atoi(value));

	ofono_modem_set_string(modem->modem, "Device", info->devnode);

	return TRUE;
}
Пример #11
0
static int
udev_input_add_devices(struct udev_input *input, struct udev *udev)
{
	struct udev_enumerate *e;
	struct udev_list_entry *entry;
	struct udev_device *device;
	const char *path, *sysname;
	struct udev_seat *seat;
	int devices_found = 0;

	e = udev_enumerate_new(udev);
	udev_enumerate_add_match_subsystem(e, "input");
	udev_enumerate_scan_devices(e);
	udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) {
		path = udev_list_entry_get_name(entry);
		device = udev_device_new_from_syspath(udev, path);

		sysname = udev_device_get_sysname(device);
		if (strncmp("event", sysname, 5) != 0) {
			udev_device_unref(device);
			continue;
		}

		if (device_added(device, input) < 0) {
			udev_device_unref(device);
			udev_enumerate_unref(e);
			return -1;
		}

		udev_device_unref(device);
	}
Пример #12
0
void Storage::checkDevice(int fd) {
    PowerManagerLock* powerLock = PowerManager::getNewLock(this);
    powerLock->activate();
    qDebug() << Q_FUNC_INFO << "FD: "<< fd;

    struct udev_device *dev;
    dev = udev_monitor_receive_device(udev_monitor);
    if (dev)
    {
        QString device = udev_device_get_devnode(dev);
        QString path = udev_device_get_devpath(dev);
        QString action = udev_device_get_action(dev);
        QString devtype = udev_device_get_devtype(dev);
        QString sysname("/dev/");
        sysname += QString(udev_device_get_sysname(dev));
        QString parent = udev_device_get_devpath( udev_device_get_parent (dev));
        if (sysname.contains(QRegExp("mmcblk[0-9]\\d*"))  || sysname.contains(QRegExp("mmcblk[0-9]")))
        {
            qDebug() << "Got " << path << ":" << action;
            qDebug() << "    Got Device";
            qDebug() << "    Node: " <<  udev_device_get_devnode(dev);
            qDebug() << "    Subsystem: "<< udev_device_get_subsystem(dev);
            qDebug() << "    Devtype: " << devtype;
            qDebug() << "    Action: " << action;
            qDebug() << "    Sysname: " << sysname;
            qDebug() << "    sysnum: " << udev_device_get_sysnum (dev);
            qDebug() << "    parent: " << parent;

            processRemovableUdevEvents(devtype, path, sysname, action);
        }
        udev_device_unref(dev);
    }
    delete powerLock;
}
Пример #13
0
int read_usb_device(struct udev_device *sdev, struct usbip_usb_device *udev)
{
	uint32_t busnum, devnum;
	const char *path, *name;

	READ_ATTR(udev, uint8_t,  sdev, bDeviceClass,		"%02x\n");
	READ_ATTR(udev, uint8_t,  sdev, bDeviceSubClass,	"%02x\n");
	READ_ATTR(udev, uint8_t,  sdev, bDeviceProtocol,	"%02x\n");

	READ_ATTR(udev, uint16_t, sdev, idVendor,		"%04x\n");
	READ_ATTR(udev, uint16_t, sdev, idProduct,		"%04x\n");
	READ_ATTR(udev, uint16_t, sdev, bcdDevice,		"%04x\n");

	READ_ATTR(udev, uint8_t,  sdev, bConfigurationValue,	"%02x\n");
	READ_ATTR(udev, uint8_t,  sdev, bNumConfigurations,	"%02x\n");
	READ_ATTR(udev, uint8_t,  sdev, bNumInterfaces,		"%02x\n");

	READ_ATTR(udev, uint8_t,  sdev, devnum,			"%d\n");
	udev->speed = read_attr_speed(sdev);

	path = udev_device_get_syspath(sdev);
	name = udev_device_get_sysname(sdev);

	strncpy(udev->path,  path,  SYSFS_PATH_MAX);
	strncpy(udev->busid, name, SYSFS_BUS_ID_SIZE);

	sscanf(name, "%u-%u", &busnum, &devnum);
	udev->busnum = busnum;

	return 0;
}
Пример #14
0
static int
udev_handle_device(void *ctx)
{
	struct udev_device *device;
	const char *subsystem, *ifname, *action;

	device = udev_monitor_receive_device(monitor);
	if (device == NULL) {
		syslog(LOG_ERR, "libudev: received NULL device");
		return -1;
	}

	subsystem = udev_device_get_subsystem(device);
	ifname = udev_device_get_sysname(device);
	action = udev_device_get_action(device);

	/* udev filter documentation says "usually" so double check */
	if (strcmp(subsystem, "net") == 0) {
		syslog(LOG_DEBUG, "%s: libudev: %s", ifname, action);
		if (strcmp(action, "add") == 0 || strcmp(action, "move") == 0)
			dhcpcd.handle_interface(ctx, 1, ifname);
		else if (strcmp(action, "remove") == 0)
			dhcpcd.handle_interface(ctx, -1, ifname);
	}

	udev_device_unref(device);
	return 1;
}
Пример #15
0
QString Device::name() const
{
    if (!d)
        return QString();

    return QString::fromLatin1(udev_device_get_sysname(d->udev));
}
Пример #16
0
static int print_device_chain(struct udev_device *device)
{
        struct udev_device *device_parent;
        const char *str;

        printf("\n"
               "Udevadm info starts with the device specified by the devpath and then\n"
               "walks up the chain of parent devices. It prints for every device\n"
               "found, all possible attributes in the udev rules key format.\n"
               "A rule to match, can be composed by the attributes of the device\n"
               "and the attributes from one single parent device.\n"
               "\n");

        printf("  looking at device '%s':\n", udev_device_get_devpath(device));
        printf("    KERNEL==\"%s\"\n", udev_device_get_sysname(device));
        str = udev_device_get_subsystem(device);
        if (str == NULL)
                str = "";
        printf("    SUBSYSTEM==\"%s\"\n", str);
        str = udev_device_get_driver(device);
        if (str == NULL)
                str = "";
        printf("    DRIVER==\"%s\"\n", str);
        print_all_attributes(device, "ATTR");

        device_parent = device;
        do {
                device_parent = udev_device_get_parent(device_parent);
                if (device_parent == NULL)
                        break;
                printf("  looking at parent device '%s':\n", udev_device_get_devpath(device_parent));
                printf("    KERNELS==\"%s\"\n", udev_device_get_sysname(device_parent));
                str = udev_device_get_subsystem(device_parent);
                if (str == NULL)
                        str = "";
                printf("    SUBSYSTEMS==\"%s\"\n", str);
                str = udev_device_get_driver(device_parent);
                if (str == NULL)
                        str = "";
                printf("    DRIVERS==\"%s\"\n", str);
                print_all_attributes(device_parent, "ATTRS");
        } while (device_parent != NULL);

        return 0;
}
Пример #17
0
Файл: dce.c Проект: sylware/lwl
void dce_dpm_on(struct output *o)
{
  void *sysname=(void*)udev_device_get_sysname(o->d);

  ul req=IOR('d',SI_DCE_DP_DPM,o->blk_idx);
  l r=ioctl(o->fd,req,&o->blk_idx);
  if(ISERR(r)) PERR("output:%s:dce:unable to swich dpm to on\n",sysname);
  else LOG("output:%s:dce:dpm on successfully\n",sysname);
}
Пример #18
0
static virInterfacePtr
udevInterfaceLookupByMACString(virConnectPtr conn, const char *macstr)
{
    struct udev_iface_driver *driverState = conn->interfacePrivateData;
    struct udev *udev = udev_ref(driverState->udev);
    struct udev_enumerate *enumerate = NULL;
    struct udev_list_entry *dev_entry;
    struct udev_device *dev;
    const char *name;
    virInterfacePtr ret = NULL;

    enumerate = udevGetDevices(udev, VIR_UDEV_IFACE_ALL);

    if (!enumerate) {
        virReportError(VIR_ERR_INTERNAL_ERROR,
                       _("failed to lookup interface with MAC address '%s'"),
                       macstr);
        goto err;
    }

    /* Match on MAC */
    udev_enumerate_add_match_sysattr(enumerate, "address", macstr);

    /* Do the scan to load up the enumeration */
    udev_enumerate_scan_devices(enumerate);

    /* Get a list we can walk */
    dev_entry = udev_enumerate_get_list_entry(enumerate);

    /* Check that we got something back */
    if (!dev_entry) {
        virReportError(VIR_ERR_NO_INTERFACE,
                       _("couldn't find interface with MAC address '%s'"),
                       macstr);
        goto err;
    }

    /* Check that we didn't get multiple items back */
    if (udev_list_entry_get_next(dev_entry)) {
        virReportError(VIR_ERR_MULTIPLE_INTERFACES,
                       _("the MAC address '%s' matches multiple interfaces"),
                       macstr);
        goto err;
    }

    dev = udev_device_new_from_syspath(udev, udev_list_entry_get_name(dev_entry));
    name = udev_device_get_sysname(dev);
    ret = virGetInterface(conn, name, macstr);
    udev_device_unref(dev);

err:
    if (enumerate)
        udev_enumerate_unref(enumerate);
    udev_unref(udev);

    return ret;
}
Пример #19
0
  LinuxDevice::LinuxDevice(struct udev_device* dev)
  {
    log->debug("Creating a new LinuxDevice instance");
    const char *name = udev_device_get_sysattr_value(dev, "product");
    if (name) {
      log->debug("DeviceName={}", name);
      setDeviceName(name);
    }
    
    const char *id_vendor = udev_device_get_sysattr_value(dev, "idVendor");
    if (id_vendor) {
      log->debug("VendorID={}", id_vendor);
      setVendorID(id_vendor);
    }

    const char *id_product = udev_device_get_sysattr_value(dev, "idProduct");
    if (id_product) {
      log->debug("ProductID={}", id_product);
      setProductID(id_product);
    }

    const char *serial = udev_device_get_sysattr_value(dev, "serial");
    if (serial) {
      log->debug("Serial={}", serial);
      setSerialNumber(serial);
    }

    const char *syspath = udev_device_get_syspath(dev);
    if (syspath) {
      log->debug("Syspath={}", syspath);
      _syspath = syspath;
    } else {
      throw std::runtime_error("device wihtout syspath");
    }

    const char *sysname = udev_device_get_sysname(dev);
    if (sysname) {
      log->debug("Sysname={}", sysname);
      setDevicePort(sysname);
    } else {
      throw std::runtime_error("device wihtout sysname");
    }

    log->debug("DeviceHash={}", getDeviceHash());

    setTarget(Rule::Target::Unknown);

    std::ifstream descriptor_stream(_syspath + "/descriptors", std::ifstream::binary);
    if (!descriptor_stream.good()) {
      throw std::runtime_error("cannot load USB descriptors");
    }
    else {
      readDescriptors(descriptor_stream);
    }

    return;
  }
PupDrive *pup_cd_drive_new_from_udev_device(PupVMMonitor *monitor,
                                            struct udev_device *device)
{
	PupDrive *drv = PUP_DRIVE(pup_device_new(PUP_TYPE_CD_DRIVE,
	                                         udev_device_get_sysname(device)));
	                                                
	PUP_DEVICE(drv)->icon_name = g_strdup(PUP_ICON_OPTICAL_DRIVE);
	drv->unix_dev = pup_guess_devnode(device);
	if (! drv->unix_dev)
	{
		g_critical("Device node not found for %s", udev_device_get_sysname(device));
		g_object_unref(drv);
		return NULL;
	}
	
	//Find model and vendor strings
	gchar *tmpstr = g_strdup(udev_device_get_sysattr_value(device, "device/model"));
	PUP_DRIVE(drv)->model = g_strdup(g_strstrip(tmpstr));
	g_free(tmpstr);
	tmpstr = g_strdup(udev_device_get_sysattr_value(device, "device/vendor"));
	PUP_DRIVE(drv)->vendor = g_strdup(g_strstrip(tmpstr));
	g_free(tmpstr);                            

	PUP_DEVICE(drv)->display_name = pup_drive_gen_display_name(PUP_DRIVE(drv));

	//We will check for the disk later...
	pup_vm_monitor_lock(monitor);
	PupDrive *old_drv = pup_vm_monitor_lookup_drive_unlocked
		(monitor, udev_device_get_sysname(device), FALSE);
	if (old_drv)
		PUP_CD_DRIVE(drv)->status = PUP_CD_DRIVE(old_drv)->status;
	else
		PUP_CD_DRIVE(drv)->status = PUP_CD_DRIVE_NOT_READY;
	pup_vm_monitor_unlock(monitor);
	
	g_signal_connect_object(monitor, "mounts-check",
	                        G_CALLBACK(pup_cd_drive_probe_disk_cb), drv, 0);

	pup_overwrite_dev(monitor, PUP_DEVICE(drv));
	g_debug("%s added", udev_device_get_sysname(device));

	return drv;
}
Пример #21
0
static void handle_scsi_tape(struct udev_device *dev, char **suffix)
{
	const char *name;

	name = udev_device_get_sysname(dev);
	if (strncmp(name, "nst", 3) == 0 && strchr("lma", name[3]) != NULL)
		asprintf(suffix, "nst%c", name[3]);
	else if (strncmp(name, "st", 2) == 0 && strchr("lma", name[2]) != NULL)
		asprintf(suffix, "st%c", name[2]);
}
Пример #22
0
Файл: dce.c Проект: sylware/lwl
void dce_double_frame_buffer_free(struct output *o)
{
  void *sysname=(void*)udev_device_get_sysname(o->d);

  ul req=IOR('d',SI_MEM_FREE,o->fb.gpu_addr);
  l r=ioctl(o->fd,req,&o->fb.gpu_addr);
  if(ISERR(r))
    PERR("output:%s:dce:unable to free frame buffer memory (LEAK!)\n",sysname);
  else LOG("output:%s:dce:double frame buffer freed successfully\n",sysname);
}
Пример #23
0
static int names_usb(struct udev_device *dev, struct netnames *names) {
        struct udev_device *usbdev;
        char name[256];
        char *ports;
        char *config;
        char *interf;
        size_t l;
        char *s;

        assert(dev);
        assert(names);

        usbdev = udev_device_get_parent_with_subsystem_devtype(dev, "usb", "usb_interface");
        if (!usbdev)
                return -ENOENT;

        /* get USB port number chain, configuration, interface */
        strscpy(name, sizeof(name), udev_device_get_sysname(usbdev));
        s = strchr(name, '-');
        if (!s)
                return -EINVAL;
        ports = s+1;

        s = strchr(ports, ':');
        if (!s)
                return -EINVAL;
        s[0] = '\0';
        config = s+1;

        s = strchr(config, '.');
        if (!s)
                return -EINVAL;
        s[0] = '\0';
        interf = s+1;

        /* prefix every port number in the chain with "u" */
        s = ports;
        while ((s = strchr(s, '.')))
                s[0] = 'u';
        s = names->usb_ports;
        l = strpcpyl(&s, sizeof(names->usb_ports), "u", ports, NULL);

        /* append USB config number, suppress the common config == 1 */
        if (!streq(config, "1"))
                l = strpcpyl(&s, sizeof(names->usb_ports), "c", config, NULL);

        /* append USB interface number, suppress the interface == 0 */
        if (!streq(interf, "0"))
                l = strpcpyl(&s, sizeof(names->usb_ports), "i", interf, NULL);
        if (l == 0)
                return -ENAMETOOLONG;

        names->type = NET_USB;
        return 0;
}
Пример #24
0
static
int read_usb_vudc_device(struct udev_device *sdev, struct usbip_usb_device *dev)
{
	const char *path, *name;
	char filepath[SYSFS_PATH_MAX];
	struct usb_device_descriptor descr;
	unsigned i;
	FILE *fd = NULL;
	struct udev_device *plat;
	const char *speed;
	int ret = 0;

	plat = udev_device_get_parent(sdev);
	path = udev_device_get_syspath(plat);
	snprintf(filepath, SYSFS_PATH_MAX, "%s/%s",
		 path, VUDC_DEVICE_DESCR_FILE);
	fd = fopen(filepath, "r");
	if (!fd)
		return -1;
	ret = fread((char *) &descr, sizeof(descr), 1, fd);
	if (ret < 0)
		return -1;
	fclose(fd);

	copy_descr_attr(dev, &descr, bDeviceClass);
	copy_descr_attr(dev, &descr, bDeviceSubClass);
	copy_descr_attr(dev, &descr, bDeviceProtocol);
	copy_descr_attr(dev, &descr, bNumConfigurations);
	copy_descr_attr16(dev, &descr, idVendor);
	copy_descr_attr16(dev, &descr, idProduct);
	copy_descr_attr16(dev, &descr, bcdDevice);

	strncpy(dev->path, path, SYSFS_PATH_MAX);

	dev->speed = USB_SPEED_UNKNOWN;
	speed = udev_device_get_sysattr_value(sdev, "current_speed");
	if (speed) {
		for (i = 0; i < ARRAY_SIZE(speed_names); i++) {
			if (!strcmp(speed_names[i].name, speed)) {
				dev->speed = speed_names[i].speed;
				break;
			}
		}
	}

	/* Only used for user output, little sense to output them in general */
	dev->bNumInterfaces = 0;
	dev->bConfigurationValue = 0;
	dev->busnum = 0;

	name = udev_device_get_sysname(plat);
	strncpy(dev->busid, name, SYSFS_BUS_ID_SIZE);
	return 0;
}
Пример #25
0
QObject *QKmsUdevDRMHandler::create(struct udev_device *device)
{
    if (strcmp(udev_device_get_subsystem(device), "drm"))
        return 0;

    QRegExp regexp("^card\\d+$");
    if (!regexp.exactMatch(udev_device_get_sysname(device)))
        return 0;

    return m_integration->createDevice(udev_device_get_devnode(device));
}
Пример #26
0
Файл: dce.c Проект: sylware/lwl
s8 dce_mode_program(s32 output_name)
{
  struct output *o=&registry[output_name].output;
  void *sysname=(void*)udev_device_get_sysname(o->d);

  //----------------------------------------------------------------------------
  //alloc a properly sized double buffered frame buffer
  o->fb.align=PAGE_SZ;//align on a cpu memory page
  u64 sz=2*(o->current->h*o->current->v*alga_pixel_fmts_sz[o->pixel_fmt]);
  o->fb.sz=sz;
  ul req=IOWR('d',SI_MEM_ALLOC,o->fb);
  l r=ioctl(o->fd,req,(l)&o->fb);
  if(ISERR(r)){
    PERR("output:%s:dce:unable to allocate proper vram for a frame buffer of"
                                         " size %llu bytes\n",sysname,o->fb.sz);
    goto err;
  }

  LOG("output:%s:dce:double buffered frame buffer of %llu bytes allocated\n",
                                                                    sysname,sz);
  //----------------------------------------------------------------------------

  //----------------------------------------------------------------------------
  //program synchronously the video mode
  struct si_dce_dp_set dp_set;
  dp_set.idx=o->blk_idx;
  dp_set.primary=o->fb.gpu_addr;
  dp_set.secondary=o->fb.gpu_addr+sz/2;
  dp_set.pixel_fmt=o->pixel_fmt;
  dp_set.timing=*(o->current);
  dp_set.pitch=o->current->h;
  req=IOW('d',SI_DCE_DP_SET,dp_set);
  r=ioctl(o->fd,req,(l)&dp_set);
  if(ISERR(r)){
    PERR("output:%s:dce:%ux%u@%u: unable to program\n",sysname,o->current->h,
                                         o->current->v,v_refresh(o->current));
    goto err_free_fb;
  }
  //----------------------------------------------------------------------------

  LOG("output:%s:dce:%ux%u@%u:programmed successfully\n",sysname,o->current->h,
                                         o->current->v,v_refresh(o->current));
  return LWL_OK;

err_free_fb:
  req=IOW('d',SI_MEM_FREE,o->fb.gpu_addr);
  r=ioctl(o->fd,req,&o->fb.gpu_addr);
  if(ISERR(r))
    PERR("output:%s:dce:unable to free frame buffer memory (LEAK!)\n",sysname);
err:
  return LWL_ERR; 
}
Пример #27
0
static void
do_list_local ()
{
  struct udev *udev;
  struct udev_enumerate *enumerate;
  struct udev_list_entry *devices, *dev_list_entry;
  struct udev_device *dev;
  const gchar *path;
  const gchar *idVendor;
  const gchar *idProduct;
  const gchar *bConfValue;
  const gchar *bNumIntfs;
  const gchar *busid;

  /* Create libudev context. */
  udev = udev_new ();

  /* Create libudev device enumeration. */
  enumerate = udev_enumerate_new (udev);

  /* Take only USB devices that are not hubs and do not have
    * the bInterfaceNumber attribute, i.e. are not interfaces.
    */
  udev_enumerate_add_match_subsystem (enumerate, "usb");
  udev_enumerate_add_nomatch_sysattr (enumerate, "bDeviceClass", "09");
  udev_enumerate_add_nomatch_sysattr (enumerate, "bInterfaceNumber", NULL);
  udev_enumerate_scan_devices (enumerate);

  devices = udev_enumerate_get_list_entry (enumerate);

  /* Show information about each device. */
  udev_list_entry_foreach (dev_list_entry, devices) {
    path = udev_list_entry_get_name (dev_list_entry);
    dev = udev_device_new_from_syspath (udev, path);

    /* Get device information. */
    idVendor = udev_device_get_sysattr_value (dev, "idVendor");
    idProduct = udev_device_get_sysattr_value (dev, "idProduct");
    bConfValue = udev_device_get_sysattr_value (dev, "bConfigurationValue");
    bNumIntfs = udev_device_get_sysattr_value (dev, "bNumInterfaces");
    busid = udev_device_get_sysname (dev);
    if (!idVendor || !idProduct || !bConfValue || !bNumIntfs) {
      g_printerr ("problem getting device attributes: %s\n",
                  g_strerror (errno));
      break;
    }

    g_print (" - busid %s (%.4s:%.4s)\n\n", busid, idVendor, idProduct);

    udev_device_unref (dev);
  }
Пример #28
0
static void print_device(struct udev_device *device)
{
    const char *str;
    dev_t devnum;
    int count;
    struct udev_list_entry *list_entry;

    printf("*** device: %p ***\n", device);
    str = udev_device_get_action(device);
    if (str != NULL)
        printf("action:    '%s'\n", str);

    str = udev_device_get_syspath(device);
    printf("syspath:   '%s'\n", str);

    str = udev_device_get_sysname(device);
    printf("sysname:   '%s'\n", str);

    str = udev_device_get_sysnum(device);
    if (str != NULL)
        printf("sysnum:    '%s'\n", str);

    str = udev_device_get_devpath(device);
    printf("devpath:   '%s'\n", str);

    str = udev_device_get_subsystem(device);
    if (str != NULL)
        printf("subsystem: '%s'\n", str);

    str = udev_device_get_devtype(device);
    if (str != NULL)
        printf("devtype:   '%s'\n", str);

    str = udev_device_get_driver(device);
    if (str != NULL)
        printf("driver:    '%s'\n", str);

    str = udev_device_get_devnode(device);
    if (str != NULL)
        printf("devname:   '%s'\n", str);

    devnum = udev_device_get_devnum(device);
    if (major(devnum) > 0)
        printf("devnum:    %u:%u\n", major(devnum), minor(devnum));

    count = 0;
    udev_list_entry_foreach(list_entry, udev_device_get_devlinks_list_entry(device)) {
        printf("link:      '%s'\n", udev_list_entry_get_name(list_entry));
        count++;
    }
Пример #29
0
int main ()
{
	udev = udev_new();
	if(!udev) {
		fprintf(stderr, "Can't create udev.\n");
		exit(EXIT_FAILURE);
	}

	mon = udev_monitor_new_from_netlink(udev, "udev");
	udev_monitor_filter_add_match_subsystem_devtype(mon, "block", NULL);
	udev_monitor_enable_receiving(mon);

	while(1)
	{
		if (mon != NULL)
			FD_SET(udev_monitor_get_fd(mon), &readfds);
		select(udev_monitor_get_fd(mon) + 1, &readfds, NULL, NULL, NULL);

		if ((mon != NULL) && FD_ISSET(udev_monitor_get_fd(mon), &readfds)) 
		{
			dev = udev_monitor_receive_device(mon);
			if(dev) {
				device = (char *) udev_device_get_sysname(dev);
			}
		}

		devnum = udev_device_get_devnum(dev);
		major = major(devnum);
		minor = minor(devnum);
		action = udev_device_get_action(dev);
		printf("Processing device %s %d:%d\n", action, major, minor);

		struct udev_list_entry * props = udev_device_get_properties_list_entry(dev);
		while(props != NULL)
		{
			printf("%s = %s\n", udev_list_entry_get_name(props), udev_list_entry_get_value(props));
			props = udev_list_entry_get_next (props);
		}

		props = udev_device_get_sysattr_list_entry(dev);
		while(props != NULL)
		{
			printf("%s = %s\n", udev_list_entry_get_name(props), udev_device_get_sysattr_value(dev, udev_list_entry_get_name(props)));
			props = udev_list_entry_get_next (props);
		}
	}

  	return 0;
}
Пример #30
0
int Storage::enumerate_mmcblk_devices(struct udev *udev)
{
    struct udev_enumerate *udev_enumerate;

    qDebug() << Q_FUNC_INFO << ": enumerate 'block' devices";
    udev_enumerate = udev_enumerate_new(udev);
    if (udev_enumerate == NULL)
        return -1;
    udev_enumerate_add_match_subsystem(udev_enumerate,"block");
    udev_enumerate_scan_devices(udev_enumerate);
    struct udev_list_entry *list_entry;

    udev_list_entry_foreach(list_entry, udev_enumerate_get_list_entry(udev_enumerate))
    {
        struct udev_device *device;

        device = udev_device_new_from_syspath(udev_enumerate_get_udev(udev_enumerate),
                                      udev_list_entry_get_name(list_entry));
        if (device != NULL) {
            QString sysname("/dev/");
            sysname += QString(udev_device_get_sysname(device));
            if (sysname.contains(QRegExp("mmcblk[1-9]\\d*"))  || sysname.contains(QRegExp("mmcblk[1-9]")))
            {
                QString path = udev_device_get_devpath(device);
                QString parent = udev_device_get_devpath( udev_device_get_parent (device));
                QString action = "add";
                QString devtype = udev_device_get_devtype(device);

                qDebug() << "Enumerate device " << path << ":" << action;
                qDebug() << "    Got Device";
                qDebug() << "    Node: " <<  udev_device_get_devnode(device);
                qDebug() << "    Subsystem: "<< udev_device_get_subsystem(device);
                qDebug() << "    Devtype: " << devtype;
                qDebug() << "    Action: " << action;
                qDebug() << "    Sysname: " << sysname;
                qDebug() << "    sysnum: " << udev_device_get_sysnum (device);
                qDebug() << "    parent: " << parent;

                processRemovableUdevEvents(devtype, path, sysname, action);
            }

            udev_device_unref(device);
        }
    }

    udev_enumerate_unref(udev_enumerate);
    return 0;
}