From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kay Sievers Date: Fri, 02 Sep 2005 00:57:33 +0000 Subject: Re: Udev support for EDD Message-Id: <20050902005733.GA10186@vrfy.org> MIME-Version: 1 Content-Type: multipart/mixed; boundary="45Z9DzgjV8m4Oswq" List-Id: References: <3177C9E428AFD2468DC6CF7F7DA63E74304AA8@ausx3mps314.aus.amer.dell.com> In-Reply-To: <3177C9E428AFD2468DC6CF7F7DA63E74304AA8@ausx3mps314.aus.amer.dell.com> To: linux-hotplug@vger.kernel.org --45Z9DzgjV8m4Oswq Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Thu, Sep 01, 2005 at 03:15:38PM -0500, John_Hull@Dell.com wrote: > I'd like to get feedback from this mailing list on a small project I've > been working on, which is adding support to udev for the persistent > naming of BIOS disk devices via EDD. EDD is mechanism to match x86 BIOS > device names (e.g. int13 device 80h) to Linux device names (e.g. > /dev/sda, /dev/hda), and a kernel module to support this was written by > Matt Domsch (see http://linux.dell.com/projects.shtml#edd for more > information). The EDD module makes device information available in > /sys/firmware/edd/int13_dev8*/, with the directory containing various > information for each device. For example, the first BIOS disk drive > would be int13_dev80, the second int13_dev81, etc. Nice to see more *_id programs. :) > My udev persistent namimg implementation for EDD results in the example > following tree: > > $ tree /dev/disk/by-bios-id > /dev/disk/by-bios-id/ > |-- int13_dev80 -> ../../sda > |-- int13_dev80part1 -> ../../sda1 > |-- int13_dev80part2 -> ../../sda2 > |-- int13_dev80part5 -> ../../sda5 > |-- int13_dev80part6 -> ../../sda6 > |-- int13_dev81 -> ../../sdb > |-- int13_dev81part1 -> ../../sdb1 > `-- int13_dev81part2 -> ../../sdb2 How about "by-firmware-id" to match the kernel sysfs name? Or putting the links just in /dev/disk/by-id/* with an edd- prefix? > To match the int13_dev8* device to the kernel block device, the > "mbr_signature" for the device exposed by EDD must be matched to the > disk signature read directly from the device by a user-space program > (signature is 4-bytes long starting at offset 0x1B8 on the disk). To > ensure that each disk can be matched to the corresponding BIOS disk, > each disk should have a unique disk signature. In my current > implementation with udev, I pass the kernel device (hd* or sd*) to a > bash script which reads its signature and then tries to match it to a > corresponding mbr_signature in the int13_dev* directories. If there is a > unique match, it returns this directory to udev, and returns nothing > otherwise. > > I have placed a rules file and the script that it calls here: > http://linux.dell.com/files/edd/udev/, as well as a Python module that > can be used to read and write the signatures. Please review my approach > and let me know how I can improve this for eventual inclusion with udev. The edd_id.sh should not check for a loaded module, otherwise it will not work with compiled in EDD, right? What is this -t option for? You need to pass an option to the program and it just checks if the option equals "disk"? I did a quick conversion to C. :) So we can use in in initramfs without all the tools needed by the shell script. Please have a look at it... Thanks, Kay --45Z9DzgjV8m4Oswq Content-Type: text/plain; charset=us-ascii Content-Disposition: inline; filename="edd-01.patch" diff --git a/extras/edd_id/Makefile b/extras/edd_id/Makefile new file mode 100644 --- /dev/null +++ b/extras/edd_id/Makefile @@ -0,0 +1,50 @@ +# Makefile for edd_id +# +# Copyright (C) 2004 Kay Sievers +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# + +PROG = edd_id + +all: $(PROG) + +prefix = +exec_prefix = ${prefix} +etcdir = ${prefix}/etc +sbindir = ${exec_prefix}/sbin +usrbindir = ${exec_prefix}/usr/bin +usrsbindir = ${exec_prefix}/usr/sbin +mandir = ${prefix}/usr/share/man +devddir = ${etcdir}/dev.d/default +configdir = ${etcdir}/udev/ +initdir = ${etcdir}/init.d/ +srcdir = . + +INSTALL = /usr/bin/install -c +INSTALL_PROGRAM = ${INSTALL} +INSTALL_DATA = ${INSTALL} -m 644 +INSTALL_SCRIPT = ${INSTALL_PROGRAM} + +OBJS = $(PROG).o $(LIBUDEV) + +$(OBJS): $(HEADERS) + +.c.o: + $(QUIET) $(CC) $(CFLAGS) -c -o $@ $< + +$(PROG): $(OBJS) $(HEADERS) + $(QUIET) $(LD) $(LDFLAGS) -o $(PROG) $(OBJS) $(LIB_OBJS) + +clean: + rm -f $(PROG) $(OBJS) + +spotless: clean + +install: all + $(INSTALL_PROGRAM) $(PROG) $(DESTDIR)$(sbindir)/$(PROG) + +uninstall: + - rm $(DESTDIR)$(sbindir)/$(PROG) diff --git a/extras/edd_id/edd_id.c b/extras/edd_id/edd_id.c new file mode 100644 --- /dev/null +++ b/extras/edd_id/edd_id.c @@ -0,0 +1,156 @@ +/* + * cdrom_id - naming of BIOS disk devices via EDD + * + * Copyright (C) 2005 John Hull + * Copyright (C) 2005 Kay Sievers + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation version 2 of the License. + * + */ + +#ifndef _GNU_SOURCE +#define _GNU_SOURCE 1 +#endif + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../../logging.h" +#include "../../udev_utils.h" + +#ifdef USE_LOG +void log_message(int priority, const char *format, ...) +{ + va_list args; + static int udev_log = -1; + + if (udev_log == -1) { + const char *value; + + value = getenv("UDEV_LOG"); + if (value) + udev_log = log_priority(value); + else + udev_log = LOG_ERR; + } + + if (priority > udev_log) + return; + + va_start(args, format); + vsyslog(priority, format, args); + va_end(args); +} +#endif + +int main(int argc, char *argv[]) +{ + const char *node = NULL; + int i; + int export = 0; + uint32_t disk_id; + struct dirent *dent; + int disk_fd; + int sysfs_fd; + DIR *dir = NULL; + int rc = 1; + + logging_init("edd_id"); + + for (i = 1 ; i < argc; i++) { + char *arg = argv[i]; + + if (strcmp(arg, "--export") == 0) { + export = 1; + } else + node = arg; + } + if (!node) { + err("no node specified"); + fprintf(stderr, "no node specified\n"); + rc = 2; + goto exit; + } + + dir = opendir("/sys/firmware/edd"); + if (!dir) { + info("no kernel EDD support"); + fprintf(stderr, "no kernel EDD support\n"); + goto exit; + } + + disk_fd = open(node, O_RDONLY); + if (disk_fd < 0) { + info("unable to open '%s'", node); + fprintf(stderr, "unable to open '%s'\n", node); + rc = 3; + goto closedir; + } + + if (lseek(disk_fd, 440, SEEK_SET) < 0) { + info("'%s' seek to signature failed", node); + rc = 4; + goto close; + } + + if (read(disk_fd, &disk_id, sizeof(disk_id)) != sizeof(disk_id)) { + info("'%s' read signature failed", node); + rc = 5; + goto close; + } + info("read id 0x%08x from '%s'", disk_id, node); + + for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) { + char file[PATH_SIZE]; + char sysfs_id_buf[256]; + uint32_t sysfs_id; + ssize_t size; + + if (dent->d_name[0] == '.') + continue; + + snprintf(file, sizeof(file), "/sys/firmware/edd/%s/mbr_signature", dent->d_name); + file[sizeof(file)-1] = '\0'; + + sysfs_fd = open(file, O_RDONLY); + if (sysfs_fd < 0) { + info("unable to open sysfs '%s'", file); + continue; + } + + size = read(sysfs_fd, sysfs_id_buf, sizeof(sysfs_id_buf)-1); + close(sysfs_fd); + if (size < 0) { + info("read sysfs '%s' failed", file); + continue; + } + sysfs_id_buf[size] = '\0'; + info("read '%s' from '%s'", sysfs_id_buf, file); + + sysfs_id = strtoul(sysfs_id_buf, NULL, 16); + if (disk_id == sysfs_id) { + if (export) + printf("ID_EDD=%s\n", dent->d_name); + else + printf("%s\n", dent->d_name); + rc = 0; + break; + } + } + +close: + close(disk_fd); +closedir: + closedir(dir); +exit: + logging_close(); + return rc; +} diff --git a/test/simple-build-check.sh b/test/simple-build-check.sh --- a/test/simple-build-check.sh +++ b/test/simple-build-check.sh @@ -8,6 +8,7 @@ EXTRAS="\ extras/usb_id \ extras/dasd_id \ extras/cdrom_id \ + extras/edd_id \ extras/floppy \ extras/run_directory \ extras/firmware" --45Z9DzgjV8m4Oswq-- ------------------------------------------------------- SF.Net email is Sponsored by the Better Software Conference & EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf _______________________________________________ Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net Linux-hotplug-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel