3 # $RCSfile: fs.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:28 $
13 my $Is_VMSish = ($^O eq 'VMS');
15 my $has_link = $Config{d_link};
16 my $accurate_timestamps =
17 !($^O eq 'MSWin32' || $^O eq 'NetWare' ||
18 $^O eq 'dos' || $^O eq 'os2' ||
19 $^O eq 'mint' || $^O eq 'cygwin');
21 if (defined &Win32::IsWinNT && Win32::IsWinNT()) {
22 if (Win32::FsType() eq 'NTFS') {
24 $accurate_timestamps = 1;
30 # Not needed on HPFS, but needed on HPFS386 ?!
35 if (($^O eq 'MSWin32') || ($^O eq 'NetWare')) {
37 } elsif ($^O eq 'VMS') {
44 if (($^O eq 'MSWin32') || ($^O eq 'NetWare')) {
45 `rmdir /s /q tmp 2>nul`;
47 } elsif ($^O eq 'VMS') {
48 `if f\$search("[.tmp]*.*") .nes. "" then delete/nolog/noconfirm [.tmp]*.*.*`;
49 `if f\$search("tmp.dir") .nes. "" then delete/nolog/noconfirm tmp.dir;`;
50 `create/directory [.tmp]`;
53 `rm -f tmp 2>/dev/null; mkdir tmp 2>/dev/null`;
58 `/bin/rm -rf a b c x` if -x '/bin/rm';
62 if (($^O eq 'MSWin32') || ($^O eq 'NetWare')) {
63 pass("Skip - bogus umask");
64 } elsif ((umask(0)&0777) == 022) {
70 open(fh,'>x') || die "Can't create x";
72 open(fh,'>a') || die "Can't create a";
75 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
79 skip("no link", 4) unless $has_link;
81 ok(link('a','b'), "link a b");
82 ok(link('b','c'), "link b c");
84 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
85 $blksize,$blocks) = stat('c');
87 if ($Config{dont_use_nlink}) {
88 pass("Skip - dont_use_nlink");
90 is($nlink, 3, "link count of triply-linked file");
93 if ($^O eq 'amigaos') {
94 pass("Skip - hard links are not that hard in $^O");
96 is($mode & 0777, 0666, "mode of triply-linked file");
100 $newmode = (($^O eq 'MSWin32') || ($^O eq 'NetWare')) ? 0444 : 0777;
102 is(chmod($newmode,'a'), 1, "chmod succeeding");
105 skip("no link", 9) unless $has_link;
107 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
108 $blksize,$blocks) = stat('c');
110 is($mode & 0777, $newmode, "chmod going through");
116 is(chmod($newmode,'c','x'), 2, "chmod two files");
118 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
119 $blksize,$blocks) = stat('c');
121 is($mode & 0777, $newmode, "chmod going through to c");
123 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
124 $blksize,$blocks) = stat('x');
126 is($mode & 0777, $newmode, "chmod going through to x");
128 is(unlink('b','x'), 2, "unlink two files");
130 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
131 $blksize,$blocks) = stat('b');
133 is($ino, undef, "ino of removed file b should be undef");
135 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
136 $blksize,$blocks) = stat('x');
138 is($ino, undef, "ino of removed file x should be undef");
141 is(rename('a','b'), 1, "rename a b");
143 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
144 $blksize,$blocks) = stat('a');
146 is($ino, undef, "ino of renamed file a should be undef");
148 $delta = $accurate_timestamps ? 1 : 2; # Granularity of time on the filesystem
150 $foo = (utime 500000000,500000000 + $delta,'b');
152 is($foo, 1, "utime");
154 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
155 $blksize,$blocks) = stat('b');
157 if (($^O eq 'MSWin32') || ($^O eq 'NetWare')) {
158 pass("Skip - bogus (stat)[1]\n");
160 pass("non-zero ino $ino");
165 if ($wd =~ m#$Config{'afsroot'}/# ||
167 $^O eq 'dos' || $^O eq 'MSWin32' || $^O eq 'NetWare' || $^O eq 'cygwin') {
168 fail("Skip - granularity of the atime/mtime");
169 } elsif ($atime == 500000000 && $mtime == 500000000 + $delta) {
171 } elsif ($^O =~ /\blinux\b/i) {
172 # Maybe stat() cannot get the correct atime, as happens via NFS on linux?
173 $foo = (utime 400000000,500000000 + 2*$delta,'b');
174 my ($new_atime, $new_mtime) = (stat('b'))[8,9];
175 if ($new_atime == $atime && $new_mtime - $mtime == $delta) {
176 pass("atime/mtime - accounted for possible NFS/glibc2.2 bug on linux");
178 fail("atime mtime - $atime/$new_atime $mtime/$new_mtime");
180 } elsif ($^O eq 'VMS') {
181 if ($atime == 500000001 && $mtime == 500000000 + $delta) {
184 fail("atime $atime mtime $mtime");
186 } elsif ($^O eq 'beos') {
187 if ($mtime == 500000001) {
188 pass("mtime (atime not updated)");
190 fail("mtime $mtime (atime not updated)");
196 is(unlink('b'), 1, "unlink b");
198 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
199 $blksize,$blocks) = stat('b');
200 is($ino, undef, "ino of unlinked file b should be undef");
203 chdir $wd || die "Can't cd back to $wd";
205 # Yet another way to look for links (perhaps those that cannot be
206 # created by perl?). Hopefully there is an ls utility in your
207 # %PATH%. N.B. that $^O is 'cygwin' on Cygwin.
209 if ((($^O eq 'MSWin32') || ($^O eq 'NetWare')) &&
210 `ls -l perl 2>nul` =~ /^l.*->/) {
211 # we have symbolic links
212 system("cp TEST TEST$$");
213 # we have to copy because e.g. GNU grep gets huffy if we have
214 # a symlink forest to another disk (it complains about too many
215 # levels of symbolic links, even if we have only two)
216 is(symlink("TEST$$","c"), 1, "symlink");
217 $foo = `grep perl c 2>&1`;
218 ok($foo, "found perl in c");
223 if ( ($^O eq 'MSWin32') || ($^O eq 'NetWare') ) {
224 pass("Skip - no symbolic links") for 1..2;
227 pass("Skip - '$^O' is neither 'MSWin32' nor 'NetWare'") for 1..2;
232 open IOFSCOM, ">Iofs.tmp" or die "Could not write IOfs.tmp: $!";
233 print IOFSCOM 'helloworld';
236 # TODO: pp_truncate needs to be taught about F_CHSIZE and F_FREESP,
240 eval { truncate "Iofs.tmp", 5; };
242 skip("no truncate - $@", 4) if $@;
244 is(-s "Iofs.tmp", 5, "truncation to five bytes");
246 truncate "Iofs.tmp", 0;
248 ok(-z "Iofs.tmp", "truncation to zero bytes");
250 open(FH, ">Iofs.tmp") or die "Can't create Iofs.tmp";
259 print FH "x\n" x 200;
260 ok(truncate(FH, 200), "fh resize to 200");
263 if ($needs_fh_reopen) {
264 close (FH); open (FH, ">>Iofs.tmp") or die "Can't reopen Iofs.tmp";
267 is(-s "Iofs.tmp", 200, "fh resize to 200 working");
269 ok(truncate(FH, 0), "fh resize to zero");
271 if ($needs_fh_reopen) {
272 close (FH); open (FH, ">>Iofs.tmp") or die "Can't reopen Iofs.tmp";
275 ok(-z "Iofs.tmp", "fh resize to zero working");
280 # check if rename() can be used to just change case of filename
281 if ($^O eq 'cygwin') {
282 pass("Skip - works in $^O only if check_case is set to relaxed");
285 open(fh,'>x') || die "Can't create x";
289 # this works on win32 only, because fs isn't casesensitive
290 ok(-e 'X', "rename working");
293 chdir $wd || die "Can't cd back to $wd";
296 # check if rename() works on directories
298 # must have delete access to rename a directory
299 `set file tmp.dir/protection=o:d`;
300 ok(rename('tmp.dir', 'tmp1.dir'), "rename on directories");
302 ok(rename('tmp', 'tmp1'), "rename on directories");
305 ok(-d 'tmp1', "rename on directories working");
307 # need to remove 'tmp' if rename() in test 28 failed!
308 END { rmdir 'tmp1'; rmdir 'tmp'; unlink "Iofs.tmp"; }