1 # NOTE: this file tests how large files (>2GB) work with raw system IO.
2 # stdio: open(), tell(), seek(), print(), read() is tested in t/op/lfs.t.
3 # If you modify/add tests here, remember to update also t/op/lfs.t.
8 require Config; import Config;
9 # Don't bother if there are no quad offsets.
10 if ($Config{lseeksize} < 8) {
11 print "1..0 # Skip: no 64-bit file offsets\n";
14 require Fcntl; import Fcntl qw(/^O_/ /^SEEK_/);
32 # If the lfs (large file support: large meaning larger than two gigabytes)
33 # tests are skipped or fail, it may mean either that your process
34 # (or process group) is not allowed to write large files (resource
35 # limits) or that the file system you are running the tests on doesn't
36 # let your user/group have large files (quota) or the filesystem simply
37 # doesn't support large files. You may even need to reconfigure your kernel.
38 # (This is all very operating system and site-dependent.)
40 # Perl may still be able to support large files, once you have
41 # such a process, enough quota, and such a (file) system.
46 print "# checking whether we have sparse files...\n";
49 if ($^O eq 'win32' || $^O eq 'vms') {
50 print "1..0 # Skip: no sparse files (because this is $^O) \n";
54 # Known haves that have problems running this test
55 # (for example because they do not support sparse files, like UNICOS)
56 if ($^O eq 'unicos') {
57 print "1..0 # Skip: large files known to work but unable to test them here ($^O)\n";
61 # Then try heuristically to deduce whether we have sparse files.
63 # We'll start off by creating a one megabyte file which has
64 # only three "true" bytes. If we have sparseness, we should
65 # consume less blocks than one megabyte (assuming nobody has
66 # one megabyte blocks...)
68 sysopen(BIG, "big1", O_WRONLY|O_CREAT|O_TRUNC) or
69 do { warn "sysopen big1 failed: $!\n"; bye };
70 sysseek(BIG, 1_000_000, SEEK_SET) or
71 do { warn "sysseek big1 failed: $!\n"; bye };
72 syswrite(BIG, "big") or
73 do { warn "syswrite big1 failed; $!\n"; bye };
75 do { warn "close big1 failed: $!\n"; bye };
77 my @s1 = stat("big1");
81 sysopen(BIG, "big2", O_WRONLY|O_CREAT|O_TRUNC) or
82 do { warn "sysopen big2 failed: $!\n"; bye };
83 sysseek(BIG, 2_000_000, SEEK_SET) or
84 do { warn "sysseek big2 failed: $!\n"; bye };
85 syswrite(BIG, "big") or
86 do { warn "syswrite big2 failed; $!\n"; bye };
88 do { warn "close big2 failed: $!\n"; bye };
90 my @s2 = stat("big2");
96 unless ($s1[7] == 1_000_003 && $s2[7] == 2_000_003 &&
97 $s1[11] == $s2[11] && $s1[12] == $s2[12]) {
98 print "1..0 # Skip: no sparse files?\n";
102 print "# we seem to have sparse files...\n";
104 # By now we better be sure that we do have sparse files:
105 # if we are not, the following will hog 5 gigabytes of disk. Ooops.
106 # This may fail by producing some signal; run in a subprocess first for safety
110 my $r = system '../perl', '-I../lib', '-e', <<'EOF';
111 use Fcntl qw(/^O_/ /^SEEK_/);
112 sysopen(BIG, "big", O_WRONLY|O_CREAT|O_TRUNC) or die $!;
113 my $sysseek = sysseek(BIG, 5_000_000_000, SEEK_SET);
114 my $syswrite = syswrite(BIG, "big");
118 sysopen(BIG, "big", O_WRONLY|O_CREAT|O_TRUNC) or
119 do { warn "sysopen 'big' failed: $!\n"; bye };
120 my $sysseek = sysseek(BIG, 5_000_000_000, SEEK_SET);
121 unless (! $r && defined $sysseek && $sysseek == 5_000_000_000) {
122 $sysseek = 'undef' unless defined $sysseek;
123 print "1..0 # Skip: seeking past 2GB failed: ",
124 $r ? 'signal '.($r & 0x7f) : "$! (sysseek returned $sysseek)", "\n";
129 # The syswrite will fail if there are are filesize limitations (process or fs).
130 my $syswrite = syswrite(BIG, "big");
131 print "# syswrite failed: $! (syswrite returned ",
132 defined $syswrite ? $syswrite : 'undef', ")\n"
133 unless defined $syswrite && $syswrite == 3;
134 my $close = close BIG;
135 print "# close failed: $!\n" unless $close;
136 unless($syswrite && $close) {
137 if ($! =~/too large/i) {
138 print "1..0 # Skip: writing past 2GB failed: process limits?\n";
139 } elsif ($! =~ /quota/i) {
140 print "1..0 # Skip: filesystem quota limits?\n";
150 unless ($s[7] == 5_000_000_003) {
151 print "1..0 # Skip: not configured to use large files?\n";
165 fail unless $s[7] == 5_000_000_003; # exercizes pp_stat
168 fail unless -s "big" == 5_000_000_003; # exercizes pp_ftsize
171 fail unless -e "big";
174 fail unless -f "big";
177 sysopen(BIG, "big", O_RDONLY) or do { warn "sysopen failed: $!\n"; bye };
179 fail unless sysseek(BIG, 4_500_000_000, SEEK_SET) == 4_500_000_000;
182 fail unless sysseek(BIG, 0, SEEK_CUR) == 4_500_000_000;
185 fail unless sysseek(BIG, 1, SEEK_CUR) == 4_500_000_001;
188 fail unless sysseek(BIG, 0, SEEK_CUR) == 4_500_000_001;
191 fail unless sysseek(BIG, -1, SEEK_CUR) == 4_500_000_000;
194 fail unless sysseek(BIG, 0, SEEK_CUR) == 4_500_000_000;
197 fail unless sysseek(BIG, -3, SEEK_END) == 5_000_000_000;
200 fail unless sysseek(BIG, 0, SEEK_CUR) == 5_000_000_000;
205 fail unless sysread(BIG, $big, 3) == 3;
208 fail unless $big eq "big";
211 # 705_032_704 = (I32)5_000_000_000
212 fail unless sysseek(BIG, 705_032_704, SEEK_SET);
217 fail unless read(BIG, $zero, 3) == 3;
220 fail unless $zero eq "\0\0\0";
225 bye(); # does the necessary cleanup
228 unlink "big"; # be paranoid about leaving 5 gig files lying around