summaryrefslogtreecommitdiffstats
path: root/bin/dd
diff options
context:
space:
mode:
authorgreen <green@FreeBSD.org>1999-08-27 16:36:46 +0000
committergreen <green@FreeBSD.org>1999-08-27 16:36:46 +0000
commit1b913741fc989b87e05d87474114dad1d6572006 (patch)
tree95fdea19fde95436a1be803a933577f59b3276c7 /bin/dd
parent080e369bf20e9a57db62ba812782c46f7290d657 (diff)
downloadFreeBSD-src-1b913741fc989b87e05d87474114dad1d6572006.zip
FreeBSD-src-1b913741fc989b87e05d87474114dad1d6572006.tar.gz
Use FIODTYPE to unbogosify much of the file type checking in dd.
Diffstat (limited to 'bin/dd')
-rw-r--r--bin/dd/dd.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/bin/dd/dd.c b/bin/dd/dd.c
index b6e0ebb..ece32c4 100644
--- a/bin/dd/dd.c
+++ b/bin/dd/dd.c
@@ -46,12 +46,14 @@ static char const copyright[] =
static char sccsid[] = "@(#)dd.c 8.5 (Berkeley) 4/2/94";
#endif
static const char rcsid[] =
- "$Id: dd.c,v 1.18 1999/06/20 14:58:51 green Exp $";
+ "$Id: dd.c,v 1.19 1999/07/13 18:44:56 green Exp $";
#endif /* not lint */
#include <sys/param.h>
#include <sys/stat.h>
+#include <sys/conf.h>
#include <sys/diskslice.h>
+#include <sys/filio.h>
#include <sys/mtio.h>
#include <ctype.h>
@@ -224,19 +226,22 @@ static void
getfdtype(io)
IO *io;
{
- struct mtget mt;
- struct diskslices ds;
struct stat sb;
+ int type;
if (fstat(io->fd, &sb))
err(1, "%s", io->name);
- if ((S_ISCHR(sb.st_mode) || S_ISBLK(sb.st_mode)) &&
- ioctl(io->fd, DIOCGSLICEINFO, &ds) != -1)
- io->flags |= ISDISK;
- if (S_ISCHR(sb.st_mode))
- io->flags |= ioctl(io->fd, MTIOCGET, &mt) ? ISCHR : ISTAPE;
- else if (lseek(io->fd, (off_t)0, SEEK_CUR) == -1 && errno == ESPIPE)
- io->flags |= ISPIPE; /* XXX fixed in 4.4BSD */
+ if (S_ISCHR(sb.st_mode) || S_ISBLK(sb.st_mode)) {
+ if (ioctl(io->fd, FIODTYPE, &type) == -1)
+ err(1, "%s", io->name);
+ if (type & D_TAPE)
+ io->flags |= ISTAPE;
+ else if (type & D_DISK)
+ io->flags |= ISDISK;
+ if (S_ISCHR(sb.st_mode) && (type & D_TAPE) == 0)
+ io->flags |= ISCHR;
+ } else if (!S_ISREG(sb.st_mode))
+ io->flags |= ISPIPE;
}
static void
OpenPOWER on IntegriCloud