/* try-lfs2.c -- one of LFS subsystem tests by Matti Aarnio This test-program tries mmap() of MAP_PRIVATE, which should 1) allow 512 byte file offset alignments, 2) check consistency. While writing this, some lowlevel (filesystem related?) oddities were noticed, which may harm "misaligned" accesses. Over NFS this did work just fine, but not locally at EXT2 :-/ */ #include #include #include #include #include #define LFS "lfs-test.dat" int main() { int fd, i, ii; loff_t off, pos; int rc; char buf[512]; char *pp[20]; fd = open(LFS,O_RDWR|O_CREAT|O_TRUNC,0644); if (fd < 0) { perror("open('"LFS"',O_RDWR|O_CREAT|O_TRUNC,0644)"); exit(88); } for (i = 0; i < 30; ++i) { memset(buf, i, 512); write(fd, buf, 512); } fsync(fd); lseek(fd,8192,SEEK_SET); #define mmm(fd,off) mmap(NULL, 2*4096, PROT_WRITE|PROT_READ|PROT_EXEC, MAP_PRIVATE, fd, off) for (i = 19; i >= 0; --i) { pp[i] = mmm(fd, i*512); } for (i = 0; i < 20; ++i) { printf("idx = %2d p%02d[0] = %2d p%02d[512] = %2d", i, i, pp[i][0], i, pp[i][512]); if (pp[i][0] != i || pp[i][512] != i+1) printf(" 512 BYTE ALIGNMENT BUG"); printf("\n"); } close(fd); exit(99); }