3 # $RCSfile: fs.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:28 $
12 my $Is_VMSish = ($^O eq 'VMS');
13 $Is_Dosish = ($^O eq 'MSWin32' or $^O eq 'NetWare' or $^O eq 'dos' or
14 $^O eq 'os2' or $^O eq 'mint' or $^O eq 'cygwin' or
17 if (defined &Win32::IsWinNT && Win32::IsWinNT()) {
18 $Is_Dosish = '' if Win32::FsType() eq 'NTFS';
23 $wd = ((($^O eq 'MSWin32') || ($^O eq 'NetWare')) ? `cd` : ($Is_VMSish) ? `show default` : `pwd`);
26 if (($^O eq 'MSWin32') || ($^O eq 'NetWare')) {
27 `rmdir /s /q tmp 2>nul`;
31 `if f\$search("[.tmp]*.*") .nes. "" then delete/nolog/noconfirm [.tmp]*.*.*`;
32 `if f\$search("tmp.dir") .nes. "" then delete/nolog/noconfirm tmp.dir;`;
33 `create/directory [.tmp]`;
36 `rm -f tmp 2>/dev/null; mkdir tmp 2>/dev/null`;
39 `/bin/rm -rf a b c x` if -x '/bin/rm';
43 if (($^O eq 'MSWin32') || ($^O eq 'NetWare')) { print "ok 1 # skipped: bogus umask()\n"; }
44 elsif ((umask(0)&0777) == 022) {print "ok 1\n";} else {print "not ok 1\n";}
45 open(fh,'>x') || die "Can't create x";
47 open(fh,'>a') || die "Can't create a";
50 if ($Is_Dosish || $Is_VMSish) {print "ok 2 # skipped: no link\n";}
51 elsif (eval {link('a','b')}) {print "ok 2\n";}
52 else {print "not ok 2\n";}
54 if ($Is_Dosish || $Is_VMSish) {print "ok 3 # skipped: no link\n";}
55 elsif (eval {link('b','c')}) {print "ok 3\n";}
56 else {print "not ok 3\n";}
58 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
59 $blksize,$blocks) = stat('c');
61 if ($Config{dont_use_nlink} || $Is_Dosish || $Is_VMSish)
62 {print "ok 4 # skipped: no link\n";}
65 else {print "not ok 4\n";}
67 if ($^O eq 'amigaos' || $Is_Dosish || $Is_VMSish)
68 {print "ok 5 # skipped: no link\n";}
69 elsif (($mode & 0777) == 0666)
71 else {print "not ok 5\n";}
73 $newmode = (($^O eq 'MSWin32') || ($^O eq 'NetWare')) ? 0444 : 0777;
74 if ((chmod $newmode,'a') == 1) {print "ok 6\n";} else {print "not ok 6\n";}
76 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
77 $blksize,$blocks) = stat('c');
78 if ($Is_Dosish || $Is_VMSish) {print "ok 7 # skipped: no link\n";}
79 elsif (($mode & 0777) == $newmode) {print "ok 7\n";}
80 else {print "not ok 7\n";}
83 if (($^O eq 'MSWin32') || ($^O eq 'NetWare')) {
88 if ($Is_Dosish || $Is_VMSish) {print "ok 8 # skipped: no link\n";}
89 elsif ((chmod $newmode,'c','x') == 2) {print "ok 8\n";}
90 else {print "not ok 8\n";}
92 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
93 $blksize,$blocks) = stat('c');
94 if ($Is_Dosish || $Is_VMSish) {print "ok 9 # skipped: no link\n";}
95 elsif (($mode & 0777) == $newmode) {print "ok 9\n";}
96 else {print "not ok 9\n";}
98 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
99 $blksize,$blocks) = stat('x');
100 if ($Is_Dosish || $Is_VMSish) {print "ok 10 # skipped: no link\n";}
101 elsif (($mode & 0777) == $newmode) {print "ok 10\n";}
102 else {print "not ok 10\n";}
104 if ($Is_Dosish || $Is_VMSish) {print "ok 11 # skipped: no link\n"; unlink 'b','x'; }
105 elsif ((unlink 'b','x') == 2) {print "ok 11\n";}
106 else {print "not ok 11\n";}
107 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
108 $blksize,$blocks) = stat('b');
109 if ($ino == 0) {print "ok 12\n";} else {print "not ok 12\n";}
110 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
111 $blksize,$blocks) = stat('x');
112 if ($ino == 0) {print "ok 13\n";} else {print "not ok 13\n";}
114 if (rename('a','b')) {print "ok 14\n";} else {print "not ok 14\n";}
115 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
116 $blksize,$blocks) = stat('a');
117 if ($ino == 0) {print "ok 15\n";} else {print "not ok 15\n";}
118 $delta = $Is_Dosish ? 2 : 1; # Granularity of time on the filesystem
120 $foo = (utime 500000000,500000000 + $delta,'b');
121 if ($foo == 1) {print "ok 16\n";} else {print "not ok 16 $foo\n";}
122 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
123 $blksize,$blocks) = stat('b');
124 if (($^O eq 'MSWin32') || ($^O eq 'NetWare')) { print "ok 17 # skipped: bogus (stat)[1]\n"; }
125 elsif ($ino) {print "ok 17\n";} else {print "not ok 17\n";}
126 if ($wd =~ m#$Config{'afsroot'}/# || $^O eq 'amigaos' || $^O eq 'dos' || $^O eq 'MSWin32' || $^O eq 'NetWare' || $^O eq 'cygwin')
127 {print "ok 18 # skipped: granularity of the filetime\n";}
128 elsif ($atime == 500000000 && $mtime == 500000000 + $delta)
130 elsif ($^O =~ /\blinux\b/i) {
131 # Maybe stat() cannot get the correct atime, as happens via NFS on linux?
132 $foo = (utime 400000000,500000000 + 2*$delta,'b');
133 my ($new_atime, $new_mtime) = (stat('b'))[8,9];
134 if ($new_atime == $atime && $new_mtime - $mtime == $delta)
135 {print "ok 18 # accounted for possible NFS/glibc2.2 bug on linux\n";}
137 {print "not ok 18 $atime/$new_atime $mtime/$new_mtime\n";}
140 if ($atime == 500000001 && $mtime == 500000000 + $delta)
143 {print "not ok 18 $atime $mtime\n";}
145 {print "not ok 18 $atime $mtime\n";}
147 if ((unlink 'b') == 1) {print "ok 19\n";} else {print "not ok 19\n";}
148 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
149 $blksize,$blocks) = stat('b');
150 if ($ino == 0) {print "ok 20\n";} else {print "not ok 20\n";}
153 chdir $wd || die "Can't cd back to $wd";
156 # Yet another way to look for links (perhaps those that cannot be created by perl?).
157 # Hopefully there is an ls utility in your %PATH%. N.B. that $^O is 'cygwin' on Cygwin.
158 if ((($^O eq 'MSWin32') || ($^O eq 'NetWare')) and `ls -l perl 2>nul` =~ /^l.*->/) {
159 # we have symbolic links
160 system("cp TEST TEST$$");
161 # we have to copy because e.g. GNU grep gets huffy if we have
162 # a symlink forest to another disk (it complains about too many
163 # levels of symbolic links, even if we have only two)
164 if (symlink("TEST$$","c")) {print "ok 21\n";} else {print "not ok 21\n";}
165 $foo = `grep perl c 2>&1`;
166 if ($foo) {print "ok 22\n";} else {print "not ok 22\n";}
171 if ( ($^O eq 'MSWin32') || ($^O eq 'NetWare') ) {
172 print "ok 21 # skipped: no link\nok 22 # skipped: no link\n";
175 print "ok 21 # skipped: '$^O' is neither 'MSWin32' nor 'NetWare'\nok 22 # skipped: $^O is neither 'MSWin32' nor 'NetWare'\n";
179 # truncate (may not be implemented everywhere)
182 open IOFSCOM, ">Iofs.tmp" or die "Could not write IOfs.tmp: $!";
183 print IOFSCOM 'helloworld';
187 `echo helloworld > Iofs.tmp`;
190 # Perhaps the eval would be better written with a construct such as?:
191 #if (defined($Config{d_truncate}) && $Config{d_truncate} eq 'define') {
193 eval { truncate "Iofs.tmp", 5; };
195 if ($@ =~ /not implemented/) {
196 print "# truncate not implemented -- skipping tests 23 through 26\n";
198 print "ok $_ # Skip: no truncate\n";
201 warn "io/fs before test 23: truncate dies with \$\@[$@]";
205 if (-s "Iofs.tmp" == 5) {
208 my $s = -s "Iofs.tmp";
209 printf "# -s Iofs.tmp: %s\n", defined($s) ? $s : "UNDEFINED";
212 truncate "Iofs.tmp", 0;
213 if (-z "Iofs.tmp") {print "ok 24\n"} else {print "not ok 24\n"}
214 open(FH, ">Iofs.tmp") or die "Can't create Iofs.tmp";
216 { select FH; $| = 1; select STDOUT }
219 print FH "x\n" x 200;
220 truncate(FH, 200) or die "Can't truncate FH: $!";
223 # Not needed on HPFS, but needed on HPFS386 ?!
226 close (FH); open (FH, ">>Iofs.tmp") or die "Can't reopen Iofs.tmp";
228 if (-s "Iofs.tmp" == 200) {
232 my $s = -s "Iofs.tmp";
233 printf "# -s Iofs.tmp: %s\n", defined($s) ? $s : "UNDEFINED";
238 # Not needed on HPFS, but needed on HPFS386 ?!
241 close (FH); open (FH, ">>Iofs.tmp") or die "Can't reopen Iofs.tmp";
243 if (-z "Iofs.tmp") {print "ok 26\n"} else {print "not ok 26\n"}
247 # check if rename() can be used to just change case of filename
248 if ($^O eq 'cygwin') {
249 print "ok 27 # skipped: works only if check_case is set to relaxed.\n";
252 open(fh,'>x') || die "Can't create x";
256 # this works on win32 only, because fs isn't casesensitive
257 print 'not ' unless -e 'X';
261 chdir $wd || die "Can't cd back to $wd";
264 # check if rename() works on directories
266 # must have delete access to rename a directory
267 `set file tmp.dir/protection=o:d`;
268 rename 'tmp.dir', 'tmp1.dir' or print "not ";
271 rename 'tmp', 'tmp1' or print "not ";
274 -d 'tmp1' or print "not ";
277 # need to remove 'tmp' if rename() in test 28 failed!
278 END { rmdir 'tmp1'; rmdir 'tmp'; unlink "Iofs.tmp"; }