util-linux/raw-handle-nonpresent-devs.patch
Stephen Tweedie 0d8034120b Update raw(8) for 2.6 kernels and udev: Handle up to 8192 raw minor devices
Don't complain when binding a raw device whose device node does not yet
    exist (udev will create it.)
2004-10-13 22:34:40 +00:00

74 lines
1.8 KiB
Diff

--- util-linux-2.12a/disk-utils/raw.c.=K0000=.orig
+++ util-linux-2.12a/disk-utils/raw.c
@@ -31,6 +31,7 @@
#endif
#define DEVFS_RAWCTLDEV "/dev/raw/rawctl"
+#define RAW_NR_MINORS 8192
char * progname;
int do_query = 0;
@@ -94,7 +95,7 @@ int main(int argc, char *argv[])
if (do_query_all) {
if (optind < argc)
usage(1);
- for (i=1; i<255; i++)
+ for (i = 1; i < RAW_NR_MINORS; i++)
query(i, 1);
exit(0);
}
@@ -109,9 +110,16 @@ int main(int argc, char *argv[])
err = stat(raw_name, &statbuf);
if (err) {
- fprintf (stderr, "Cannot locate raw device '%s' (%s)\n",
- raw_name, strerror(errno));
- exit(2);
+ int rc;
+
+ rc = sscanf(raw_name, RAWDEVDIR "raw%d", &raw_minor);
+ if (rc != 1) {
+ fprintf (stderr,
+ "Cannot locate raw device '%s' (%s)\n",
+ raw_name, strerror(errno));
+ exit(2);
+ }
+ goto skip_test_rawdev;
}
if (!S_ISCHR(statbuf.st_mode)) {
@@ -127,6 +135,7 @@ int main(int argc, char *argv[])
raw_minor = minor(statbuf.st_rdev);
+skip_test_rawdev:
if (do_query)
return query(raw_minor, 0);
@@ -193,6 +202,7 @@ void open_raw_ctl(void)
int query(int minor, int quiet)
{
struct raw_config_request rq;
+ static int has_worked = 0;
int err;
rq.raw_minor = minor;
@@ -200,11 +210,17 @@ int query(int minor, int quiet)
if (err < 0) {
if (quiet && errno == ENODEV)
return 3;
+ if (has_worked && errno == EINVAL)
+ return 0;
fprintf (stderr,
"Error querying raw device (%s)\n",
strerror(errno));
exit(3);
}
+ /* If one query has worked, mark that fact so that we don't
+ * report spurious fatal errors if raw(8) has been built to
+ * support more raw minor numbers than the kernel has. */
+ has_worked = 1;
if (quiet && !rq.block_major && !rq.block_minor)
return 0;
printf (RAWDEVDIR "raw%d: bound to major %d, minor %d\n",