[Pvfs-users] pvfs_read beyond EOF
Wei-keng Liao
wkliao at ece.northwestern.edu
Mon Jan 23 23:52:29 EST 2006
What will happen if a read (pvfs_read) reads beyond the current end of
file (EOF)? According to POSIX, read() should stop at EOF and return the
number of bytes read to the buffer. The buffer beyond EOF should not be
touched. (Please correct me if this is wrong.)
But, I found the pvfs_read will set the buffer contents to null for the
beyond part. Here is the example code I tested: 1) create a new file, 2)
initialize read buffer, 3) read 10 bytes, 4) print out buffer. (I am using
PVFS 1.6.3) Is this the way PVFS behaves for reading beyond EOF?
Wei-keng Liao
---------------------------------------------------------------------
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <pvfs.h>
#define PVFS_FILE_NAME "/pvfs/wkliao/testfile.dat"
#define UNIX_FILE_NAME "testfile.dat"
#define TEST_FILE(filename,ofunc,cfunc,rfunc) { \
fd = ofunc(filename, flag, 0600, 0, 0); \
\
readsize = rfunc(fd, buf, 10); \
cfunc(fd); \
\
printf("readsize for %s = %d bytes\n", filename, readsize); \
printf("buf[*]= "); \
for (i=0; i<10; i++) printf(" '%c'", buf[i]); \
printf("\n"); \
}
int main(int argc, char **argv) {
int i, readsize, flag;
int fd;
char buf[10];
flag = O_TRUNC | O_CREAT | O_RDWR;
/* test pvfs file -------------------------------------------*/
for (i=0; i<10; i++) buf[i] = '1';
TEST_FILE(PVFS_FILE_NAME, pvfs_open, pvfs_close, pvfs_read);
/* test unix file -------------------------------------------*/
for (i=0; i<10; i++) buf[i] = '1';
TEST_FILE(UNIX_FILE_NAME, open, close, read);
return 1;
}
More information about the Pvfs-users
mailing list