3 # $RCSfile: fs.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:28 $
12 $Is_Dosish = ($^O eq 'MSWin32' or $^O eq 'NetWare' or $^O eq 'dos' or
13 $^O eq 'os2' or $^O eq 'mint' or $^O eq 'cygwin' or
16 if (defined &Win32::IsWinNT && Win32::IsWinNT()) {
17 $Is_Dosish = '' if Win32::FsType() eq 'NTFS';
22 $wd = ((($^O eq 'MSWin32') || ($^O eq 'NetWare')) ? `cd` : `pwd`);
25 if (($^O eq 'MSWin32') || ($^O eq 'NetWare')) { `rmdir /s /q tmp 2>nul`; `mkdir tmp`; }
26 else { `rm -f tmp 2>/dev/null; mkdir tmp 2>/dev/null`; }
28 `/bin/rm -rf a b c x` if -x '/bin/rm';
32 if (($^O eq 'MSWin32') || ($^O eq 'NetWare')) { print "ok 1 # skipped: bogus umask()\n"; }
33 elsif ((umask(0)&0777) == 022) {print "ok 1\n";} else {print "not ok 1\n";}
34 open(fh,'>x') || die "Can't create x";
36 open(fh,'>a') || die "Can't create a";
39 if ($Is_Dosish) {print "ok 2 # skipped: no link\n";}
40 elsif (eval {link('a','b')}) {print "ok 2\n";}
41 else {print "not ok 2\n";}
43 if ($Is_Dosish) {print "ok 3 # skipped: no link\n";}
44 elsif (eval {link('b','c')}) {print "ok 3\n";}
45 else {print "not ok 3\n";}
47 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
48 $blksize,$blocks) = stat('c');
50 if ($Config{dont_use_nlink} || $Is_Dosish)
51 {print "ok 4 # skipped: no link\n";}
54 else {print "not ok 4\n";}
56 if ($^O eq 'amigaos' || $Is_Dosish)
57 {print "ok 5 # skipped: no link\n";}
58 elsif (($mode & 0777) == 0666)
60 else {print "not ok 5\n";}
62 $newmode = (($^O eq 'MSWin32') || ($^O eq 'NetWare')) ? 0444 : 0777;
63 if ((chmod $newmode,'a') == 1) {print "ok 6\n";} else {print "not ok 6\n";}
65 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
66 $blksize,$blocks) = stat('c');
67 if ($Is_Dosish) {print "ok 7 # skipped: no link\n";}
68 elsif (($mode & 0777) == $newmode) {print "ok 7\n";}
69 else {print "not ok 7\n";}
72 if (($^O eq 'MSWin32') || ($^O eq 'NetWare')) {
77 if ($Is_Dosish) {print "ok 8 # skipped: no link\n";}
78 elsif ((chmod $newmode,'c','x') == 2) {print "ok 8\n";}
79 else {print "not ok 8\n";}
81 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
82 $blksize,$blocks) = stat('c');
83 if ($Is_Dosish) {print "ok 9 # skipped: no link\n";}
84 elsif (($mode & 0777) == $newmode) {print "ok 9\n";}
85 else {print "not ok 9\n";}
87 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
88 $blksize,$blocks) = stat('x');
89 if ($Is_Dosish) {print "ok 10 # skipped: no link\n";}
90 elsif (($mode & 0777) == $newmode) {print "ok 10\n";}
91 else {print "not ok 10\n";}
93 if ($Is_Dosish) {print "ok 11 # skipped: no link\n"; unlink 'b','x'; }
94 elsif ((unlink 'b','x') == 2) {print "ok 11\n";}
95 else {print "not ok 11\n";}
96 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
97 $blksize,$blocks) = stat('b');
98 if ($ino == 0) {print "ok 12\n";} else {print "not ok 12\n";}
99 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
100 $blksize,$blocks) = stat('x');
101 if ($ino == 0) {print "ok 13\n";} else {print "not ok 13\n";}
103 if (rename('a','b')) {print "ok 14\n";} else {print "not ok 14\n";}
104 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
105 $blksize,$blocks) = stat('a');
106 if ($ino == 0) {print "ok 15\n";} else {print "not ok 15\n";}
107 $delta = $Is_Dosish ? 2 : 1; # Granularity of time on the filesystem
109 $foo = (utime 500000000,500000000 + $delta,'b');
110 if ($foo == 1) {print "ok 16\n";} else {print "not ok 16 $foo\n";}
111 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
112 $blksize,$blocks) = stat('b');
113 if (($^O eq 'MSWin32') || ($^O eq 'NetWare')) { print "ok 17 # skipped: bogus (stat)[1]\n"; }
114 elsif ($ino) {print "ok 17\n";} else {print "not ok 17\n";}
115 if ($wd =~ m#$Config{'afsroot'}/# || $^O eq 'amigaos' || $^O eq 'dos' || $^O eq 'MSWin32' || $^O eq 'NetWare' || $^O eq 'cygwin')
116 {print "ok 18 # skipped: granularity of the filetime\n";}
117 elsif ($atime == 500000000 && $mtime == 500000000 + $delta)
119 elsif ($^O =~ /\blinux\b/i) {
120 # Maybe stat() cannot get the correct atime, as happens via NFS on linux?
121 $foo = (utime 400000000,500000000 + 2*$delta,'b');
122 my ($new_atime, $new_mtime) = (stat('b'))[8,9];
123 if ($new_atime == $atime && $new_mtime - $mtime == $delta)
124 {print "ok 18 # accounted for possible NFS/glibc2.2 bug on linux\n";}
126 {print "not ok 18 $atime/$new_atime $mtime/$new_mtime\n";}
128 {print "not ok 18 $atime $mtime\n";}
130 if ((unlink 'b') == 1) {print "ok 19\n";} else {print "not ok 19\n";}
131 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
132 $blksize,$blocks) = stat('b');
133 if ($ino == 0) {print "ok 20\n";} else {print "not ok 20\n";}
136 chdir $wd || die "Can't cd back to $wd";
139 if ((($^O eq 'MSWin32') || ($^O eq 'NetWare')) and `ls -l perl 2>/dev/null` =~ /^l.*->/) {
140 # we have symbolic links
141 system("cp TEST TEST$$");
142 # we have to copy because e.g. GNU grep gets huffy if we have
143 # a symlink forest to another disk (it complains about too many
144 # levels of symbolic links, even if we have only two)
145 if (symlink("TEST$$","c")) {print "ok 21\n";} else {print "not ok 21\n";}
146 $foo = `grep perl c 2>&1`;
147 if ($foo) {print "ok 22\n";} else {print "not ok 22\n";}
152 print "ok 21\nok 22\n";
155 # truncate (may not be implemented everywhere)
157 `echo helloworld > Iofs.tmp`;
158 eval { truncate "Iofs.tmp", 5; };
160 if ($@ =~ /not implemented/) {
161 print "# truncate not implemented -- skipping tests 23 through 26\n";
163 print "ok $_ # Skip: no truncate\n";
166 warn "io/fs before test 23: truncate dies with \$\@[$@]";
170 if (-s "Iofs.tmp" == 5) {
173 my $s = -s "Iofs.tmp";
174 printf "# -s Iofs.tmp: %s\n", defined($s) ? $s : "UNDEFINED";
177 truncate "Iofs.tmp", 0;
178 if (-z "Iofs.tmp") {print "ok 24\n"} else {print "not ok 24\n"}
179 open(FH, ">Iofs.tmp") or die "Can't create Iofs.tmp";
181 { select FH; $| = 1; select STDOUT }
184 print FH "x\n" x 200;
185 truncate(FH, 200) or die "Can't truncate FH: $!";
188 # Not needed on HPFS, but needed on HPFS386 ?!
191 close (FH); open (FH, ">>Iofs.tmp") or die "Can't reopen Iofs.tmp";
193 if (-s "Iofs.tmp" == 200) {print "ok 25\n"} else {print "not ok 25\n"}
196 # Not needed on HPFS, but needed on HPFS386 ?!
199 close (FH); open (FH, ">>Iofs.tmp") or die "Can't reopen Iofs.tmp";
201 if (-z "Iofs.tmp") {print "ok 26\n"} else {print "not ok 26\n"}
205 # check if rename() can be used to just change case of filename
207 open(fh,'>x') || die "Can't create x";
210 print 'not ' unless -e 'X';
213 chdir $wd || die "Can't cd back to $wd";
215 # check if rename() works on directories
216 rename 'tmp', 'tmp1' or print "not ";
218 -d 'tmp1' or print "not ";
221 END { rmdir 'tmp1'; unlink "Iofs.tmp"; }