Support character device as input file.

PR:             103500
This commit is contained in:
Max Khon 2007-03-06 17:04:15 +00:00
parent d73d2e1de2
commit 27d0a1a493
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=167272

View file

@ -11,6 +11,7 @@
*/
#include <sys/types.h>
#include <sys/disk.h>
#include <sys/endian.h>
#include <sys/param.h>
#include <sys/stat.h>
@ -122,10 +123,28 @@ int main(int argc, char **argv)
signal(SIGXFSZ, exit);
atexit(cleanup);
if (stat(iname, &sb) != 0) {
err(1, "stat(%s)", iname);
fdr = open(iname, O_RDONLY);
if (fdr < 0) {
err(1, "open(%s)", iname);
/* Not reached */
}
if (fstat(fdr, &sb) != 0) {
err(1, "fstat(%s)", iname);
/* Not reached */
}
if (S_ISCHR(sb.st_mode)) {
off_t ms;
if (ioctl(fdr, DIOCGMEDIASIZE, &ms) < 0) {
err(1, "ioctl(DIOCGMEDIASIZE)");
/* Not reached */
}
sb.st_size = ms;
} else if (!S_ISREG(sb.st_mode)) {
fprintf(stderr, "%s: not a character device or regular file\n",
iname);
exit(1);
}
hdr.nblocks = sb.st_size / hdr.blksz;
if ((sb.st_size % hdr.blksz) != 0) {
if (verbose != 0)
@ -135,11 +154,6 @@ int main(int argc, char **argv)
}
toc = safe_malloc((hdr.nblocks + 1) * sizeof(*toc));
fdr = open(iname, O_RDONLY);
if (fdr < 0) {
err(1, "open(%s)", iname);
/* Not reached */
}
fdw = open(oname, O_WRONLY | O_TRUNC | O_CREAT,
S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
if (fdw < 0) {