Пример #1
0
/**
 * udev_device_new_from_syspath:
 * @udev: udev library context
 * @syspath: sys device path including sys directory
 *
 * Create new udev device, and fill in information from the sys
 * device and the udev database entry. The syspath is the absolute
 * path to the device, including the sys mount point.
 *
 * The initial refcount is 1, and needs to be decremented to
 * release the resources of the udev device.
 *
 * Returns: a new udev device, or #NULL, if it does not exist
 **/
_public_ struct udev_device *udev_device_new_from_syspath(struct udev *udev, const char *syspath) {
        struct udev_device *udev_device;
        int r;

        udev_device = udev_device_new(udev);
        if (!udev_device)
                return NULL;

        r = sd_device_new_from_syspath(&udev_device->device, syspath);
        if (r < 0) {
                errno = -r;
                udev_device_unref(udev_device);
                return NULL;
        }

        return udev_device;
}
Пример #2
0
struct udev_device *udev_device_new_from_synthetic_event(struct udev *udev, const char *syspath, const char *action) {
        struct udev_device *device;
        int r;

        device = udev_device_new(udev);
        if (!device)
                return NULL;

        r = device_new_from_synthetic_event(&device->device, syspath, action);
        if (r < 0) {
                udev_device_unref(device);
                errno = -r;
                return NULL;
        }

        return device;
}
Пример #3
0
struct udev_device *udev_device_new_from_nulstr(struct udev *udev, char *nulstr, ssize_t buflen) {
        struct udev_device *device;
        int r;

        device = udev_device_new(udev);
        if (!device)
                return NULL;

        r = device_new_from_nulstr(&device->device, (uint8_t*)nulstr, buflen);
        if (r < 0) {
                udev_device_unref(device);
                errno = -r;
                return NULL;
        }

        return device;
}
Пример #4
0
/**
 * udev_device_new_from_environment
 * @udev: udev library context
 *
 * Create new udev device, and fill in information from the
 * current process environment. This only works reliable if
 * the process is called from a udev rule. It is usually used
 * for tools executed from IMPORT= rules.
 *
 * The initial refcount is 1, and needs to be decremented to
 * release the resources of the udev device.
 *
 * Returns: a new udev device, or #NULL, if it does not exist
 **/
_public_ struct udev_device *udev_device_new_from_environment(struct udev *udev)
{
        struct udev_device *udev_device;
        int r;

        udev_device = udev_device_new(udev);
        if (!udev_device)
                return NULL;

        r = device_new_from_strv(&udev_device->device, environ);
        if (r < 0) {
                errno = -r;
                udev_device_unref(udev_device);
                return NULL;
        }

        return udev_device;
}
Пример #5
0
/**
 * udev_device_new_from_devnum:
 * @udev: udev library context
 * @type: char or block device
 * @devnum: device major/minor number
 *
 * Create new udev device, and fill in information from the sys
 * device and the udev database entry. The device is looked-up
 * by its major/minor number and type. Character and block device
 * numbers are not unique across the two types.
 *
 * The initial refcount is 1, and needs to be decremented to
 * release the resources of the udev device.
 *
 * Returns: a new udev device, or #NULL, if it does not exist
 **/
_public_ struct udev_device *udev_device_new_from_devnum(struct udev *udev, char type, dev_t devnum)
{
        struct udev_device *udev_device;
        int r;

        udev_device = udev_device_new(udev);
        if (!udev_device)
                return NULL;

        r = sd_device_new_from_devnum(&udev_device->device, type, devnum);
        if (r < 0) {
                errno = -r;
                udev_device_unref(udev_device);
                return NULL;
        }

        return udev_device;
}
Пример #6
0
struct udev_device *udev_device_clone_with_db(struct udev_device *udev_device_old) {
        struct udev_device *udev_device;
        int r;

        assert(udev_device_old);

        udev_device = udev_device_new(udev_device_old->udev);
        if (!udev_device)
                return NULL;

        r = device_clone_with_db(udev_device_old->device, &udev_device->device);
        if (r < 0) {
                udev_device_unref(udev_device);
                errno = -r;
                return NULL;
        }

        return udev_device;
}
Пример #7
0
struct udev_device *udev_device_shallow_clone(struct udev_device *old_device) {
        struct udev_device *device;
        int r;

        assert(old_device);

        device = udev_device_new(old_device->udev);
        if (!device)
                return NULL;

        r = device_shallow_clone(old_device->device, &device->device);
        if (r < 0) {
                udev_device_unref(device);
                errno = -r;
                return NULL;
        }

        return device;
}
Пример #8
0
static struct udev_device *device_new_from_parent(struct udev_device *child)
{
        struct udev_device *parent;
        int r;

        assert_return_errno(child, NULL, EINVAL);

        parent = udev_device_new(child->udev);
        if (!parent)
                return NULL;

        r = sd_device_get_parent(child->device, &parent->device);
        if (r < 0) {
                errno = -r;
                udev_device_unref(parent);
                return NULL;
        }

        /* the parent is unref'ed with the child, so take a ref from libudev as well */
        sd_device_ref(parent->device);

        return parent;
}