From: Kay Sievers <kay.sievers@vrfy.org>
To: linux-hotplug@vger.kernel.org
Subject: Re: Re: [PATCH] udev callout for reading filesystem labels
Date: Fri, 07 May 2004 14:02:00 +0000 [thread overview]
Message-ID: <20040507140200.GA3204@vrfy.org> (raw)
In-Reply-To: <20040429210446.GA9836@vrfy.org>
[-- Attachment #1: Type: text/plain, Size: 1320 bytes --]
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 <kay.sievers@vrfy.org> 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
[-- Attachment #2: 01-dasd-volume_id.patch --]
[-- Type: text/plain, Size: 13267 bytes --]
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 = ${INSTALL_PROGRAM}
override CFLAGS+=-Wall -fno-builtin
-OBJS = volume_id.o udev_volume_id.o
-HEADERS = volume_id.h
+
+SYSFS = ../../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 = volume_id.o udev_volume_id.o dasdlabel.o $(SYSFS)
+HEADERS = volume_id.h dasdlabel.h
$(OBJS): $(HEADERS)
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 <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+
+#include "dasdlabel.h"
+
+static unsigned char EBCtoASC[256] =
+{
+/* 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 */
+ 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 ä ---- */
+ 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 ß ! $ * ) ; */
+ 0x8D, 0xE1, 0x21, 0x24, 0x2A, 0x29, 0x3B, 0xAA,
+/* 0x60 - / ---- Ä ---- ---- ---- */
+ 0x2D, 0x2F, 0x07, 0x8E, 0x07, 0x07, 0x07, 0x8F,
+/* 0x68 ---- , % _ > ? */
+ 0x80, 0xA5, 0x07, 0x2C, 0x25, 0x5F, 0x3E, 0x3F,
+/* 0x70 --- ---- ---- ---- ---- ---- ---- */
+ 0x07, 0x90, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
+/* 0x78 * ` : # @ ' = " */
+ 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 ° 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 ^ ---- § ---- */
+ 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 ---- ö ---- */
+ 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 ---- ü */
+ 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 ---- Ö ---- ---- ---- */
+ 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 ---- ---- Ü ---- ---- ---- */
+ 0x38, 0x39, 0x07, 0x07, 0x9A, 0x07, 0x07, 0x07
+};
+
+static void vtoc_ebcdic_dec (unsigned char *source, unsigned char *target, int l)
+{
+ int i;
+
+ for (i = 0; i < l; i++)
+ target[i]=EBCtoASC[(unsigned char)(source[i])];
+}
+
+/*
+ * 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] = {0,};
+ unsigned char data[16];
+
+ if (ioctl(fd, BIODASDINFO, (unsigned long)&info) != 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) != 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_volume_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 <kay.sievers@vrfy.org>
*
* sample udev rule for creation of a symlink with the filsystem uuid:
- * KERNEL="sd*", PROGRAM="/sbin/udev_volume_id -M%M -m%m -u", SYMLINK="%c"
+ * KERNEL="sd*", PROGRAM="/sbin/udev_volume_id -u", SYMLINK="%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 <stdlib.h>
#include <unistd.h>
+#include "../../udev_lib.h"
+#include "../../libsysfs/sysfs/libsysfs.h"
#include "volume_id.h"
+#include "dasdlabel.h"
-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[] = "usage: udev_volume_id -m<minor> -M<major> [-t|-l|-u]\n";
- int major = -1;
- int minor = -1;
- char *tail;
- static const char short_options[] = "M:m:htlu";
+ struct sysfs_attribute *attr;
+ int major, minor;
+
+ attr = sysfs_get_classdev_attr(class_dev, "dev");
+
+ if (attr == NULL) {
+ printf("error reading 'dev' attribute\n");
+ return NULL;
+ }
+
+ if (sscanf(attr->value, "%u:%u", &major, &minor) != 2) {
+ printf("error getting major/minor number\n");
+ return NULL;
+ }
+
+ vid = volume_id_open_dev_t(makedev(major, minor));
+ if (vid == NULL) {
+ printf("error open volume\n");
+ return NULL;
+ }
+
+ return vid;
+}
+
+int main(int argc, char *argv[])
+{
+ const char help[] = "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[] = "htlud";
int option;
+ char sysfs_path[SYSFS_PATH_MAX];
+ char dev_path[SYSFS_PATH_MAX];
+ struct sysfs_class_device *class_dev = NULL;
+ struct sysfs_class_device *class_dev_parent = NULL;
+ struct volume_id *vid = NULL;
+ char *devpath;
char print = '\0';
- int rc;
+ int dasd = 0;
+ char dasd_label[7];
+ int rc = 1;
while (1) {
@@ -46,29 +85,18 @@
break;
switch (option) {
- case 'M':
- major = (int) strtoul(optarg, &tail, 10);
- if (tail[0] != '\0') {
- printf("invalid major\n");
- exit(1);
- }
- break;
- case 'm':
- minor = (int) strtoul(optarg, &tail, 10);
- if (tail[0] != '\0') {
- printf("invalid minor\n");
- exit(1);
- }
- break;
case 't':
print = 't';
- break;
+ continue;
case 'l':
print = 'l';
- break;
+ continue;
case 'u':
print = 'u';
- break;
+ continue;
+ case 'd':
+ dasd = 1;
+ continue;
case 'h':
case '?':
default:
@@ -77,23 +105,57 @@
}
}
- if (major == -1 || minor == -1) {
- printf(help);
- exit(1);
+ devpath = getenv("DEVPATH");
+ if (devpath == NULL) {
+ printf("error DEVPATH empty\n");
+ goto exit;
}
- vid = volume_id_open_dev_t(makedev(major, minor));
- if (vid == NULL) {
- printf("error open volume\n");
- exit(1);
+ if (sysfs_get_mnt_path(sysfs_path, SYSFS_PATH_MAX) != 0) {
+ printf("error getting sysfs mount path\n");
+ goto exit;
}
- rc = volume_id_probe(vid, ALL);
- if (rc != 0) {
- printf("error probing volume\n");
- exit(1);
+ strfieldcpy(dev_path, sysfs_path);
+ strfieldcat(dev_path, devpath);
+
+ class_dev = sysfs_open_class_device_path(dev_path);
+ if (class_dev == NULL) {
+ printf("error getting class device\n");
+ goto exit;
+ }
+
+ vid = open_classdev(class_dev);
+ if (vid != NULL) {
+ if (volume_id_probe(vid, ALL) == 0)
+ goto print;
}
+ if (dasd == 0)
+ goto exit;
+
+ /* if we are on a partition, close it and open main block device */
+ class_dev_parent = sysfs_get_classdev_parent(class_dev);
+ if (class_dev_parent != NULL) {
+ volume_id_close(vid);
+ vid = open_classdev(class_dev_parent);
+ if (vid == NULL) {
+ printf("error open main block device\n");
+ goto exit;
+ }
+ }
+
+ if (probe_ibm_partition(vid->fd, dasd_label) == 0) {
+ vid->fs_name = "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);
}
- volume_id_close(vid);
-
- exit(0);
+exit:
+ if (class_dev != NULL)
+ sysfs_close_class_device(class_dev);
+ if (vid != 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];
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] = '\0';
/* create tempory node to open the block device */
+ unlink(tmp_node);
if (mknod(tmp_node, (S_IFBLK | 0600), devt) != 0)
return NULL;
next prev parent reply other threads:[~2004-05-07 14:02 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-04-29 21:04 [PATCH] udev callout for reading filesystem labels Kay Sievers
2004-04-30 13:35 ` Kevin P. Fleming
2004-04-30 14:36 ` Oliver Neukum
2004-04-30 22:29 ` Greg KH
2004-05-05 1:14 ` Kay Sievers
2004-05-05 21:24 ` Greg KH
2004-05-06 9:30 ` Arnd Bergmann
2004-05-06 20:18 ` Kay Sievers
2004-05-06 22:59 ` Kay Sievers
2004-05-07 14:02 ` Kay Sievers [this message]
2004-05-07 18:25 ` Arnd Bergmann
2004-05-07 21:52 ` Kay Sievers
2004-05-08 11:29 ` Kay Sievers
-- strict thread matches above, loose matches on Subject: below --
2004-05-06 22:44 Arnd Bergmann
2004-05-07 22:54 ` Arnd Bergmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20040507140200.GA3204@vrfy.org \
--to=kay.sievers@vrfy.org \
--cc=linux-hotplug@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).