1 # NOTE: this file tests how large files (>2GB) work with raw system IO.
2 # open(), tell(), seek(), print(), read() are tested in t/op/lfs.t.
3 # If you modify/add tests here, remember to update also t/op/lfs.t.
7 unshift @INC, '../lib';
8 require Config; import Config;
9 # Don't bother if there are no quad offsets.
10 if ($Config{lseeksize} < 8) {
11 print "1..0\n# no 64-bit file offsets\n";
14 require Fcntl; import Fcntl qw(/^O_/ /^SEEK_/);
26 # If the lfs (large file support: large meaning larger than two gigabytes)
27 # tests are skipped or fail, it may mean either that your process
28 # (or process group) is not allowed to write large files (resource
29 # limits) or that the file system you are running the tests on doesn't
30 # let your user/group have large files (quota) or the filesystem simply
31 # doesn't support large files. You may even need to reconfigure your kernel.
32 # (This is all very operating system and site-dependent.)
34 # Perl may still be able to support large files, once you have
35 # such a process, enough quota, and such a (file) system.
40 print "# checking whether we have sparse files...\n";
43 if ($^O eq 'win32' || $^O eq 'vms') {
44 print "1..0\n# no sparse files (because this is $^O) \n";
48 # Known haves that have problems running this test
49 # (for example because they do not support sparse files, like UNICOS)
50 if ($^O eq 'unicos') {
51 print "1..0\n# large files known to work but unable to test them here ($^O)\n";
55 # Then try heuristically to deduce whether we have sparse files.
57 # We'll start off by creating a one megabyte file which has
58 # only three "true" bytes. If we have sparseness, we should
59 # consume less blocks than one megabyte (assuming nobody has
60 # one megabyte blocks...)
62 sysopen(BIG, "big", O_WRONLY|O_CREAT|O_TRUNC) or
63 do { warn "sysopen failed: $!\n"; bye };
64 sysseek(BIG, 1_000_000, SEEK_SET);
74 my $BLOCKSIZE = $s[11] || 512;
79 $BLOCKSIZE * $s[12] < 1_000_003) {
80 print "1..0\n# no sparse files?\n";
84 print "# we seem to have sparse files...\n";
86 # By now we better be sure that we do have sparse files:
87 # if we are not, the following will hog 5 gigabytes of disk. Ooops.
91 sysopen(BIG, "big", O_WRONLY|O_CREAT|O_TRUNC) or
92 do { warn "sysopen 'big' failed: $!\n"; bye };
93 my $sysseek = sysseek(BIG, 5_000_000_000, SEEK_SET);
94 unless (defined $sysseek && $sysseek == 5_000_000_000) {
95 print "1..0\n# seeking past 2GB failed: $! (sysseek returned ",
96 defined $sysseek ? $sysseek : 'undef', ")\n";
101 # The syswrite will fail if there are are filesize limitations (process or fs).
102 my $syswrite = syswrite(BIG, "big");
103 print "# syswrite failed: $! (syswrite returned ",
104 defined $syswrite ? $syswrite : 'undef', ")\n"
105 unless defined $syswrite && $syswrite == 3;
106 my $close = close BIG;
107 print "# close failed: $!\n" unless $close;
108 unless($syswrite && $close) {
109 if ($! =~/too large/i) {
110 print "1..0\n# writing past 2GB failed: process limits?\n";
111 } elsif ($! =~ /quota/i) {
112 print "1..0\n# filesystem quota limits?\n";
122 unless ($s[7] == 5_000_000_003) {
123 print "1..0\n# not configured to use large files?\n";
137 fail unless $s[7] == 5_000_000_003; # exercizes pp_stat
140 fail unless -s "big" == 5_000_000_003; # exercizes pp_ftsize
143 fail unless -e "big";
146 fail unless -f "big";
149 sysopen(BIG, "big", O_RDONLY) or do { warn "sysopen failed: $!\n"; bye };
151 fail unless sysseek(BIG, 4_500_000_000, SEEK_SET) == 4_500_000_000;
154 fail unless sysseek(BIG, 0, SEEK_CUR) == 4_500_000_000;
157 fail unless sysseek(BIG, 1, SEEK_CUR) == 4_500_000_001;
160 fail unless sysseek(BIG, 0, SEEK_CUR) == 4_500_000_001;
163 fail unless sysseek(BIG, -1, SEEK_CUR) == 4_500_000_000;
166 fail unless sysseek(BIG, 0, SEEK_CUR) == 4_500_000_000;
169 fail unless sysseek(BIG, -3, SEEK_END) == 5_000_000_000;
172 fail unless sysseek(BIG, 0, SEEK_CUR) == 5_000_000_000;
177 fail unless sysread(BIG, $big, 3) == 3;
180 fail unless $big eq "big";
183 # 705_032_704 = (I32)5_000_000_000
184 fail unless seek(BIG, 705_032_704, $SEEK_SET);
189 fail unless read(BIG, $zero, 3) == 3;
192 fail unless $zero eq "\0\0\0";
197 bye(); # does the necessary cleanup
200 unlink "big"; # be paranoid about leaving 5 gig files lying around