udev-builtin-path_id.c revision f073b1b3c0f4f0df1b0bd61042ce85fb5d27d407
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/*
* compose persistent device path
*
* Copyright (C) 2009-2011 Kay Sievers <kay@vrfy.org>
*
* Logic based on Hannes Reinecke's shell script.
*
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <getopt.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "alloc-util.h"
#include "string-util.h"
#include "udev.h"
char *pre;
int err = 0;
if (err < 0)
goto out;
char *new;
if (err < 0)
goto out;
} else {
}
out:
return err;
}
/*
** Linux only supports 32 bit luns.
** See drivers/scsi/scsi_scan.c::scsilun_to_int() for more details.
*/
/* address method 0, peripheral device addressing with bus id of zero */
if (lun < 256)
/* handle all other lun addressing methods by using a variant of the original lun format */
}
const char *subsystem;
break;
}
return dev;
}
struct udev_device *targetdev;
const char *port;
return NULL;
fcdev = udev_device_new_from_subsystem_sysname(udev, "fc_transport", udev_device_get_sysname(targetdev));
return NULL;
goto out;
}
out:
return parent;
}
struct udev_device *targetdev;
struct udev_device *target_parent;
struct udev_device *sasdev;
const char *sas_address;
return NULL;
if (target_parent == NULL)
return NULL;
return NULL;
if (sas_address == NULL) {
goto out;
}
out:
return parent;
}
{
struct udev_device *targetdev;
struct udev_device *target_parent;
struct udev_device *port;
struct udev_device *expander;
const char *sas_address = NULL;
const char *phy_id;
const char *phy_count;
return NULL;
if (target_parent == NULL)
return NULL;
/* Get sas device */
if (target_sasdev == NULL)
return NULL;
/* The next parent is sas port */
goto out;
}
/* Get port device */
goto out;
}
/* Check if we are simple disk */
goto out;
}
/* Get connected phy */
goto out;
}
/* The port's parent is either hba or expander */
goto out;
}
/* Get expander device */
if (expander_sasdev != NULL) {
/* Get expander's address */
"sas_address");
if (sas_address == NULL) {
goto out;
}
}
if (sas_address)
else
out:
return parent;
}
struct udev_device *transportdev;
const char *target;
char *connname;
const char *addr;
const char *port;
/* find iscsi session */
for (;;) {
if (transportdev == NULL)
return NULL;
break;
}
/* find iscsi session device */
sessiondev = udev_device_new_from_subsystem_sysname(udev, "iscsi_session", udev_device_get_sysname(transportdev));
if (sessiondev == NULL)
return NULL;
goto out;
}
goto out;
}
goto out;
}
goto out;
}
out:
return parent;
}
struct udev_device *targetdev;
struct udev_device *target_parent;
struct udev_device *atadev;
const char *port_no;
if (!targetdev)
return NULL;
if (!target_parent)
return NULL;
atadev = udev_device_new_from_subsystem_sysname(udev, "ata_port", udev_device_get_sysname(target_parent));
if (!atadev)
return NULL;
if (!port_no) {
goto out;
}
out:
return parent;
}
struct udev_device *hostdev;
const char *name;
char *base;
char *pos;
int basenum;
return NULL;
return NULL;
/*
* 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.
*
* controller directly, without the need for rebase magic like
* get into the way of this "I hope it works" logic.
*/
basenum = -1;
return NULL;
goto out;
}
pos[0] = '\0';
goto out;
}
char *rest;
int i;
continue;
continue;
continue;
if (rest[0] != '\0')
continue;
/*
* 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
*/
basenum = i;
}
if (basenum == -1) {
goto out;
}
out:
return hostdev;
}
struct udev_device *hostdev;
struct udev_device *vmbusdev;
const char *guid_str;
char guid[38];
size_t i, k;
if (!hostdev)
return NULL;
if (!vmbusdev)
return NULL;
if (!guid_str)
return NULL;
return NULL;
for (i = 1, k = 0; i < 36; i++) {
if (guid_str[i] == '-')
continue;
}
guid[k] = '\0';
return parent;
}
static struct udev_device *handle_scsi(struct udev_device *parent, char **path, bool *supported_parent) {
const char *devtype;
const char *name;
const char *id;
return parent;
/* firewire */
*supported_parent = true;
goto out;
}
/* scsi sysfs does not have a "subsystem" for the transport */
*supported_parent = true;
goto out;
}
*supported_parent = true;
goto out;
}
*supported_parent = true;
goto out;
}
goto out;
}
goto out;
}
out:
return parent;
}
const char *str;
unsigned int controller, disk;
return NULL;
return parent;
}
const char *name;
/* must be the last device in the syspath */
return;
}
const char *devtype;
const char *str;
const char *port;
return parent;
return parent;
return parent;
port++;
return parent;
}
const char *sysname;
unsigned int core;
return NULL;
return parent;
}
/* Handle devices of AP bus in System z platform. */
goto out;
}
out:
return parent;
}
struct udev_device *parent;
bool supported_transport = false;
bool supported_parent = false;
/* walk up the chain of devices and compose path */
const char *subsys;
;
supported_transport = true;
supported_transport = true;
supported_transport = true;
supported_transport = true;
supported_parent = true;
supported_transport = true;
supported_parent = true;
supported_parent = true;
supported_parent = true;
supported_transport = true;
supported_parent = true;
supported_transport = true;
supported_parent = true;
supported_transport = true;
supported_parent = true;
supported_transport = true;
supported_parent = true;
supported_transport = true;
supported_parent = true;
supported_transport = true;
supported_parent = true;
}
if (parent)
}
/*
* 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.
*/
if (!supported_parent)
/*
* 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.
*/
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 '_' */
continue;
tag[i++] = '_';
}
/* strip trailing '_' */
i--;
tag[i] = '\0';
return EXIT_SUCCESS;
}
return EXIT_FAILURE;
}
const struct udev_builtin udev_builtin_path_id = {
.name = "path_id",
.cmd = builtin_path_id,
.help = "Compose persistent device path",
.run_once = true,
};