2017-11-18 17:14:42 +01:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0+ */
|
2011-08-05 02:00:30 +02:00
|
|
|
/*
|
|
|
|
* compose persistent device path
|
|
|
|
*
|
|
|
|
* Logic based on Hannes Reinecke's shell script.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <ctype.h>
|
2015-10-24 22:58:24 +02:00
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
2011-08-05 02:00:30 +02:00
|
|
|
#include <getopt.h>
|
2015-10-24 22:58:24 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
2011-08-05 02:00:30 +02:00
|
|
|
|
2015-10-27 03:01:06 +01:00
|
|
|
#include "alloc-util.h"
|
2016-12-09 10:04:30 +01:00
|
|
|
#include "dirent-util.h"
|
2017-11-22 10:23:45 +01:00
|
|
|
#include "fd-util.h"
|
2015-10-24 22:58:24 +02:00
|
|
|
#include "string-util.h"
|
2017-11-22 10:32:45 +01:00
|
|
|
#include "sysexits.h"
|
2011-08-05 02:00:30 +02:00
|
|
|
#include "udev.h"
|
|
|
|
|
2013-12-14 13:09:07 +01:00
|
|
|
_printf_(2,3)
|
2017-11-22 10:32:45 +01:00
|
|
|
static void path_prepend(char **path, const char *fmt, ...) {
|
2012-01-10 01:34:15 +01:00
|
|
|
va_list va;
|
2017-11-22 10:23:45 +01:00
|
|
|
_cleanup_free_ char *pre = NULL;
|
|
|
|
int r;
|
2012-01-10 01:34:15 +01:00
|
|
|
|
|
|
|
va_start(va, fmt);
|
2017-11-22 10:23:45 +01:00
|
|
|
r = vasprintf(&pre, fmt, va);
|
2012-01-10 01:34:15 +01:00
|
|
|
va_end(va);
|
2017-11-22 10:32:45 +01:00
|
|
|
if (r < 0) {
|
|
|
|
log_oom();
|
|
|
|
exit(EX_OSERR);
|
|
|
|
}
|
2012-01-10 01:34:15 +01:00
|
|
|
|
2017-11-22 10:23:45 +01:00
|
|
|
if (*path) {
|
2012-01-10 01:34:15 +01:00
|
|
|
char *new;
|
|
|
|
|
2017-11-22 10:23:45 +01:00
|
|
|
new = strjoin(pre, "-", *path);
|
2017-11-22 10:32:45 +01:00
|
|
|
if (!new) {
|
|
|
|
log_oom();
|
|
|
|
exit(EX_OSERR);
|
|
|
|
}
|
|
|
|
|
2017-11-22 10:23:45 +01:00
|
|
|
free_and_replace(*path, new);
|
2018-03-22 16:53:26 +01:00
|
|
|
} else
|
|
|
|
*path = TAKE_PTR(pre);
|
2011-08-05 02:00:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Linux only supports 32 bit luns.
|
|
|
|
** See drivers/scsi/scsi_scan.c::scsilun_to_int() for more details.
|
|
|
|
*/
|
2017-11-22 10:32:45 +01:00
|
|
|
static void format_lun_number(struct udev_device *dev, char **path) {
|
2012-01-10 01:34:15 +01:00
|
|
|
unsigned long lun = strtoul(udev_device_get_sysnum(dev), NULL, 10);
|
2011-08-05 02:00:30 +02:00
|
|
|
|
2012-01-10 01:34:15 +01:00
|
|
|
if (lun < 256)
|
2017-11-22 10:32:45 +01:00
|
|
|
/* address method 0, peripheral device addressing with bus id of zero */
|
|
|
|
path_prepend(path, "lun-%lu", lun);
|
|
|
|
else
|
|
|
|
/* handle all other lun addressing methods by using a variant of the original lun format */
|
|
|
|
path_prepend(path, "lun-0x%04lx%04lx00000000", lun & 0xffff, (lun >> 16) & 0xffff);
|
2011-08-05 02:00:30 +02:00
|
|
|
}
|
|
|
|
|
2014-07-29 15:47:41 +02:00
|
|
|
static struct udev_device *skip_subsystem(struct udev_device *dev, const char *subsys) {
|
2012-01-10 01:34:15 +01:00
|
|
|
struct udev_device *parent = dev;
|
|
|
|
|
2015-06-02 16:52:07 +02:00
|
|
|
assert(dev);
|
|
|
|
assert(subsys);
|
|
|
|
|
2017-11-22 10:23:45 +01:00
|
|
|
while (parent) {
|
2012-01-10 01:34:15 +01:00
|
|
|
const char *subsystem;
|
|
|
|
|
|
|
|
subsystem = udev_device_get_subsystem(parent);
|
2017-11-22 10:23:45 +01:00
|
|
|
if (!streq_ptr(subsystem, subsys))
|
2012-01-10 01:34:15 +01:00
|
|
|
break;
|
2017-11-22 10:23:45 +01:00
|
|
|
|
2012-01-10 01:34:15 +01:00
|
|
|
dev = parent;
|
|
|
|
parent = udev_device_get_parent(parent);
|
|
|
|
}
|
2017-11-22 10:23:45 +01:00
|
|
|
|
2012-01-10 01:34:15 +01:00
|
|
|
return dev;
|
2011-08-05 02:00:30 +02:00
|
|
|
}
|
|
|
|
|
2014-07-29 15:47:41 +02:00
|
|
|
static struct udev_device *handle_scsi_fibre_channel(struct udev_device *parent, char **path) {
|
2012-01-10 01:34:15 +01:00
|
|
|
struct udev_device *targetdev;
|
tree-wide: drop redundant _cleanup_ macros (#8810)
This drops a good number of type-specific _cleanup_ macros, and patches
all users to just use the generic ones.
In most recent code we abstained from defining type-specific macros, and
this basically removes all those added already, with the exception of
the really low-level ones.
Having explicit macros for this is not too useful, as the expression
without the extra macro is generally just 2ch wider. We should generally
emphesize generic code, unless there are really good reasons for
specific code, hence let's follow this in this case too.
Note that _cleanup_free_ and similar really low-level, libc'ish, Linux
API'ish macros continue to be defined, only the really high-level OO
ones are dropped. From now on this should really be the rule: for really
low-level stuff, such as memory allocation, fd handling and so one, go
ahead and define explicit per-type macros, but for high-level, specific
program code, just use the generic _cleanup_() macro directly, in order
to keep things simple and as readable as possible for the uninitiated.
Note that before this patch some of the APIs (notable libudev ones) were
already used with the high-level macros at some places and with the
generic _cleanup_ macro at others. With this patch we hence unify on the
latter.
2018-04-25 12:31:45 +02:00
|
|
|
_cleanup_(udev_device_unrefp) struct udev_device *fcdev = NULL;
|
2012-01-10 01:34:15 +01:00
|
|
|
const char *port;
|
2017-11-22 10:23:45 +01:00
|
|
|
_cleanup_free_ char *lun = NULL;
|
2012-01-10 01:34:15 +01:00
|
|
|
|
2015-06-02 16:52:07 +02:00
|
|
|
assert(parent);
|
|
|
|
assert(path);
|
|
|
|
|
2017-11-22 10:23:45 +01:00
|
|
|
|
2012-01-10 01:34:15 +01:00
|
|
|
targetdev = udev_device_get_parent_with_subsystem_devtype(parent, "scsi", "scsi_target");
|
2017-11-22 10:23:45 +01:00
|
|
|
if (!targetdev)
|
2012-01-10 01:34:15 +01:00
|
|
|
return NULL;
|
|
|
|
|
2018-08-22 12:57:32 +02:00
|
|
|
fcdev = udev_device_new_from_subsystem_sysname(NULL, "fc_transport", udev_device_get_sysname(targetdev));
|
2017-11-22 10:23:45 +01:00
|
|
|
if (!fcdev)
|
2012-01-10 01:34:15 +01:00
|
|
|
return NULL;
|
2017-11-22 10:23:45 +01:00
|
|
|
|
2012-01-10 01:34:15 +01:00
|
|
|
port = udev_device_get_sysattr_value(fcdev, "port_name");
|
2017-11-22 10:23:45 +01:00
|
|
|
if (!port)
|
|
|
|
return NULL;
|
2012-01-10 01:34:15 +01:00
|
|
|
|
|
|
|
format_lun_number(parent, &lun);
|
|
|
|
path_prepend(path, "fc-%s-%s", port, lun);
|
|
|
|
return parent;
|
2011-08-05 02:00:30 +02:00
|
|
|
}
|
|
|
|
|
2014-09-22 11:48:57 +02:00
|
|
|
static struct udev_device *handle_scsi_sas_wide_port(struct udev_device *parent, char **path) {
|
2017-11-22 10:23:45 +01:00
|
|
|
struct udev_device *targetdev, *target_parent;
|
tree-wide: drop redundant _cleanup_ macros (#8810)
This drops a good number of type-specific _cleanup_ macros, and patches
all users to just use the generic ones.
In most recent code we abstained from defining type-specific macros, and
this basically removes all those added already, with the exception of
the really low-level ones.
Having explicit macros for this is not too useful, as the expression
without the extra macro is generally just 2ch wider. We should generally
emphesize generic code, unless there are really good reasons for
specific code, hence let's follow this in this case too.
Note that _cleanup_free_ and similar really low-level, libc'ish, Linux
API'ish macros continue to be defined, only the really high-level OO
ones are dropped. From now on this should really be the rule: for really
low-level stuff, such as memory allocation, fd handling and so one, go
ahead and define explicit per-type macros, but for high-level, specific
program code, just use the generic _cleanup_() macro directly, in order
to keep things simple and as readable as possible for the uninitiated.
Note that before this patch some of the APIs (notable libudev ones) were
already used with the high-level macros at some places and with the
generic _cleanup_ macro at others. With this patch we hence unify on the
latter.
2018-04-25 12:31:45 +02:00
|
|
|
_cleanup_(udev_device_unrefp) struct udev_device *sasdev = NULL;
|
2012-01-10 01:34:15 +01:00
|
|
|
const char *sas_address;
|
2017-11-22 10:23:45 +01:00
|
|
|
_cleanup_free_ char *lun = NULL;
|
2012-01-10 01:34:15 +01:00
|
|
|
|
2015-06-02 16:52:07 +02:00
|
|
|
assert(parent);
|
|
|
|
assert(path);
|
|
|
|
|
2017-11-22 10:23:45 +01:00
|
|
|
|
2012-01-10 01:34:15 +01:00
|
|
|
targetdev = udev_device_get_parent_with_subsystem_devtype(parent, "scsi", "scsi_target");
|
2017-11-22 10:23:45 +01:00
|
|
|
if (!targetdev)
|
2012-01-10 01:34:15 +01:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
target_parent = udev_device_get_parent(targetdev);
|
2017-11-22 10:23:45 +01:00
|
|
|
if (!target_parent)
|
2012-01-10 01:34:15 +01:00
|
|
|
return NULL;
|
|
|
|
|
2018-08-22 12:57:32 +02:00
|
|
|
sasdev = udev_device_new_from_subsystem_sysname(NULL, "sas_device",
|
2017-11-22 10:23:45 +01:00
|
|
|
udev_device_get_sysname(target_parent));
|
|
|
|
if (!sasdev)
|
2012-01-10 01:34:15 +01:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
sas_address = udev_device_get_sysattr_value(sasdev, "sas_address");
|
2017-11-22 10:23:45 +01:00
|
|
|
if (!sas_address)
|
|
|
|
return NULL;
|
2012-01-10 01:34:15 +01:00
|
|
|
|
|
|
|
format_lun_number(parent, &lun);
|
|
|
|
path_prepend(path, "sas-%s-%s", sas_address, lun);
|
|
|
|
return parent;
|
2011-08-05 02:00:30 +02:00
|
|
|
}
|
|
|
|
|
2014-09-22 11:48:57 +02:00
|
|
|
static struct udev_device *handle_scsi_sas(struct udev_device *parent, char **path)
|
|
|
|
{
|
2017-11-22 10:23:45 +01:00
|
|
|
struct udev_device *targetdev, *target_parent, *port, *expander;
|
tree-wide: drop redundant _cleanup_ macros (#8810)
This drops a good number of type-specific _cleanup_ macros, and patches
all users to just use the generic ones.
In most recent code we abstained from defining type-specific macros, and
this basically removes all those added already, with the exception of
the really low-level ones.
Having explicit macros for this is not too useful, as the expression
without the extra macro is generally just 2ch wider. We should generally
emphesize generic code, unless there are really good reasons for
specific code, hence let's follow this in this case too.
Note that _cleanup_free_ and similar really low-level, libc'ish, Linux
API'ish macros continue to be defined, only the really high-level OO
ones are dropped. From now on this should really be the rule: for really
low-level stuff, such as memory allocation, fd handling and so one, go
ahead and define explicit per-type macros, but for high-level, specific
program code, just use the generic _cleanup_() macro directly, in order
to keep things simple and as readable as possible for the uninitiated.
Note that before this patch some of the APIs (notable libudev ones) were
already used with the high-level macros at some places and with the
generic _cleanup_ macro at others. With this patch we hence unify on the
latter.
2018-04-25 12:31:45 +02:00
|
|
|
_cleanup_(udev_device_unrefp) struct udev_device
|
2017-11-22 10:23:45 +01:00
|
|
|
*target_sasdev = NULL, *expander_sasdev = NULL, *port_sasdev = NULL;
|
2014-09-22 11:48:57 +02:00
|
|
|
const char *sas_address = NULL;
|
|
|
|
const char *phy_id;
|
|
|
|
const char *phy_count;
|
2017-11-22 10:23:45 +01:00
|
|
|
_cleanup_free_ char *lun = NULL;
|
2014-09-22 11:48:57 +02:00
|
|
|
|
2015-06-02 16:52:07 +02:00
|
|
|
assert(parent);
|
|
|
|
assert(path);
|
|
|
|
|
2017-11-22 10:23:45 +01:00
|
|
|
|
2014-09-22 11:48:57 +02:00
|
|
|
targetdev = udev_device_get_parent_with_subsystem_devtype(parent, "scsi", "scsi_target");
|
2017-11-22 10:23:45 +01:00
|
|
|
if (!targetdev)
|
2014-09-22 11:48:57 +02:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
target_parent = udev_device_get_parent(targetdev);
|
2017-11-22 10:23:45 +01:00
|
|
|
if (!target_parent)
|
2014-09-22 11:48:57 +02:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* Get sas device */
|
2018-08-22 12:57:32 +02:00
|
|
|
target_sasdev = udev_device_new_from_subsystem_sysname(NULL, "sas_device", udev_device_get_sysname(target_parent));
|
2017-11-22 10:23:45 +01:00
|
|
|
if (!target_sasdev)
|
2014-09-22 11:48:57 +02:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* The next parent is sas port */
|
|
|
|
port = udev_device_get_parent(target_parent);
|
2017-11-22 10:23:45 +01:00
|
|
|
if (!port)
|
|
|
|
return NULL;
|
2014-09-22 11:48:57 +02:00
|
|
|
|
|
|
|
/* Get port device */
|
2018-08-22 12:57:32 +02:00
|
|
|
port_sasdev = udev_device_new_from_subsystem_sysname(NULL, "sas_port", udev_device_get_sysname(port));
|
2014-09-22 11:48:57 +02:00
|
|
|
|
|
|
|
phy_count = udev_device_get_sysattr_value(port_sasdev, "num_phys");
|
2017-11-22 10:23:45 +01:00
|
|
|
if (!phy_count)
|
|
|
|
return NULL;
|
2014-09-22 11:48:57 +02:00
|
|
|
|
|
|
|
/* Check if we are simple disk */
|
2017-11-22 10:23:45 +01:00
|
|
|
if (strncmp(phy_count, "1", 2) != 0)
|
|
|
|
return handle_scsi_sas_wide_port(parent, path);
|
2014-09-22 11:48:57 +02:00
|
|
|
|
|
|
|
/* Get connected phy */
|
|
|
|
phy_id = udev_device_get_sysattr_value(target_sasdev, "phy_identifier");
|
2017-11-22 10:23:45 +01:00
|
|
|
if (!phy_id)
|
|
|
|
return NULL;
|
2014-09-22 11:48:57 +02:00
|
|
|
|
|
|
|
/* The port's parent is either hba or expander */
|
|
|
|
expander = udev_device_get_parent(port);
|
2017-11-22 10:23:45 +01:00
|
|
|
if (!expander)
|
|
|
|
return NULL;
|
2014-09-22 11:48:57 +02:00
|
|
|
|
|
|
|
/* Get expander device */
|
2018-08-22 12:57:32 +02:00
|
|
|
expander_sasdev = udev_device_new_from_subsystem_sysname(NULL, "sas_device", udev_device_get_sysname(expander));
|
2017-11-22 10:23:45 +01:00
|
|
|
if (expander_sasdev) {
|
2014-09-22 11:48:57 +02:00
|
|
|
/* Get expander's address */
|
2018-08-22 12:57:32 +02:00
|
|
|
sas_address = udev_device_get_sysattr_value(expander_sasdev, "sas_address");
|
2017-11-22 10:23:45 +01:00
|
|
|
if (!sas_address)
|
|
|
|
return NULL;
|
2014-09-22 11:48:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
format_lun_number(parent, &lun);
|
|
|
|
if (sas_address)
|
|
|
|
path_prepend(path, "sas-exp%s-phy%s-%s", sas_address, phy_id, lun);
|
|
|
|
else
|
|
|
|
path_prepend(path, "sas-phy%s-%s", phy_id, lun);
|
|
|
|
|
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
|
2014-07-29 15:47:41 +02:00
|
|
|
static struct udev_device *handle_scsi_iscsi(struct udev_device *parent, char **path) {
|
2012-01-10 01:34:15 +01:00
|
|
|
struct udev_device *transportdev;
|
tree-wide: drop redundant _cleanup_ macros (#8810)
This drops a good number of type-specific _cleanup_ macros, and patches
all users to just use the generic ones.
In most recent code we abstained from defining type-specific macros, and
this basically removes all those added already, with the exception of
the really low-level ones.
Having explicit macros for this is not too useful, as the expression
without the extra macro is generally just 2ch wider. We should generally
emphesize generic code, unless there are really good reasons for
specific code, hence let's follow this in this case too.
Note that _cleanup_free_ and similar really low-level, libc'ish, Linux
API'ish macros continue to be defined, only the really high-level OO
ones are dropped. From now on this should really be the rule: for really
low-level stuff, such as memory allocation, fd handling and so one, go
ahead and define explicit per-type macros, but for high-level, specific
program code, just use the generic _cleanup_() macro directly, in order
to keep things simple and as readable as possible for the uninitiated.
Note that before this patch some of the APIs (notable libudev ones) were
already used with the high-level macros at some places and with the
generic _cleanup_ macro at others. With this patch we hence unify on the
latter.
2018-04-25 12:31:45 +02:00
|
|
|
_cleanup_(udev_device_unrefp) struct udev_device
|
2017-11-22 10:23:45 +01:00
|
|
|
*sessiondev = NULL, *conndev = NULL;
|
|
|
|
const char *target, *connname, *addr, *port;
|
|
|
|
_cleanup_free_ char *lun = NULL;
|
2012-01-10 01:34:15 +01:00
|
|
|
|
2015-06-02 16:52:07 +02:00
|
|
|
assert(parent);
|
|
|
|
assert(path);
|
|
|
|
|
2017-11-22 10:23:45 +01:00
|
|
|
|
2012-01-10 01:34:15 +01:00
|
|
|
/* find iscsi session */
|
|
|
|
transportdev = parent;
|
|
|
|
for (;;) {
|
|
|
|
transportdev = udev_device_get_parent(transportdev);
|
2017-11-22 10:23:45 +01:00
|
|
|
if (!transportdev)
|
2012-01-10 01:34:15 +01:00
|
|
|
return NULL;
|
2012-04-16 20:27:44 +02:00
|
|
|
if (startswith(udev_device_get_sysname(transportdev), "session"))
|
2012-01-10 01:34:15 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* find iscsi session device */
|
2018-08-22 12:57:32 +02:00
|
|
|
sessiondev = udev_device_new_from_subsystem_sysname(NULL, "iscsi_session", udev_device_get_sysname(transportdev));
|
2017-11-22 10:23:45 +01:00
|
|
|
if (!sessiondev)
|
2012-01-10 01:34:15 +01:00
|
|
|
return NULL;
|
2017-11-22 10:23:45 +01:00
|
|
|
|
2012-01-10 01:34:15 +01:00
|
|
|
target = udev_device_get_sysattr_value(sessiondev, "targetname");
|
2017-11-22 10:23:45 +01:00
|
|
|
if (!target)
|
|
|
|
return NULL;
|
2012-01-10 01:34:15 +01:00
|
|
|
|
2017-11-22 10:23:45 +01:00
|
|
|
connname = strjoina("connection", udev_device_get_sysnum(transportdev), ":0");
|
2018-08-22 12:57:32 +02:00
|
|
|
conndev = udev_device_new_from_subsystem_sysname(NULL, "iscsi_connection", connname);
|
2017-11-22 10:23:45 +01:00
|
|
|
if (!conndev)
|
|
|
|
return NULL;
|
|
|
|
|
2012-01-10 01:34:15 +01:00
|
|
|
addr = udev_device_get_sysattr_value(conndev, "persistent_address");
|
|
|
|
port = udev_device_get_sysattr_value(conndev, "persistent_port");
|
2017-11-22 10:23:45 +01:00
|
|
|
if (!addr || !port)
|
|
|
|
return NULL;
|
2012-01-10 01:34:15 +01:00
|
|
|
|
|
|
|
format_lun_number(parent, &lun);
|
|
|
|
path_prepend(path, "ip-%s:%s-iscsi-%s-%s", addr, port, target, lun);
|
|
|
|
return parent;
|
2011-08-05 02:00:30 +02:00
|
|
|
}
|
|
|
|
|
2015-09-08 22:27:51 +02:00
|
|
|
static struct udev_device *handle_scsi_ata(struct udev_device *parent, char **path) {
|
2017-11-22 10:23:45 +01:00
|
|
|
struct udev_device *targetdev, *target_parent;
|
tree-wide: drop redundant _cleanup_ macros (#8810)
This drops a good number of type-specific _cleanup_ macros, and patches
all users to just use the generic ones.
In most recent code we abstained from defining type-specific macros, and
this basically removes all those added already, with the exception of
the really low-level ones.
Having explicit macros for this is not too useful, as the expression
without the extra macro is generally just 2ch wider. We should generally
emphesize generic code, unless there are really good reasons for
specific code, hence let's follow this in this case too.
Note that _cleanup_free_ and similar really low-level, libc'ish, Linux
API'ish macros continue to be defined, only the really high-level OO
ones are dropped. From now on this should really be the rule: for really
low-level stuff, such as memory allocation, fd handling and so one, go
ahead and define explicit per-type macros, but for high-level, specific
program code, just use the generic _cleanup_() macro directly, in order
to keep things simple and as readable as possible for the uninitiated.
Note that before this patch some of the APIs (notable libudev ones) were
already used with the high-level macros at some places and with the
generic _cleanup_ macro at others. With this patch we hence unify on the
latter.
2018-04-25 12:31:45 +02:00
|
|
|
_cleanup_(udev_device_unrefp) struct udev_device *atadev = NULL;
|
2015-09-08 22:27:51 +02:00
|
|
|
const char *port_no;
|
|
|
|
|
|
|
|
assert(parent);
|
|
|
|
assert(path);
|
|
|
|
|
2017-11-22 10:23:45 +01:00
|
|
|
|
2015-09-08 22:27:51 +02:00
|
|
|
targetdev = udev_device_get_parent_with_subsystem_devtype(parent, "scsi", "scsi_host");
|
|
|
|
if (!targetdev)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
target_parent = udev_device_get_parent(targetdev);
|
|
|
|
if (!target_parent)
|
|
|
|
return NULL;
|
|
|
|
|
2018-08-22 12:57:32 +02:00
|
|
|
atadev = udev_device_new_from_subsystem_sysname(NULL, "ata_port", udev_device_get_sysname(target_parent));
|
2015-09-08 22:27:51 +02:00
|
|
|
if (!atadev)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
port_no = udev_device_get_sysattr_value(atadev, "port_no");
|
2017-11-22 10:23:45 +01:00
|
|
|
if (!port_no)
|
|
|
|
return NULL;
|
|
|
|
|
2015-09-08 22:27:51 +02:00
|
|
|
path_prepend(path, "ata-%s", port_no);
|
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
|
2014-07-29 15:47:41 +02:00
|
|
|
static struct udev_device *handle_scsi_default(struct udev_device *parent, char **path) {
|
2012-01-10 01:34:15 +01:00
|
|
|
struct udev_device *hostdev;
|
|
|
|
int host, bus, target, lun;
|
2017-11-22 10:23:45 +01:00
|
|
|
const char *name, *base, *pos;
|
|
|
|
_cleanup_closedir_ DIR *dir = NULL;
|
2012-01-10 01:34:15 +01:00
|
|
|
struct dirent *dent;
|
2017-11-22 10:23:45 +01:00
|
|
|
int basenum = -1;
|
2012-01-10 01:34:15 +01:00
|
|
|
|
2015-06-02 16:52:07 +02:00
|
|
|
assert(parent);
|
|
|
|
assert(path);
|
|
|
|
|
2012-01-10 01:34:15 +01:00
|
|
|
hostdev = udev_device_get_parent_with_subsystem_devtype(parent, "scsi", "scsi_host");
|
2017-11-22 10:23:45 +01:00
|
|
|
if (!hostdev)
|
2012-01-10 01:34:15 +01:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
name = udev_device_get_sysname(parent);
|
|
|
|
if (sscanf(name, "%d:%d:%d:%d", &host, &bus, &target, &lun) != 4)
|
|
|
|
return NULL;
|
|
|
|
|
2012-08-03 10:52:24 +02:00
|
|
|
/*
|
|
|
|
* Rebase host offset to get the local relative number
|
|
|
|
*
|
|
|
|
* Note: This is by definition racy, unreliable and too simple.
|
|
|
|
* Please do not copy this model anywhere. It's just a left-over
|
|
|
|
* from the time we had no idea how things should look like in
|
|
|
|
* the end.
|
|
|
|
*
|
|
|
|
* Making assumptions about a global in-kernel counter and use
|
|
|
|
* that to calculate a local offset is a very broken concept. It
|
|
|
|
* can only work as long as things are in strict order.
|
|
|
|
*
|
|
|
|
* The kernel needs to export the instance/port number of a
|
|
|
|
* controller directly, without the need for rebase magic like
|
|
|
|
* this. Manual driver unbind/bind, parallel hotplug/unplug will
|
|
|
|
* get into the way of this "I hope it works" logic.
|
|
|
|
*/
|
2017-11-22 10:23:45 +01:00
|
|
|
|
|
|
|
base = udev_device_get_syspath(hostdev);
|
2012-01-10 01:34:15 +01:00
|
|
|
pos = strrchr(base, '/');
|
2017-11-22 10:23:45 +01:00
|
|
|
if (!pos)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
base = strndupa(base, pos - base);
|
2012-01-10 01:34:15 +01:00
|
|
|
dir = opendir(base);
|
2017-11-22 10:23:45 +01:00
|
|
|
if (!dir)
|
|
|
|
return NULL;
|
|
|
|
|
2016-12-09 10:04:30 +01:00
|
|
|
FOREACH_DIRENT_ALL(dent, dir, break) {
|
2012-01-10 01:34:15 +01:00
|
|
|
char *rest;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (dent->d_name[0] == '.')
|
|
|
|
continue;
|
2017-09-29 09:58:22 +02:00
|
|
|
if (!IN_SET(dent->d_type, DT_DIR, DT_LNK))
|
2012-01-10 01:34:15 +01:00
|
|
|
continue;
|
2012-04-16 20:27:44 +02:00
|
|
|
if (!startswith(dent->d_name, "host"))
|
2012-01-10 01:34:15 +01:00
|
|
|
continue;
|
|
|
|
i = strtoul(&dent->d_name[4], &rest, 10);
|
|
|
|
if (rest[0] != '\0')
|
|
|
|
continue;
|
2012-03-13 12:55:53 +01:00
|
|
|
/*
|
|
|
|
* find the smallest number; the host really needs to export its
|
|
|
|
* own instance number per parent device; relying on the global host
|
|
|
|
* enumeration and plainly rebasing the numbers sounds unreliable
|
|
|
|
*/
|
2012-01-10 01:34:15 +01:00
|
|
|
if (basenum == -1 || i < basenum)
|
|
|
|
basenum = i;
|
|
|
|
}
|
2017-11-22 10:23:45 +01:00
|
|
|
if (basenum == -1)
|
|
|
|
return hostdev;
|
2012-01-10 01:34:15 +01:00
|
|
|
host -= basenum;
|
|
|
|
|
|
|
|
path_prepend(path, "scsi-%u:%u:%u:%u", host, bus, target, lun);
|
|
|
|
return hostdev;
|
2011-08-05 02:00:30 +02:00
|
|
|
}
|
|
|
|
|
2018-03-21 11:51:28 +01:00
|
|
|
static struct udev_device *handle_scsi_hyperv(struct udev_device *parent, char **path, size_t guid_str_len) {
|
2012-11-23 14:12:39 +01:00
|
|
|
struct udev_device *hostdev;
|
|
|
|
struct udev_device *vmbusdev;
|
|
|
|
const char *guid_str;
|
2017-11-22 10:23:45 +01:00
|
|
|
_cleanup_free_ char *lun = NULL;
|
2018-03-21 11:51:28 +01:00
|
|
|
char guid[39];
|
2012-11-23 14:12:39 +01:00
|
|
|
size_t i, k;
|
|
|
|
|
2015-06-02 16:52:07 +02:00
|
|
|
assert(parent);
|
|
|
|
assert(path);
|
2018-03-21 11:51:28 +01:00
|
|
|
assert(guid_str_len < sizeof(guid));
|
2015-06-02 16:52:07 +02:00
|
|
|
|
2012-11-23 14:12:39 +01:00
|
|
|
hostdev = udev_device_get_parent_with_subsystem_devtype(parent, "scsi", "scsi_host");
|
|
|
|
if (!hostdev)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
vmbusdev = udev_device_get_parent(hostdev);
|
|
|
|
if (!vmbusdev)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
guid_str = udev_device_get_sysattr_value(vmbusdev, "device_id");
|
|
|
|
if (!guid_str)
|
|
|
|
return NULL;
|
|
|
|
|
2018-03-21 11:51:28 +01:00
|
|
|
if (strlen(guid_str) < guid_str_len || guid_str[0] != '{' || guid_str[guid_str_len-1] != '}')
|
2012-11-23 14:12:39 +01:00
|
|
|
return NULL;
|
|
|
|
|
2018-03-21 11:51:28 +01:00
|
|
|
for (i = 1, k = 0; i < guid_str_len-1; i++) {
|
2012-11-23 14:12:39 +01:00
|
|
|
if (guid_str[i] == '-')
|
|
|
|
continue;
|
|
|
|
guid[k++] = guid_str[i];
|
|
|
|
}
|
|
|
|
guid[k] = '\0';
|
|
|
|
|
|
|
|
format_lun_number(parent, &lun);
|
|
|
|
path_prepend(path, "vmbus-%s-%s", guid, lun);
|
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
|
2014-10-28 16:50:24 +01:00
|
|
|
static struct udev_device *handle_scsi(struct udev_device *parent, char **path, bool *supported_parent) {
|
2017-11-22 10:23:45 +01:00
|
|
|
const char *devtype, *id, *name;
|
2012-01-10 01:34:15 +01:00
|
|
|
|
|
|
|
devtype = udev_device_get_devtype(parent);
|
2017-11-22 10:23:45 +01:00
|
|
|
if (!streq_ptr(devtype, "scsi_device"))
|
2012-01-10 01:34:15 +01:00
|
|
|
return parent;
|
|
|
|
|
|
|
|
/* firewire */
|
|
|
|
id = udev_device_get_sysattr_value(parent, "ieee1394_id");
|
2017-11-22 10:23:45 +01:00
|
|
|
if (id) {
|
2012-01-10 01:34:15 +01:00
|
|
|
path_prepend(path, "ieee1394-0x%s", id);
|
2014-10-28 16:50:24 +01:00
|
|
|
*supported_parent = true;
|
2017-11-22 10:23:45 +01:00
|
|
|
return skip_subsystem(parent, "scsi");
|
2012-01-10 01:34:15 +01:00
|
|
|
}
|
|
|
|
|
2013-01-17 00:00:02 +01:00
|
|
|
/* scsi sysfs does not have a "subsystem" for the transport */
|
2012-01-10 01:34:15 +01:00
|
|
|
name = udev_device_get_syspath(parent);
|
|
|
|
|
2017-11-22 10:23:45 +01:00
|
|
|
if (strstr(name, "/rport-")) {
|
2014-10-28 16:50:24 +01:00
|
|
|
*supported_parent = true;
|
2017-11-22 10:23:45 +01:00
|
|
|
return handle_scsi_fibre_channel(parent, path);
|
2012-01-10 01:34:15 +01:00
|
|
|
}
|
|
|
|
|
2017-11-22 10:23:45 +01:00
|
|
|
if (strstr(name, "/end_device-")) {
|
2014-10-28 16:50:24 +01:00
|
|
|
*supported_parent = true;
|
2017-11-22 10:23:45 +01:00
|
|
|
return handle_scsi_sas(parent, path);
|
2012-01-10 01:34:15 +01:00
|
|
|
}
|
|
|
|
|
2017-11-22 10:23:45 +01:00
|
|
|
if (strstr(name, "/session")) {
|
2014-10-28 16:50:24 +01:00
|
|
|
*supported_parent = true;
|
2017-11-22 10:23:45 +01:00
|
|
|
return handle_scsi_iscsi(parent, path);
|
2012-01-10 01:34:15 +01:00
|
|
|
}
|
|
|
|
|
2017-11-22 10:23:45 +01:00
|
|
|
if (strstr(name, "/ata"))
|
|
|
|
return handle_scsi_ata(parent, path);
|
2012-03-12 18:40:23 +01:00
|
|
|
|
2017-11-22 10:23:45 +01:00
|
|
|
if (strstr(name, "/vmbus_"))
|
2018-03-21 11:51:28 +01:00
|
|
|
return handle_scsi_hyperv(parent, path, 37);
|
|
|
|
else if (strstr(name, "/VMBUS"))
|
|
|
|
return handle_scsi_hyperv(parent, path, 38);
|
2012-11-23 14:12:39 +01:00
|
|
|
|
2017-11-22 10:23:45 +01:00
|
|
|
return handle_scsi_default(parent, path);
|
2011-08-05 02:00:30 +02:00
|
|
|
}
|
|
|
|
|
2014-07-29 15:47:41 +02:00
|
|
|
static struct udev_device *handle_cciss(struct udev_device *parent, char **path) {
|
2012-05-10 13:18:07 +02:00
|
|
|
const char *str;
|
|
|
|
unsigned int controller, disk;
|
|
|
|
|
|
|
|
str = udev_device_get_sysname(parent);
|
|
|
|
if (sscanf(str, "c%ud%u%*s", &controller, &disk) != 2)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
path_prepend(path, "cciss-disk%u", disk);
|
2017-11-22 10:23:45 +01:00
|
|
|
return skip_subsystem(parent, "cciss");
|
2012-05-10 13:18:07 +02:00
|
|
|
}
|
|
|
|
|
2014-07-29 15:47:41 +02:00
|
|
|
static void handle_scsi_tape(struct udev_device *dev, char **path) {
|
2012-01-10 01:34:15 +01:00
|
|
|
const char *name;
|
2011-08-05 02:00:30 +02:00
|
|
|
|
2012-01-10 01:34:15 +01:00
|
|
|
/* must be the last device in the syspath */
|
2017-11-22 10:23:45 +01:00
|
|
|
if (*path)
|
2012-01-10 01:34:15 +01:00
|
|
|
return;
|
2011-08-05 02:00:30 +02:00
|
|
|
|
2012-01-10 01:34:15 +01:00
|
|
|
name = udev_device_get_sysname(dev);
|
2017-11-22 10:23:45 +01:00
|
|
|
if (startswith(name, "nst") && strchr("lma", name[3]))
|
2012-01-10 01:34:15 +01:00
|
|
|
path_prepend(path, "nst%c", name[3]);
|
2017-11-22 10:23:45 +01:00
|
|
|
else if (startswith(name, "st") && strchr("lma", name[2]))
|
2012-01-10 01:34:15 +01:00
|
|
|
path_prepend(path, "st%c", name[2]);
|
2011-08-05 02:00:30 +02:00
|
|
|
}
|
|
|
|
|
2014-07-29 15:47:41 +02:00
|
|
|
static struct udev_device *handle_usb(struct udev_device *parent, char **path) {
|
2017-11-22 10:23:45 +01:00
|
|
|
const char *devtype, *str, *port;
|
2012-01-10 01:34:15 +01:00
|
|
|
|
|
|
|
devtype = udev_device_get_devtype(parent);
|
2017-11-22 10:23:45 +01:00
|
|
|
if (!devtype)
|
2012-01-10 01:34:15 +01:00
|
|
|
return parent;
|
2017-11-22 10:23:45 +01:00
|
|
|
if (!STR_IN_SET(devtype, "usb_interface", "usb_device"))
|
2012-01-10 01:34:15 +01:00
|
|
|
return parent;
|
|
|
|
|
|
|
|
str = udev_device_get_sysname(parent);
|
|
|
|
port = strchr(str, '-');
|
2017-11-22 10:23:45 +01:00
|
|
|
if (!port)
|
2012-01-10 01:34:15 +01:00
|
|
|
return parent;
|
|
|
|
port++;
|
|
|
|
|
|
|
|
path_prepend(path, "usb-0:%s", port);
|
2017-11-22 10:23:45 +01:00
|
|
|
return skip_subsystem(parent, "usb");
|
2011-08-05 02:00:30 +02:00
|
|
|
}
|
|
|
|
|
2014-07-29 15:47:41 +02:00
|
|
|
static struct udev_device *handle_bcma(struct udev_device *parent, char **path) {
|
2013-10-26 12:22:04 +02:00
|
|
|
const char *sysname;
|
|
|
|
unsigned int core;
|
|
|
|
|
|
|
|
sysname = udev_device_get_sysname(parent);
|
|
|
|
if (sscanf(sysname, "bcma%*u:%u", &core) != 1)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
path_prepend(path, "bcma-%u", core);
|
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
|
2015-11-13 11:50:42 +01:00
|
|
|
/* Handle devices of AP bus in System z platform. */
|
|
|
|
static struct udev_device *handle_ap(struct udev_device *parent, char **path) {
|
|
|
|
const char *type, *func;
|
2012-01-10 01:34:15 +01:00
|
|
|
|
2015-06-02 16:52:07 +02:00
|
|
|
assert(parent);
|
|
|
|
assert(path);
|
|
|
|
|
2015-11-13 11:50:42 +01:00
|
|
|
type = udev_device_get_sysattr_value(parent, "type");
|
|
|
|
func = udev_device_get_sysattr_value(parent, "ap_functions");
|
2012-01-10 01:34:15 +01:00
|
|
|
|
2017-11-22 10:23:45 +01:00
|
|
|
if (type && func)
|
2015-11-13 11:50:42 +01:00
|
|
|
path_prepend(path, "ap-%s-%s", type, func);
|
2017-11-22 10:23:45 +01:00
|
|
|
else
|
|
|
|
path_prepend(path, "ap-%s", udev_device_get_sysname(parent));
|
|
|
|
|
|
|
|
return skip_subsystem(parent, "ap");
|
2011-08-05 02:00:30 +02:00
|
|
|
}
|
|
|
|
|
2014-07-29 15:47:41 +02:00
|
|
|
static int builtin_path_id(struct udev_device *dev, int argc, char *argv[], bool test) {
|
2012-01-10 01:34:15 +01:00
|
|
|
struct udev_device *parent;
|
2017-11-22 10:23:45 +01:00
|
|
|
_cleanup_free_ char *path = NULL;
|
2014-08-04 18:15:34 +02:00
|
|
|
bool supported_transport = false;
|
|
|
|
bool supported_parent = false;
|
2012-01-10 01:34:15 +01:00
|
|
|
|
2015-06-02 16:52:07 +02:00
|
|
|
assert(dev);
|
|
|
|
|
2012-01-10 01:34:15 +01:00
|
|
|
/* walk up the chain of devices and compose path */
|
|
|
|
parent = dev;
|
2017-11-22 10:23:45 +01:00
|
|
|
while (parent) {
|
2012-01-10 01:34:15 +01:00
|
|
|
const char *subsys;
|
|
|
|
|
|
|
|
subsys = udev_device_get_subsystem(parent);
|
2017-11-22 10:23:45 +01:00
|
|
|
if (!subsys) {
|
2012-01-10 01:34:15 +01:00
|
|
|
;
|
2013-02-13 18:13:22 +01:00
|
|
|
} else if (streq(subsys, "scsi_tape")) {
|
2012-01-10 01:34:15 +01:00
|
|
|
handle_scsi_tape(parent, &path);
|
2013-02-13 18:13:22 +01:00
|
|
|
} else if (streq(subsys, "scsi")) {
|
2014-10-28 16:50:24 +01:00
|
|
|
parent = handle_scsi(parent, &path, &supported_parent);
|
2014-08-04 18:15:34 +02:00
|
|
|
supported_transport = true;
|
2013-02-13 18:13:22 +01:00
|
|
|
} else if (streq(subsys, "cciss")) {
|
2012-05-10 13:18:07 +02:00
|
|
|
parent = handle_cciss(parent, &path);
|
2014-08-04 18:15:34 +02:00
|
|
|
supported_transport = true;
|
2013-02-13 18:13:22 +01:00
|
|
|
} else if (streq(subsys, "usb")) {
|
2012-01-10 01:34:15 +01:00
|
|
|
parent = handle_usb(parent, &path);
|
2014-08-04 18:15:34 +02:00
|
|
|
supported_transport = true;
|
2013-10-26 12:22:04 +02:00
|
|
|
} else if (streq(subsys, "bcma")) {
|
|
|
|
parent = handle_bcma(parent, &path);
|
2014-08-04 18:15:34 +02:00
|
|
|
supported_transport = true;
|
2013-02-13 18:13:22 +01:00
|
|
|
} else if (streq(subsys, "serio")) {
|
2012-01-10 01:34:15 +01:00
|
|
|
path_prepend(&path, "serio-%s", udev_device_get_sysnum(parent));
|
|
|
|
parent = skip_subsystem(parent, "serio");
|
2013-02-13 18:13:22 +01:00
|
|
|
} else if (streq(subsys, "pci")) {
|
2012-01-10 01:34:15 +01:00
|
|
|
path_prepend(&path, "pci-%s", udev_device_get_sysname(parent));
|
|
|
|
parent = skip_subsystem(parent, "pci");
|
2014-08-04 18:15:34 +02:00
|
|
|
supported_parent = true;
|
2013-02-13 18:13:22 +01:00
|
|
|
} else if (streq(subsys, "platform")) {
|
2012-01-10 01:34:15 +01:00
|
|
|
path_prepend(&path, "platform-%s", udev_device_get_sysname(parent));
|
|
|
|
parent = skip_subsystem(parent, "platform");
|
2014-08-04 18:15:34 +02:00
|
|
|
supported_transport = true;
|
|
|
|
supported_parent = true;
|
2013-02-13 18:13:22 +01:00
|
|
|
} else if (streq(subsys, "acpi")) {
|
2012-01-10 01:34:15 +01:00
|
|
|
path_prepend(&path, "acpi-%s", udev_device_get_sysname(parent));
|
|
|
|
parent = skip_subsystem(parent, "acpi");
|
2014-08-04 18:15:34 +02:00
|
|
|
supported_parent = true;
|
2013-02-13 18:13:22 +01:00
|
|
|
} else if (streq(subsys, "xen")) {
|
2012-01-10 01:34:15 +01:00
|
|
|
path_prepend(&path, "xen-%s", udev_device_get_sysname(parent));
|
|
|
|
parent = skip_subsystem(parent, "xen");
|
2014-08-04 18:15:34 +02:00
|
|
|
supported_parent = true;
|
2016-02-09 09:57:45 +01:00
|
|
|
} else if (streq(subsys, "virtio")) {
|
2017-03-01 21:30:17 +01:00
|
|
|
parent = skip_subsystem(parent, "virtio");
|
2016-02-09 09:57:45 +01:00
|
|
|
supported_transport = true;
|
2013-02-13 18:13:22 +01:00
|
|
|
} else if (streq(subsys, "scm")) {
|
2012-10-09 15:57:54 +02:00
|
|
|
path_prepend(&path, "scm-%s", udev_device_get_sysname(parent));
|
|
|
|
parent = skip_subsystem(parent, "scm");
|
2014-08-04 18:15:34 +02:00
|
|
|
supported_transport = true;
|
|
|
|
supported_parent = true;
|
2015-11-13 11:50:42 +01:00
|
|
|
} else if (streq(subsys, "ccw")) {
|
|
|
|
path_prepend(&path, "ccw-%s", udev_device_get_sysname(parent));
|
|
|
|
parent = skip_subsystem(parent, "ccw");
|
|
|
|
supported_transport = true;
|
|
|
|
supported_parent = true;
|
|
|
|
} else if (streq(subsys, "ccwgroup")) {
|
|
|
|
path_prepend(&path, "ccwgroup-%s", udev_device_get_sysname(parent));
|
|
|
|
parent = skip_subsystem(parent, "ccwgroup");
|
|
|
|
supported_transport = true;
|
|
|
|
supported_parent = true;
|
|
|
|
} else if (streq(subsys, "ap")) {
|
|
|
|
parent = handle_ap(parent, &path);
|
|
|
|
supported_transport = true;
|
|
|
|
supported_parent = true;
|
|
|
|
} else if (streq(subsys, "iucv")) {
|
|
|
|
path_prepend(&path, "iucv-%s", udev_device_get_sysname(parent));
|
|
|
|
parent = skip_subsystem(parent, "iucv");
|
|
|
|
supported_transport = true;
|
|
|
|
supported_parent = true;
|
2016-09-26 21:01:07 +02:00
|
|
|
} else if (streq(subsys, "nvme")) {
|
|
|
|
const char *nsid = udev_device_get_sysattr_value(dev, "nsid");
|
|
|
|
|
|
|
|
if (nsid) {
|
|
|
|
path_prepend(&path, "nvme-%s", nsid);
|
|
|
|
parent = skip_subsystem(parent, "nvme");
|
|
|
|
supported_parent = true;
|
|
|
|
supported_transport = true;
|
|
|
|
}
|
2012-01-10 01:34:15 +01:00
|
|
|
}
|
|
|
|
|
2015-06-02 16:53:36 +02:00
|
|
|
if (parent)
|
|
|
|
parent = udev_device_get_parent(parent);
|
2012-01-10 01:34:15 +01:00
|
|
|
}
|
2012-05-07 18:47:58 +02:00
|
|
|
|
2017-11-22 10:23:45 +01:00
|
|
|
if (!path)
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
2012-05-07 18:47:58 +02:00
|
|
|
/*
|
2014-10-30 01:18:34 +01:00
|
|
|
* Do not return devices with an unknown parent device type. They
|
|
|
|
* might produce conflicting IDs if the parent does not provide a
|
|
|
|
* unique and predictable name.
|
2012-05-07 18:47:58 +02:00
|
|
|
*/
|
2015-07-31 19:56:38 +02:00
|
|
|
if (!supported_parent)
|
2017-11-22 10:23:45 +01:00
|
|
|
return EXIT_FAILURE;
|
2014-08-04 18:15:34 +02:00
|
|
|
|
|
|
|
/*
|
2014-10-30 01:18:34 +01:00
|
|
|
* Do not return block devices without a well-known transport. Some
|
|
|
|
* devices do not expose their buses and do not provide a unique
|
|
|
|
* and predictable name that way.
|
2014-08-04 18:15:34 +02:00
|
|
|
*/
|
2016-02-19 15:21:18 +01:00
|
|
|
if (streq_ptr(udev_device_get_subsystem(dev), "block") && !supported_transport)
|
2017-11-22 10:23:45 +01:00
|
|
|
return EXIT_FAILURE;
|
2012-05-07 18:47:58 +02:00
|
|
|
|
2017-11-22 10:23:45 +01:00
|
|
|
{
|
2012-01-10 01:34:15 +01:00
|
|
|
char tag[UTIL_NAME_SIZE];
|
|
|
|
size_t i;
|
|
|
|
const char *p;
|
|
|
|
|
|
|
|
/* compose valid udev tag name */
|
|
|
|
for (p = path, i = 0; *p; p++) {
|
|
|
|
if ((*p >= '0' && *p <= '9') ||
|
|
|
|
(*p >= 'A' && *p <= 'Z') ||
|
|
|
|
(*p >= 'a' && *p <= 'z') ||
|
|
|
|
*p == '-') {
|
|
|
|
tag[i++] = *p;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* skip all leading '_' */
|
|
|
|
if (i == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* avoid second '_' */
|
|
|
|
if (tag[i-1] == '_')
|
|
|
|
continue;
|
|
|
|
|
|
|
|
tag[i++] = '_';
|
|
|
|
}
|
|
|
|
/* strip trailing '_' */
|
|
|
|
while (i > 0 && tag[i-1] == '_')
|
|
|
|
i--;
|
|
|
|
tag[i] = '\0';
|
|
|
|
|
|
|
|
udev_builtin_add_property(dev, test, "ID_PATH", path);
|
|
|
|
udev_builtin_add_property(dev, test, "ID_PATH_TAG", tag);
|
|
|
|
}
|
2017-11-22 10:23:45 +01:00
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
2011-08-05 02:00:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const struct udev_builtin udev_builtin_path_id = {
|
2012-01-10 01:34:15 +01:00
|
|
|
.name = "path_id",
|
|
|
|
.cmd = builtin_path_id,
|
2015-01-05 13:19:55 +01:00
|
|
|
.help = "Compose persistent device path",
|
2012-01-10 01:34:15 +01:00
|
|
|
.run_once = true,
|
2011-08-05 02:00:30 +02:00
|
|
|
};
|