From ac63841b827307ed6eac081c9536253d8c1fb21b Mon Sep 17 00:00:00 2001 From: green Date: Tue, 13 Jul 1999 18:44:56 +0000 Subject: Implement seekability for disk devices (not just regular files). Also, fix pos_out() to do the same checks pos_in() did. Done for: jdp, luigi, the good of the world --- bin/dd/dd.c | 7 ++++++- bin/dd/dd.h | 5 +++-- bin/dd/position.c | 12 ++++-------- 3 files changed, 13 insertions(+), 11 deletions(-) (limited to 'bin') diff --git a/bin/dd/dd.c b/bin/dd/dd.c index b817b00..b6e0ebb 100644 --- a/bin/dd/dd.c +++ b/bin/dd/dd.c @@ -46,11 +46,12 @@ 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.16 1999/04/25 21:13:33 imp Exp $"; + "$Id: dd.c,v 1.18 1999/06/20 14:58:51 green Exp $"; #endif /* not lint */ #include #include +#include #include #include @@ -224,10 +225,14 @@ getfdtype(io) IO *io; { struct mtget mt; + struct diskslices ds; struct stat sb; 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) diff --git a/bin/dd/dd.h b/bin/dd/dd.h index bc3fd60..9344d3d 100644 --- a/bin/dd/dd.h +++ b/bin/dd/dd.h @@ -35,7 +35,7 @@ * SUCH DAMAGE. * * @(#)dd.h 8.3 (Berkeley) 4/2/94 - * $Id: dd.h,v 1.8 1998/02/11 02:23:31 asami Exp $ + * $Id: dd.h,v 1.10 1999/06/20 14:58:51 green Exp $ */ /* Input/output stream state. */ @@ -49,7 +49,8 @@ typedef struct { #define ISCHR 0x01 /* character device (warn on short) */ #define ISPIPE 0x02 /* pipe (not truncatable) */ #define ISTAPE 0x04 /* tape (not seekable) */ -#define NOREAD 0x08 /* not readable */ +#define ISDISK 0x08 /* disk (valid to seek on) */ +#define NOREAD 0x10 /* not readable */ u_int flags; char *name; /* name */ diff --git a/bin/dd/position.c b/bin/dd/position.c index 7bab913..ae5191f 100644 --- a/bin/dd/position.c +++ b/bin/dd/position.c @@ -40,7 +40,7 @@ static char sccsid[] = "@(#)position.c 8.3 (Berkeley) 4/2/94"; #endif static const char rcsid[] = - "$Id: position.c,v 1.8 1998/05/13 07:33:54 charnier Exp $"; + "$Id: position.c,v 1.10 1999/06/20 14:58:55 green Exp $"; #endif /* not lint */ #include @@ -66,7 +66,7 @@ pos_in() off_t cnt; /* If not a character, pipe or tape device, try to seek on it. */ - if (!(in.flags & (ISCHR|ISPIPE|ISTAPE))) { + if (!(in.flags & (ISCHR|ISPIPE|ISTAPE)) || in.flags & ISDISK) { if (lseek(in.fd, in.offset * in.dbsz, SEEK_CUR) == -1) err(1, "%s", in.name); return; @@ -121,12 +121,8 @@ pos_out() off_t cnt; ssize_t n; - /* - * If not a tape, try seeking on the file. Seeking on a pipe is - * going to fail, but don't protect the user -- they shouldn't - * have specified the seek operand. - */ - if (!(out.flags & ISTAPE)) { + /* If not a character, pipe or tape device, try to seek on it. */ + if (!(out.flags & (ISCHR|ISPIPE|ISTAPE)) || out.flags & ISDISK) { if (lseek(out.fd, out.offset * out.dbsz, SEEK_SET) == -1) err(1, "%s", out.name); return; -- cgit v1.1