[PATCH] added ability to put format specifiers in the CALLOUT program string.
This commit is contained in:
parent
e5fbfe0a13
commit
f3b04a2e0a
118
namedev.c
118
namedev.c
|
@ -487,6 +487,66 @@ static mode_t get_default_mode(struct sysfs_class_device *class_dev)
|
||||||
return 0666;
|
return 0666;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void build_kernel_number(struct sysfs_class_device *class_dev, struct udevice *udev)
|
||||||
|
{
|
||||||
|
char *dig;
|
||||||
|
|
||||||
|
/* FIXME, figure out how to handle stuff like sdaj which will not work right now. */
|
||||||
|
dig = class_dev->name + strlen(class_dev->name);
|
||||||
|
while (isdigit(*(dig-1)))
|
||||||
|
dig--;
|
||||||
|
strfieldcpy(udev->kernel_number, dig);
|
||||||
|
dbg("kernel_number = %s", udev->kernel_number);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void apply_format(struct udevice *udev, unsigned char *string)
|
||||||
|
{
|
||||||
|
char name[NAME_SIZE];
|
||||||
|
char *pos;
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
pos = strchr(string, '%');
|
||||||
|
|
||||||
|
if (pos) {
|
||||||
|
strfieldcpy(name, pos+2);
|
||||||
|
*pos = 0x00;
|
||||||
|
switch (pos[1]) {
|
||||||
|
case 'b':
|
||||||
|
if (strlen(udev->bus_id) == 0)
|
||||||
|
break;
|
||||||
|
strcat(string, udev->bus_id);
|
||||||
|
dbg("substitute bus_id '%s'", udev->bus_id);
|
||||||
|
break;
|
||||||
|
case 'n':
|
||||||
|
if (strlen(udev->kernel_number) == 0)
|
||||||
|
break;
|
||||||
|
strcat(pos, udev->kernel_number);
|
||||||
|
dbg("substitute kernel number '%s'", udev->kernel_number);
|
||||||
|
break;
|
||||||
|
case 'm':
|
||||||
|
sprintf(pos, "%u", udev->minor);
|
||||||
|
dbg("substitute minor number '%u'", udev->minor);
|
||||||
|
break;
|
||||||
|
case 'M':
|
||||||
|
sprintf(pos, "%u", udev->major);
|
||||||
|
dbg("substitute major number '%u'", udev->major);
|
||||||
|
break;
|
||||||
|
case 'c':
|
||||||
|
if (strlen(udev->callout_value) == 0)
|
||||||
|
break;
|
||||||
|
strcat(pos, udev->callout_value);
|
||||||
|
dbg("substitute callout output '%s'", udev->callout_value);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
dbg("unknown substitution type '%%%c'", pos[1]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
strcat(string, name);
|
||||||
|
} else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static int exec_callout(struct config_device *dev, char *value, int len)
|
static int exec_callout(struct config_device *dev, char *value, int len)
|
||||||
{
|
{
|
||||||
|
@ -577,7 +637,7 @@ static int exec_callout(struct config_device *dev, char *value, int len)
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int do_callout(struct sysfs_class_device *class_dev, struct udevice *udev, char *value, int len)
|
static int do_callout(struct sysfs_class_device *class_dev, struct udevice *udev)
|
||||||
{
|
{
|
||||||
struct config_device *dev;
|
struct config_device *dev;
|
||||||
struct list_head *tmp;
|
struct list_head *tmp;
|
||||||
|
@ -586,9 +646,12 @@ static int do_callout(struct sysfs_class_device *class_dev, struct udevice *udev
|
||||||
dev = list_entry(tmp, struct config_device, node);
|
dev = list_entry(tmp, struct config_device, node);
|
||||||
if (dev->type != CALLOUT)
|
if (dev->type != CALLOUT)
|
||||||
continue;
|
continue;
|
||||||
if (exec_callout(dev, value, len))
|
|
||||||
|
/* substitute anything that needs to be in the program name */
|
||||||
|
apply_format(udev, dev->exec_program);
|
||||||
|
if (exec_callout(dev, udev->callout_value, NAME_SIZE))
|
||||||
continue;
|
continue;
|
||||||
if (strncmp_wildcard(value, dev->id, len) != 0)
|
if (strncmp_wildcard(udev->callout_value, dev->id, NAME_SIZE) != 0)
|
||||||
continue;
|
continue;
|
||||||
strfieldcpy(udev->name, dev->name);
|
strfieldcpy(udev->name, dev->name);
|
||||||
if (dev->mode != 0) {
|
if (dev->mode != 0) {
|
||||||
|
@ -808,7 +871,6 @@ static int get_attr(struct sysfs_class_device *class_dev, struct udevice *udev)
|
||||||
struct sysfs_class_device *class_dev_parent = NULL;
|
struct sysfs_class_device *class_dev_parent = NULL;
|
||||||
int retval = 0;
|
int retval = 0;
|
||||||
char *temp = NULL;
|
char *temp = NULL;
|
||||||
char value[ID_SIZE];
|
|
||||||
|
|
||||||
udev->mode = 0;
|
udev->mode = 0;
|
||||||
|
|
||||||
|
@ -846,12 +908,15 @@ static int get_attr(struct sysfs_class_device *class_dev, struct udevice *udev)
|
||||||
if (sysfs_device) {
|
if (sysfs_device) {
|
||||||
dbg_parse("sysfs_device->path='%s'", sysfs_device->path);
|
dbg_parse("sysfs_device->path='%s'", sysfs_device->path);
|
||||||
dbg_parse("sysfs_device->bus_id='%s'", sysfs_device->bus_id);
|
dbg_parse("sysfs_device->bus_id='%s'", sysfs_device->bus_id);
|
||||||
|
strfieldcpy(udev->bus_id, sysfs_device->bus_id);
|
||||||
} else {
|
} else {
|
||||||
dbg_parse("class_dev->name = '%s'", class_dev->name);
|
dbg_parse("class_dev->name = '%s'", class_dev->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
build_kernel_number(class_dev, udev);
|
||||||
|
|
||||||
/* rules are looked at in priority order */
|
/* rules are looked at in priority order */
|
||||||
retval = do_callout(class_dev, udev, value, sizeof(value));
|
retval = do_callout(class_dev, udev);
|
||||||
if (retval == 0)
|
if (retval == 0)
|
||||||
goto found;
|
goto found;
|
||||||
|
|
||||||
|
@ -876,48 +941,7 @@ static int get_attr(struct sysfs_class_device *class_dev, struct udevice *udev)
|
||||||
|
|
||||||
found:
|
found:
|
||||||
/* substitute placeholder in NAME */
|
/* substitute placeholder in NAME */
|
||||||
while (1) {
|
apply_format(udev, udev->name);
|
||||||
char *pos = strchr(udev->name, '%');
|
|
||||||
char *dig;
|
|
||||||
char name[NAME_SIZE];
|
|
||||||
|
|
||||||
if (pos) {
|
|
||||||
strfieldcpy(name, pos+2);
|
|
||||||
*pos = 0x00;
|
|
||||||
switch (pos[1]) {
|
|
||||||
case 'b':
|
|
||||||
if (!sysfs_device)
|
|
||||||
break;
|
|
||||||
strcat(udev->name, sysfs_device->bus_id);
|
|
||||||
dbg("substitute bus_id '%s'", sysfs_device->bus_id);
|
|
||||||
break;
|
|
||||||
case 'n':
|
|
||||||
dig = class_dev->name + strlen(class_dev->name);
|
|
||||||
while (isdigit(*(dig-1)))
|
|
||||||
dig--;
|
|
||||||
strcat(pos, dig);
|
|
||||||
dbg("substitute kernel number '%s'", dig);
|
|
||||||
break;
|
|
||||||
case 'm':
|
|
||||||
sprintf(pos, "%u", udev->minor);
|
|
||||||
dbg("substitute minor number '%u'", udev->minor);
|
|
||||||
break;
|
|
||||||
case 'M':
|
|
||||||
sprintf(pos, "%u", udev->major);
|
|
||||||
dbg("substitute major number '%u'", udev->major);
|
|
||||||
break;
|
|
||||||
case 'c':
|
|
||||||
strcat(pos, value);
|
|
||||||
dbg("substitute callout output '%s'", value);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
dbg("unknown substitution type '%%%c'", pos[1]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
strcat(udev->name, name);
|
|
||||||
} else
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
done:
|
done:
|
||||||
/* mode was never set above */
|
/* mode was never set above */
|
||||||
|
|
|
@ -90,6 +90,15 @@ CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n special-device", ID="special--*", NAM
|
||||||
CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n special-device", ID="special-device-", NAME="%c-3-%n"
|
CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n special-device", ID="special-device-", NAME="%c-3-%n"
|
||||||
CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n special-device", ID="special-devic", NAME="%c-4-%n"
|
CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n special-device", ID="special-devic", NAME="%c-4-%n"
|
||||||
CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n special-device", ID="special-*", NAME="%c-%n"
|
CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n special-device", ID="special-*", NAME="%c-%n"
|
||||||
|
EOF
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc => "callout program subtitution",
|
||||||
|
subsys => "block",
|
||||||
|
devpath => "block/sda/sda3",
|
||||||
|
expected => "test-0:0:0:0" ,
|
||||||
|
conf => <<EOF
|
||||||
|
CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n test-%b", ID="test-*", NAME="%c"
|
||||||
EOF
|
EOF
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
@ -245,6 +245,8 @@ int udev_add_device(char *path, char *subsystem)
|
||||||
struct udevice dev;
|
struct udevice dev;
|
||||||
int retval = -EINVAL;
|
int retval = -EINVAL;
|
||||||
|
|
||||||
|
memset(&dev, 0x00, sizeof(dev));
|
||||||
|
|
||||||
/* for now, the block layer is the only place where block devices are */
|
/* for now, the block layer is the only place where block devices are */
|
||||||
if (strcmp(subsystem, "block") == 0)
|
if (strcmp(subsystem, "block") == 0)
|
||||||
dev.type = 'b';
|
dev.type = 'b';
|
||||||
|
|
6
udev.h
6
udev.h
|
@ -68,6 +68,12 @@ struct udevice {
|
||||||
int major;
|
int major;
|
||||||
int minor;
|
int minor;
|
||||||
mode_t mode;
|
mode_t mode;
|
||||||
|
|
||||||
|
/* fields that help us in building strings */
|
||||||
|
unsigned char bus_id[SYSFS_NAME_LEN];
|
||||||
|
unsigned char callout_value[NAME_SIZE];
|
||||||
|
unsigned char kernel_number[NAME_SIZE];
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#define strfieldcpy(to, from) \
|
#define strfieldcpy(to, from) \
|
||||||
|
|
Loading…
Reference in New Issue