/* try-lfs1.c -- one of LFS subsystem tests by Matti Aarnio This test-program tries for largest writable offset in the current filesystem. While the system in Linux may allow file sizes up to 1 TB, the filesystem where this program is run at to produce its "lfs-test.dat" file, might not support all that much... For example all triply-indirected classical UNIX filesystems have inherent limitation from following formula: B = filesystem block size (0.5k, 1k, 2k, 4k) Max block number = 10 + B/4 + (B/4)^2 + (B/4)^3 Highest term of the polynome for the filesize is thus: (B^4)/64 and next highest (e.g. largest factor for an "epsilon") is: (B^3)/16 or 4/B part of the highest term. B MaxIndirection 0.5k 1 GB + epsilon1 1.0k 16 GB + epsilon2 2.0k 256 GB + epsilon3 4.0k 4096 GB + epsilon4 The last one is, of course, more than 32-bit system will be able to address with PGOFF_SHIFT = 9 ... */ #include #include #include #include #ifndef O_LARGEFILE # define O_LARGEFILE 0100000 /* i386 only ! */ #endif extern loff_t llseek(int fd, loff_t pos, int whence); #define LFS "lfs-test.dat" int main() { int fd; loff_t off, pos; int rc; fd = open(LFS,O_RDWR|O_CREAT|O_TRUNC|O_LARGEFILE,0644); if (fd < 0) { perror("open('"LFS"',O_RDWR|O_CREAT|O_TRUNC|O_LARGEFILE,0644)"); exit(88); } off = 0LL; while (1) { off += 0x2000000LL; /* 32 MB */ pos = llseek(fd, off - 4LL, SEEK_SET); if (pos == (loff_t)-1) { fprintf(stdout,"llseek(fd,off,SEEK_SET) off=%Ld; errno=%s\n", off,strerror(errno)); break; } fprintf(stdout,"llseek(fd,off,SEEK_SET) new pos = %Ld\n",pos); if (write(fd,"01234567",8) != 8) { perror("write(fd,'....',8) failed"); break; } } close(fd); exit(99); }