Allow seeks on raw devices. A `f_offset' field is added to the file structure
which is maintained in lseek(), read() and write(), and passed along to the device's strategy routine.
This commit is contained in:
parent
3a375fb249
commit
b461ef1d17
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: lseek.c,v 1.2 1994/10/26 05:44:51 cgd Exp $ */
|
||||
/* $NetBSD: lseek.c,v 1.3 1996/06/21 20:09:03 pk Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1993
|
||||
@ -79,10 +79,23 @@ lseek(fd, offset, where)
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/* seek is not supported on raw devices */
|
||||
if (f->f_flags & F_RAW) {
|
||||
errno = EOFFSET;
|
||||
return ((off_t)-1);
|
||||
/*
|
||||
* On RAW devices, update internal offset.
|
||||
*/
|
||||
switch (where) {
|
||||
case SEEK_SET:
|
||||
f->f_offset = offset;
|
||||
break;
|
||||
case SEEK_CUR:
|
||||
f->f_offset += offset;
|
||||
break;
|
||||
case SEEK_END:
|
||||
default:
|
||||
errno = EOFFSET;
|
||||
return (-1);
|
||||
}
|
||||
return (f->f_offset);
|
||||
}
|
||||
|
||||
return (f->f_ops->seek)(f, offset, where);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: read.c,v 1.5 1995/09/14 23:45:35 pk Exp $ */
|
||||
/* $NetBSD: read.c,v 1.6 1996/06/21 20:09:04 pk Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1993
|
||||
@ -64,6 +64,7 @@
|
||||
* rights to redistribute these changes.
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
#include "stand.h"
|
||||
|
||||
ssize_t
|
||||
@ -82,9 +83,10 @@ read(fd, dest, bcount)
|
||||
if (f->f_flags & F_RAW) {
|
||||
twiddle();
|
||||
errno = (f->f_dev->dv_strategy)(f->f_devdata, F_READ,
|
||||
(daddr_t)0, bcount, dest, &resid);
|
||||
btodb(f->f_offset), bcount, dest, &resid);
|
||||
if (errno)
|
||||
return (-1);
|
||||
f->f_offset += (bcount - resid);
|
||||
return (resid);
|
||||
}
|
||||
resid = bcount;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: stand.h,v 1.13 1996/01/13 22:25:42 leo Exp $ */
|
||||
/* $NetBSD: stand.h,v 1.14 1996/06/21 20:09:06 pk Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1993
|
||||
@ -90,6 +90,7 @@ struct open_file {
|
||||
void *f_devdata; /* device specific data */
|
||||
struct fs_ops *f_ops; /* pointer to file system operations */
|
||||
void *f_fsdata; /* file system specific data */
|
||||
off_t f_offset; /* current file offset (F_RAW) */
|
||||
};
|
||||
|
||||
#define SOPEN_MAX 4
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: write.c,v 1.5 1995/09/14 23:45:41 pk Exp $ */
|
||||
/* $NetBSD: write.c,v 1.6 1996/06/21 20:09:07 pk Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1993
|
||||
@ -64,6 +64,7 @@
|
||||
* rights to redistribute these changes.
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
#include "stand.h"
|
||||
|
||||
ssize_t
|
||||
@ -82,9 +83,10 @@ write(fd, dest, bcount)
|
||||
if (f->f_flags & F_RAW) {
|
||||
twiddle();
|
||||
errno = (f->f_dev->dv_strategy)(f->f_devdata, F_WRITE,
|
||||
(daddr_t)0, bcount, dest, &resid);
|
||||
btodb(f->f_offset), bcount, dest, &resid);
|
||||
if (errno)
|
||||
return (-1);
|
||||
f->f_offset += (bcount - resid);
|
||||
return (resid);
|
||||
}
|
||||
resid = bcount;
|
||||
|
Loading…
Reference in New Issue
Block a user