3
0
forked from pool/util-linux
util-linux/util-linux-2.12-multipleraw.diff

66 lines
1.4 KiB
Diff

--- disk-utils/raw.c
+++ disk-utils/raw.c
@@ -100,7 +100,7 @@
}
/*
- * It's a bind or a single query. Either way we need a raw device.
+ * It's a bind or a single query.
*/
if (optind >= argc)
@@ -108,27 +108,38 @@
raw_name = argv[optind++];
err = stat(raw_name, &statbuf);
- if (err) {
+ if (err && do_query) {
fprintf (stderr, "Cannot locate raw device '%s' (%s)\n",
raw_name, strerror(errno));
exit(2);
}
- if (!S_ISCHR(statbuf.st_mode)) {
- fprintf (stderr, "raw device '%s' is not a character dev\n",
- raw_name);
- exit(2);
- }
- if (major(statbuf.st_rdev) != RAW_MAJOR) {
- fprintf (stderr, "Device '%s' is not a raw dev\n",
- raw_name);
- exit(2);
- }
-
- raw_minor = minor(statbuf.st_rdev);
+ if (!err) {
+ if (!S_ISCHR(statbuf.st_mode)) {
+ fprintf (stderr, "raw device '%s' is not a character dev\n",
+ raw_name);
+ exit(2);
+ }
+ if (major(statbuf.st_rdev) != RAW_MAJOR) {
+ fprintf (stderr, "Device '%s' is not a raw dev\n",
+ raw_name);
+ exit(2);
+ }
- if (do_query)
- return query(raw_minor, 0);
+ raw_minor = minor(statbuf.st_rdev);
+ if (do_query)
+ return query(raw_minor, 0);
+ } else {
+ char *p;
+ p = strrchr(raw_name, '/');
+ if (p) {
+ p = strpbrk(p, "0123456789");
+ if (p)
+ raw_minor = atoi(p);
+ }
+ if (!p)
+ raw_minor = -1;
+ }
/*
* It's not a query, so we still have some parsing to do. Have