From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kay Sievers Date: Fri, 07 May 2004 14:02:00 +0000 Subject: Re: Re: [PATCH] udev callout for reading filesystem labels Message-Id: <20040507140200.GA3204@vrfy.org> MIME-Version: 1 Content-Type: multipart/mixed; boundary="qMm9M+Fa2AknHoGS" List-Id: References: <20040429210446.GA9836@vrfy.org> In-Reply-To: <20040429210446.GA9836@vrfy.org> To: linux-hotplug@vger.kernel.org --qMm9M+Fa2AknHoGS Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Fri, May 07, 2004 at 12:59:16AM +0200, Kay Sievers wrote: > On Fri, May 07, 2004 at 12:44:01AM +0200, Arnd Bergmann wrote: > > Kay Sievers schrieb am 06.05.2004, 22:18:41: > > > On Thu, May 06, 2004 at 11:30:23AM +0200, Arnd Bergmann wrote: > > > > On Thursday 29 April 2004 23:04, Kay Sievers wrote: > > > > > > Sure, we can do this. How much code do we need, for the parsing? > > > > The attachment contains the code from the linux kernel that does > > the equivalent, somewhat adapted to user interfaces (but probably > > not functional due to lack of sleep). I'll try to do a working > > patch tomorrow. > > > > What would you do to find out the disk minor when udev is > > called for a partition of the disk? Is this handled by udev > > already or do we need additional logic in the callout program? > > Hmm, we can take libsysfs's get_parent() for the partition, to get the main > device. Hi Arnd, here is a untested first try. udev_volume_id uses libsysfs to get the major/minor numbers now and therefore relies on the DEVPATH environment variable instead of the command line options: If called with the -d option, it tries to read the dasd label from the main device too. KERNEL="sd*", PROGRAM="/sbin/udev_volume_id -l -d", NAME="%c" Is this what you had in mind? thanks, Kay --qMm9M+Fa2AknHoGS Content-Type: text/plain; charset=utf-8 Content-Disposition: inline; filename="01-dasd-volume_id.patch" Content-Transfer-Encoding: quoted-printable diff -Nru a/extras/volume_id/Makefile b/extras/volume_id/Makefile --- a/extras/volume_id/Makefile Fri May 7 15:55:58 2004 +++ b/extras/volume_id/Makefile Fri May 7 15:55:58 2004 @@ -29,8 +29,19 @@ INSTALL_SCRIPT =3D ${INSTALL_PROGRAM} =20 override CFLAGS+=3D-Wall -fno-builtin -OBJS =3D volume_id.o udev_volume_id.o -HEADERS =3D volume_id.h + +SYSFS =3D ../../libsysfs/sysfs_bus.o \ + ../../libsysfs/sysfs_class.o \ + ../../libsysfs/sysfs_device.o \ + ../../libsysfs/sysfs_dir.o \ + ../../libsysfs/sysfs_driver.o \ + ../../libsysfs/sysfs_utils.o \ + ../../libsysfs/dlist.o + + + +OBJS =3D volume_id.o udev_volume_id.o dasdlabel.o $(SYSFS) +HEADERS =3D volume_id.h dasdlabel.h =20 $(OBJS): $(HEADERS) =20 diff -Nru a/extras/volume_id/dasdlabel.c b/extras/volume_id/dasdlabel.c --- /dev/null Wed Dec 31 16:00:00 1969 +++ b/extras/volume_id/dasdlabel.c Fri May 7 15:55:58 2004 @@ -0,0 +1,163 @@ +/* + * dasdlabel.c + * + */ + + +#include +#include +#include +#include +#include +#include + +#include "dasdlabel.h" + +static unsigned char EBCtoASC[256] =3D +{ +/* 0x00 NUL SOH STX ETX *SEL HT *RNL DEL */ + 0x00, 0x01, 0x02, 0x03, 0x07, 0x09, 0x07, 0x7F, +/* 0x08 -GE -SPS -RPT VT FF CR SO SI */ + 0x07, 0x07, 0x07, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, +/* 0x10 DLE DC1 DC2 DC3 -RES -NL BS -POC + -ENP ->LF */ + 0x10, 0x11, 0x12, 0x13, 0x07, 0x0A, 0x08, 0x07, +/* 0x18 CAN EM -UBS -CU1 -IFS -IGS -IRS -ITB + -IUS */ + 0x18, 0x19, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, +/* 0x20 -DS -SOS FS -WUS -BYP LF ETB ESC + -INP */ + 0x07, 0x07, 0x1C, 0x07, 0x07, 0x0A, 0x17, 0x1B, +/* 0x28 -SA -SFE -SM -CSP -MFA ENQ ACK BEL + -SW */=20 + 0x07, 0x07, 0x07, 0x07, 0x07, 0x05, 0x06, 0x07, +/* 0x30 ---- ---- SYN -IR -PP -TRN -NBS EOT */ + 0x07, 0x07, 0x16, 0x07, 0x07, 0x07, 0x07, 0x04, +/* 0x38 -SBS -IT -RFF -CU3 DC4 NAK ---- SUB */ + 0x07, 0x07, 0x07, 0x07, 0x14, 0x15, 0x07, 0x1A, +/* 0x40 SP RSP =C3=A4 ---- */ + 0x20, 0xFF, 0x83, 0x84, 0x85, 0xA0, 0x07, 0x86, +/* 0x48 . < ( + | */ + 0x87, 0xA4, 0x9B, 0x2E, 0x3C, 0x28, 0x2B, 0x7C, +/* 0x50 & ---- */ + 0x26, 0x82, 0x88, 0x89, 0x8A, 0xA1, 0x8C, 0x07, +/* 0x58 =C3=9F ! $ * ) ; */ + 0x8D, 0xE1, 0x21, 0x24, 0x2A, 0x29, 0x3B, 0xAA, +/* 0x60 - / ---- =C3=84 ---- ---- ---- */ + 0x2D, 0x2F, 0x07, 0x8E, 0x07, 0x07, 0x07, 0x8F, +/* 0x68 ---- , % _ > ? */=20 + 0x80, 0xA5, 0x07, 0x2C, 0x25, 0x5F, 0x3E, 0x3F, +/* 0x70 --- ---- ---- ---- ---- ---- ---- */ + 0x07, 0x90, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, +/* 0x78 * ` : # @ ' =3D " */ + 0x70, 0x60, 0x3A, 0x23, 0x40, 0x27, 0x3D, 0x22, +/* 0x80 * a b c d e f g */ + 0x07, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, +/* 0x88 h i ---- ---- ---- */ + 0x68, 0x69, 0xAE, 0xAF, 0x07, 0x07, 0x07, 0xF1, +/* 0x90 =C2=B0 j k l m n o p */ + 0xF8, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, +/* 0x98 q r ---- ---- */ + 0x71, 0x72, 0xA6, 0xA7, 0x91, 0x07, 0x92, 0x07, +/* 0xA0 ~ s t u v w x */ + 0xE6, 0x7E, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, +/* 0xA8 y z ---- ---- ---- ---- */ + 0x79, 0x7A, 0xAD, 0xAB, 0x07, 0x07, 0x07, 0x07, +/* 0xB0 ^ ---- =C2=A7 ---- */ + 0x5E, 0x9C, 0x9D, 0xFA, 0x07, 0x07, 0x07, 0xAC, +/* 0xB8 ---- [ ] ---- ---- ---- ---- */ + 0xAB, 0x07, 0x5B, 0x5D, 0x07, 0x07, 0x07, 0x07, +/* 0xC0 { A B C D E F G */ + 0x7B, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, +/* 0xC8 H I ---- =C3=B6 ---- */ + 0x48, 0x49, 0x07, 0x93, 0x94, 0x95, 0xA2, 0x07, +/* 0xD0 } J K L M N O P */ + 0x7D, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, +/* 0xD8 Q R ---- =C3=BC */ + 0x51, 0x52, 0x07, 0x96, 0x81, 0x97, 0xA3, 0x98, +/* 0xE0 \ S T U V W X */ + 0x5C, 0xF6, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, +/* 0xE8 Y Z ---- =C3=96 ---- ---- ---- */ + 0x59, 0x5A, 0xFD, 0x07, 0x99, 0x07, 0x07, 0x07, +/* 0xF0 0 1 2 3 4 5 6 7 */ + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, +/* 0xF8 8 9 ---- ---- =C3=9C ---- ---- ---- */ + 0x38, 0x39, 0x07, 0x07, 0x9A, 0x07, 0x07, 0x07 +}; + +static void vtoc_ebcdic_dec (unsigned char *source, unsigned char *targe= t, int l)=20 +{ + int i; + + for (i =3D 0; i < l; i++)=20 + target[i]=3DEBCtoASC[(unsigned char)(source[i])]; +} + +/*=20 + * struct dasd_information_t + * represents any data about the data, which is visible to userspace + */ +typedef struct dasd_information_t { + unsigned int devno; /* S/390 devno */ + unsigned int real_devno; /* for aliases */ + unsigned int schid; /* S/390 subchannel identifier */ + unsigned int cu_type : 16; /* from SenseID */ + unsigned int cu_model : 8; /* from SenseID */ + unsigned int dev_type : 16; /* from SenseID */ + unsigned int dev_model : 8; /* from SenseID */ + unsigned int open_count; + unsigned int req_queue_len; + unsigned int chanq_len; /* length of chanq */ + char type[4]; /* from discipline.name, 'none' for unknown */ + unsigned int status; /* current device level */ + unsigned int label_block; /* where to find the VOLSER */ + unsigned int FBA_layout; /* fixed block size (like AIXVOL) */ + unsigned int characteristics_size; + unsigned int confdata_size; + char characteristics[64]; /* from read_device_characteristics */ + char configuration_data[256]; /* from read_configuration_data */ +} dasd_information_t; + +#define _IOC_NRBITS 8 +#define _IOC_TYPEBITS 8 +#define _IOC_SIZEBITS 14 +#define _IOC_DIRBITS 2 +#define _IOC_NRMASK ((1 << _IOC_NRBITS)-1) +#define _IOC_TYPEMASK ((1 << _IOC_TYPEBITS)-1) +#define _IOC_SIZEMASK ((1 << _IOC_SIZEBITS)-1) +#define _IOC_DIRMASK ((1 << _IOC_DIRBITS)-1) +#define _IOC_NRSHIFT 0 +#define _IOC_TYPESHIFT (_IOC_NRSHIFT+_IOC_NRBITS) +#define _IOC_SIZESHIFT (_IOC_TYPESHIFT+_IOC_TYPEBITS) +#define _IOC_DIRSHIFT (_IOC_SIZESHIFT+_IOC_SIZEBITS) +#define DASD_IOCTL_LETTER 'D' + +#define BIODASDINFO _IOR(DASD_IOCTL_LETTER,1,dasd_information_t) +#define BLKSSZGET _IO(0x12,104) + +int probe_ibm_partition(int fd, char *out) +{ + int blocksize; + dasd_information_t info; + char name[7] =3D {0,}; + unsigned char data[16]; + + if (ioctl(fd, BIODASDINFO, (unsigned long)&info) !=3D 0) + return -1; + + if (ioctl(fd, BLKSSZGET, (unsigned long)&blocksize)) + return -1; + + lseek(fd, info.label_block * blocksize, SEEK_SET); + if (read(fd, &data, 16) !=3D 16) + return -1; + + if ((!info.FBA_layout) && (!strcmp(info.type, "ECKD"))) + strncpy(name, data + 8, 6); + else + strncpy(name, data + 4, 6); + + vtoc_ebcdic_dec(name, out, 6); + + return 0; +} diff -Nru a/extras/volume_id/dasdlabel.h b/extras/volume_id/dasdlabel.h --- /dev/null Wed Dec 31 16:00:00 1969 +++ b/extras/volume_id/dasdlabel.h Fri May 7 15:55:58 2004 @@ -0,0 +1,11 @@ +/* + * dasdlabel.h + * + */ + +#ifndef _DASDLABEL_H_ +#define _DASDLABEL_H_ + +extern int probe_ibm_partition(int fd, char *out); + +#endif diff -Nru a/extras/volume_id/udev_volume_id.c b/extras/volume_id/udev_vol= ume_id.c --- a/extras/volume_id/udev_volume_id.c Fri May 7 15:55:58 2004 +++ b/extras/volume_id/udev_volume_id.c Fri May 7 15:55:58 2004 @@ -4,7 +4,7 @@ * Copyright (C) 2004 Kay Sievers * * sample udev rule for creation of a symlink with the filsystem uuid: - * KERNEL=3D"sd*", PROGRAM=3D"/sbin/udev_volume_id -M%M -m%m -u", SYMLIN= K=3D"%c" + * KERNEL=3D"sd*", PROGRAM=3D"/sbin/udev_volume_id -u", SYMLINK=3D"%c" * * 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 @@ -25,19 +25,58 @@ #include #include =20 +#include "../../udev_lib.h" +#include "../../libsysfs/sysfs/libsysfs.h" #include "volume_id.h" +#include "dasdlabel.h" =20 -int main(int argc, char *argv[]) +static struct volume_id *open_classdev(struct sysfs_class_device *class_= dev) { struct volume_id *vid; - const char help[] =3D "usage: udev_volume_id -m -M [-t|-l= |-u]\n"; - int major =3D -1; - int minor =3D -1; - char *tail; - static const char short_options[] =3D "M:m:htlu"; + struct sysfs_attribute *attr; + int major, minor; + + attr =3D sysfs_get_classdev_attr(class_dev, "dev"); + + if (attr =3D=3D NULL) { + printf("error reading 'dev' attribute\n"); + return NULL; + } + + if (sscanf(attr->value, "%u:%u", &major, &minor) !=3D 2) { + printf("error getting major/minor number\n"); + return NULL; + } + + vid =3D volume_id_open_dev_t(makedev(major, minor)); + if (vid =3D=3D NULL) { + printf("error open volume\n"); + return NULL; + } + + return vid; +} + +int main(int argc, char *argv[]) +{ + const char help[] =3D "usage: udev_volume_id [-t|-l|-u|-d]\n" + " -t filesystem type\n" + " -l filesystem label\n" + " -u filesystem uuid\n" + " -d also try to read dasd label from parent device\n" + "\n"; + static const char short_options[] =3D "htlud"; int option; + char sysfs_path[SYSFS_PATH_MAX]; + char dev_path[SYSFS_PATH_MAX]; + struct sysfs_class_device *class_dev =3D NULL; + struct sysfs_class_device *class_dev_parent =3D NULL; + struct volume_id *vid =3D NULL; + char *devpath; char print =3D '\0'; - int rc; + int dasd =3D 0; + char dasd_label[7]; + int rc =3D 1; =20 =20 while (1) { @@ -46,29 +85,18 @@ break; =20 switch (option) { - case 'M': - major =3D (int) strtoul(optarg, &tail, 10); - if (tail[0] !=3D '\0') { - printf("invalid major\n"); - exit(1); - } - break; - case 'm': - minor =3D (int) strtoul(optarg, &tail, 10); - if (tail[0] !=3D '\0') { - printf("invalid minor\n"); - exit(1); - } - break; case 't': print =3D 't'; - break; + continue; case 'l': print =3D 'l'; - break; + continue; case 'u': print =3D 'u'; - break; + continue; + case 'd': + dasd =3D 1; + continue; case 'h': case '?': default: @@ -77,23 +105,57 @@ } } =20 - if (major =3D=3D -1 || minor =3D=3D -1) { - printf(help); - exit(1); + devpath =3D getenv("DEVPATH"); + if (devpath =3D=3D NULL) { + printf("error DEVPATH empty\n"); + goto exit; } =20 - vid =3D volume_id_open_dev_t(makedev(major, minor)); - if (vid =3D=3D NULL) { - printf("error open volume\n"); - exit(1); + if (sysfs_get_mnt_path(sysfs_path, SYSFS_PATH_MAX) !=3D 0) { + printf("error getting sysfs mount path\n"); + goto exit; } =20 - rc =3D volume_id_probe(vid, ALL); - if (rc !=3D 0) { - printf("error probing volume\n"); - exit(1); + strfieldcpy(dev_path, sysfs_path); + strfieldcat(dev_path, devpath); + + class_dev =3D sysfs_open_class_device_path(dev_path); + if (class_dev =3D=3D NULL) { + printf("error getting class device\n"); + goto exit; + } + + vid =3D open_classdev(class_dev); + if (vid !=3D NULL) { + if (volume_id_probe(vid, ALL) =3D=3D 0) + goto print; } =20 + if (dasd =3D=3D 0) + goto exit; + + /* if we are on a partition, close it and open main block device */ + class_dev_parent =3D sysfs_get_classdev_parent(class_dev); + if (class_dev_parent !=3D NULL) { + volume_id_close(vid); + vid =3D open_classdev(class_dev_parent); + if (vid =3D=3D NULL) { + printf("error open main block device\n"); + goto exit; + } + } + + if (probe_ibm_partition(vid->fd, dasd_label) =3D=3D 0) { + vid->fs_name =3D "dasd"; + strncpy(vid->label_string, dasd_label, 6); + goto print; + } + + printf("unknown volume type\n"); + goto exit; + + +print: switch (print) { case 't': printf("%s\n", vid->fs_name); @@ -114,7 +176,10 @@ printf("U:%s\n", vid->uuid_string); } =20 - volume_id_close(vid); - - exit(0); +exit: + if (class_dev !=3D NULL) + sysfs_close_class_device(class_dev); + if (vid !=3D NULL) + volume_id_close(vid); + exit(rc); } diff -Nru a/extras/volume_id/volume_id.c b/extras/volume_id/volume_id.c --- a/extras/volume_id/volume_id.c Fri May 7 15:55:58 2004 +++ b/extras/volume_id/volume_id.c Fri May 7 15:55:58 2004 @@ -839,10 +839,11 @@ char tmp_node[VOLUME_ID_PATH_MAX]; =20 snprintf(tmp_node, VOLUME_ID_PATH_MAX, - "/tmp/volume-%u-%u", major(devt), minor(devt)); + "/tmp/volume-%u-%u-%u", getpid(), major(devt), minor(devt)); tmp_node[VOLUME_ID_PATH_MAX] =3D '\0'; =20 /* create tempory node to open the block device */ + unlink(tmp_node); if (mknod(tmp_node, (S_IFBLK | 0600), devt) !=3D 0) return NULL; =20 --qMm9M+Fa2AknHoGS-- ------------------------------------------------------- This SF.Net email is sponsored by Sleepycat Software Learn developer strategies Cisco, Motorola, Ericsson & Lucent use to deliver higher performing products faster, at low TCO. http://www.sleepycat.com/telcomwpreg.php?From=osdnemail3 _______________________________________________ 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