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 unless ($explained++) {
35 # If the lfs (large file support: large meaning larger than two
36 # gigabytes) tests are skipped or fail, it may mean either that your
37 # process (or process group) is not allowed to write large files
38 # (resource limits) or that the file system (the network filesystem?)
39 # you are running the tests on doesn't let your user/group have large
40 # files (quota) or the filesystem simply doesn't support large files.
41 # You may even need to reconfigure your kernel. (This is all very
42 # operating system and site-dependent.)
44 # Perl may still be able to support large files, once you have
45 # such a process, enough quota, and such a (file) system.
46 # It is just that the test failed now.
50 print "1..0 # Skip: @_\n" if @_;
53 print "# checking whether we have sparse files...\n";
56 if ($^O eq 'MSWin32' || $^O eq 'VMS') {
57 print "1..0 # Skip: no sparse files in $^O\n";
61 # Known haves that have problems running this test
62 # (for example because they do not support sparse files, like UNICOS)
63 if ($^O eq 'unicos') {
64 print "1..0 # Skip: no sparse files in $^0, unable to test large files\n";
68 # Then try heuristically to deduce whether we have sparse files.
70 # We'll start off by creating a one megabyte file which has
71 # only three "true" bytes. If we have sparseness, we should
72 # consume less blocks than one megabyte (assuming nobody has
73 # one megabyte blocks...)
75 sysopen(BIG, "big1", O_WRONLY|O_CREAT|O_TRUNC) or
76 do { warn "sysopen big1 failed: $!\n"; bye };
77 sysseek(BIG, 1_000_000, SEEK_SET) or
78 do { warn "sysseek big1 failed: $!\n"; bye };
79 syswrite(BIG, "big") or
80 do { warn "syswrite big1 failed; $!\n"; bye };
82 do { warn "close big1 failed: $!\n"; bye };
84 my @s1 = stat("big1");
88 sysopen(BIG, "big2", O_WRONLY|O_CREAT|O_TRUNC) or
89 do { warn "sysopen big2 failed: $!\n"; bye };
90 sysseek(BIG, 2_000_000, SEEK_SET) or
91 do { warn "sysseek big2 failed: $!\n"; bye };
92 syswrite(BIG, "big") or
93 do { warn "syswrite big2 failed; $!\n"; bye };
95 do { warn "close big2 failed: $!\n"; bye };
97 my @s2 = stat("big2");
103 unless ($s1[7] == 1_000_003 && $s2[7] == 2_000_003 &&
104 $s1[11] == $s2[11] && $s1[12] == $s2[12]) {
105 print "1..0 # Skip: no sparse files?\n";
109 print "# we seem to have sparse files...\n";
111 # By now we better be sure that we do have sparse files:
112 # if we are not, the following will hog 5 gigabytes of disk. Ooops.
113 # This may fail by producing some signal; run in a subprocess first for safety
117 my $r = system '../perl', '-I../lib', '-e', <<'EOF';
118 use Fcntl qw(/^O_/ /^SEEK_/);
119 sysopen(BIG, "big", O_WRONLY|O_CREAT|O_TRUNC) or die $!;
120 my $sysseek = sysseek(BIG, 5_000_000_000, SEEK_SET);
121 my $syswrite = syswrite(BIG, "big");
125 sysopen(BIG, "big", O_WRONLY|O_CREAT|O_TRUNC) or
126 do { warn "sysopen 'big' failed: $!\n"; bye };
127 my $sysseek = sysseek(BIG, 5_000_000_000, SEEK_SET);
128 unless (! $r && defined $sysseek && $sysseek == 5_000_000_000) {
129 $sysseek = 'undef' unless defined $sysseek;
130 explain("seeking past 2GB failed: ",
131 $r ? 'signal '.($r & 0x7f) : "$! (sysseek returned $sysseek)");
135 # The syswrite will fail if there are are filesize limitations (process or fs).
136 my $syswrite = syswrite(BIG, "big");
137 print "# syswrite failed: $! (syswrite returned ",
138 defined $syswrite ? $syswrite : 'undef', ")\n"
139 unless defined $syswrite && $syswrite == 3;
140 my $close = close BIG;
141 print "# close failed: $!\n" unless $close;
142 unless($syswrite && $close) {
143 if ($! =~/too large/i) {
144 explain("writing past 2GB failed: process limits?");
145 } elsif ($! =~ /quota/i) {
146 explain("filesystem quota limits?");
148 explain("error: $!");
157 unless ($s[7] == 5_000_000_003) {
158 explain("kernel/fs not configured to use large files?");
171 fail unless $s[7] == 5_000_000_003; # exercizes pp_stat
174 fail unless -s "big" == 5_000_000_003; # exercizes pp_ftsize
177 fail unless -e "big";
180 fail unless -f "big";
183 sysopen(BIG, "big", O_RDONLY) or do { warn "sysopen failed: $!\n"; bye };
185 fail unless sysseek(BIG, 4_500_000_000, SEEK_SET) == 4_500_000_000;
188 fail unless sysseek(BIG, 0, SEEK_CUR) == 4_500_000_000;
191 fail unless sysseek(BIG, 1, SEEK_CUR) == 4_500_000_001;
194 fail unless sysseek(BIG, 0, SEEK_CUR) == 4_500_000_001;
197 fail unless sysseek(BIG, -1, SEEK_CUR) == 4_500_000_000;
200 fail unless sysseek(BIG, 0, SEEK_CUR) == 4_500_000_000;
203 fail unless sysseek(BIG, -3, SEEK_END) == 5_000_000_000;
206 fail unless sysseek(BIG, 0, SEEK_CUR) == 5_000_000_000;
211 fail unless sysread(BIG, $big, 3) == 3;
214 fail unless $big eq "big";
217 # 705_032_704 = (I32)5_000_000_000
218 fail unless sysseek(BIG, 705_032_704, SEEK_SET);
223 fail unless read(BIG, $zero, 3) == 3;
226 fail unless $zero eq "\0\0\0";
231 bye(); # does the necessary cleanup
234 unlink "big"; # be paranoid about leaving 5 gig files lying around