From: Arnd Bergmann <arnd@arndb.de>
To: linux-hotplug@vger.kernel.org
Subject: Re: [PATCH] udev callout for reading filesystem labels
Date: Fri, 07 May 2004 18:25:34 +0000 [thread overview]
Message-ID: <200405072025.37869.arnd@arndb.de> (raw)
In-Reply-To: <20040429210446.GA9836@vrfy.org>
[-- Attachment #1.1: Type: text/plain, Size: 1267 bytes --]
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.
>
> KERNEL="sd*", PROGRAM="/sbin/udev_volume_id -l -d", NAME="%c"
>
> Is this what you had in mind?
It is almost what I wanted. This patch goes on top of yours,
changing the following things:
- Return 0 on success again. This was probably an oversight of yours.
- Call set_label_string() to normalize the dasd label like fs labels.
- Improve set_label_string() to fix up other problems with the label
beside just trailing blanks.
- 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.
- 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 <><
[-- Attachment #1.2: 02-dasd-volume_id.patch --]
[-- Type: text/x-diff, Size: 3617 bytes --]
diff -u -r udev-025-dasdvolid/extras/volume_id/udev_volume_id.c udev-025/extras/volume_id/udev_volume_id.c
--- 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.000000000 +0200
@@ -63,7 +63,7 @@
" -t filesystem type\n"
" -l filesystem label\n"
" -u filesystem uuid\n"
- " -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[] = "htlud";
int option;
@@ -126,13 +126,11 @@
}
vid = open_classdev(class_dev);
- if (vid != NULL) {
+ if (vid != NULL && dasd == 0) {
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);
@@ -147,7 +145,7 @@
if (probe_ibm_partition(vid->fd, dasd_label) == 0) {
vid->fs_name = "dasd";
- strncpy(vid->label_string, dasd_label, 6);
+ set_label_string(vid, dasd_label, 6);
goto print;
}
@@ -175,6 +173,7 @@
printf("L:%s\n", vid->label_string);
printf("U:%s\n", vid->uuid_string);
}
+ rc = 0;
exit:
if (class_dev != NULL)
diff -u -r udev-025-dasdvolid/extras/volume_id/volume_id.c udev-025/extras/volume_id/volume_id.c
--- udev-025-dasdvolid/extras/volume_id/volume_id.c 2004-05-07 19:32:03.000000000 +0200
+++ udev-025/extras/volume_id/volume_id.c 2004-05-07 20:00:45.000000000 +0200
@@ -75,19 +75,24 @@
id->label_raw_len = count;
}
-static 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;
memcpy(id->label_string, buf, count);
- /* remove trailing whitespace */
- i = strlen(id->label_string);
+ /* remove trailing whitespace and garbage */
+ i = strnlen(id->label_string, VOLUME_ID_LABEL_SIZE);
while (i--) {
- if (! isspace(id->label_string[i]))
+ id->label_string[i+1] = '\0';
+ if (isalnum(id->label_string[i]))
break;
}
- id->label_string[i+1] = '\0';
+ /* replace remaining garbage with '_' */
+ while (i--) {
+ if (!isalnum(id->label_string[i]))
+ id->label_string[i] = '_';
+ }
}
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
--- udev-025-dasdvolid/extras/volume_id/volume_id.h 2004-05-06 02:00:26.000000000 +0200
+++ udev-025/extras/volume_id/volume_id.h 2004-05-07 20:04:05.000000000 +0200
@@ -76,4 +76,7 @@
/* free allocated device info */
extern void volume_id_close(struct volume_id *id);
+/* set the label, eliminating unprintable output */
+extern void set_label_string(struct volume_id *id, char *buf, int count);
+
#endif
--- 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 @@
# raw devices
KERNEL="raw[0-9]*", NAME="raw/%k"
+
+# s390 block devices
+KERNEL="dasd*[a-z]", PROGRAM="/sbin/udev_volume_id -d -l" RESULT="[0-9A-Z]*", SYMLINK="dasd/%c/disc dasd/%b/disc"
+KERNEL="dasd*[0-9]", PROGRAM="/sbin/udev_volume_id -d -l" RESULT="[0-9A-Z]*", SYMLINK="dasd/%c/part%n dasd/%b/part%n"
+KERNEL="dasd*[a-z]", SYMLINK="dasd/%b/disc"
+KERNEL="dasd*[0-9]", SYMLINK="dasd/%b/part%n"
+KERNEL="dcssblk*", NAME="%k", SYMLINK="dcssblk/%b"
[-- Attachment #2: signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
next prev parent reply other threads:[~2004-05-07 18:25 UTC|newest]
Thread overview: 14+ 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
2004-05-07 18:25 ` Arnd Bergmann [this message]
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-08 16:52 arndb
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=200405072025.37869.arnd@arndb.de \
--to=arnd@arndb.de \
--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).