On Wed Feb 23 11, Garrett Cooper wrote:
> On Wed, Feb 23, 2011 at 3:36 PM, Alexander Best <arun...@freebsd.org> wrote:
> > On Wed Feb 23 11, Garrett Cooper wrote:
> >> On Feb 22, 2011, at 9:51 AM, John Baldwin wrote:
> >>
> >> > On Tuesday, February 22, 2011 11:46:05 am Garrett Cooper wrote:
> >> >> (Please bottom post)
> >> >>
> >> >> On Tue, Feb 22, 2011 at 8:31 AM, Andrew Duane <adu...@juniper.net> 
> >> >> wrote:
> >> >>> I thought seeking past EOF was valid; writing something creates a file
> >> > with a hole in it. I always assumed that was standard semantics.
> >> >>
> >> >>    That's with SET_HOLE/SET_DATA though, correct? If so, outside of
> >> >> that functionality I would assume relatively standard POSIX semantics.
> >> >
> >> > Err, no, you can always seek past EOF and then call write(2) to extend a 
> >> > file
> >> > (it does an implicit ftruncate(2)).  SEEK_HOLE and SEEK_DATA are 
> >> > different,
> >> > they are just used to discover sparse regions within a file.
> >> >
> >> > From the manpage:
> >> >
> >> >     The lseek() system call allows the file offset to be set beyond the 
> >> > end
> >> >     of the existing end-of-file of the file.  If data is later written at
> >> >     this point, subsequent reads of the data in the gap return bytes of 
> >> > zeros
> >> >     (until data is actually written into the gap).
> >>
> >>       You're correct. Linux (Fedora 13) isn't POSIX compliant (this is 
> >> from the official POSIX text):
> >>
> >> The lseek ( ) function shall allow the file offset to be set beyond the 
> >> end of the existing data in the file. If data is later written at this 
> >> point, subsequent reads of data in the gap shall return bytes with the 
> >> value 0 until data is actually written into the gap.
> >
> > so except for reading from /dev/zero freebsd also isn't posix compliant, 
> > right?
> 
> Huh...? Please better explain what you mean here.

this patch should make things a bit clearer.

cheers.
alex

> Thanks,
> -Garrett

-- 
a13x
diff --git a/sys/dev/null/null.c b/sys/dev/null/null.c
index 3005c19..a83be6f 100644
--- a/sys/dev/null/null.c
+++ b/sys/dev/null/null.c
@@ -47,11 +47,12 @@ static struct cdev *zero_dev;
 
 static d_write_t null_write;
 static d_ioctl_t null_ioctl;
+static d_read_t null_read;
 static d_read_t zero_read;
 
 static struct cdevsw null_cdevsw = {
        .d_version =    D_VERSION,
-       .d_read =       (d_read_t *)nullop,
+       .d_read =       null_read,
        .d_write =      null_write,
        .d_ioctl =      null_ioctl,
        .d_name =       "null",
@@ -71,6 +72,19 @@ static void *zbuf;
 static int
 null_write(struct cdev *dev __unused, struct uio *uio, int flags __unused)
 {
+
+       uio->uio_offset += uio->uio_resid;
+       uio->uio_resid = 0;
+
+       return (0);
+}
+
+/* ARGSUSED */
+static int
+null_read(struct cdev *dev __unused, struct uio *uio, int flags __unused)
+{
+
+       uio->uio_offset += uio->uio_resid;
        uio->uio_resid = 0;
 
        return (0);
_______________________________________________
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"

Reply via email to