diff options
author | Karel Zak | 2007-01-26 19:55:41 +0100 |
---|---|---|
committer | Karel Zak | 2007-01-26 19:55:41 +0100 |
commit | 34ab1590bd5001801e3417456161bd77265425f7 (patch) | |
tree | 07b8eb7f279332dd776b02c72487227cdbc99c2b /disk-utils | |
parent | raw: update man page (about dd and O_DIRECT) (diff) | |
download | kernel-qcow2-util-linux-34ab1590bd5001801e3417456161bd77265425f7.tar.gz kernel-qcow2-util-linux-34ab1590bd5001801e3417456161bd77265425f7.tar.xz kernel-qcow2-util-linux-34ab1590bd5001801e3417456161bd77265425f7.zip |
raw: don't accept raw0 as a target name
The raw0 is rawctl and cannot be used as a normal raw device. The patch
also enlarge range of <N> for raw<N> and improve the query mode.
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'disk-utils')
-rw-r--r-- | disk-utils/raw.c | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/disk-utils/raw.c b/disk-utils/raw.c index d58c58ec3..fa9e55b87 100644 --- a/disk-utils/raw.c +++ b/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; @@ -64,7 +65,7 @@ int main(int argc, char *argv[]) char * block_name; int err; int block_major, block_minor; - int i; + int i, rc; struct stat statbuf; @@ -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); } @@ -107,6 +108,20 @@ int main(int argc, char *argv[]) usage(1); raw_name = argv[optind++]; + /* + * try to check the device name before stat(), because on systems with + * udev the raw0 causes a create udev event for char 162/0, which + * causes udev to *remove* /dev/rawctl + */ + rc = sscanf(raw_name, RAWDEVDIR "raw%d", &raw_minor); + if (rc == 1 && raw_minor == 0) { + fprintf (stderr, + "Device '%s' is control raw dev " + "(use raw<N> where <N> is greater than zero)\n", + raw_name); + exit(2); + } + err = stat(raw_name, &statbuf); if (err) { fprintf (stderr, "Cannot locate raw device '%s' (%s)\n", @@ -115,7 +130,7 @@ int main(int argc, char *argv[]) } if (!S_ISCHR(statbuf.st_mode)) { - fprintf (stderr, "raw device '%s' is not a character dev\n", + fprintf (stderr, "Raw device '%s' is not a character dev\n", raw_name); exit(2); } @@ -129,7 +144,7 @@ int main(int argc, char *argv[]) if (do_query) return query(raw_minor, 0); - + /* * It's not a query, so we still have some parsing to do. Have * we been given a block device filename or a major/minor pair? @@ -193,18 +208,25 @@ 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; err = ioctl(master_fd, RAW_GETBIND, &rq); if (err < 0) { if (quiet && errno == ENODEV) return 3; - fprintf (stderr, + 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", |