mirror of
https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git
synced 2024-11-28 12:07:10 +01:00
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
This commit is contained in:
parent
f091c51c34
commit
ac63841b82
@ -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 <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/diskslice.h>
|
||||
#include <sys/mtio.h>
|
||||
|
||||
#include <ctype.h>
|
||||
@ -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)
|
||||
|
@ -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 */
|
||||
|
@ -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 <sys/types.h>
|
||||
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user