|
Description
|
Pawel Jakub Dawidek posted this on zfs- xxxxx@xxxxx.org
On Tue, Jul 22, 2008 at 04:28:45PM +0200, Pawel Jakub Dawidek wrote:
> > Hi.
> >
> > I just reproduced a problem I was chasing on FreeBSD also on
> > OpenSolaris from around 2008.01.
> >
> > Simply doing something like this:
> >
> > write 9k of random data into 'foo' file
> > truncate 'foo' file to 7k
> > truncate 'foo' file to 11k
> > read data between 7k-9k
> >
> > There should be all zeros between 7k-9k, but there is previous data.
> > It worked fine on an older ZFS versions (I'm sure it works on version 6).
> >
> > Simple test program:
[...]
There was a missing #include:
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <err.h>
static char buf0[9 * 1024], buf1[2 * 1024];
int
main(int argc, char *argv[])
{
int fd, i;
if (argc != 2)
errx(1, "usage: trunctest <filename>");
fd = open(argv[1], O_RDWR | O_CREAT | O_TRUNC, 0600);
if (fd == -1)
err(1, "open(%s)", argv[1]);
memset(buf0, 'x', sizeof(buf0));
if (write(fd, buf0, sizeof(buf0)) != sizeof(buf0))
err(1, "write()");
if (ftruncate(fd, 7 * 1024) == -1)
err(1, "ftruncate(%d)", 7 * 1024);
if (ftruncate(fd, 11 * 1024) == -1)
err(1, "ftruncate(%d)", 11 * 1024);
if (pread(fd, buf1, sizeof(buf1), 7 * 1024) != sizeof(buf1))
err(1, "pread()");
for (i = 0; i < sizeof(buf1); i++) {
if (buf1[i] != '\0')
errx(2, "unexpected data at %jd!", (intmax_t)(7 * 1024 + i));
}
exit(0);
}
I've confirmed that this program reports an error on the latest Nevada bits
# /home/marks/t file.test
t: unexpected data at 7168!
|