mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-10-30 14:55:26 +03:00
[PATCH] switch major/minor to dev_t
This commit is contained in:
parent
1cec1c2416
commit
7e720bd4ad
13
namedev.c
13
namedev.c
@ -228,12 +228,12 @@ static void apply_format(struct udevice *udev, char *string, size_t maxsize,
|
|||||||
dbg("substitute kernel number '%s'", udev->kernel_number);
|
dbg("substitute kernel number '%s'", udev->kernel_number);
|
||||||
break;
|
break;
|
||||||
case 'm':
|
case 'm':
|
||||||
strintcatmax(string, udev->minor, maxsize);
|
strintcatmax(string, minor(udev->devt), maxsize);
|
||||||
dbg("substitute minor number '%u'", udev->minor);
|
dbg("substitute minor number '%u'", minor(udev->devt));
|
||||||
break;
|
break;
|
||||||
case 'M':
|
case 'M':
|
||||||
strintcatmax(string, udev->major, maxsize);
|
strintcatmax(string, major(udev->devt), maxsize);
|
||||||
dbg("substitute major number '%u'", udev->major);
|
dbg("substitute major number '%u'", major(udev->devt));
|
||||||
break;
|
break;
|
||||||
case 'c':
|
case 'c':
|
||||||
if (strlen(udev->program_result) == 0)
|
if (strlen(udev->program_result) == 0)
|
||||||
@ -317,8 +317,9 @@ static void apply_format(struct udevice *udev, char *string, size_t maxsize,
|
|||||||
case 'N':
|
case 'N':
|
||||||
if (udev->tmp_node[0] == '\0') {
|
if (udev->tmp_node[0] == '\0') {
|
||||||
dbg("create temporary device node for callout");
|
dbg("create temporary device node for callout");
|
||||||
snprintf(udev->tmp_node, NAME_SIZE-1, "%s/.tmp-%u-%u", udev_root, udev->major, udev->minor);
|
snprintf(udev->tmp_node, NAME_SIZE, "%s/.tmp-%u-%u", udev_root, major(udev->devt), minor(udev->devt));
|
||||||
udev_make_node(udev, udev->tmp_node, udev->major, udev->minor, 0600, 0, 0);
|
udev->tmp_node[NAME_SIZE] = '\0';
|
||||||
|
udev_make_node(udev, udev->tmp_node, udev->devt, 0600, 0, 0);
|
||||||
}
|
}
|
||||||
strfieldcatmax(string, udev->tmp_node, maxsize);
|
strfieldcatmax(string, udev->tmp_node, maxsize);
|
||||||
dbg("substitute temporary device node name '%s'", udev->tmp_node);
|
dbg("substitute temporary device node name '%s'", udev->tmp_node);
|
||||||
|
5
udev.h
5
udev.h
@ -58,8 +58,7 @@ struct udevice {
|
|||||||
char group[USER_SIZE];
|
char group[USER_SIZE];
|
||||||
mode_t mode;
|
mode_t mode;
|
||||||
char type;
|
char type;
|
||||||
int major;
|
dev_t devt;
|
||||||
int minor;
|
|
||||||
|
|
||||||
char devname[NAME_SIZE];
|
char devname[NAME_SIZE];
|
||||||
char tmp_node[NAME_SIZE];
|
char tmp_node[NAME_SIZE];
|
||||||
@ -79,7 +78,7 @@ extern int udev_remove_device(struct udevice *udev);
|
|||||||
extern void udev_init_config(void);
|
extern void udev_init_config(void);
|
||||||
extern int udev_start(void);
|
extern int udev_start(void);
|
||||||
extern void udev_multiplex_directory(struct udevice *udev, const char *basedir, const char *suffix);
|
extern void udev_multiplex_directory(struct udevice *udev, const char *basedir, const char *suffix);
|
||||||
extern int udev_make_node(struct udevice *udev, const char *file, int major, int minor, mode_t mode, uid_t uid, gid_t gid);
|
extern int udev_make_node(struct udevice *udev, const char *file, dev_t devt, mode_t mode, uid_t uid, gid_t gid);
|
||||||
|
|
||||||
extern char sysfs_path[SYSFS_PATH_MAX];
|
extern char sysfs_path[SYSFS_PATH_MAX];
|
||||||
extern char udev_root[PATH_MAX];
|
extern char udev_root[PATH_MAX];
|
||||||
|
43
udev_add.c
43
udev_add.c
@ -39,35 +39,15 @@
|
|||||||
#include "libsysfs/sysfs/libsysfs.h"
|
#include "libsysfs/sysfs/libsysfs.h"
|
||||||
#include "udev.h"
|
#include "udev.h"
|
||||||
#include "udev_utils.h"
|
#include "udev_utils.h"
|
||||||
|
#include "udev_sysfs.h"
|
||||||
#include "udev_version.h"
|
#include "udev_version.h"
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
#include "namedev.h"
|
#include "namedev.h"
|
||||||
#include "udev_db.h"
|
#include "udev_db.h"
|
||||||
#include "udev_selinux.h"
|
#include "udev_selinux.h"
|
||||||
|
|
||||||
/*
|
|
||||||
* the major/minor of a device is stored in a file called "dev"
|
|
||||||
* The number is stored in decimal values in the format: M:m
|
|
||||||
*/
|
|
||||||
static int get_major_minor(struct sysfs_class_device *class_dev, struct udevice *udev)
|
|
||||||
{
|
|
||||||
struct sysfs_attribute *attr = NULL;
|
|
||||||
|
|
||||||
attr = sysfs_get_classdev_attr(class_dev, "dev");
|
int udev_make_node(struct udevice *udev, const char *file, dev_t devt, mode_t mode, uid_t uid, gid_t gid)
|
||||||
if (attr == NULL)
|
|
||||||
goto error;
|
|
||||||
dbg("dev='%s'", attr->value);
|
|
||||||
|
|
||||||
if (sscanf(attr->value, "%u:%u", &udev->major, &udev->minor) != 2)
|
|
||||||
goto error;
|
|
||||||
dbg("found major=%d, minor=%d", udev->major, udev->minor);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
error:
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int udev_make_node(struct udevice *udev, const char *file, int major, int minor, mode_t mode, uid_t uid, gid_t gid)
|
|
||||||
{
|
{
|
||||||
struct stat stats;
|
struct stat stats;
|
||||||
int retval = 0;
|
int retval = 0;
|
||||||
@ -77,7 +57,7 @@ int udev_make_node(struct udevice *udev, const char *file, int major, int minor,
|
|||||||
|
|
||||||
/* preserve node with already correct numbers, to not change the inode number */
|
/* preserve node with already correct numbers, to not change the inode number */
|
||||||
if (((stats.st_mode & S_IFMT) == S_IFBLK || (stats.st_mode & S_IFMT) == S_IFCHR) &&
|
if (((stats.st_mode & S_IFMT) == S_IFBLK || (stats.st_mode & S_IFMT) == S_IFCHR) &&
|
||||||
(stats.st_rdev == makedev(major, minor))) {
|
(stats.st_rdev == devt)) {
|
||||||
dbg("preserve file '%s', cause it has correct dev_t", file);
|
dbg("preserve file '%s', cause it has correct dev_t", file);
|
||||||
selinux_setfilecon(file, udev->kernel_name, stats.st_mode);
|
selinux_setfilecon(file, udev->kernel_name, stats.st_mode);
|
||||||
goto perms;
|
goto perms;
|
||||||
@ -106,10 +86,10 @@ create:
|
|||||||
}
|
}
|
||||||
|
|
||||||
selinux_setfscreatecon(file, udev->kernel_name, mode);
|
selinux_setfscreatecon(file, udev->kernel_name, mode);
|
||||||
retval = mknod(file, mode, makedev(major, minor));
|
retval = mknod(file, mode, devt);
|
||||||
if (retval != 0) {
|
if (retval != 0) {
|
||||||
dbg("mknod(%s, %#o, %u, %u) failed with error '%s'",
|
dbg("mknod(%s, %#o, %u, %u) failed with error '%s'",
|
||||||
file, mode, major, minor, strerror(errno));
|
file, mode, major(devt), minor(devt), strerror(errno));
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,12 +165,12 @@ static int create_node(struct udevice *udev, struct sysfs_class_device *class_de
|
|||||||
|
|
||||||
if (!udev->test_run) {
|
if (!udev->test_run) {
|
||||||
info("creating device node '%s'", filename);
|
info("creating device node '%s'", filename);
|
||||||
if (udev_make_node(udev, filename, udev->major, udev->minor, udev->mode, uid, gid) != 0)
|
if (udev_make_node(udev, filename, udev->devt, udev->mode, uid, gid) != 0)
|
||||||
goto error;
|
goto error;
|
||||||
} else {
|
} else {
|
||||||
info("creating device node '%s', major = '%d', minor = '%d', "
|
info("creating device node '%s', major = '%d', minor = '%d', "
|
||||||
"mode = '%#o', uid = '%d', gid = '%d'", filename,
|
"mode = '%#o', uid = '%d', gid = '%d'", filename,
|
||||||
udev->major, udev->minor, udev->mode, uid, gid);
|
major(udev->devt), minor(udev->devt), udev->mode, uid, gid);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* create all_partitions if requested */
|
/* create all_partitions if requested */
|
||||||
@ -208,9 +188,12 @@ static int create_node(struct udevice *udev, struct sysfs_class_device *class_de
|
|||||||
info("creating device partition nodes '%s[1-%i]'", filename, udev->partitions);
|
info("creating device partition nodes '%s[1-%i]'", filename, udev->partitions);
|
||||||
if (!udev->test_run) {
|
if (!udev->test_run) {
|
||||||
for (i = 1; i <= udev->partitions; i++) {
|
for (i = 1; i <= udev->partitions; i++) {
|
||||||
|
dev_t part_devt;
|
||||||
|
|
||||||
strfieldcpy(partitionname, filename);
|
strfieldcpy(partitionname, filename);
|
||||||
strintcat(partitionname, i);
|
strintcat(partitionname, i);
|
||||||
udev_make_node(udev, partitionname, udev->major, udev->minor + i, udev->mode, uid, gid);
|
part_devt = makedev(major(udev->devt), minor(udev->devt)+1);
|
||||||
|
udev_make_node(udev, partitionname, part_devt, udev->mode, uid, gid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -295,8 +278,8 @@ int udev_add_device(struct udevice *udev, struct sysfs_class_device *class_dev)
|
|||||||
int retval = 0;
|
int retval = 0;
|
||||||
|
|
||||||
if (udev->type == 'b' || udev->type == 'c') {
|
if (udev->type == 'b' || udev->type == 'c') {
|
||||||
retval = get_major_minor(class_dev, udev);
|
udev->devt = get_devt(class_dev);
|
||||||
if (retval != 0) {
|
if (!udev->devt) {
|
||||||
dbg("no dev-file found, do nothing");
|
dbg("no dev-file found, do nothing");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,7 @@ int udev_db_add_device(struct udevice *udev)
|
|||||||
fprintf(f, "P:%s\n", udev->devpath);
|
fprintf(f, "P:%s\n", udev->devpath);
|
||||||
fprintf(f, "N:%s\n", udev->name);
|
fprintf(f, "N:%s\n", udev->name);
|
||||||
fprintf(f, "S:%s\n", udev->symlink);
|
fprintf(f, "S:%s\n", udev->symlink);
|
||||||
fprintf(f, "M:%u:%u\n", udev->major, udev->minor);
|
fprintf(f, "M:%u:%u\n", major(udev->devt), minor(udev->devt));
|
||||||
fprintf(f, "A:%u\n", udev->partitions);
|
fprintf(f, "A:%u\n", udev->partitions);
|
||||||
fprintf(f, "R:%u\n", udev->ignore_remove);
|
fprintf(f, "R:%u\n", udev->ignore_remove);
|
||||||
|
|
||||||
@ -92,6 +92,7 @@ static int parse_db_file(struct udevice *udev, const char *filename)
|
|||||||
{
|
{
|
||||||
char line[NAME_SIZE];
|
char line[NAME_SIZE];
|
||||||
char temp[NAME_SIZE];
|
char temp[NAME_SIZE];
|
||||||
|
unsigned int major, minor;
|
||||||
char *bufline;
|
char *bufline;
|
||||||
char *buf;
|
char *buf;
|
||||||
size_t bufsize;
|
size_t bufsize;
|
||||||
@ -127,7 +128,8 @@ static int parse_db_file(struct udevice *udev, const char *filename)
|
|||||||
count = NAME_SIZE-1;
|
count = NAME_SIZE-1;
|
||||||
strncpy(temp, &bufline[2], count-2);
|
strncpy(temp, &bufline[2], count-2);
|
||||||
temp[count-2] = '\0';
|
temp[count-2] = '\0';
|
||||||
sscanf(temp, "%u:%u", &udev->major, &udev->minor);
|
sscanf(temp, "%u:%u", &major, &minor);
|
||||||
|
udev->devt = makedev(major, minor);
|
||||||
break;
|
break;
|
||||||
case 'S':
|
case 'S':
|
||||||
if (count > NAME_SIZE)
|
if (count > NAME_SIZE)
|
||||||
|
@ -85,7 +85,7 @@ static int delete_node(struct udevice *udev)
|
|||||||
if (stat(filename, &stats) != 0)
|
if (stat(filename, &stats) != 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (udev->major && stats.st_rdev != makedev(udev->major, udev->minor)) {
|
if (udev->devt && stats.st_rdev != udev->devt) {
|
||||||
info("device node '%s' points to a different device, skip removal", filename);
|
info("device node '%s' points to a different device, skip removal", filename);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
17
udev_sysfs.c
17
udev_sysfs.c
@ -59,6 +59,23 @@ static const struct subsystem_file {
|
|||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
dev_t get_devt(struct sysfs_class_device *class_dev)
|
||||||
|
{
|
||||||
|
struct sysfs_attribute *attr = NULL;
|
||||||
|
unsigned int major, minor;
|
||||||
|
|
||||||
|
attr = sysfs_get_classdev_attr(class_dev, "dev");
|
||||||
|
if (attr == NULL)
|
||||||
|
return 0;
|
||||||
|
dbg("dev='%s'", attr->value);
|
||||||
|
|
||||||
|
if (sscanf(attr->value, "%u:%u", &major, &minor) != 2)
|
||||||
|
return 0;
|
||||||
|
dbg("found major=%d, minor=%d", major, minor);
|
||||||
|
|
||||||
|
return makedev(major, minor);
|
||||||
|
}
|
||||||
|
|
||||||
int subsystem_expect_no_dev(const char *subsystem)
|
int subsystem_expect_no_dev(const char *subsystem)
|
||||||
{
|
{
|
||||||
const struct subsystem_file *file;
|
const struct subsystem_file *file;
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#define WAIT_MAX_SECONDS 5
|
#define WAIT_MAX_SECONDS 5
|
||||||
#define WAIT_LOOP_PER_SECOND 20
|
#define WAIT_LOOP_PER_SECOND 20
|
||||||
|
|
||||||
|
extern dev_t get_devt(struct sysfs_class_device *class_dev);
|
||||||
extern int subsystem_expect_no_dev(const char *subsystem);
|
extern int subsystem_expect_no_dev(const char *subsystem);
|
||||||
|
|
||||||
/* /sys/class /sys/block devices */
|
/* /sys/class /sys/block devices */
|
||||||
|
Loading…
Reference in New Issue
Block a user