<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl

# This test verifies correct function of the Inheriting File System (IFS) for
# a collection of strictly serial operations. This test does NEITHER guarantee
# total correctness of the file system code NOR does it give any indication,
# whether there are incorrectly handled race conditions or not.


require("sys/syscall.ph");
require("linux/errno.ph");
require("linux/stat.ph");


if (!$ARGV[0] || !chdir($ARGV[0])) {
    print "usage: test.pl base_directory\n";
    exit(1);
}

$A = "a";
$B = "b";
$AB = "a+b";

$first = 1;


sub pass
{
    local ($status) = @_;

    $status || die "PASS failed ($!)";
}


sub fail
{
    local ($status,$expect) = @_;

    $status &amp;&amp; die "FAIL passed ($!)";
    die "FAILed with ".($!+0)." instead of $expect." if $! != $expect;
}


sub create
{
    local ($name,$data) = @_;

    open(FILE,"&gt;$name") || return 0;
    if ($data) {
	print FILE $data;
    }
    close FILE;
    return 1;
}


sub touch
{
    return &amp;create(@_[0],"");
}


sub append
{
    local ($name,$data) = @_;

    open(FILE,"&gt;&gt;$name") || return 0;
    if ($data) {
	print FILE $data;
    }
    close FILE;
    return 1;
}


sub unlink
{
    local ($name) = @_;

    return !syscall(&amp;SYS_unlink,$name);
}


sub truncate
{
    local ($name,$length) = @_;

    open(FILE,"&gt;&gt;$name") || die "$!";
    truncate(FILE,$length);
    close(FILE);
    return 1;
}


sub rename
{
    local ($old,$new) = @_;

    return !syscall(&amp;SYS_rename,$old,$new);
}


sub unwhiteout
{
    local ($dir,$name) = @_;
    local ($status);

    open(DIR,$dir) || die "open directory $dir: $!";
    $status = ioctl(DIR,0x53464900,$name);
    close(DIR);
    return $status;
}


sub tree
{
    local ($dir) = @_;
    local (@dir,@new,$name,$dot,$dotdot);

    opendir(DIR,$dir) || die("opendir $dir: $!");
    @dir = readdir(DIR);
    closedir(DIR);
    @new = ();
    $dor = $dotdot = 0;
    for (@dir) {
	$name = $_;
	if ($name eq ".") {
	    if ($dot) { die "duplicate . in $dir"; }
	    $dot = 1;
	}
	elsif ($name eq "..") {
	    if ($dotdot) { die "duplicate .. in $dir"; }
	    $dotdot = 1;
	}
	else {
	    push(@new,$name);
	    if (&amp;S_ISDIR((lstat($dir."/".$name))[2])) {
	        push(@new,grep($_ = $name."/".$_,&amp;tree($dir."/".$name)));
	    }
	}
    }
    if (!$dot) { die "no . in $dir"; }
    if (!$dotdot) { die "no .. in $dir"; }
    return @new;
}


sub clean
{
    &amp;pass(system("smount -u $AB") == 0);
# &amp;pass(chdir("/"));
# &amp;pass(system("umount /scratch") == 0);
# &amp;pass(system("mount /scratch") == 0);
# &amp;pass(chdir("/scratch"));
    $mounted = 0;
    for (reverse @left) {
	if (m,^(.*)/$,) {
	    &amp;pass(rmdir($1));
	}
	elsif (m/^([^-=(|]+)([-=(|].*)?$/) {
	    &amp;pass(unlink($1));
	}
	else {
	    die("Unknown file \"$_\"");
	}
    }
    @left = ();
    &amp;pass(rmdir($A));
    &amp;pass(rmdir($B));
    &amp;pass(rmdir($AB));
}


sub begin
{
    $tests++;
    print "@_\n";
    if (!$first) {
	&amp;clean();
    }
    $first = 0;
    &amp;pass(mkdir($A,0777));
    &amp;pass(mkdir($B,0777));
    &amp;pass(mkdir($AB,0777));
}


sub init
{
    local ($dir);

    $dir = shift(@_);
    for (@_) {
	if (m,^(.*)/$,) {
	    &amp;pass(mkdir($dir."/".$1,0777));
	}
	elsif (m/^([^-=(]+)(=|-&gt;|\(|\|)(.*)$/) {
	    if ($2 eq "=") { &amp;pass(&amp;create($dir."/".$1,$3)); }
	    elsif ($2 eq "-&gt;") { &amp;pass(symlink($3,$dir."/".$1)); }
	    elsif ($2 eq "|") { die "not yet supported"; }
	    elsif ($2 eq "(") { die "not yet supported"; }
	    else { die "unknown attribute \"$2\""; }
	}
	else {
	    &amp;pass(&amp;touch($dir."/".$_));
	}
    }
}

# Must be called before performing any operations on the IFS in a test
# sequence. test implicitly calls commit.

sub commit
{
    if (!$mounted) {
	&amp;pass(system("smount -t ifs $A,$B $AB") == 0);
	$mounted = 1;
    }
}


sub test
{
    local ($dir,$mode,$rdev,@dir,@expect,$file);

    $dir = shift(@_);
    &amp;commit();
    if ($dir ne $AB) {
	for (@_) {
	    push(@left,$dir."/".$_);
	}
    }
    @dir = &amp;tree($dir);
    for (@dir) {
	($mode,$rdev) = (lstat($dir."/".$_))[2,6];
	if (&amp;S_ISREG($mode)) { ; }
	elsif (&amp;S_ISDIR($mode)) { $_ .= "/"; }
	elsif (&amp;S_ISLNK($mode)) { $_ .= "-&gt;".readlink($dir."/".$_); }
	elsif (&amp;S_ISFIFO($mode)) { $_ .= "|"; }
	elsif (&amp;S_ISCHR($mode) || &amp;S_ISBLK($mode)) {
	    $_ .= sprintf("(%d,%d)",$rdev &gt;&gt; 8,$rdev &amp; 0xff);
	}
	else {
	    die "unknown mode ".sprintf("0%o",$mode);
	}
    }
    @expect = sort(@_);
    @dir = sort(@dir);
    if ($#_ != $#dir) {
	die "directories \"@expect\" and \"@dir\" differ in size";
    }
    for (0..$#_) {
	if ($expect[$_] =~ /^([^=]*)=(.*)$/) {
	    if ($1 ne $dir[$_]) {
		die "directories \"@expect\" and \"@dir\" differ";
	    }
	    open(FILE,$dir."/".$1) || die "can't open $1: $!";
	    $file = join("\n",&lt;FILE&gt;);
	    if ($2 ne $file) {
		die "content of file $dir/$1 is \"$file\" instead of \"$2\"";
	    }
	    close FILE;
	}
	else {
	    if ($expect[$_] ne $dir[$_]) {
		die "directories \"@expect\" and \"@dir\" differ";
	     }
	}
    }
}


# INITIALIZATION

# system("smount -u /scratch; smount -u $AB; rm -rf $A $B $AB");

# READDIR

&amp;begin("readdir, no files");
&amp;test($A);
&amp;test($B);
&amp;test($AB);

&amp;begin("readdir, on upper layer");
&amp;init($A,"file_a");
&amp;test($A,"file_a");
&amp;test($B);
&amp;test($AB,"file_a");

&amp;begin("readdir, on lower layer");
&amp;init($B,"file_b");
&amp;test($A);
&amp;test($B,"file_b");
&amp;test($AB,"file_b");

&amp;begin("readdir, on both layers");
&amp;init($A,"file_a","file_c");
&amp;init($B,"file_b","file_c");
&amp;test($A,"file_a","file_c");
&amp;test($B,"file_b","file_c");
&amp;test($AB,"file_a","file_b","file_c");

&amp;begin("readdir, on lower layer, whiteout");
&amp;init($A,".../",".../file_b");
&amp;init($B,"file_b");
&amp;test($A,".../",".../file_b");
&amp;test($B,"file_b");
&amp;test($AB);

&amp;begin("readdir, no files, whiteout (corrupt)");
&amp;init($A,".../",".../file");
&amp;init($B);
&amp;test($A,".../",".../file");
&amp;test($B);
&amp;test($AB);

&amp;begin("readdir, multiple directories");
&amp;init($A,"0/","2/","2/3");
&amp;init($B,"1/","2/","2/4");
&amp;test($A,"0/","2/","2/3");
&amp;test($B,"1/","2/","2/4");
&amp;test($AB,"0/","1/","2/","2/3","2/4");

&amp;begin("readdir, lower hidden");
&amp;init($A,"dir/","dir/1=one","dir/2=two",".../",".../dir/");
&amp;init($B,"dir/","dir/3=three");
&amp;test($A,"dir/","dir/1=one","dir/2=two",".../",".../dir/");
&amp;test($B,"dir/","dir/3=three");
&amp;test($AB,"dir/","dir/1=one","dir/2=two");

# READ FILE

&amp;begin("read file, doesn't exist");
&amp;commit();
&amp;fail(open(DUMMY,"$AB/file"),&amp;ENOENT);

&amp;begin("read file, doesn't exist, whiteout (corrupt)");
&amp;init($A,".../",".../file");
&amp;test($A,".../",".../file");
&amp;fail(open(DUMMY,"$AB/file"),&amp;ENOENT);

&amp;begin("read file, on upper layer");
&amp;init($A,"file=just_a_file");
&amp;test($A,"file=just_a_file");
&amp;test($AB,"file=just_a_file");

&amp;begin("read file, on lower layer");
&amp;init($B,"file=just_a_file");
&amp;test($B,"file=just_a_file");
&amp;test($AB,"file=just_a_file");

&amp;begin("read file, on both layers");
&amp;init($A,"file=file_on_A");
&amp;init($B,"file=file_on_B");
&amp;test($A,"file=file_on_A");
&amp;test($B,"file=file_on_B");
&amp;test($AB,"file=file_on_A");

&amp;begin("read file, on upper layer, whiteout (corrupt)");
&amp;init($A,"file=just_a_file",".../",".../file");
&amp;test($A,"file=just_a_file",".../",".../file");
&amp;fail(open(DUMMY,"$AB/file"),&amp;ENOENT);

&amp;begin("read file, on lower layer, whiteout");
&amp;init($A,".../",".../file");
&amp;init($B,"file=a_file");
&amp;test($A,".../",".../file");
&amp;test($B,"file=a_file");
&amp;fail(open(DUMMY,"$AB/file"),&amp;ENOENT);

&amp;begin("read file, on both layers, whiteout (corrupt)");
&amp;init($A,"file=file_on_A",".../",".../file");
&amp;init($B,"file=file_on_B");
&amp;test($A,"file=file_on_A",".../",".../file");
&amp;test($B,"file=file_on_B");
&amp;fail(open(DUMMY,"$AB/file"),&amp;ENOENT);

&amp;begin("read file ..., on upper layer (invalid name)");
&amp;init($A,"...");
&amp;commit();
&amp;fail(open(DUMMY,"$AB/..."),&amp;ENOENT);
&amp;test($A,"...");

# CREATE FILE

&amp;begin("create file, file is new");
&amp;commit();
&amp;pass(&amp;create("$A/file","a_file_..."));
&amp;test($A,"file=a_file_...");
&amp;test($AB,"file=a_file_...");

&amp;begin("create file, file is new, whiteout (corrupt)");
&amp;init($A,".../",".../file");
&amp;commit();
&amp;pass(&amp;create("$AB/file","a_file_..."));
&amp;test($A,"file=a_file_...",".../");
&amp;test($AB,"file=a_file_...");

&amp;begin("create file, exists on upper layer");
&amp;init($A,"file=on A");
&amp;commit();
&amp;pass(&amp;create("$AB/file","a_file"));
&amp;test($A,"file=a_file");
&amp;test($AB,"file=a_file");

&amp;begin("create file, exists on lower layer");
&amp;init($B,"file=on_B");
&amp;commit();
&amp;pass(&amp;create("$AB/file","a_file_..."));
&amp;test($A,"file=a_file_...");
&amp;test($B,"file=on_B");
&amp;test($AB,"file=a_file_...");

&amp;begin("create file, exists on upper layer, whiteout (corrupt)");
&amp;init($A,"file=on_A",".../",".../file");
&amp;commit();
&amp;fail(&amp;create("$AB/file","a_file"),&amp;EEXIST);
&amp;test($A,"file=on_A",".../",".../file");
&amp;test($AB);

&amp;begin("create file, exists on lower layer, whiteout");
&amp;init($A,".../",".../file");
&amp;init($B,"file=on_B");
&amp;commit();
&amp;pass(&amp;create("$AB/file","a_file_..."));
&amp;test($A,"file=a_file_...",".../");
&amp;test($B,"file=on_B");
&amp;test($AB,"file=a_file_...");

&amp;begin("create file ..., new file (invalid name)");
&amp;commit();
&amp;fail(&amp;create("$AB/...",""),&amp;EINVAL);
&amp;test($A);

&amp;begin("create file, with entire directory tree");
&amp;init($A,"1/","1/2/","1/2/3/");
&amp;init($B,"1/","1/2/","1/2/3/");
&amp;commit();
&amp;pass(&amp;create("$AB/1/2/3/file",""));
&amp;test($A,"1/","1/2/","1/2/3/","1/2/3/file");
&amp;test($B,"1/","1/2/","1/2/3/");
&amp;test($AB,"1/","1/2/","1/2/3/","1/2/3/file");

&amp;begin("create file, with partial directory tree");
&amp;init($A,"1/");
&amp;init($B,"1/","1/2/","1/2/3/");
&amp;commit();
&amp;pass(&amp;create("$AB/1/2/3/file",""));
&amp;test($A,"1/","1/2/","1/2/3/","1/2/3/file");
&amp;test($B,"1/","1/2/","1/2/3/");
&amp;test($AB,"1/","1/2/","1/2/3/","1/2/3/file");

&amp;begin("create file, with empty directory tree");
&amp;init($A);
&amp;init($B,"1/","1/2/","1/2/3/");
&amp;commit();
&amp;pass(&amp;create("$AB/1/2/3/file",""));
&amp;test($A,"1/","1/2/","1/2/3/","1/2/3/file");
&amp;test($B,"1/","1/2/","1/2/3/");
&amp;test($AB,"1/","1/2/","1/2/3/","1/2/3/file");

# APPEND TO FILE

&amp;begin("append to existing file, upper layer");
&amp;init($A,"file=on_A");
&amp;commit();
&amp;pass(&amp;append("$AB/file","_more"));
&amp;test($A,"file=on_A_more");
&amp;test($B);
&amp;test($AB,"file=on_A_more");

&amp;begin("append to existing file, lower layer");
&amp;init($B,"file=on_B");
&amp;commit();
&amp;pass(&amp;append("$AB/file","_more"));
&amp;test($A,"file=on_B_more");
&amp;test($B,"file=on_B");
&amp;test($AB,"file=on_B_more");

&amp;begin("append to existing file, both layers");
&amp;init($A,"file=on_A");
&amp;init($B,"file=on_B");
&amp;commit();
&amp;pass(&amp;append("$AB/file","_more"));
&amp;test($A,"file=on_A_more");
&amp;test($B,"file=on_B");
&amp;test($AB,"file=on_A_more");

&amp;begin("append to file, with entire directory tree");
&amp;init($A,"1/","1/2/","1/2/3/");
&amp;init($B,"1/","1/2/","1/2/3/","1/2/3/file=B");
&amp;commit();
&amp;pass(&amp;append("$AB/1/2/3/file","_more"));
&amp;test($A,"1/","1/2/","1/2/3/","1/2/3/file=B_more");
&amp;test($B,"1/","1/2/","1/2/3/","1/2/3/file=B");
&amp;test($AB,"1/","1/2/","1/2/3/","1/2/3/file=B_more");

&amp;begin("append to file, with partial directory tree");
&amp;init($A,"1/");
&amp;init($B,"1/","1/2/","1/2/3/","1/2/3/file=B");
&amp;commit();
&amp;pass(&amp;append("$AB/1/2/3/file","_more"));
&amp;test($A,"1/","1/2/","1/2/3/","1/2/3/file=B_more");
&amp;test($B,"1/","1/2/","1/2/3/","1/2/3/file=B");
&amp;test($AB,"1/","1/2/","1/2/3/","1/2/3/file=B_more");

&amp;begin("append to file, with empty directory tree");
&amp;init($A);
&amp;init($B,"1/","1/2/","1/2/3/","1/2/3/file=B");
&amp;commit();
&amp;pass(&amp;append("$AB/1/2/3/file","_more"));
&amp;test($A,"1/","1/2/","1/2/3/","1/2/3/file=B_more");
&amp;test($B,"1/","1/2/","1/2/3/","1/2/3/file=B");
&amp;test($AB,"1/","1/2/","1/2/3/","1/2/3/file=B_more");

# TRUNCATE FILE

&amp;begin("truncating file, upper layer");
&amp;init($A,"file=abcde");
&amp;commit();
&amp;pass(&amp;truncate("$AB/file",2));
&amp;test($A,"file=ab");
&amp;test($B);
&amp;test($AB,"file=ab");

&amp;begin("truncating file, lower layer");
&amp;init($B,"file=abcde");
&amp;commit();
&amp;pass(&amp;truncate("$AB/file",3));
&amp;test($A,"file=abc");
&amp;test($B,"file=abcde");
&amp;test($AB,"file=abc");

# UNLINK

&amp;begin("unlink, file doesn't exist");
&amp;commit();
&amp;fail(&amp;unlink("$AB/file"),&amp;ENOENT);

&amp;begin("unlink, file doesn't exist, whiteout (corrupt)");
&amp;init($A,".../",".../file");
&amp;commit();
&amp;fail(&amp;unlink("$AB/file"),&amp;ENOENT);
&amp;test($A,".../",".../file");
&amp;test($AB);

&amp;begin("unlink, exists on upper layer");
&amp;init($A,"file");
&amp;commit();
&amp;pass(&amp;unlink("$AB/file"));
&amp;test($A);
&amp;test($AB);

&amp;begin("unlink, exists on lower layer");
&amp;init($B,"file");
&amp;commit();
&amp;pass(&amp;unlink("$AB/file"));
&amp;test($A,".../",".../file");
&amp;test($B,"file");
&amp;test($AB);

&amp;begin("unlink, exists on both layers");
&amp;init($A,"file=A");
&amp;init($B,"file=B");
&amp;commit();
&amp;pass(&amp;unlink("$AB/file"));
&amp;test($A,".../",".../file");
&amp;test($B,"file=B");
&amp;test($AB);

&amp;begin("unlink, exists on upper layer, whiteout (corrupt)");
&amp;init($A,"file",".../",".../file");
&amp;commit();
&amp;fail(&amp;unlink("$AB/file"),&amp;ENOENT);
&amp;test($A,"file",".../",".../file");
&amp;test($AB);

&amp;begin("unlink, exists on lower layer, whiteout");
&amp;init($A,".../",".../file");
&amp;init($B,"file");
&amp;commit();
&amp;fail(&amp;unlink("$AB/file"),&amp;ENOENT);
&amp;test($A,".../",".../file");
&amp;test($B,"file");
&amp;test($AB);

&amp;begin("unlink, with entire directory tree");
&amp;init($A,"1/","1/2/","1/2/3/");
&amp;init($B,"1/","1/2/","1/2/3/","1/2/3/file");
&amp;commit();
&amp;pass(&amp;unlink("$AB/1/2/3/file"));
&amp;test($A,"1/","1/2/","1/2/3/","1/2/3/.../","1/2/3/.../file");
&amp;test($B,"1/","1/2/","1/2/3/","1/2/3/file");
&amp;test($AB,"1/","1/2/","1/2/3/");

&amp;begin("unlink, with partial directory tree");
&amp;init($A,"1/");
&amp;init($B,"1/","1/2/","1/2/3/","1/2/3/file");
&amp;commit();
&amp;pass(&amp;unlink("$AB/1/2/3/file"));
&amp;test($A,"1/","1/2/","1/2/3/","1/2/3/.../","1/2/3/.../file");
&amp;test($B,"1/","1/2/","1/2/3/","1/2/3/file");
&amp;test($AB,"1/","1/2/","1/2/3/");

&amp;begin("unlink, with empty directory tree");
&amp;init($A);
&amp;init($B,"1/","1/2/","1/2/3/","1/2/3/file");
&amp;commit();
&amp;pass(&amp;unlink("$AB/1/2/3/file"));
&amp;test($A,"1/","1/2/","1/2/3/","1/2/3/.../","1/2/3/.../file");
&amp;test($B,"1/","1/2/","1/2/3/","1/2/3/file");
&amp;test($AB,"1/","1/2/","1/2/3/");

# MKDIR

&amp;begin("mkdir, directory is new");
&amp;commit();
&amp;pass(mkdir("$AB/dir",0777));
&amp;test($A,"dir/");
&amp;test($B);
&amp;test($AB,"dir/");

&amp;begin("mkdir, directory is new, whiteout (corrupt)");
&amp;init($A,".../",".../dir");
&amp;commit();
&amp;pass(mkdir("$AB/dir",0777));
&amp;test($A,"dir/",".../");
&amp;test($B);
&amp;test($AB,"dir/");

&amp;begin("mkdir, exists on upper layer");
&amp;init($A,"dir/");
&amp;commit();
&amp;fail(mkdir("$AB/dir",0777),&amp;EEXIST);
&amp;test($A,"dir/");
&amp;test($B);
&amp;test($AB,"dir/");

&amp;begin("mkdir, exists on lower layer");
&amp;init($B,"dir/");
&amp;commit();
&amp;fail(mkdir("$AB/dir",0777),&amp;EEXIST);
&amp;test($A);
&amp;test($B,"dir/");
&amp;test($AB,"dir/");

&amp;begin("mkdir, exists on upper layer, whiteout (corrupt)");
&amp;init($A,"dir/",".../",".../dir");
&amp;commit();
&amp;fail(mkdir("$AB/dir",0777),&amp;EEXIST);
&amp;test($A,"dir/",".../",".../dir");
&amp;test($B);
&amp;test($AB);

&amp;begin("mkdir, exists on lower layer, whiteout");
&amp;init($A,".../",".../dir");
&amp;init($B,"dir/");
&amp;commit();
&amp;pass(mkdir("$AB/dir",0777));
&amp;test($A,"dir/",".../",".../dir/");
&amp;test($B,"dir/");
&amp;test($AB,"dir/");

# RMDIR

&amp;begin("rmdir, directory doesn't exist");
&amp;commit();
&amp;fail(rmdir("$A/dir"),&amp;ENOENT);
&amp;test($AB);

&amp;begin("rmdir, directory doesn't exist, whiteout (corrupt)");
&amp;init($A,".../",".../dir");
&amp;commit();
&amp;fail(rmdir("$AB/dir"),&amp;ENOENT);
&amp;test($A,".../",".../dir");
&amp;test($AB);

&amp;begin("rmdir, exists on upper layer, empty");
&amp;init($A,"dir/");
&amp;commit();
&amp;pass(rmdir("$AB/dir"));
&amp;test($A);
&amp;test($AB);

&amp;begin("rmdir, exists on lower layer, empty");
&amp;init($B,"dir/");
&amp;commit();
&amp;pass(rmdir("$AB/dir"));
&amp;test($A,".../",".../dir");
&amp;test($B,"dir/");
&amp;test($AB);

&amp;begin("rmdir, exists on upper layer, empty, whiteout (corrupt)");
&amp;init($A,"dir/",".../",".../dir");
&amp;commit();
&amp;fail(rmdir("$AB/dir"),&amp;ENOENT);
&amp;test($A,"dir/",".../",".../dir");
&amp;test($AB);

&amp;begin("rmdir, exists on lower layer, empty, whiteout");
&amp;init($A,".../",".../dir");
&amp;init($B,"dir/");
&amp;commit();
&amp;fail(rmdir("$AB/dir"),&amp;ENOENT);
&amp;test($A,".../",".../dir");
&amp;test($B,"dir/");
&amp;test($AB);

&amp;begin("rmdir, exists on upper layer, full");
&amp;init($A,"dir/","dir/1","dir/2");
&amp;commit();
&amp;fail(rmdir("$AB/dir"),&amp;ENOTEMPTY);
&amp;test($A,"dir/","dir/1","dir/2");
&amp;test($AB,"dir/","dir/1","dir/2");

&amp;begin("rmdir, exists on both layers, files in lower");
&amp;init($A,"dir/");
&amp;init($B,"dir/","dir/1","dir/2");
&amp;commit();
&amp;fail(rmdir("$AB/dir"),&amp;ENOTEMPTY);
&amp;test($A,"dir/");
&amp;test($B,"dir/","dir/1","dir/2");
&amp;test($AB,"dir/","dir/1","dir/2");

&amp;begin("rmdir, exists on lower layer, full");
&amp;init($B,"dir/","dir/1","dir/2");
&amp;commit();
&amp;fail(rmdir("$AB/dir"),&amp;ENOTEMPTY);
&amp;test($A);
&amp;test($B,"dir/","dir/1","dir/2");
&amp;test($AB,"dir/","dir/1","dir/2");

&amp;begin("rmdir, exists on both layers, files in lower, all files whited out");
&amp;init($A,"dir/","dir/.../","dir/.../1","dir/.../2");
&amp;init($B,"dir/","dir/1","dir/2");
&amp;commit();
&amp;pass(rmdir("$AB/dir"));
&amp;test($A,".../",".../dir");
&amp;test($B,"dir/","dir/1","dir/2");
&amp;test($AB);

&amp;begin("rmdir, exists on both layers, empty, lower hidden");
&amp;init($A,"dir/",".../",".../dir/");
&amp;init($B,"dir/");
&amp;commit();
&amp;pass(rmdir("$AB/dir"));
&amp;test($A,".../",".../dir");
&amp;test($B,"dir/");
&amp;test($AB);

# SYMLINK

&amp;begin("symlink, file is new");
&amp;commit();
&amp;pass(symlink("dummy","$AB/link"));
&amp;test($A,"link-&gt;dummy");
&amp;test($AB,"link-&gt;dummy");

&amp;begin("symlink, file is new, whiteout (corrupt)");
&amp;init($A,".../",".../link");
&amp;commit();
&amp;pass(symlink("dummy","$AB/link"));
&amp;test($A,"link-&gt;dummy",".../");
&amp;test($AB,"link-&gt;dummy");

&amp;begin("symlink, exists on upper layer");
&amp;init($A,"file");
&amp;commit();
&amp;fail(symlink("dummy","$AB/file"),&amp;EEXIST);
&amp;test($A,"file");
&amp;test($AB,"file");

&amp;begin("symlink, exists on lower layer");
&amp;init($B,"file");
&amp;commit();
&amp;fail(symlink("dummy","$AB/file"),&amp;EEXIST);
&amp;test($A);
&amp;test($B,"file");
&amp;test($AB,"file");

&amp;begin("symlink, exists on upper layer, whiteout (corrupt)");
&amp;init($A,"link",".../",".../link");
&amp;commit();
&amp;fail(symlink("dummy","$AB/link"),&amp;EEXIST);
&amp;test($A,"link",".../",".../link");
&amp;test($AB);

&amp;begin("symlink, exists on lower layer, whiteout");
&amp;init($A,".../",".../link");
&amp;init($B,"link");
&amp;commit();
&amp;pass(symlink("dummy","$AB/link"));
&amp;test($A,"link-&gt;dummy",".../");
&amp;test($B,"link");
&amp;test($AB,"link-&gt;dummy");

# LINK

# &amp;begin("link, same FS, file is new");
# &amp;begin("link, same FS, file is new, whiteout");
# &amp;begin("link, same FS, exists on upper layer");
# &amp;begin("link, same FS, exists on lower layer");
# &amp;begin("link, same FS, exists on upper layer, whiteout");
# &amp;begin("link, same FS, exists on lower layer, whiteout");
# &amp;begin("link, different FS");

# MKNOD

# &amp;begin("mknod, file is new");
# &amp;begin("mknod, file is new, whiteout");
# &amp;begin("mknod, exists on upper layer");
# &amp;begin("mknod, exists on lower layer");
# &amp;begin("mknod, exists on upper layer, whiteout");
# &amp;begin("mknod, exists on lower layer, whiteout");

# RENAME

&amp;begin("rename file, non-existing source name");
&amp;init($A);
&amp;commit();
&amp;fail(&amp;rename("$AB/src","$AB/dst"),&amp;ENOENT);
&amp;test($A);
&amp;test($AB);

&amp;begin("rename file, non-existing source name, whiteout (corrupt)");
&amp;init($A,".../",".../src");
&amp;commit();
&amp;fail(&amp;rename("$AB/src","$AB/dst"),&amp;ENOENT);
&amp;test($A,".../",".../src");
&amp;test($AB);

&amp;begin("rename file, src and dst on the same FS, same directory");
&amp;init($A,"src=test");
&amp;commit();
&amp;pass(&amp;rename("$AB/src","$AB/dst"));
&amp;test($A,"dst=test");
&amp;test($AB,"dst=test");

&amp;begin("rename file, same FS, same directory, whiteout");
&amp;init($A,"src",".../",".../src");
&amp;commit();
&amp;fail(&amp;rename("$AB/src","$AB/dst"),&amp;ENOENT);
&amp;test($A,"src",".../",".../src");
&amp;test($AB);

&amp;begin("rename file, same FS, same directory, dst whiteout");
&amp;init($A,"src=test",".../",".../dst");
&amp;init($B,"dst");
&amp;commit();
&amp;pass(&amp;rename("$AB/src","$AB/dst"));
&amp;test($A,"dst=test",".../");
&amp;test($B,"dst");
&amp;test($AB,"dst=test");

&amp;begin("rename file, same FS, different directory");
&amp;init($A,"src=test","dir/");
&amp;commit();
&amp;pass(&amp;rename("$AB/src","$AB/dir/dst"));
&amp;test($A,"dir/","dir/dst=test");
&amp;test($AB,"dir/","dir/dst=test");

&amp;begin("rename file, same FS, different directory, src whiteout");
&amp;init($A,"src",".../",".../src","dir/");
&amp;commit();
&amp;fail(&amp;rename("$AB/src","$AB/dir/dst"),&amp;ENOENT);
&amp;test($A,"src",".../",".../src","dir/");
&amp;test($AB,"dir/");

&amp;begin("rename file, same FS, different directory, dst whiteout");
&amp;init($A,"src=foo","dir/","dir/.../","dir/.../dst");
&amp;init($B,"dir/","dir/dst=bar");
&amp;commit();
&amp;pass(&amp;rename("$AB/src","$AB/dir/dst"));
&amp;test($A,"dir/","dir/.../","dir/dst=foo");
&amp;test($B,"dir/","dir/dst=bar");
&amp;test($AB,"dir/","dir/dst=foo");

&amp;begin("rename file, same FS, diff. directory, dst ex. &amp; whiteout (corrupt)");
&amp;init($A,"src=foo","dir/","dir/.../","dir/.../dst","dir/dst=baz");
&amp;init($B,"dir/","dir/dst=bar");
&amp;commit();
&amp;pass(&amp;rename("$AB/src","$AB/dir/dst"));
&amp;test($A,"dir/","dir/.../","dir/dst=foo");
&amp;test($B,"dir/","dir/dst=bar");
&amp;test($AB,"dir/","dir/dst=foo");

&amp;begin("rename file, same FS, different directory, dst dir. whiteout");
&amp;init($A,"src=foo","dir/",".../",".../dir");
&amp;init($B,"dir/");
&amp;commit();
&amp;fail(&amp;rename("$AB/src","$AB/dir/dst"),&amp;ENOENT);
&amp;test($A,"src=foo","dir/",".../",".../dir");
&amp;test($B,"dir/");
&amp;test($AB,"src=foo");

&amp;begin("rename file, same FS, different directory, incomplete path");
&amp;init($A,"src=foo");
&amp;init($B,"dir/");
&amp;commit();
&amp;pass(&amp;rename("$AB/src","$AB/dir/dst"));
&amp;test($A,"dir/","dir/dst=foo");
&amp;test($B,"dir/");
&amp;test($AB,"dir/","dir/dst=foo");

&amp;begin("rename file, same FS, diff. level, same directory");
&amp;init($A);
&amp;init($B,"src=test");
&amp;commit();
&amp;pass(&amp;rename("$AB/src","$AB/dst"));
&amp;test($A,"dst=test",".../",".../src");
&amp;test($B,"src=test");
&amp;test($AB,"dst=test");

&amp;begin("rename file, same FS, diff. level, different directory");
&amp;init($A);
&amp;init($B,"dir/","dir/src=foo");
&amp;commit();
&amp;pass(&amp;rename("$AB/dir/src","$AB/dst"));
&amp;test($A,"dst=foo","dir/","dir/.../","dir/.../src",".../");
&amp;test($B,"dir/","dir/src=foo");
&amp;test($AB,"dst=foo","dir/");

&amp;begin("rename file, same FS, diff. level, diff. dir., dst exists on upper");
&amp;init($A,"dst=foo");
&amp;init($B,"dir/","dir/src=bar");
&amp;commit();
&amp;pass(&amp;rename("$AB/dir/src","$AB/dst"));
&amp;test($A,"dst=bar","dir/","dir/.../","dir/.../src",".../");
&amp;test($B,"dir/","dir/src=bar");
&amp;test($AB,"dst=bar","dir/");

&amp;begin("rename file, same FS, diff. level, diff. dir., dst exists on lower");
&amp;init($A);
&amp;init($B,"dst=foo","dir/","dir/src=bar");
&amp;commit();
&amp;pass(&amp;rename("$AB/dir/src","$AB/dst"));
&amp;test($A,"dst=bar","dir/","dir/.../","dir/.../src",".../");
&amp;test($B,"dst=foo","dir/","dir/src=bar");
&amp;test($AB,"dst=bar","dir/");

&amp;begin("rename file, same FS, diff. level, different directory, whiteout");
&amp;init($A,".../",".../src");
&amp;init($B,"src=test");
&amp;commit();
&amp;fail(&amp;rename("$AB/src","$AB/dir/dst"),&amp;ENOENT);
&amp;test($A,".../",".../src");
&amp;test($B,"src=test");
&amp;test($AB);

# &amp;begin("rename file, different FS, top-level");
# &amp;begin("rename file, different FS, top-level, whiteout");
# &amp;begin("rename file, different FS, different levels, 'same' dir.");
# &amp;begin("rename file, different FS, different levels, 'diff.' dir.");
# &amp;begin("rename file, different FS, different levels, dd, whiteout");

# UNWHITEOUT

&amp;begin("unwhiteout file, does not exist, no whiteout");
&amp;init($A);
&amp;commit();
&amp;fail(&amp;unwhiteout("$AB","file"),&amp;ENOENT);
&amp;test($A);
&amp;test($AB);

&amp;begin("unwhiteout file, does not exist, whiteout (corrupt)");
&amp;init($A,".../",".../file");
&amp;commit();
&amp;pass(&amp;unwhiteout("$AB","file"));
&amp;test($A,".../");
&amp;test($AB);

&amp;begin("unwhiteout file, exists on upper, no whiteout");
&amp;init($A,"file=foo");
&amp;commit();
&amp;fail(&amp;unwhiteout("$AB","file"),&amp;ENOENT);
&amp;test($A,"file=foo");
&amp;test($AB,"file=foo");

&amp;begin("unwhiteout file, exists on upper, whiteout (corrupt)");
&amp;init($A,"file",".../",".../file");
&amp;commit();
&amp;pass(&amp;unwhiteout("$AB","file"));
&amp;test($A,"file",".../");
&amp;test($AB,"file");

&amp;begin("unwhiteout file, exists on lower, no whiteout");
&amp;init($A);
&amp;init($B,"file=test");
&amp;commit();
&amp;fail(&amp;unwhiteout("$AB","file"),&amp;ENOENT);
&amp;test($A);
&amp;test($B,"file=test");
&amp;test($AB,"file=test");

&amp;begin("unwhiteout file, exists on lower, whiteout");
&amp;init($A,".../",".../file");
&amp;init($B,"file=test");
&amp;commit();
&amp;pass(&amp;unwhiteout("$AB","file"));
&amp;test($A,".../");
&amp;test($B,"file=test");
&amp;test($AB,"file=test");

# Missing test:
#   create path across file systems

&amp;clean();
print "Passed all $tests test sequences.\n";
exit(0);
</pre></body></html>