udev-builtin-path_id.c revision ba86822db70d9ffd02ad78cd02b237ff8c569c7a
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek * compose persistent device path
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek * Copyright (C) 2009-2011 Kay Sievers <kay@vrfy.org>
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek * Logic based on Hannes Reinecke's shell script.
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek * This program is free software: you can redistribute it and/or modify
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek * it under the terms of the GNU General Public License as published by
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek * the Free Software Foundation, either version 2 of the License, or
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek * (at your option) any later version.
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek * This program is distributed in the hope that it will be useful,
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek * but WITHOUT ANY WARRANTY; without even the implied warranty of
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek * GNU General Public License for more details.
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek * You should have received a copy of the GNU General Public License
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek * along with this program. If not, see <http://www.gnu.org/licenses/>.
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmekstatic int path_prepend(char **path, const char *fmt, ...) {
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek err = asprintf(&new, "%s-%s", pre, *path);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek** Linux only supports 32 bit luns.
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek** See drivers/scsi/scsi_scan.c::scsilun_to_int() for more details.
26687bf8a907009dedcff79346860ed41511405eOleksii Shevchukstatic int format_lun_number(struct udev_device *dev, char **path) {
7f1ad696a273703789b624fe0b209fb63e953016Lennart Poettering unsigned long lun = strtoul(udev_device_get_sysnum(dev), NULL, 10);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek /* address method 0, peripheral device addressing with bus id of zero */
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek return path_prepend(path, "lun-%lu", lun);
2c5859afecee81e345fc9526b1083bf79990ffb8Daniel Mack /* handle all other lun addressing methods by using a variant of the original lun format */
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek return path_prepend(path, "lun-0x%04lx%04lx00000000", lun & 0xffff, (lun >> 16) & 0xffff);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmekstatic struct udev_device *skip_subsystem(struct udev_device *dev, const char *subsys) {
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek struct udev_device *parent = dev;
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek if (subsystem == NULL || !streq(subsystem, subsys))
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek parent = udev_device_get_parent(parent);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmekstatic struct udev_device *handle_scsi_fibre_channel(struct udev_device *parent, char **path) {
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek struct udev *udev = udev_device_get_udev(parent);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek struct udev_device *fcdev = NULL;
7fd1b19bc9e9f5574f2877936b8ac267c7706947Harald Hoyer const char *port;
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek targetdev = udev_device_get_parent_with_subsystem_devtype(parent, "scsi", "scsi_target");
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek fcdev = udev_device_new_from_subsystem_sysname(udev, "fc_transport", udev_device_get_sysname(targetdev));
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek port = udev_device_get_sysattr_value(fcdev, "port_name");
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek format_lun_number(parent, &lun);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek path_prepend(path, "fc-%s-%s", port, lun);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmekstatic struct udev_device *handle_scsi_sas_wide_port(struct udev_device *parent, char **path) {
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek struct udev *udev = udev_device_get_udev(parent);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek struct udev_device *target_parent;
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek targetdev = udev_device_get_parent_with_subsystem_devtype(parent, "scsi", "scsi_target");
0371ca0dac1d70b2e5060a3c4e6fbbc2bdbd8671Florian Weimer target_parent = udev_device_get_parent(targetdev);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek sasdev = udev_device_new_from_subsystem_sysname(udev, "sas_device",
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek udev_device_get_sysname(target_parent));
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek sas_address = udev_device_get_sysattr_value(sasdev, "sas_address");
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek format_lun_number(parent, &lun);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek path_prepend(path, "sas-%s-%s", sas_address, lun);
348ced909724a1331b85d57aede80a102a00e428Zbigniew Jędrzejewski-Szmekstatic struct udev_device *handle_scsi_sas(struct udev_device *parent, char **path)
348ced909724a1331b85d57aede80a102a00e428Zbigniew Jędrzejewski-Szmek struct udev *udev = udev_device_get_udev(parent);
348ced909724a1331b85d57aede80a102a00e428Zbigniew Jędrzejewski-Szmek struct udev_device *target_parent;
348ced909724a1331b85d57aede80a102a00e428Zbigniew Jędrzejewski-Szmek struct udev_device *target_sasdev = NULL;
348ced909724a1331b85d57aede80a102a00e428Zbigniew Jędrzejewski-Szmek struct udev_device *expander_sasdev = NULL;
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek struct udev_device *port_sasdev = NULL;
670b110c3b59dfa335ac43065b2038400d1d04a9Zbigniew Jędrzejewski-Szmek targetdev = udev_device_get_parent_with_subsystem_devtype(parent, "scsi", "scsi_target");
670b110c3b59dfa335ac43065b2038400d1d04a9Zbigniew Jędrzejewski-Szmek target_parent = udev_device_get_parent(targetdev);
670b110c3b59dfa335ac43065b2038400d1d04a9Zbigniew Jędrzejewski-Szmek /* Get sas device */
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek target_sasdev = udev_device_new_from_subsystem_sysname(udev,
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek "sas_device", udev_device_get_sysname(target_parent));
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek /* The next parent is sas port */
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek port = udev_device_get_parent(target_parent);
4608af4333d0f7f5f8e3bc632801b04ef07d246dLennart Poettering /* Get port device */
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek port_sasdev = udev_device_new_from_subsystem_sysname(udev,
4608af4333d0f7f5f8e3bc632801b04ef07d246dLennart Poettering "sas_port", udev_device_get_sysname(port));
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek phy_count = udev_device_get_sysattr_value(port_sasdev, "num_phys");
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek /* Check if we are simple disk */
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek if (strncmp(phy_count, "1", 2) != 0) {
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek parent = handle_scsi_sas_wide_port(parent, path);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek /* Get connected phy */
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek phy_id = udev_device_get_sysattr_value(target_sasdev, "phy_identifier");
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek /* The port's parent is either hba or expander */
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek expander = udev_device_get_parent(port);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek /* Get expander device */
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek expander_sasdev = udev_device_new_from_subsystem_sysname(udev,
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek "sas_device", udev_device_get_sysname(expander));
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek /* Get expander's address */
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek sas_address = udev_device_get_sysattr_value(expander_sasdev,
ed375bebf46c1251f4baa170b39ee93761dbdb19Zbigniew Jędrzejewski-Szmek format_lun_number(parent, &lun);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek path_prepend(path, "sas-exp%s-phy%s-%s", sas_address, phy_id, lun);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek path_prepend(path, "sas-phy%s-%s", phy_id, lun);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek udev_device_unref(target_sasdev);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek udev_device_unref(expander_sasdev);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmekstatic struct udev_device *handle_scsi_iscsi(struct udev_device *parent, char **path) {
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek struct udev *udev = udev_device_get_udev(parent);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek struct udev_device *transportdev;
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek struct udev_device *sessiondev = NULL;
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek struct udev_device *conndev = NULL;
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek /* find iscsi session */
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek transportdev = udev_device_get_parent(transportdev);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek if (startswith(udev_device_get_sysname(transportdev), "session"))
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek /* find iscsi session device */
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek sessiondev = udev_device_new_from_subsystem_sysname(udev, "iscsi_session", udev_device_get_sysname(transportdev));
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek target = udev_device_get_sysattr_value(sessiondev, "targetname");
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek if (asprintf(&connname, "connection%s:0", udev_device_get_sysnum(transportdev)) < 0) {
fc55baee9964a118afbddbf82b8e667a0ad80b99Zbigniew Jędrzejewski-Szmek conndev = udev_device_new_from_subsystem_sysname(udev, "iscsi_connection", connname);
fc55baee9964a118afbddbf82b8e667a0ad80b99Zbigniew Jędrzejewski-Szmek addr = udev_device_get_sysattr_value(conndev, "persistent_address");
fc55baee9964a118afbddbf82b8e667a0ad80b99Zbigniew Jędrzejewski-Szmek port = udev_device_get_sysattr_value(conndev, "persistent_port");
fc55baee9964a118afbddbf82b8e667a0ad80b99Zbigniew Jędrzejewski-Szmek if (addr == NULL || port == NULL) {
fc55baee9964a118afbddbf82b8e667a0ad80b99Zbigniew Jędrzejewski-Szmek format_lun_number(parent, &lun);
fc55baee9964a118afbddbf82b8e667a0ad80b99Zbigniew Jędrzejewski-Szmek path_prepend(path, "ip-%s:%s-iscsi-%s-%s", addr, port, target, lun);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmekstatic struct udev_device *handle_scsi_ata(struct udev_device *parent, char **path) {
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek struct udev *udev = udev_device_get_udev(parent);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek struct udev_device *target_parent;
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek targetdev = udev_device_get_parent_with_subsystem_devtype(parent, "scsi", "scsi_host");
fc55baee9964a118afbddbf82b8e667a0ad80b99Zbigniew Jędrzejewski-Szmek target_parent = udev_device_get_parent(targetdev);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek atadev = udev_device_new_from_subsystem_sysname(udev, "ata_port", udev_device_get_sysname(target_parent));
26687bf8a907009dedcff79346860ed41511405eOleksii Shevchuk port_no = udev_device_get_sysattr_value(atadev, "port_no");
26687bf8a907009dedcff79346860ed41511405eOleksii Shevchukstatic struct udev_device *handle_scsi_default(struct udev_device *parent, char **path) {
26687bf8a907009dedcff79346860ed41511405eOleksii Shevchuk hostdev = udev_device_get_parent_with_subsystem_devtype(parent, "scsi", "scsi_host");
63c8666b824e8762ffb73647e1caee165dfbc868Zbigniew Jędrzejewski-Szmek name = udev_device_get_sysname(parent);
63c8666b824e8762ffb73647e1caee165dfbc868Zbigniew Jędrzejewski-Szmek if (sscanf(name, "%d:%d:%d:%d", &host, &bus, &target, &lun) != 4)
63c8666b824e8762ffb73647e1caee165dfbc868Zbigniew Jędrzejewski-Szmek * Rebase host offset to get the local relative number
63c8666b824e8762ffb73647e1caee165dfbc868Zbigniew Jędrzejewski-Szmek * Note: This is by definition racy, unreliable and too simple.
63c8666b824e8762ffb73647e1caee165dfbc868Zbigniew Jędrzejewski-Szmek * Please do not copy this model anywhere. It's just a left-over
63c8666b824e8762ffb73647e1caee165dfbc868Zbigniew Jędrzejewski-Szmek * from the time we had no idea how things should look like in
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek * Making assumptions about a global in-kernel counter and use
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek * that to calculate a local offset is a very broken concept. It
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek * can only work as long as things are in strict order.
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek * The kernel needs to export the instance/port number of a
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek * controller directly, without the need for rebase magic like
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek * this. Manual driver unbind/bind, parallel hotplug/unplug will
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek * get into the way of this "I hope it works" logic.
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek base = strdup(udev_device_get_syspath(hostdev));
0c24bb2346b6b6232d67aacd5236b56ea4989de4Lennart Poettering for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
0c24bb2346b6b6232d67aacd5236b56ea4989de4Lennart Poettering if (dent->d_type != DT_DIR && dent->d_type != DT_LNK)
0c24bb2346b6b6232d67aacd5236b56ea4989de4Lennart Poettering i = strtoul(&dent->d_name[4], &rest, 10);
0c24bb2346b6b6232d67aacd5236b56ea4989de4Lennart Poettering * find the smallest number; the host really needs to export its
0c24bb2346b6b6232d67aacd5236b56ea4989de4Lennart Poettering * own instance number per parent device; relying on the global host
0c24bb2346b6b6232d67aacd5236b56ea4989de4Lennart Poettering * enumeration and plainly rebasing the numbers sounds unreliable
0c24bb2346b6b6232d67aacd5236b56ea4989de4Lennart Poettering path_prepend(path, "scsi-%u:%u:%u:%u", host, bus, target, lun);
0c24bb2346b6b6232d67aacd5236b56ea4989de4Lennart Poetteringstatic struct udev_device *handle_scsi_hyperv(struct udev_device *parent, char **path) {
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek hostdev = udev_device_get_parent_with_subsystem_devtype(parent, "scsi", "scsi_host");
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek vmbusdev = udev_device_get_parent(hostdev);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek guid_str = udev_device_get_sysattr_value(vmbusdev, "device_id");
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek if (strlen(guid_str) < 37 || guid_str[0] != '{' || guid_str[36] != '}')
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek for (i = 1, k = 0; i < 36; i++) {
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek format_lun_number(parent, &lun);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek path_prepend(path, "vmbus-%s-%s", guid, lun);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmekstatic struct udev_device *handle_scsi(struct udev_device *parent, char **path, bool *supported_parent) {
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek devtype = udev_device_get_devtype(parent);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek if (devtype == NULL || !streq(devtype, "scsi_device"))
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek id = udev_device_get_sysattr_value(parent, "ieee1394_id");
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek parent = skip_subsystem(parent, "scsi");
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek path_prepend(path, "ieee1394-0x%s", id);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek /* scsi sysfs does not have a "subsystem" for the transport */
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek name = udev_device_get_syspath(parent);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek if (strstr(name, "/rport-") != NULL) {
26687bf8a907009dedcff79346860ed41511405eOleksii Shevchuk parent = handle_scsi_fibre_channel(parent, path);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek if (strstr(name, "/end_device-") != NULL) {
e40ec7aec5e64cd0cfa5fc556d6a9747229b5794Zbigniew Jędrzejewski-Szmek parent = handle_scsi_sas(parent, path);
e40ec7aec5e64cd0cfa5fc556d6a9747229b5794Zbigniew Jędrzejewski-Szmek if (strstr(name, "/session") != NULL) {
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek parent = handle_scsi_iscsi(parent, path);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek if (strstr(name, "/ata") != NULL) {
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek parent = handle_scsi_ata(parent, path);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek if (strstr(name, "/vmbus_") != NULL) {
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek parent = handle_scsi_hyperv(parent, path);
e40ec7aec5e64cd0cfa5fc556d6a9747229b5794Zbigniew Jędrzejewski-Szmek parent = handle_scsi_default(parent, path);
d07f7b9ef2835c290d6beadebd17d15308608eeaLennart Poetteringstatic struct udev_device *handle_cciss(struct udev_device *parent, char **path) {
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek str = udev_device_get_sysname(parent);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek if (sscanf(str, "c%ud%u%*s", &controller, &disk) != 2)
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek path_prepend(path, "cciss-disk%u", disk);
968f319679d9069af037240d0c3bcd126181cdacZbigniew Jędrzejewski-Szmek parent = skip_subsystem(parent, "cciss");
968f319679d9069af037240d0c3bcd126181cdacZbigniew Jędrzejewski-Szmekstatic void handle_scsi_tape(struct udev_device *dev, char **path) {
ae018d9bc900d6355dea4af05119b49c67945184Lennart Poettering /* must be the last device in the syspath */
968f319679d9069af037240d0c3bcd126181cdacZbigniew Jędrzejewski-Szmek name = udev_device_get_sysname(dev);
968f319679d9069af037240d0c3bcd126181cdacZbigniew Jędrzejewski-Szmek if (startswith(name, "nst") && strchr("lma", name[3]) != NULL)
968f319679d9069af037240d0c3bcd126181cdacZbigniew Jędrzejewski-Szmek path_prepend(path, "nst%c", name[3]);
968f319679d9069af037240d0c3bcd126181cdacZbigniew Jędrzejewski-Szmek else if (startswith(name, "st") && strchr("lma", name[2]) != NULL)
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek path_prepend(path, "st%c", name[2]);
82499507b369fea3033a74c22813bf423301aef4Lennart Poetteringstatic struct udev_device *handle_usb(struct udev_device *parent, char **path) {
968f319679d9069af037240d0c3bcd126181cdacZbigniew Jędrzejewski-Szmek devtype = udev_device_get_devtype(parent);
ae018d9bc900d6355dea4af05119b49c67945184Lennart Poettering if (!streq(devtype, "usb_interface") && !streq(devtype, "usb_device"))
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek str = udev_device_get_sysname(parent);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek parent = skip_subsystem(parent, "usb");
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek path_prepend(path, "usb-0:%s", port);
ae018d9bc900d6355dea4af05119b49c67945184Lennart Poetteringstatic struct udev_device *handle_bcma(struct udev_device *parent, char **path) {
c2457105d76e3daf159f554a9bafb9751b23d756Holger Hans Peter Freyther sysname = udev_device_get_sysname(parent);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek if (sscanf(sysname, "bcma%*u:%u", &core) != 1)
968f319679d9069af037240d0c3bcd126181cdacZbigniew Jędrzejewski-Szmek path_prepend(path, "bcma-%u", core);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmekstatic struct udev_device *handle_ccw(struct udev_device *parent, struct udev_device *dev, char **path) {
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek scsi_dev = udev_device_get_parent_with_subsystem_devtype(dev, "scsi", "scsi_device");
3a83211689bdf4ab617a4fb79e11980c50918123Shawn Landden hba_id = udev_device_get_sysattr_value(scsi_dev, "hba_id");
3a83211689bdf4ab617a4fb79e11980c50918123Shawn Landden wwpn = udev_device_get_sysattr_value(scsi_dev, "wwpn");
3a83211689bdf4ab617a4fb79e11980c50918123Shawn Landden lun = udev_device_get_sysattr_value(scsi_dev, "fcp_lun");
3a83211689bdf4ab617a4fb79e11980c50918123Shawn Landden if (hba_id != NULL && lun != NULL && wwpn != NULL) {
3a83211689bdf4ab617a4fb79e11980c50918123Shawn Landden path_prepend(path, "ccw-%s-zfcp-%s:%s", hba_id, wwpn, lun);
0a20e3c10761378869af7bbef2733e3ae879d0f1Holger Hans Peter Freyther path_prepend(path, "ccw-%s", udev_device_get_sysname(parent));
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmekstatic int builtin_path_id(struct udev_device *dev, int argc, char *argv[], bool test) {
e9174f29c7e3ee45137537b126458718913a3ec5Lennart Poettering /* S390 ccw bus */
7027ff61a34a12487712b382a061c654acc3a679Lennart Poettering parent = udev_device_get_parent_with_subsystem_devtype(dev, "ccw", NULL);
ae018d9bc900d6355dea4af05119b49c67945184Lennart Poettering /* walk up the chain of devices and compose path */
ae018d9bc900d6355dea4af05119b49c67945184Lennart Poettering subsys = udev_device_get_subsystem(parent);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek handle_scsi_tape(parent, &path);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek parent = handle_scsi(parent, &path, &supported_parent);
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek } else if (streq(subsys, "cciss")) {
19cace379f3f680d3201cd257ab3ca6708b2d45dLennart Poettering path_prepend(&path, "serio-%s", udev_device_get_sysnum(parent));
968f319679d9069af037240d0c3bcd126181cdacZbigniew Jędrzejewski-Szmek parent = skip_subsystem(parent, "serio");
968f319679d9069af037240d0c3bcd126181cdacZbigniew Jędrzejewski-Szmek path_prepend(&path, "pci-%s", udev_device_get_sysname(parent));
19cace379f3f680d3201cd257ab3ca6708b2d45dLennart Poettering path_prepend(&path, "platform-%s", udev_device_get_sysname(parent));
ae018d9bc900d6355dea4af05119b49c67945184Lennart Poettering parent = skip_subsystem(parent, "platform");
0a244b8ecb6dfcb381fe831dc2aa9bacb2c12975Lennart Poettering path_prepend(&path, "acpi-%s", udev_device_get_sysname(parent));
2d43b190901902dbd98ccea77c1d1ddc9e2a9955Dan McGee path_prepend(&path, "xen-%s", udev_device_get_sysname(parent));
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek path_prepend(&path, "scm-%s", udev_device_get_sysname(parent));
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek parent = skip_subsystem(parent, "scm");
d682b3a7e7c7c2941a4d3e193f1e330dbc9fae89Lennart Poettering * Do not return devices with an unknown parent device type. They
d682b3a7e7c7c2941a4d3e193f1e330dbc9fae89Lennart Poettering * might produce conflicting IDs if the parent does not provide a
e7ff4e7fe9f3abd2297e4ef7b95dcb2804e051c3Greg Kroah-Hartman * unique and predictable name.
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek * Do not return block devices without a well-known transport. Some
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek * devices do not expose their buses and do not provide a unique
968f319679d9069af037240d0c3bcd126181cdacZbigniew Jędrzejewski-Szmek * and predictable name that way.
968f319679d9069af037240d0c3bcd126181cdacZbigniew Jędrzejewski-Szmek if (streq(udev_device_get_subsystem(dev), "block") && !supported_transport)
968f319679d9069af037240d0c3bcd126181cdacZbigniew Jędrzejewski-Szmek /* compose valid udev tag name */
968f319679d9069af037240d0c3bcd126181cdacZbigniew Jędrzejewski-Szmek for (p = path, i = 0; *p; p++) {
968f319679d9069af037240d0c3bcd126181cdacZbigniew Jędrzejewski-Szmek /* skip all leading '_' */
968f319679d9069af037240d0c3bcd126181cdacZbigniew Jędrzejewski-Szmek /* avoid second '_' */
968f319679d9069af037240d0c3bcd126181cdacZbigniew Jędrzejewski-Szmek /* strip trailing '_' */
968f319679d9069af037240d0c3bcd126181cdacZbigniew Jędrzejewski-Szmek while (i > 0 && tag[i-1] == '_')
968f319679d9069af037240d0c3bcd126181cdacZbigniew Jędrzejewski-Szmek udev_builtin_add_property(dev, test, "ID_PATH", path);
968f319679d9069af037240d0c3bcd126181cdacZbigniew Jędrzejewski-Szmek udev_builtin_add_property(dev, test, "ID_PATH_TAG", tag);
968f319679d9069af037240d0c3bcd126181cdacZbigniew Jędrzejewski-Szmekconst struct udev_builtin udev_builtin_path_id = {
968f319679d9069af037240d0c3bcd126181cdacZbigniew Jędrzejewski-Szmek .help = "Compose persistent device path",