Hi,
I'm running XFS under PowerPC linux. Kernel version 2.4.5 with XFS 1.0.1
release code patched in.
The problem is that fseek() to the end of the file is returning a value
which is actually past the end of the file. I'm attaching the code used
to generate this error to this email, and some sample runs on my system.
The actual problem was discovered with a zip archive utility, but I
wanted a simpler way to reproduce it.
Any ideas? Is there a patch I can apply to my 2.4.5 / XFS 1.0.1 to fix
this?
Test on ext2 filesystem:
STORM-47.131.125.203> seektest /testfs/file 1
STORM-47.131.125.203> ls -l /testfs/file
-rw-rw-rw- 1 root root 2048 Jun 20 07:04 /testfs/file
STORM-47.131.125.203> seektest /testfs/file 2
STORM-47.131.125.203> ls -l /testfs/file
-rw-rw-rw- 1 root root 4096 Jun 20 07:04 /testfs/file
STORM-47.131.125.203> seektest /testfs/file 3
STORM-47.131.125.203> ls -l /testfs/file
-rw-rw-rw- 1 root root 6144 Jun 20 07:04 /testfs/file
STORM-47.131.125.203> seektest /testfs/file 4
STORM-47.131.125.203> ls -l /testfs/file
-rw-rw-rw- 1 root root 8192 Jun 20 07:06 /testfs/file
STORM-47.131.125.203> hexdump /testfs/file
100148c0 0101 0101 0101 0101 0101 0101 0101 0101
*
100148d8
Running the same test on an XFS filesystem:
STORM-47.131.125.203> seektest /xfstest/file 1
STORM-47.131.125.203> ls -l /xfstest/file
-rw-rw-rw- 1 root root 2048 Jun 20 07:05 /xfstest/file
STORM-47.131.125.203> seektest /xfstest/file 2
STORM-47.131.125.203> ls -l /xfstest/file
-rw-rw-rw- 1 root root 4096 Jun 20 07:05 /xfstest/file
STORM-47.131.125.203> seektest /xfstest/file 3
curroff != totalsize : 8192 != 6144
STORM-47.131.125.203> ls -l /xfstest/file
-rw-rw-rw- 1 root root 6144 Jun 20 07:05 /xfstest/file
STORM-47.131.125.203> seektest /xfstest/file 4
curroff != totalsize : 8192 != 6144
currentoffset != totalsizewritten 8192 != 6144
curroff != totalsize : 12288 != 8192
STORM-47.131.125.203> ls -l /xfstest/file
-rw-rw-rw- 1 root root 10240 Jun 20 07:05 /xfstest/file
STORM-47.131.125.203> hexdump /xfstest/file
100148c0 0101 0101 0101 0101 0101 0101 0101 0101
*
100148c0 0000 0000 0000 0000 0000 0000 0000 0000
*
100148d8 0101 0101 0101 0101 0101 0101 0101 0101
*
100148d8
The source code for the seektest program follows:
#include <stdio.h>
#include <errno.h>
#include <string.h>
int
main(int argc, char* argv[])
{
char buffer[1024];
FILE* fp;
unsigned long i;
unsigned long fsize;
unsigned long totalsize = 0;
unsigned long wrotesize;
unsigned long curroff;
if( argc != 3 )
{
printf("Usage: %s <filename> <iterations)>\n", argv[0]);
return(-1);
}
memset(buffer, 1, 1024);
fsize = atoi( argv[2] );
unlink( argv[1] );
fp = fopen( argv[1], "w+");
if( fp == 0 )
{
perror("fopen failed");
return(-1);
}
for(i = 0; i<fsize; i++ )
{
curroff=ftell(fp);
if( curroff != totalsize )
{
printf("currentoffset != totalsizewritten %d != %d\n",
curroff, totalsize);
}
fseek(fp, 1024, SEEK_END);
wrotesize = fwrite( buffer, 1, 1024, fp);
if ( wrotesize != 1024 )
{
printf("Wrote != 1024\n");
}
totalsize = totalsize + wrotesize;
fseek(fp, curroff, SEEK_SET);
wrotesize = fwrite( buffer, 1, 1024, fp);
if ( wrotesize != 1024 )
{
printf("Wrote != 1024\n");
}
totalsize = totalsize + wrotesize;
if( 0 != fseek(fp, 0, SEEK_END))
{
perror("Fseek to end failed");
}
curroff = ftell(fp);
if(curroff != totalsize)
{
printf("curroff != totalsize : %d != %d\n", curroff,
totalsize);
}
}
}
--
Sean C. Kormilo, SAM21/STORM Software Architect, Nortel Networks
email: skormilo@xxxxxxxxxxxxxxxxxx
|