Exemplo n.º 1
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;
}
Exemplo n.º 2
0
void udev_watch_begin(struct udev *udev, struct udev_device *dev) {
        char filename[UTIL_PATH_SIZE];
        int wd;
        int r;

        if (inotify_fd < 0)
                return;

        log_debug("adding watch on '%s'", udev_device_get_devnode(dev));
        wd = inotify_add_watch(inotify_fd, udev_device_get_devnode(dev), IN_CLOSE_WRITE);
        if (wd < 0) {
                log_error_errno(errno, "inotify_add_watch(%d, %s, %o) failed: %m",
                                inotify_fd, udev_device_get_devnode(dev), IN_CLOSE_WRITE);
                return;
        }

        snprintf(filename, sizeof(filename), "/run/udev/watch/%d", wd);
        mkdir_parents(filename, 0755);
        unlink(filename);
        r = symlink(udev_device_get_id_filename(dev), filename);
        if (r < 0)
                log_error_errno(errno, "Failed to create symlink %s: %m", filename);

        udev_device_set_watch_handle(dev, wd);
}
Exemplo n.º 3
0
static char *find_device_file (int capability)
{
	struct udev *udev;
	struct udev_enumerate *enumerate;
	struct udev_list_entry *devices, *dev_list_entry;
	struct udev_device *dev;
	const char *path;
	char *device = NULL;

	udev = udev_new();
	if (!udev) return NULL;

	enumerate = udev_enumerate_new(udev);
	udev_enumerate_add_match_property(enumerate, "MBM_CAPABILITY",
									  gps_capabilities[capability]);
	udev_enumerate_scan_devices(enumerate);

	devices = udev_enumerate_get_list_entry(enumerate);
	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);
		if (!udev_device_get_devnode(dev))
			continue;
		device = strdup(udev_device_get_devnode(dev));
		udev_device_unref (dev);
		if (mbm_options_debug ()) {
			g_debug ("found device %s for capability %s",
					 device, gps_capabilities[capability]);
		}
		/*
		 * the code returns the first matching device found
		 */
		break;
	}
Exemplo n.º 4
0
    void DeviceManager::processHotplugEvents()
    {
        udev_device * device;

        device = udev_monitor_receive_device(hotplugMonitor);

        if (device)
        {
            if (string(udev_device_get_action(device)) == "remove")
            {
                map <string, Device *>::iterator it;

                for (it = devices.begin(); it != devices.end(); it++)
                {
                    if (it->second->getNode() == udev_device_get_devnode(device))
                    {
                        Device * dev = it->second;

                        remove(dev);

                        delete dev;

                        break;
                    }
                }
            }
            else
            {
                add(new DeviceHard(udev_device_get_devnode(device)));
            }

            udev_device_unref(device);
        }
    }
Exemplo n.º 5
0
void udev_watch_begin(struct udev *udev, struct udev_device *dev)
{
    char filename[UTIL_PATH_SIZE];
    char majmin[UTIL_PATH_SIZE];
    int wd;

    if (inotify_fd < 0)
        return;

    info(udev, "adding watch on '%s'\n", udev_device_get_devnode(dev));
    wd = inotify_add_watch(inotify_fd, udev_device_get_devnode(dev), IN_CLOSE_WRITE);
    if (wd < 0) {
        err(udev, "inotify_add_watch(%d, %s, %o) failed: %m\n",
            inotify_fd, udev_device_get_devnode(dev), IN_CLOSE_WRITE);
        return;
    }

    snprintf(majmin, sizeof(majmin), "%c%i:%i",
             strcmp(udev_device_get_subsystem(dev), "block") == 0 ? 'b' : 'c',
             major(udev_device_get_devnum(dev)), minor(udev_device_get_devnum(dev)));
    snprintf(filename, sizeof(filename), "%s/.udev/watch/%d", udev_get_dev_path(udev), wd);
    util_create_path(udev, filename);
    unlink(filename);
    symlink(majmin, filename);

    udev_device_set_watch_handle(dev, wd);
}
Exemplo n.º 6
0
void udev_node_add(struct udev_device *dev, mode_t mode, uid_t uid, gid_t gid)
{
        struct udev *udev = udev_device_get_udev(dev);
        char filename[UTIL_PATH_SIZE];
        struct udev_list_entry *list_entry;
        int err = 0;

        info(udev, "handling device node '%s', devnum=%s, mode=%#o, uid=%d, gid=%d\n",
             udev_device_get_devnode(dev), udev_device_get_id_filename(dev), mode, uid, gid);

        if (node_fixup(dev, mode, uid, gid) < 0)
                return;

        /* always add /dev/{block,char}/$major:$minor */
        snprintf(filename, sizeof(filename), "%s/%s/%u:%u",
                 udev_get_dev_path(udev),
                 strcmp(udev_device_get_subsystem(dev), "block") == 0 ? "block" : "char",
                 major(udev_device_get_devnum(dev)), minor(udev_device_get_devnum(dev)));
        node_symlink(udev, udev_device_get_devnode(dev), filename);

        /* create/update symlinks, add symlinks to name index */
        udev_list_entry_foreach(list_entry, udev_device_get_devlinks_list_entry(dev)) {
                if (udev_list_entry_get_num(list_entry))
                        /* simple unmanaged link name */
                        node_symlink(udev, udev_device_get_devnode(dev), udev_list_entry_get_name(list_entry));
                else
                        link_update(dev, udev_list_entry_get_name(list_entry), 1);
        }
}
Exemplo n.º 7
0
/* find device node of device with highest priority */
static const char *link_find_prioritized(struct udev_device *dev, bool add, const char *stackdir, char *buf, size_t bufsize)
{
        struct udev *udev = udev_device_get_udev(dev);
        DIR *dir;
        int priority = 0;
        const char *target = NULL;

        if (add) {
                priority = udev_device_get_devlink_priority(dev);
                util_strscpy(buf, bufsize, udev_device_get_devnode(dev));
                target = buf;
        }

        dir = opendir(stackdir);
        if (dir == NULL)
                return target;
        for (;;) {
                struct udev_device *dev_db;
                struct dirent *dent;

                dent = readdir(dir);
                if (dent == NULL || dent->d_name[0] == '\0')
                        break;
                if (dent->d_name[0] == '.')
                        continue;

                info(udev, "found '%s' claiming '%s'\n", dent->d_name, stackdir);

                /* did we find ourself? */
                if (strcmp(dent->d_name, udev_device_get_id_filename(dev)) == 0)
                        continue;

                dev_db = udev_device_new_from_device_id(udev, dent->d_name);
                if (dev_db != NULL) {
                        const char *devnode;

                        devnode = udev_device_get_devnode(dev_db);
                        if (devnode != NULL) {
                                dbg(udev, "compare priority of '%s'(%i) > '%s'(%i)\n", target, priority,
                                    udev_device_get_devnode(dev_db), udev_device_get_devlink_priority(dev_db));
                                if (target == NULL || udev_device_get_devlink_priority(dev_db) > priority) {
                                        info(udev, "'%s' claims priority %i for '%s'\n",
                                             udev_device_get_syspath(dev_db), udev_device_get_devlink_priority(dev_db), stackdir);
                                        priority = udev_device_get_devlink_priority(dev_db);
                                        util_strscpy(buf, bufsize, devnode);
                                        target = buf;
                                }
                        }
                        udev_device_unref(dev_db);
                }
        }
        closedir(dir);
        return target;
}
void joystick_linux::monitor_joysticks(udev *p_udev) {

	udev_device *dev = NULL;
	udev_monitor *mon = udev_monitor_new_from_netlink(p_udev, "udev");
	udev_monitor_filter_add_match_subsystem_devtype(mon, "input", NULL);
	udev_monitor_enable_receiving(mon);
	int fd = udev_monitor_get_fd(mon);

	while (!exit_udev) {

		fd_set fds;
		struct timeval tv;
		int ret;

		FD_ZERO(&fds);
		FD_SET(fd, &fds);
		tv.tv_sec = 0;
		tv.tv_usec = 0;

		ret = select(fd+1, &fds, NULL, NULL, &tv);

		/* Check if our file descriptor has received data. */
		if (ret > 0 && FD_ISSET(fd, &fds)) {
			/* Make the call to receive the device.
			   select() ensured that this will not block. */
			dev = udev_monitor_receive_device(mon);

			if (dev && udev_device_get_devnode(dev) != 0) {

				joy_mutex->lock();
				String action = udev_device_get_action(dev);
				const char* devnode = udev_device_get_devnode(dev);
				if (devnode) {

					String devnode_str = devnode;
					if (devnode_str.find(ignore_str) == -1) {

						if (action == "add")
							open_joystick(devnode);
						else if (String(action) == "remove")
							close_joystick(get_joy_from_path(devnode));
					}
				}

				udev_device_unref(dev);
				joy_mutex->unlock();
			}
		}
		usleep(50000);
	}
	//printf("exit udev\n");
	udev_monitor_unref(mon);
}
Exemplo n.º 9
0
/* find device node of device with highest priority */
static const char *link_find_prioritized(struct udev_device *dev, bool add, const char *stackdir, char *buf, size_t bufsize) {
        struct udev *udev = udev_device_get_udev(dev);
        DIR *dir;
        struct dirent *dent;
        int priority = 0;
        const char *target = NULL;

        if (add) {
                priority = udev_device_get_devlink_priority(dev);
                strscpy(buf, bufsize, udev_device_get_devnode(dev));
                target = buf;
        }

        dir = opendir(stackdir);
        if (dir == NULL)
                return target;
        FOREACH_DIRENT_ALL(dent, dir, break) {
                struct udev_device *dev_db;

                if (dent->d_name[0] == '\0')
                        break;
                if (dent->d_name[0] == '.')
                        continue;

                log_debug("found '%s' claiming '%s'", dent->d_name, stackdir);

                /* did we find ourself? */
                if (streq(dent->d_name, udev_device_get_id_filename(dev)))
                        continue;

                dev_db = udev_device_new_from_device_id(udev, dent->d_name);
                if (dev_db != NULL) {
                        const char *devnode;

                        devnode = udev_device_get_devnode(dev_db);
                        if (devnode != NULL) {
                                if (target == NULL || udev_device_get_devlink_priority(dev_db) > priority) {
                                        log_debug("'%s' claims priority %i for '%s'",
                                                  udev_device_get_syspath(dev_db), udev_device_get_devlink_priority(dev_db), stackdir);
                                        priority = udev_device_get_devlink_priority(dev_db);
                                        strscpy(buf, bufsize, devnode);
                                        target = buf;
                                }
                        }
                        udev_device_unref(dev_db);
                }
        }
        closedir(dir);
        return target;
}
Exemplo n.º 10
0
static int node_fixup(struct udev_device *dev, mode_t mode, uid_t uid, gid_t gid)
{
        struct udev *udev = udev_device_get_udev(dev);
        const char *devnode = udev_device_get_devnode(dev);
        dev_t devnum = udev_device_get_devnum(dev);
        struct stat stats;
        int err = 0;

        if (strcmp(udev_device_get_subsystem(dev), "block") == 0)
                mode |= S_IFBLK;
        else
                mode |= S_IFCHR;

        if (lstat(devnode, &stats) != 0) {
                err = -errno;
                info(udev, "can not stat() node '%s' (%m)\n", devnode);
                goto out;
        }

        if (((stats.st_mode & S_IFMT) != (mode & S_IFMT)) || (stats.st_rdev != devnum)) {
                err = -EEXIST;
                info(udev, "found node '%s' with non-matching devnum %s, skip handling\n",
                     udev_device_get_devnode(dev), udev_device_get_id_filename(dev));
                goto out;
        }

        if ((stats.st_mode & 0777) != (mode & 0777) || stats.st_uid != uid || stats.st_gid != gid) {
                info(udev, "set permissions %s, %#o, uid=%u, gid=%u\n", devnode, mode, uid, gid);
                chmod(devnode, mode);
                chown(devnode, uid, gid);
        } else {
                info(udev, "preserve permissions %s, %#o, uid=%u, gid=%u\n", devnode, mode, uid, gid);
        }

        /*
         * Set initial selinux file context only on add events.
         * We set the proper context on bootup (triger) or for newly
         * added devices, but we don't change it later, in case
         * something else has set a custom context in the meantime.
         */
        if (strcmp(udev_device_get_action(dev), "add") == 0)
                udev_selinux_lsetfilecon(udev, devnode, mode);

        /* always update timestamp when we re-use the node, like on media change events */
        utimensat(AT_FDCWD, devnode, NULL, 0);
out:
        return err;
}
Exemplo n.º 11
0
QString Device::primaryDeviceFile() const
{
    if (!d)
        return QString();

    return QString::fromLatin1(udev_device_get_devnode(d->udev));
}
Exemplo n.º 12
0
    void GamePadManager::deviceEventProc(
        struct udev_device &    _device
    )
    {
        const auto  PATH = udev_device_get_devnode( &_device );

        if( PATH == nullptr ) {
            return;
        }

        if( isGamePadPath( PATH ) == false ) {
            return;
        }

        const auto  ACTION = udev_device_get_action( &_device );
        auto        removed = ACTION != nullptr && std::strcmp(
            ACTION
            , "remove"
        ) == 0;

        if( removed ) {
            this->removeGamePad( PATH );
        } else {
            this->addGamePad( PATH );
        }
    }
Exemplo n.º 13
0
static int media_get_devname_udev(struct udev *udev,
		struct media_entity *entity)
{
	struct udev_device *device;
	dev_t devnum;
	const char *p;
	int ret = -ENODEV;

	if (udev == NULL)
		return -EINVAL;

	devnum = makedev(entity->info.v4l.major, entity->info.v4l.minor);
	media_dbg(entity->media, "looking up device: %u:%u\n",
		  major(devnum), minor(devnum));
	device = udev_device_new_from_devnum(udev, 'c', devnum);
	if (device) {
		p = udev_device_get_devnode(device);
		if (p) {
			strncpy(entity->devname, p, sizeof(entity->devname));
			entity->devname[sizeof(entity->devname) - 1] = '\0';
		}
		ret = 0;
	}

	udev_device_unref(device);

	return ret;
}
Exemplo n.º 14
0
/* add or remove a ACL for a given uid from all matching devices */
static void apply_acl_to_devices(uid_t uid, int add)
{
	struct udev *udev;
	struct udev_enumerate *enumerate;
	struct udev_list_entry *list_entry;

	/* iterate over all devices tagged with ACL_SET */
	udev = udev_new();
	enumerate = udev_enumerate_new(udev);
	udev_enumerate_add_match_tag(enumerate, "udev-acl");
	udev_enumerate_scan_devices(enumerate);
	udev_list_entry_foreach(list_entry, udev_enumerate_get_list_entry(enumerate)) {
		struct udev_device *device;
		const char *node;

		device = udev_device_new_from_syspath(udev_enumerate_get_udev(enumerate),
						      udev_list_entry_get_name(list_entry));
		if (device == NULL)
			continue;
		node = udev_device_get_devnode(device);
		if (node == NULL) {
			udev_device_unref(device);
			continue;
		}
		set_facl(node, uid, add);
		udev_device_unref(device);
	}
	udev_enumerate_unref(enumerate);
	udev_unref(udev);
}
Exemplo n.º 15
0
bool Renderer::connectEmotiv()
{
   /* Opens Emotiv if Emotiv is only HID Device attached */
  struct udev_device *dev;
  struct udev *udev;
  struct udev_list_entry *devices, *dev_list_entry;
  struct udev_enumerate *enumerate;
  udev = udev_new();
  enumerate = udev_enumerate_new(udev);
  udev_enumerate_add_match_subsystem(enumerate, "hidraw");
  udev_enumerate_scan_devices(enumerate);
  devices = udev_enumerate_get_list_entry(enumerate);
  udev_list_entry_foreach(dev_list_entry, devices) 
    {
      const char * path = udev_list_entry_get_name(dev_list_entry);
      dev = udev_device_new_from_syspath(udev,path);
    }
  emotiv_fd = open(udev_device_get_devnode(dev), O_RDONLY);
  if (emotiv_fd > 0) 
    {
      int res = read(emotiv_fd, emotivBuffer, 32);
      if(res < 0) {perror("read"); return false;}
      return true;
    }
  else 
    {
      perror("Unable to open device");
      return false;
    }
}
Exemplo n.º 16
0
char *
loader_get_device_name_for_fd(int fd)
{
   char *device_name = NULL;
#ifdef HAVE_LIBUDEV
   struct udev *udev;
   struct udev_device *device;
   const char *const_device_name;
   UDEV_SYMBOL(struct udev *, udev_new, (void));
   UDEV_SYMBOL(const char *, udev_device_get_devnode,
               (struct udev_device *));
   UDEV_SYMBOL(struct udev_device *, udev_device_unref,
               (struct udev_device *));
   UDEV_SYMBOL(struct udev *, udev_unref, (struct udev *));

   udev = udev_new();
   device = udev_device_new_from_fd(udev, fd);
   if (device == NULL)
      return NULL;

   const_device_name = udev_device_get_devnode(device);
   if (!const_device_name)
      goto out;
   device_name = strdup(const_device_name);

out:
   udev_device_unref(device);
   udev_unref(udev);
#endif
   return device_name;
}
Exemplo n.º 17
0
GamepadController::GamepadController()
    : m_gamepadDevices(Nix::Gamepads::itemsLengthCap)
{
    m_udev = udev_new();
    m_gamepadsMonitor = udev_monitor_new_from_netlink(m_udev, "udev");

    udev_monitor_enable_receiving(m_gamepadsMonitor);
    udev_monitor_filter_add_match_subsystem_devtype(m_gamepadsMonitor, "input", 0);

    GIOChannel *channel = g_io_channel_unix_new(udev_monitor_get_fd(m_gamepadsMonitor));
    g_io_add_watch(channel, GIOCondition(G_IO_IN), static_cast<GIOFunc>(&GamepadController::onGamepadChange), this);
    g_io_channel_unref(channel);

    struct udev_enumerate* enumerate = udev_enumerate_new(m_udev);
    udev_enumerate_add_match_subsystem(enumerate, "input");
    udev_enumerate_add_match_property(enumerate, "ID_INPUT_JOYSTICK", "1");
    udev_enumerate_scan_devices(enumerate);
    struct udev_list_entry* cur;
    struct udev_list_entry* devs = udev_enumerate_get_list_entry(enumerate);
    udev_list_entry_foreach(cur, devs)
    {
        const char* devname = udev_list_entry_get_name(cur);
        struct udev_device* device = udev_device_new_from_syspath(m_udev, devname);
        if (isGamepadDevice(device))
            registerDevice(udev_device_get_devnode(device));
        udev_device_unref(device);
    }
    udev_enumerate_unref(enumerate);
}
Exemplo n.º 18
0
int scan_connected_devices(detector_state_t *state) {
	struct udev_list_entry *cursor;
	struct udev_enumerate *ue;
	struct udev_device *ud;

	const char *devnode = NULL;

	if( !(ue = udev_enumerate_new(state->u)) )
		return 1;

	udev_enumerate_add_match_subsystem(ue, "tty");
	udev_enumerate_add_match_property(ue, "ID_BUS", "usb");
	udev_enumerate_scan_devices(ue);
	cursor = udev_enumerate_get_list_entry(ue);

	do {
		ud = udev_device_new_from_syspath(
			state->u, udev_list_entry_get_name(cursor));

		if( (devnode = udev_device_get_devnode(ud)) )
			spawn_server(state->exec_path, devnode);

		udev_device_unref(ud);
	} while( (cursor = udev_list_entry_get_next(cursor)) );

	udev_enumerate_unref(ue);
	return 0;
}
Exemplo n.º 19
0
static void set_trackpoint_sensitivity(struct udev_device *dev, const char *value)
{
        struct udev_device *pdev;
        char val_s[DECIMAL_STR_MAX(int)];
        int r, val_i;

        assert(dev);
        assert(value);

        /* The sensitivity sysfs attr belongs to the serio parent device */
        pdev = udev_device_get_parent_with_subsystem_devtype(dev, "serio", NULL);
        if (!pdev) {
                log_warning("Failed to get serio parent for '%s'", udev_device_get_devnode(dev));
                return;
        }

        r = safe_atoi(value, &val_i);
        if (r < 0) {
                log_error("Unable to parse POINTINGSTICK_SENSITIVITY '%s' for '%s'", value, udev_device_get_devnode(dev));
                return;
        }

        xsprintf(val_s, "%d", val_i);

        r = udev_device_set_sysattr_value(pdev, "sensitivity", val_s);
        if (r < 0)
                log_error_errno(r, "Failed to write 'sensitivity' attribute for '%s': %m", udev_device_get_devnode(pdev));
}
Exemplo n.º 20
0
static int usb_unmount_dev(const char *devname, struct udev *udev)
{
  struct udev_enumerate *enumerate;
  struct udev_list_entry *dev_list, *dev_list_entry;
  struct udev_device *device = NULL, *parent_device = NULL;
  int device_found = 0;
  int retval = 0;
  FILE *remfile = NULL;
  struct stat buf;


  enumerate = udev_enumerate_new(udev);
  udev_enumerate_add_match_subsystem(enumerate, "block");
  udev_enumerate_scan_devices(enumerate);
  dev_list = udev_enumerate_get_list_entry(enumerate);

  udev_list_entry_foreach(dev_list_entry, dev_list)
  {
    device = udev_device_new_from_syspath(udev,
                                          udev_list_entry_get_name(dev_list_entry));

    if(!strcmp(udev_device_get_devnode(device), devname))
    {
      device_found = 1;
      break;
    }
    else
    {
      udev_device_unref(device);
      device = NULL;
    }
  }
Exemplo n.º 21
0
Arquivo: ldm.c Projeto: vodik/ldm
int
device_unmount (struct udev_device *dev)
{
    struct device_t *device;
    char cmdline[256];
    int tries = 10;

    device = device_search((char *)udev_device_get_devnode(dev));

    /* When using eject the remove command is issued 2 times, one when you 
     * execute eject and one when you unplug the device. We already have
     * destroyed the device the first time so the second time it wont find
     * it. So no bitching in the log.                                   */
    if (!device) {
        return 0;
    }

    device->mounted = device_is_mounted(device->devnode);
    if (device->mounted) {
        sprintf(cmdline, UMOUNT_CMD, device->devnode);
        do {
            if (!system(cmdline))
                break;
            sleep(2);
        } while (tries--);
    }

    rmdir(device->mountpoint);

    device_destroy(device);
    
    return 1;
}
Exemplo n.º 22
0
Arquivo: ldm.c Projeto: vodik/ldm
struct device_t *
device_new (struct udev_device *dev)
{
    struct device_t *device;

    const char *dev_type;
    const char *dev_idtype;
   
    device = malloc(sizeof(struct device_t));

    device->udev = dev;

    device->devnode = s_strdup(udev_device_get_devnode(dev));
    device->filesystem = s_strdup(udev_device_get_property_value(dev, "ID_FS_TYPE"));

    dev_type    = udev_device_get_devtype(dev);
    dev_idtype  = udev_device_get_property_value(dev, "ID_TYPE");

    device->type = DEVICE_UNK;

    if (!device->filesystem) {
        device_destroy(device);
        return NULL;
    }

    if (!strcmp(dev_type,   "partition")|| 
        !strcmp(dev_type,   "disk")     || 
        !strcmp(dev_idtype, "floppy"))  {
        device->type = DEVICE_VOLUME;
    } else if (!strcmp(dev_idtype, "cd")) {
        device->type = DEVICE_CD;
    }

    if (device->type == DEVICE_UNK) {
        device_destroy(device);
        return NULL;
    }

    device->has_media = device_has_media(device);
    device->fstab_entry = fstab_search(g_fstab, device);

    device->mountpoint = NULL;

    if (device->has_media) {
        if (device->fstab_entry) {
            device->mountpoint = s_strdup(device->fstab_entry->path);
        } else {
            device->mountpoint = device_create_mountpoint(device);
        }
    }

    device->mounted = device_is_mounted(device->devnode);

    if (!device_register(device)) {
        device_destroy(device);
        return NULL;
    }

    return device;
}
Exemplo n.º 23
0
static char *
drm_get_device_name(int fd)
{
   char *device_name = NULL;
#ifdef HAVE_LIBUDEV
   struct udev *udev;
   struct udev_device *device;
   struct stat buf;
   const char *tmp;

   udev = udev_new();
   if (fstat(fd, &buf) < 0) {
      _eglLog(_EGL_WARNING, "failed to stat fd %d", fd);
      goto out;
   }

   device = udev_device_new_from_devnum(udev, 'c', buf.st_rdev);
   if (device == NULL) {
      _eglLog(_EGL_WARNING,
              "could not create udev device for fd %d", fd);
      goto out;
   }

   tmp = udev_device_get_devnode(device);
   if (!tmp)
      goto out;
   device_name = strdup(tmp);

out:
   udev_device_unref(device);
   udev_unref(udev);

#endif
   return device_name;
}
Exemplo n.º 24
0
static int loopback_list_get(MountPoint **head) {
        _cleanup_udev_enumerate_unref_ struct udev_enumerate *e = NULL;
        struct udev_list_entry *item = NULL, *first = NULL;
        _cleanup_udev_unref_ struct udev *udev = NULL;
        int r;

        assert(head);

        udev = udev_new();
        if (!udev)
                return -ENOMEM;

        e = udev_enumerate_new(udev);
        if (!e)
                return -ENOMEM;

        r = udev_enumerate_add_match_subsystem(e, "block");
        if (r < 0)
                return r;

        r = udev_enumerate_add_match_sysname(e, "loop*");
        if (r < 0)
                return r;

        r = udev_enumerate_add_match_sysattr(e, "loop/backing_file", NULL);
        if (r < 0)
                return r;

        r = udev_enumerate_scan_devices(e);
        if (r < 0)
                return r;

        first = udev_enumerate_get_list_entry(e);
        udev_list_entry_foreach(item, first) {
                MountPoint *lb;
                _cleanup_udev_device_unref_ struct udev_device *d;
                char *loop;
                const char *dn;

                d = udev_device_new_from_syspath(udev, udev_list_entry_get_name(item));
                if (!d)
                        return -ENOMEM;

                dn = udev_device_get_devnode(d);
                if (!dn)
                        continue;

                loop = strdup(dn);
                if (!loop)
                        return -ENOMEM;

                lb = new0(MountPoint, 1);
                if (!lb) {
                        free(loop);
                        return -ENOMEM;
                }

                lb->path = loop;
                LIST_PREPEND(mount_point, *head, lb);
        }
Exemplo n.º 25
0
int
wgbm_get_default_fd_for_pattern(const char *pattern)
{
    struct udev *ud;
    struct udev_enumerate *en;
    struct udev_list_entry *devices, *entry;
    const char *path, *filename;
    struct udev_device *device;
    int fd;

    ud = udev_new();
    en = udev_enumerate_new(ud);
    udev_enumerate_add_match_subsystem(en, "drm");
    udev_enumerate_add_match_sysname(en, pattern);
    udev_enumerate_scan_devices(en);
    devices = udev_enumerate_get_list_entry(en);

    udev_list_entry_foreach(entry, devices) {
        path = udev_list_entry_get_name(entry);
        device = udev_device_new_from_syspath(ud, path);
        filename = udev_device_get_devnode(device);
        fd = open(filename, O_RDWR | O_CLOEXEC);
        udev_device_unref(device);
        if (fd >= 0) {
            udev_enumerate_unref(en);
            udev_unref(ud);
            return fd;
        }
    }
Exemplo n.º 26
0
static monome_t *monitor_attach(detector_state_t *state) {
	struct udev_device *ud;
	struct pollfd fds[1];

	fds[0].fd = udev_monitor_get_fd(state->um);
	fds[0].events = POLLIN;

	do {
		if( poll(fds, 1, -1) < 0 )
			switch( errno ) {
			case EINVAL:
				perror("error in poll()");
				exit(1);

			case EINTR:
			case EAGAIN:
				continue;
			}

		ud = udev_monitor_receive_device(state->um);

		/* check if this was an add event.
		   "add"[0] == 'a' */
		if( *(udev_device_get_action(ud)) == 'a' )
			spawn_server(state->exec_path, udev_device_get_devnode(ud));

		udev_device_unref(ud);
	} while( 1 );
}
void joystick_linux::enumerate_joysticks(udev *p_udev) {

	udev_enumerate *enumerate;
	udev_list_entry *devices, *dev_list_entry;
	udev_device *dev;

	enumerate = udev_enumerate_new(p_udev);
	udev_enumerate_add_match_subsystem(enumerate,"input");
	udev_enumerate_add_match_property(enumerate, "ID_INPUT_JOYSTICK", "1");

	udev_enumerate_scan_devices(enumerate);
	devices = udev_enumerate_get_list_entry(enumerate);
	udev_list_entry_foreach(dev_list_entry, devices) {

		const char* path = udev_list_entry_get_name(dev_list_entry);
		dev = udev_device_new_from_syspath(p_udev, path);
		const char* devnode = udev_device_get_devnode(dev);

		if (devnode) {

			String devnode_str = devnode;
			if (devnode_str.find(ignore_str) == -1) {
				joy_mutex->lock();
				open_joystick(devnode);
				joy_mutex->unlock();
			}
		}
		udev_device_unref(dev);
	}
	udev_enumerate_unref(enumerate);
}
Exemplo n.º 28
0
static void print_record(struct udev_device *device) {
        const char *str;
        int i;
        struct udev_list_entry *list_entry;

        printf("P: %s\n", udev_device_get_devpath(device));

        str = udev_device_get_devnode(device);
        if (str != NULL)
                printf("N: %s\n", str + STRLEN("/dev/"));

        i = udev_device_get_devlink_priority(device);
        if (i != 0)
                printf("L: %i\n", i);

        udev_list_entry_foreach(list_entry, udev_device_get_devlinks_list_entry(device))
                printf("S: %s\n",
                       udev_list_entry_get_name(list_entry) + STRLEN("/dev/"));

        udev_list_entry_foreach(list_entry, udev_device_get_properties_list_entry(device))
                printf("E: %s=%s\n",
                       udev_list_entry_get_name(list_entry),
                       udev_list_entry_get_value(list_entry));
        printf("\n");
}
Exemplo n.º 29
0
int udev_node_add(struct udev_device *dev, mode_t mode, uid_t uid, gid_t gid, int test)
{
	struct udev *udev = udev_device_get_udev(dev);
	int i;
	int num;
	struct udev_list_entry *list_entry;
	int err = 0;

	info(udev, "creating device node '%s', devnum=%d:%d, mode=%#o, uid=%d, gid=%d\n",
	     udev_device_get_devnode(dev),
	     major(udev_device_get_devnum(dev)), minor(udev_device_get_devnum(dev)),
	     mode, uid, gid);

	util_create_path(udev, udev_device_get_devnode(dev));
	if (!test)
		if (udev_node_mknod(dev, NULL, makedev(0,0), mode, uid, gid) != 0) {
			err = -1;
			goto exit;
		}

	/* create all_partitions if requested */
	num = udev_device_get_num_fake_partitions(dev);
	if (num > 0) {
		info(udev, "creating device partition nodes '%s[1-%i]'\n", udev_device_get_devnode(dev), num);
		if (!test) {
			for (i = 1; i <= num; i++) {
				char partitionname[UTIL_PATH_SIZE];
				dev_t part_devnum;

				snprintf(partitionname, sizeof(partitionname), "%s%d",
					 udev_device_get_devnode(dev), i);
				partitionname[sizeof(partitionname)-1] = '\0';
				part_devnum = makedev(major(udev_device_get_devnum(dev)),
						    minor(udev_device_get_devnum(dev)) + i);
				udev_node_mknod(dev, partitionname, part_devnum, mode, uid, gid);
			}
		}
	}

	/* add node to name index */
	name_index(udev, udev_device_get_devpath(dev), udev_device_get_devnode(dev), 1, test);

	/* create/update symlinks, add symlinks to name index */
	udev_list_entry_foreach(list_entry, udev_device_get_devlinks_list_entry(dev)) {
		name_index(udev, udev_device_get_devpath(dev), udev_list_entry_get_name(list_entry), 1, test);
		update_link(dev, udev_list_entry_get_name(list_entry), test);
	}
Exemplo n.º 30
0
QStringList QDeviceDiscovery::scanConnectedDevices()
{
    QStringList devices;

    if (!m_udev)
        return devices;

    udev_enumerate *ue = udev_enumerate_new(m_udev);
    udev_enumerate_add_match_subsystem(ue, "input");
    udev_enumerate_add_match_subsystem(ue, "drm");

    if (m_types & Device_Mouse)
        udev_enumerate_add_match_property(ue, "ID_INPUT_MOUSE", "1");
    if (m_types & Device_Touchpad)
        udev_enumerate_add_match_property(ue, "ID_INPUT_TOUCHPAD", "1");
    if (m_types & Device_Touchscreen)
        udev_enumerate_add_match_property(ue, "ID_INPUT_TOUCHSCREEN", "1");
    if (m_types & Device_Keyboard) {
        udev_enumerate_add_match_property(ue, "ID_INPUT_KEYBOARD", "1");
        udev_enumerate_add_match_property(ue, "ID_INPUT_KEY", "1");
    }
    if (m_types & Device_Tablet)
        udev_enumerate_add_match_property(ue, "ID_INPUT_TABLET", "1");

    if (udev_enumerate_scan_devices(ue) != 0) {
#ifdef QT_QPA_DEVICE_DISCOVERY_DEBUG
        qWarning() << "UDeviceHelper scan connected devices for enumeration failed";
#endif
        return devices;
    }

    udev_list_entry *entry;
    udev_list_entry_foreach (entry, udev_enumerate_get_list_entry(ue)) {
        const char *syspath = udev_list_entry_get_name(entry);
        udev_device *udevice = udev_device_new_from_syspath(m_udev, syspath);
        QString candidate = QString::fromUtf8(udev_device_get_devnode(udevice));
        if ((m_types & Device_InputMask) && candidate.startsWith(QLatin1String(QT_EVDEV_DEVICE)))
            devices << candidate;
        if ((m_types & Device_VideoMask) && candidate.startsWith(QLatin1String(QT_DRM_DEVICE))) {
            if (m_types & Device_DRM_PrimaryGPU) {
                udev_device *pci = udev_device_get_parent_with_subsystem_devtype(udevice, "pci", 0);
                if (pci) {
                    if (qstrcmp(udev_device_get_sysattr_value(pci, "boot_vga"), "1") == 0)
                        devices << candidate;
                }
            } else
                devices << candidate;
        }

        udev_device_unref(udevice);
    }
    udev_enumerate_unref(ue);

#ifdef QT_QPA_DEVICE_DISCOVERY_DEBUG
    qWarning() << "UDeviceHelper found matching devices" << devices;
#endif

    return devices;
}