Esempio n. 1
0
void test30c()
{
  int fd, does_truncate;

  subtest = 3;

  System("rm -rf ../DIR_30/*");

  if (!superuser) {
	/* Test if creat is not usable to open files with the wrong mode */
	System("> nono; chmod 177 nono");
	fd = creat("nono", 0777);
	if (fd != -1) e(1);
	if (errno != EACCES) e(2);
  }
  if (mkdir("bar", 0777) != 0) e(3);	/* make bar */

  /* Check if no access on part of path generates the correct error. */
  System("chmod 577 bar");	/* r-xrwxrwx */
  if (!superuser) {
	/* Normal users can't creat without write permision. */
	if (creat("bar/nono", 0666) != -1) e(4);
	if (errno != EACCES) e(5);
	if (creat("bar/../nono", 0666) != -1) e(6);
	if (errno != EACCES) e(7);
  }
  if (superuser) {
	/* Super user can still creat stuff. */
	if ((fd = creat("bar/nono", 0666)) != 3) e(8);
	if (close(fd) != 0) e(9);
	if (unlink("bar/nono") != 0) e(10);
  }

  /* Clean up bar. */
  System("rm -rf bar");

  /* Test ToLongName and ToLongPath */
  does_truncate = does_fs_truncate();
  fd = creat(ToLongName, 0777);
  if (does_truncate) {
	if (fd == -1) e(11);
	if (close(fd) != 0) e(12);
  } else {
	if (fd != -1) e(13);
	if (errno != ENAMETOOLONG) e(14);
	(void) close(fd);			/* Just in case. */
  }

  ToLongPath[PATH_MAX - 2] = '/';
  ToLongPath[PATH_MAX - 1] = 'a';
  if ((fd = creat(ToLongPath, 0777)) != -1) e(15);
  if (errno != ENAMETOOLONG) e(16);
  if (close(fd) != -1) e(17);
  ToLongPath[PATH_MAX - 1] = '/';
}
Esempio n. 2
0
void test24c()
{
/* Test whether wrong things go wrong right. */

  DIR *dirp;
  int does_truncate;

  subtest = 3;

  System("rm -rf ../DIR_24/*");

  if (opendir("foo/bar/nono") != ((DIR *) NULL)) e(1);	/* nonexistent */
  if (errno != ENOENT) e(2);
  System("mkdir foo; chmod 677 foo");	/* foo inaccesable */
  if (opendir("foo/bar/nono") != ((DIR *) NULL)) e(3);
  if (superuser) {
	if (errno != ENOENT) e(4);	/* su has access */
	System("chmod 377 foo");
	if ((dirp = opendir("foo")) == ((DIR *) NULL)) e(5);
	if (closedir(dirp) != 0) e(6);
  }
  if (!superuser) {
	if (errno != EACCES) e(7);	/* we don't ;-) */
	System("chmod 377 foo");
	if (opendir("foo") != ((DIR *) NULL)) e(8);
  }
  System("chmod 777 foo");

  if (mkdir(MaxName, 0777) != 0) e(9);	/* make longdir */
  if ((dirp = opendir(MaxName)) == ((DIR *) NULL)) e(10);	/* open it */
  if (closedir(dirp) != 0) e(11);	/* close it */
  if (rmdir(MaxName) != 0) e(12);	/* then remove it */
  if ((dirp = opendir(MaxPath)) == ((DIR *) NULL)) e(13);	/* open '.'  */
  if (closedir(dirp) != 0) e(14);	/* close it */

  does_truncate = does_fs_truncate();
  if (opendir(ToLongName) != ((DIR *) NULL)) e(17);	/* is too long */
  if (does_truncate) {
	if (errno != ENOENT) e(18);
  } else {
	if (errno != ENAMETOOLONG) e(19);
  }

  if (opendir(ToLongPath) != ((DIR *) NULL)) e(20);	/* path is too long */
  if (errno != ENAMETOOLONG) e(21);
  System("touch foo/abc");	/* make a file */
  if (opendir("foo/abc") != ((DIR *) NULL)) e(22);	/* not a dir */
  if (errno != ENOTDIR) e(23);
}
Esempio n. 3
0
void test23b()
{				/* Test critical values. */
  int does_truncate;
  subtest = 2;

  System("rm -rf ../DIR_23/*");

  /* Fiddle with the size (2nd) parameter of `getcwd ()'. */
  if (getcwd(cwd, PATH_MAX) != cwd) e(1);	/* get cwd */
  if (getcwd(buf, strlen(cwd)) != (char *) 0) e(2);   /* size 1 to small */
  if (errno != ERANGE) e(3);
  if (getcwd(buf, PATH_MAX) != buf) e(4);
  if (strcmp(buf, cwd) != 0) e(5);
  Chdir(cwd);			/* getcwd might cd / */
  if (getcwd(buf, strlen(cwd) + 1) != buf) e(6);	/* size just ok */
  if (getcwd(buf, PATH_MAX) != buf) e(7);
  if (strcmp(buf, cwd) != 0) e(8);

  /* Let's see how "MaxName" and "ToLongName" are handled. */
  if (mkdir(MaxName, 0777) != 0) e(9);
  if (chdir(MaxName) != 0) e(10);
  if (chdir("..") != 0) e(11);
  if (rmdir(MaxName) != 0) e(12);
  if (getcwd(buf, PATH_MAX) != buf) e(13);
  if (strcmp(buf, cwd) != 0) e(14);
  if (chdir(MaxPath) != 0) e(15);
  if (getcwd(buf, PATH_MAX) != buf) e(16);
  if (strcmp(buf, cwd) != 0) e(17);

  does_truncate = does_fs_truncate();
  if (chdir(ToLongName) != -1) e(18);
  if (does_truncate) {
	if (errno != ENOENT) e(19);
  } else {
  	if (errno != ENAMETOOLONG) e(20);
  }

  if (getcwd(buf, PATH_MAX) != buf) e(21);
  if (strcmp(buf, cwd) != 0) e(22);
  if (chdir(ToLongPath) != -1) e(23);
  if (errno != ENAMETOOLONG) e(24);
  if (getcwd(buf, PATH_MAX) != buf) e(25);
  if (strcmp(buf, cwd) != 0) e(26);
}
Esempio n. 4
0
void test35c()
{
  gid_t gid, gid2;
  uid_t uid, uid2;
  struct utimbuf ub;
  int fd, does_truncate, stat_loc;

  subtest = 3;

  /* Access problems. */
  Mkdir("bar");
  Creat("bar/tryme");
  if (superuser) {
	Chmod("bar", 0000);	/* No search permisson at all. */
	if (utime("bar/tryme", NULL) != 0) e(1);
  }
  if (!superuser) {
	Chmod("bar", 0677);	/* No search permisson. */
	if (utime("bar/tryme", NULL) != -1) e(2);
	if (errno != EACCES) e(3);
  }
  Chmod("bar", 0777);

  if (I_can_chown) {
	switch (fork()) {
	    case -1:	printf("Can't fork\n");	break;
	    case 0:
		alarm(20);

		/* Get two differend non root uids. */
		if (superuser) {
			getids(&uid, &gid);
			if (uid == 0) getids(&uid, &gid);
			if (uid == 0) e(4);
		}
		if (!superuser) {
			uid = geteuid();
			gid = getegid();
		}
		getids(&uid2, &gid);
		if (uid == uid2) getids(&uid2, &gid2);
		if (uid == uid2) e(5);

		/* Creat a number of files for root, user and user2. */
		Creat("rootfile");	/* Owned by root. */
		Chmod("rootfile", 0600);
		Chown("rootfile", 0, 0);
		Creat("user2file");	/* Owned by user 2, writeable. */
		Chmod("user2file", 0020);
		Chown("user2file", uid2, gid);
		Creat("user2private");	/* Owned by user 2, privately. */
		Chmod("user2private", 0600);
		Chown("user2private", uid2, gid);

		if (superuser) {
			setgid(gid);
			setuid(uid);
		}

		/* We now are user ``uid'' from group ``gid''. */
		ub.actime = (time_t) 12345L;
		ub.modtime = (time_t) 12345L;

		if (utime("rootfile", NULL) != -1) e(6);
		if (errno != EACCES) e(7);
		if (utime("rootfile", &ub) != -1) e(8);
		if (errno != EPERM) e(9);

		if (utime("user2file", NULL) != 0) e(10);
		if (utime("user2file", &ub) != -1) e(11);
		if (errno != EPERM) e(12);

		if (utime("user2private", NULL) != -1) e(13);
		if (errno != EACCES) e(14);
		if (utime("user2private", &ub) != -1) e(15);
		if (errno != EPERM) e(16);

		exit(errct ? 1 : 0);
	    default:
		wait(&stat_loc);
		if (stat_loc != 0) e(17);	/* Alarm? */
	}
  }

  /* Test names that are too long. */
  does_truncate = does_fs_truncate();
  fd = creat(NameTooLong, 0777);
  if (does_truncate) {
	if (utime(NameTooLong, NULL) != 0) e(18);
  } else {
	if (utime(NameTooLong, NULL) != -1) e(19);
	if (errno != ENAMETOOLONG) e(20);
  }
  (void) close(fd);

  /* Make PathTooLong contain ././.../a */
  PathTooLong[strlen(PathTooLong) - 2] = '/';
  PathTooLong[strlen(PathTooLong) - 1] = 'a';
  Creat("a");
  if (utime(PathTooLong, NULL) != -1) e(21);
  if (errno != ENAMETOOLONG) e(22);

  /* Non existing file name. */
  if (utime("nonexist", NULL) != -1) e(23);
  if (errno != ENOENT) e(24);

  /* Empty file name. */
  if (utime("", NULL) != -1) e(25);
  if (errno != ENOENT) e(26);

  System("rm -rf ../DIR_35/*");
}
Esempio n. 5
0
void test33c()
{				/* Test errors returned. */
  int i, fd, does_truncate;

  subtest = 3;
  System("rm -rf ../DIR_33/*");

  /* Test what access() does with non existing files. */
  System("rm -rf nonexist");
  if (access("noexist", F_OK) != -1) e(1);
  if (errno != ENOENT) e(2);
  if (access("noexist", R_OK) != -1) e(3);
  if (errno != ENOENT) e(4);
  if (access("noexist", W_OK) != -1) e(5);
  if (errno != ENOENT) e(6);
  if (access("noexist", X_OK) != -1) e(7);
  if (errno != ENOENT) e(8);
  if (access("noexist", R_OK | W_OK) != -1) e(9);
  if (errno != ENOENT) e(10);
  if (access("noexist", R_OK | X_OK) != -1) e(11);
  if (errno != ENOENT) e(12);
  if (access("noexist", W_OK | X_OK) != -1) e(13);
  if (errno != ENOENT) e(14);
  if (access("noexist", R_OK | W_OK | X_OK) != -1) e(15);
  if (errno != ENOENT) e(16);

  /* Test access on a nonsearchable path. */
  if (mkdir("nosearch", 0777) != 0) e(1000);
  if ( (i = creat("nosearch/file", 0666)) < 0) e(1001);
  if (close(i) < 0) e(1002);
  if ( (i = creat("file", 0666) < 0)) e(1003);
  if (close(i) < 0) e(1004);
  if (chmod("nosearch/file", 05777) < 0) e(1005);
  if (chmod("file", 05777) < 0) e(1006);
  if (chmod("nosearch", 0677) != 0) e(1007);
  if (access("nosearch/file", F_OK) != 0) e(17);

  /* Test ToLongName and ToLongPath */
  does_truncate = does_fs_truncate();
  if (does_truncate) {
  	if ((fd = creat(ToLongName, 0777)) != 0) e(18);
  	if (close(fd) != 0) e(19);
	if (access(ToLongName, F_OK) != 0) e(20);
  } else {
  	if ((fd = creat(ToLongName, 0777)) != -1) e(21);
	if (errno != ENAMETOOLONG) e(22);
  	(void) close(fd);	/* Just in case */
	if (access(ToLongName, F_OK) != -1) e(23);
	if (errno != ENAMETOOLONG) e(24);
  }

  ToLongPath[PATH_MAX - 2] = '/';
  ToLongPath[PATH_MAX - 1] = 'a';
  if (access(ToLongPath, F_OK) != -1) e(27);
  if (errno != ENAMETOOLONG) e(28);
  ToLongPath[PATH_MAX - 1] = '/';

  /* Test empty strings. */
  if (access("", F_OK) != -1) e(29);
  if (errno != ENOENT) e(30);
  System("rm -rf idonotexist");
  if (access("idonotexist", F_OK) != -1) e(31);
  if (errno != ENOENT) e(32);

  /* Test non directorys in prefix of path. */
  if (access("/etc/passwd/dir/foo", F_OK) != -1) e(33);
  if (errno != ENOTDIR) e(34);
  System("rm -rf nodir; > nodir");
  if (access("nodir/foo", F_OK) != -1) e(35);
  if (errno != ENOTDIR) e(36);

  /* Test if invalid amode arguments are signaled. */
  System("> allmod");
  Chmod("allmod", 05777);
  for (i = -1025; i < 1025; i++) {
	if ((mode_t) i != F_OK && ((mode_t) i & ~(R_OK | W_OK | X_OK)) != 0) {
		if (access("allmod", (mode_t) i) != -1) e(37);
		if (errno != EINVAL) e(38);
	} else 
		if (access("allmod", (mode_t) i) != 0) e(39);
  }
}
Esempio n. 6
0
void test25e()
{
  int fd, does_truncate;
  char *noread = "noread";	/* Name for unreadable file. */
  char *nowrite = "nowrite";	/* Same for unwritable. */
  int stat_loc;

  subtest = 5;

  System("rm -rf ../DIR_25/*");

  mkdir("bar", 0777);		/* make bar */

  /* Check if no access on part of path generates the correct error. */
  System("chmod 677 bar");	/* rw-rwxrwx */
  if (open("bar/nono", O_RDWR | O_CREAT, 0666) != -1) e(1);
  if (errno != EACCES) e(2);

  /* Ditto for no write permission. */
  System("chmod 577 bar");	/* r-xrwxrwx */
  if (open("bar/nono", O_RDWR | O_CREAT, 0666) != -1) e(3);
  if (errno != EACCES) e(4);

  /* Clean up bar. */
  System("rm -rf bar");

  /* Improper flags set on existing file. */
  System("touch noread; chmod 377 noread");	/* noread */
  if (open(noread, O_RDONLY) != -1) e(5);
  if (open(noread, O_RDWR) != -1) e(6);
  if (open(noread, O_RDWR | O_CREAT, 0777) != -1) e(7);
  if (open(noread, O_RDWR | O_CREAT | O_TRUNC, 0777) != -1) e(8);
  if ((fd = open(noread, O_WRONLY)) != 3) e(9);
  if (close(fd) != 0) e(10);
  System("touch nowrite; chmod 577 nowrite");	/* nowrite */
  if (open(nowrite, O_WRONLY) != -1) e(11);
  if (open(nowrite, O_RDWR) != -1) e(12);
  if (open(nowrite, O_RDWR | O_CREAT, 0777) != -1) e(13);
  if (open(nowrite, O_RDWR | O_CREAT | O_TRUNC, 0777) != -1) e(14);
  if ((fd = open(nowrite, O_RDONLY)) != 3) e(15);
  if (close(fd) != 0) e(16);
  if (superuser) {
	/* If we can make a file ownd by some one else, test access again. */
	System("chmod 733 noread");
	System("chown bin noread");
	System("chgrp system noread");
	System("chmod 755 nowrite");
	System("chown bin nowrite");
	System("chgrp system nowrite");
	switch (fork()) {
	    case -1:	printf("Can't fork\n");	break;
	    case 0:
		setuid(1);
		setgid(1);	/* become daemon */
		if (open(noread, O_RDONLY) != -1) e(17);
		if (open(noread, O_RDWR) != -1) e(18);
		if (open(noread, O_RDWR | O_CREAT, 0777) != -1) e(19);
		fd = open(noread, O_RDWR | O_CREAT | O_TRUNC, 0777);
		if (fd != -1) e(20);
		if ((fd = open(noread, O_WRONLY)) != 3) e(21);
		if (close(fd) != 0) e(22);
		if (open(nowrite, O_WRONLY) != -1) e(23);
		if (open(nowrite, O_RDWR) != -1) e(24);
		if (open(nowrite, O_RDWR | O_CREAT, 0777) != -1) e(25);
		fd = open(nowrite, O_RDWR | O_CREAT | O_TRUNC, 0777);
		if (fd != -1) e(26);
		if ((fd = open(nowrite, O_RDONLY)) != 3) e(27);
		if (close(fd) != 0) e(28);
		exit(0);
	    default:
		if (wait(&stat_loc) == -1) e(29);
	}
  }

  /* Clean up the noread and nowrite files. */
  System("rm -rf noread nowrite");

  /* Test the O_EXCL flag. */
  System("echo > exists");
  if (open("exists", O_RDWR | O_CREAT | O_EXCL, 0777) != -1) e(30);
  if (errno != EEXIST) e(31);
  if (open("exists", O_RDONLY | O_CREAT | O_EXCL, 0777) != -1) e(32);
  if (errno != EEXIST) e(33);
  if (open("exists", O_WRONLY | O_CREAT | O_EXCL, 0777) != -1) e(34);
  if (errno != EEXIST) e(35);
  fd = open("exists", O_RDWR | O_CREAT | O_EXCL | O_TRUNC, 0777);
  if (fd != -1) e(36);
  if (errno != EEXIST) e(37);
  fd = open("exists", O_RDONLY | O_CREAT | O_EXCL | O_TRUNC, 0777);
  if (fd != -1) e(38);
  if (errno != EEXIST) e(39);
  fd = open("exists", O_WRONLY | O_CREAT | O_EXCL | O_TRUNC, 0777);
  if (fd != -1) e(40);
  if (errno != EEXIST) e(41);

  /* open should fail when O_CREAT|O_EXCL are set and a symbolic link names
     a file with EEXIST (regardless of link actually works or not) */
  if (symlink("exists", "slinktoexists") == -1) e(42);
  if (open("slinktoexists", O_RDWR | O_CREAT | O_EXCL, 0777) != -1) e(43);
  if (unlink("exists") == -1) e(44);
  /* "slinktoexists has become a dangling symlink. open(2) should still fail
     with EEXIST */
  if (open("slinktoexists", O_RDWR | O_CREAT | O_EXCL, 0777) != -1) e(45);
  if (errno != EEXIST) e(46);
  

  /* Test ToLongName and ToLongPath */
  does_truncate = does_fs_truncate();
  fd = open(ToLongName, O_RDWR | O_CREAT, 0777);
  if (does_truncate) {
  	if (fd == -1) e(47);
  	if (close(fd) != 0) e(48);
  } else {
  	if (fd != -1) e(49);
  	(void) close(fd);		/* Just in case */
  }

  ToLongPath[PATH_MAX - 2] = '/';
  ToLongPath[PATH_MAX - 1] = 'a';
  if ((fd = open(ToLongPath, O_RDWR | O_CREAT, 0777)) != -1) e(50);
  if (errno != ENAMETOOLONG) e(51);
  if (close(fd) != -1) e(52);
  ToLongPath[PATH_MAX - 1] = '/';
}
Esempio n. 7
0
void test28b()
{				/* Test critical values. */
  struct stat st;
  DIR *dirp;
  struct dirent *dep;
  int fd;			/* file descriptor */
  int other = 0, dot = 0, dotdot = 0;	/* dirent counters */
  int r;			/* Intermediate result */
  int rmdir_result;		/* tmp var */
  nlink_t nlink;
  static char bar[20];
  int stat_loc, does_truncate;

  subtest = 2;

  System("rm -rf ../DIR_28/*");

  /* Check funny but valid path names */
  if (mkdir("/../../..////.//../tmp/foo/", 0777) != 0) e(1);
  if (mkdir("/tmp/foo//////..//foo//../foo/bar/", 0777) != 0) e(2);
  if (rmdir("///tmp/..//tmp/foo/bar//../..//foo/bar") != 0) e(3);
  if (mkdir("///tmp/foo/foobar//", 0777) != 0) e(4);
  if (rmdir("/tmp/foo/foobar//") != 0) e(5);
  if (rmdir("/.././/././/tmp/foo///////////////") != 0) e(6);
  if (rmdir("/tmp/foo") != -1) e(7);	/* try again */

  /* Test max path ed. */
  if (mkdir(MaxName, 0777) != 0) e(9);	/* make dir MaxName */
  if (rmdir(MaxName) != 0) e(10);	/* and remove it */
  MaxPath[strlen(MaxPath) - 2] = '/';	/* convert MaxPath */
  MaxPath[strlen(MaxPath) - 1] = 'a';	/* to ././.../a */
  if (mkdir(MaxPath, 0777) != 0) e(11);	/* it should be */
  if (rmdir(MaxPath) != 0) e(12);	/* ok */

  /* Test too long path ed. */
  does_truncate = does_fs_truncate();
  r =  mkdir(ToLongName, 0777);
  if (does_truncate ) {
  	/* FS truncates names, mkdir should've worked */
  	if (r != 0) e(13);	/* Try ToLongName */
	if (rmdir(ToLongName) != 0) e(14);	/* and remove it */
  } else {
  	/* Too long, should've failed with ENAMETOOLONG */
  	if (r == 0) e(15);
  	if (errno != ENAMETOOLONG) e(16);
  }
  ToLongPath[strlen(ToLongPath) - 2] = '/';	/* make ToLongPath */
  ToLongPath[strlen(ToLongPath) - 1] = 'a';	/* contain ././.../a */
  if (mkdir(ToLongPath, 0777) != -1) e(17);	/* it should */
  if (errno != ENAMETOOLONG) e(18);	/* not be ok */
  if (rmdir(ToLongPath) != -1) e(19);
  if (errno != ENAMETOOLONG) e(20);

  if (mkdir("foo", 0777) != 0) e(21);
  System("touch foo/xyzzy");
#if 0
  /* Test what happens if the parent link count > LINK_MAX. */
  /* This takes too long. */
  for (nlink = 1; nlink < LINK_MAX; nlink++) {	/* make all */
  	sprintf(bar, "foo/bar.%d", nlink);
	if (link("foo/xyzzy", bar) != 0) e(24);
  }
  if (stat("foo/xyzzy", &st) != 0) e(25);	/* foo now */
  if (st.st_nlink != LINK_MAX) e(26);	/* is full */
  if (link("foo/xyzzy", "nono") != -1) e(27);	/* no more */
  if (errno != EMLINK) e(28);	/* entrys. */
  System("rm -rf foo/nono");	/* Just in case. */
#endif

  /* Test if rmdir removes only empty dirs */
  if (rmdir("foo") != -1) e(29);/* not empty */
  if (errno != EEXIST && errno != ENOTEMPTY) e(30);
  /* Test if rmdir removes a dir with an empty file (it shouldn't.) */
  System("rm -rf foo");		/* cleanup */
  if (mkdir("foo", 0777) != 0) e(31);
  System("> foo/empty");	/* > empty */
  if (rmdir("foo") != -1) e(32);/* not empty */
  if (errno != EEXIST && errno != ENOTEMPTY) e(33);
  if (unlink("foo/empty") != 0) e(34);	/* rm empty */

  /* See what happens if foo is linked. */
#if 0
  if (superuser) {
	if (link("foo", "footoo") != 0) e(35);	/* foo still */
	if (rmdir("footoo") != 0) e(36);	/* exist */
	if (chdir("footoo") != -1) e(37);	/* footoo */
	if (errno != ENOENT) e(38);	/* is gone */
  }
#endif
#ifdef _MINIX
  /* Some implementations might allow users to link directories. */
  if (!superuser) {
	if (link("foo", "footoo") != -1) e(39);
	if (errno != EPERM) e(40);
	if (unlink("foo") != -1) e(41);
	if (errno != EPERM) e(42);
  }
#endif

  /* See if ".." and "." are removed from the dir, and if it is
   * unwriteable
   * Note, we can not remove any files in the PARENT
   * process, because this
   * will make readdir unpredicatble. (see
   * 1003.1 page 84 line 30.) However
   * removal of the directory is
   * not specified in the standard.
   */
  System("rm -rf /tmp/sema[12].07");
  switch (fork()) {
      case -1:	printf("Can't fork\n");	break;

      case 0:
	alarm(20);
	if ((fd = open("foo", O_RDONLY)) <= 2) e(43);	/* open */
	if ((dirp = opendir("foo")) == (DIR *) NULL) e(44);	/* opendir */
	/* UpA downB */
	system(">/tmp/sema1.07; while test -f /tmp/sema1.07; do sleep 1;done");
	while ((dep = readdir(dirp)) != DIRENT0) {
		if (strcmp(dep->d_name, "..") == 0)
			dotdot += 1;
		else if (strcmp(dep->d_name, ".") == 0)
			dot += 1;
		else
			other += 1;
	}
	if (dotdot != 0) e(45);	/* no entrys */
	if (dot != 0) e(46);	/* shoul be */
	if (other != 0) e(47);	/* left or */

	/* No new files (entrys) are allowed on foo */
	if (creat("foo/nono", 0777) != -1) e(48);	/* makeable */
	if (closedir(dirp) != 0) e(49);	/* close foo */
	system("while test ! -f /tmp/sema2.07; do sleep 1; done");  /* downA */
	System("rm -f /tmp/sema2.07");	/* clean up */

	/* Foo still exist, so we should be able to get a fstat */
	if (fstat(fd, &st) != 0) e(50);
	if (st.st_nlink != (nlink_t) 0) e(51);	/* 0 left */
	if (close(fd) != 0) e(52);	/* last one */
	exit(0);

      default:
	system("while test ! -f /tmp/sema1.07; do sleep 1; done");  /* downA */
	if (rmdir("foo") != 0) e(53);	/* cleanerup */
	System("rm -f /tmp/sema1.07");	/* upB */
	if (chdir("foo") != -1) e(54);	/* it should */
	if (errno != ENOENT) e(55);	/* be gone */
	System("> /tmp/sema2.07");	/* upA */
	if (wait(&stat_loc) == -1) e(56);
	if (stat_loc != 0) e(57);
  }

  /* See if foo isn't accessible any more */
  if (chdir("foo") != -1) e(58);
  if (errno != ENOENT) e(59);

  /* Let's see if we can get a EBUSSY..... */
  if (mkdir("foo", 0777) != 0) e(60);	/* mkdir foo */
  System("rm -f /tmp/sema.07");	/* unness */
  switch (fork()) {
      case -1:	printf("Can't fork\n");	break;
      case 0:
	alarm(20);
	if (chdir("foo") != 0) e(61);	/* child goes */
	System("> /tmp/sema.07");	/* upA */
	system("while test -f /tmp/sema.07; do sleep 1; done");	/* downB */
	sleep(1);
	exit(0);
      default:
	system("while test ! -f /tmp/sema.07; do sleep 1; done");   /* downA */
	rmdir_result = rmdir("foo");	/* try remove */
	if (rmdir_result == -1) {	/* if it failed */
		if (errno != EBUSY) e(62);	/* foo is busy */
	} else {
		if (rmdir_result != 0) e(63);
		if (rmdir("foo") != -1) e(64);	/* not removable */
		if (errno != ENOENT) e(65);	/* again. */
		if (chdir("foo") != -1) e(66);	/* we can't go */
		if (errno != ENOENT) e(67);	/* there any more */
		if (mkdir("foo", 0777) != 0) e(68);	/* we can remake foo */
	}
	System("rm -f /tmp/sema.07");	/* upB */
	if (wait(&stat_loc) == -1) e(69);
	if (stat_loc != 0) e(70);
  }
  if (rmdir("foo") != 0) e(71);	/* clean up */
}