From mboxrd@z Thu Jan 1 00:00:00 1970 From: Arnd Bergmann Date: Fri, 07 May 2004 18:25:34 +0000 Subject: Re: [PATCH] udev callout for reading filesystem labels Message-Id: <200405072025.37869.arnd@arndb.de> MIME-Version: 1 Content-Type: multipart/mixed; boundary="Boundary-03=_hS9mAQL3V8bmpAo" List-Id: References: <20040429210446.GA9836@vrfy.org> In-Reply-To: <20040429210446.GA9836@vrfy.org> To: linux-hotplug@vger.kernel.org --Boundary-03=_hS9mAQL3V8bmpAo Content-Type: multipart/mixed; boundary="Boundary-01=_eS9mA3xgVBoW6kr" Content-Transfer-Encoding: 7bit Content-Disposition: inline --Boundary-01=_eS9mA3xgVBoW6kr Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On Friday 07 May 2004 16:02, Kay Sievers wrote: > 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. >=20 > KERNEL=3D"sd*", PROGRAM=3D"/sbin/udev_volume_id -l -d", NAME=3D"%c" >=20 > Is this what you had in mind? It is almost what I wanted. This patch goes on top of yours, changing the following things: =2D Return 0 on success again. This was probably an oversight of yours. =2D Call set_label_string() to normalize the dasd label like fs labels. =2D Improve set_label_string() to fix up other problems with the label beside just trailing blanks. =2D Don't try to look for an fs label if told to get the dasd label. Otherwise we would practically always find a valid fs signature and then no label if there is none set. This is also more consistant with the old devfs behavior that always created node by dasd label. =2D add an entry in udev.rules to actually read the dasd label (drop that if you feel it does not belong in the default config). With these changes, it's working now. Arnd <>< --Boundary-01=_eS9mA3xgVBoW6kr Content-Type: text/x-diff; charset="iso-8859-1"; name="02-dasd-volume_id.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="02-dasd-volume_id.patch" diff -u -r udev-025-dasdvolid/extras/volume_id/udev_volume_id.c udev-025/ex= tras/volume_id/udev_volume_id.c =2D-- udev-025-dasdvolid/extras/volume_id/udev_volume_id.c 2004-05-07 19:32= :03.000000000 +0200 +++ udev-025/extras/volume_id/udev_volume_id.c 2004-05-07 20:04:32.00000000= 0 +0200 @@ -63,7 +63,7 @@ " -t filesystem type\n" " -l filesystem label\n" " -u filesystem uuid\n" =2D " -d also try to read dasd label from parent device\n" + " -d read dasd label from parent device\n" "\n"; static const char short_options[] =3D "htlud"; int option; @@ -126,13 +126,11 @@ } =20 vid =3D open_classdev(class_dev); =2D if (vid !=3D NULL) { + if (vid !=3D NULL && dasd =3D=3D 0) { if (volume_id_probe(vid, ALL) =3D=3D 0) goto print; =2D } =2D =2D if (dasd =3D=3D 0) goto exit; + } =20 /* if we are on a partition, close it and open main block device */ class_dev_parent =3D sysfs_get_classdev_parent(class_dev); @@ -147,7 +145,7 @@ =20 if (probe_ibm_partition(vid->fd, dasd_label) =3D=3D 0) { vid->fs_name =3D "dasd"; =2D strncpy(vid->label_string, dasd_label, 6); + set_label_string(vid, dasd_label, 6); goto print; } =20 @@ -175,6 +173,7 @@ printf("L:%s\n", vid->label_string); printf("U:%s\n", vid->uuid_string); } + rc =3D 0; =20 exit: if (class_dev !=3D NULL) diff -u -r udev-025-dasdvolid/extras/volume_id/volume_id.c udev-025/extras/= volume_id/volume_id.c =2D-- udev-025-dasdvolid/extras/volume_id/volume_id.c 2004-05-07 19:32:03.0= 00000000 +0200 +++ udev-025/extras/volume_id/volume_id.c 2004-05-07 20:00:45.000000000 +02= 00 @@ -75,19 +75,24 @@ id->label_raw_len =3D count; } =20 =2Dstatic void set_label_string(struct volume_id *id, char *buf, int count) +void set_label_string(struct volume_id *id, char *buf, int count) { int i; =20 memcpy(id->label_string, buf, count); =20 =2D /* remove trailing whitespace */ =2D i =3D strlen(id->label_string); + /* remove trailing whitespace and garbage */ + i =3D strnlen(id->label_string, VOLUME_ID_LABEL_SIZE); while (i--) { =2D if (! isspace(id->label_string[i])) + id->label_string[i+1] =3D '\0'; + if (isalnum(id->label_string[i])) break; } =2D id->label_string[i+1] =3D '\0'; + /* replace remaining garbage with '_' */ + while (i--) { + if (!isalnum(id->label_string[i])) + id->label_string[i] =3D '_'; + } } =20 static void set_uuid(struct volume_id *id, unsigned char *buf, int count) diff -u -r udev-025-dasdvolid/extras/volume_id/volume_id.h udev-025/extras/= volume_id/volume_id.h =2D-- udev-025-dasdvolid/extras/volume_id/volume_id.h 2004-05-06 02:00:26.0= 00000000 +0200 +++ udev-025/extras/volume_id/volume_id.h 2004-05-07 20:04:05.000000000 +02= 00 @@ -76,4 +76,7 @@ /* free allocated device info */ extern void volume_id_close(struct volume_id *id); =20 +/* set the label, eliminating unprintable output */ +extern void set_label_string(struct volume_id *id, char *buf, int count); + #endif =2D-- udev-025-dasdvolid/etc/udev/udev.rules 2004-05-07 20:11:36.000000000 = +0200 +++ udev-025/etc/udev/udev.rules 2004-05-07 20:11:18.000000000 +0200 @@ -45,3 +45,10 @@ =20 # raw devices KERNEL=3D"raw[0-9]*", NAME=3D"raw/%k"=20 + +# s390 block devices +KERNEL=3D"dasd*[a-z]", PROGRAM=3D"/sbin/udev_volume_id -d -l" RESULT=3D"[0= =2D9A-Z]*", SYMLINK=3D"dasd/%c/disc dasd/%b/disc" +KERNEL=3D"dasd*[0-9]", PROGRAM=3D"/sbin/udev_volume_id -d -l" RESULT=3D"[0= =2D9A-Z]*", SYMLINK=3D"dasd/%c/part%n dasd/%b/part%n" +KERNEL=3D"dasd*[a-z]", SYMLINK=3D"dasd/%b/disc" +KERNEL=3D"dasd*[0-9]", SYMLINK=3D"dasd/%b/part%n" +KERNEL=3D"dcssblk*", NAME=3D"%k", SYMLINK=3D"dcssblk/%b" --Boundary-01=_eS9mA3xgVBoW6kr-- --Boundary-03=_hS9mAQL3V8bmpAo Content-Type: application/pgp-signature Content-Description: signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (GNU/Linux) iD8DBQBAm9Sh5t5GS2LDRf4RAt3KAJ4k4mvVbSnVsAiTYeY2JXsCnNf4bQCdHde+ Oduprc0WZ2IXc8aZCEkC1Ac= =KN/T -----END PGP SIGNATURE----- --Boundary-03=_hS9mAQL3V8bmpAo-- ------------------------------------------------------- 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