ChangeLog, random_exercise.c:
  random_exercise.c: Add support for making the test files have a
  	certain size, and also add directories as test inodes as well.

diff --git a/tests/progs/ChangeLog b/tests/progs/ChangeLog
index cfbd719..286af8b 100644
--- a/tests/progs/ChangeLog
+++ b/tests/progs/ChangeLog
@@ -1,3 +1,9 @@
+2000-10-18    <tytso@valinux.com>
+
+	* random_exercise.c: Add support for making the test files have a
+		certain size, and also add directories as test inodes as
+		well. 
+
 2000-08-20    <tytso@valinux.com>
 
 	* random_exercise.c: New file which feeds a lot of file creations
diff --git a/tests/progs/random_exercise.c b/tests/progs/random_exercise.c
index 8d55709..e9e86bc 100644
--- a/tests/progs/random_exercise.c
+++ b/tests/progs/random_exercise.c
@@ -24,6 +24,7 @@
 struct state {
 	char	name[16];
 	int	state;
+	int	isdir;
 };
 
 #define STATE_CLEAR	0
@@ -32,6 +33,8 @@
 
 struct state state_array[MAXFDS];
 
+char data_buffer[4096];
+
 void clear_state_array()
 {
 	int	i;
@@ -55,12 +58,23 @@
 {
 	char template[16] = "EX.XXXXXX";
 	int	fd;
+	int	isdir = 0;
 	
 	mktemp(template);
-	fd = open(template, O_CREAT|O_RDWR, 0600);
+	isdir = random() & 1;
+	if (isdir) {
+		if (mkdir(template, 0700) < 0)
+			return;
+		fd = open(template, O_RDONLY, 0600);
+	} else {
+		fd = open(template, O_CREAT|O_RDWR, 0600);
+		write(fd, data_buffer, sizeof(data_buffer));
+	}
 	if (fd < 0)
 		return;
-	printf("Created temp file %s, fd = %d\n", template, fd);
+	printf("Created temp %s %s, fd = %d\n",
+	       isdir ? "directory" : "file", template, fd);
+	state_array[fd].isdir = isdir;
 	state_array[fd].state = STATE_CREATED;
 	strcpy(state_array[fd].name, template);
 }
@@ -69,9 +83,12 @@
 {
 	char *filename = state_array[fd].name;
 	
-	printf("Unlinking %s, fd = %d\n", filename, fd);
-	
-	unlink(filename);
+	printf("Deleting %s, fd = %d\n", filename, fd);
+
+	if (state_array[fd].isdir)
+		rmdir(filename);
+	else
+		unlink(filename);
 	state_array[fd].state = STATE_DELETED;
 }
 
@@ -89,7 +106,10 @@
 main(int argc, char **argv)
 {
 	int	i, fd;
-	
+
+	memset(data_buffer, 0, sizeof(data_buffer));
+	sprintf(data_buffer, "This is a test file created by the "
+		"random_exerciser program\n");
 	
 	for (i=0; i < 100000; i++) {
 		fd = get_random_fd();