ChangeLog, hold_inode.c, random_exercise.c:
random_exercise.c: New file which feeds a lot of file creations and
deletions (while leaving the file descriptor open, and then closing
the file descriptor later). This generates lots of fodder for the
orphan list code, as well as for the ext3 journal.
hold_inode.c: New file which holds an inode or a directory open (for
testing orphan list code).
ChangeLog, run_e2fsck, expect.1, expect.2, image.gz, name, expect:
run_e2fsck: Filter out JFS DEBUG messages when comparing e2fsck output.
f_journal: New test case which checks out running the ext3 journal.
f_orphan: New test case which checks clearing the list of orphan
inodes (files and directories).
f_swapfs/expect: Update to reflect new debugfs format for dumping the
blocks of an inode.
2000-08-21 01:48:45 +04:00
|
|
|
/*
|
|
|
|
* random_exercise.c --- Test program which exercises an ext2
|
|
|
|
* filesystem. It creates a lot of random files in the current
|
|
|
|
* directory, while holding some files open while they are being
|
|
|
|
* deleted. This exercises the orphan list code, as well as
|
|
|
|
* creating lots of fodder for the ext3 journal.
|
2008-08-28 07:07:54 +04:00
|
|
|
*
|
ChangeLog, hold_inode.c, random_exercise.c:
random_exercise.c: New file which feeds a lot of file creations and
deletions (while leaving the file descriptor open, and then closing
the file descriptor later). This generates lots of fodder for the
orphan list code, as well as for the ext3 journal.
hold_inode.c: New file which holds an inode or a directory open (for
testing orphan list code).
ChangeLog, run_e2fsck, expect.1, expect.2, image.gz, name, expect:
run_e2fsck: Filter out JFS DEBUG messages when comparing e2fsck output.
f_journal: New test case which checks out running the ext3 journal.
f_orphan: New test case which checks clearing the list of orphan
inodes (files and directories).
f_swapfs/expect: Update to reflect new debugfs format for dumping the
blocks of an inode.
2000-08-21 01:48:45 +04:00
|
|
|
* Copyright (C) 2000 Theodore Ts'o.
|
|
|
|
*
|
|
|
|
* %Begin-Header%
|
|
|
|
* This file may be redistributed under the terms of the GNU Public
|
|
|
|
* License.
|
|
|
|
* %End-Header%
|
|
|
|
*/
|
|
|
|
|
2011-09-19 01:34:37 +04:00
|
|
|
#include "config.h"
|
ChangeLog, hold_inode.c, random_exercise.c:
random_exercise.c: New file which feeds a lot of file creations and
deletions (while leaving the file descriptor open, and then closing
the file descriptor later). This generates lots of fodder for the
orphan list code, as well as for the ext3 journal.
hold_inode.c: New file which holds an inode or a directory open (for
testing orphan list code).
ChangeLog, run_e2fsck, expect.1, expect.2, image.gz, name, expect:
run_e2fsck: Filter out JFS DEBUG messages when comparing e2fsck output.
f_journal: New test case which checks out running the ext3 journal.
f_orphan: New test case which checks clearing the list of orphan
inodes (files and directories).
f_swapfs/expect: Update to reflect new debugfs format for dumping the
blocks of an inode.
2000-08-21 01:48:45 +04:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
#define MAXFDS 128
|
|
|
|
|
|
|
|
struct state {
|
|
|
|
char name[16];
|
|
|
|
int state;
|
2000-10-18 23:06:13 +04:00
|
|
|
int isdir;
|
ChangeLog, hold_inode.c, random_exercise.c:
random_exercise.c: New file which feeds a lot of file creations and
deletions (while leaving the file descriptor open, and then closing
the file descriptor later). This generates lots of fodder for the
orphan list code, as well as for the ext3 journal.
hold_inode.c: New file which holds an inode or a directory open (for
testing orphan list code).
ChangeLog, run_e2fsck, expect.1, expect.2, image.gz, name, expect:
run_e2fsck: Filter out JFS DEBUG messages when comparing e2fsck output.
f_journal: New test case which checks out running the ext3 journal.
f_orphan: New test case which checks clearing the list of orphan
inodes (files and directories).
f_swapfs/expect: Update to reflect new debugfs format for dumping the
blocks of an inode.
2000-08-21 01:48:45 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#define STATE_CLEAR 0
|
|
|
|
#define STATE_CREATED 1
|
|
|
|
#define STATE_DELETED 2
|
|
|
|
|
|
|
|
struct state state_array[MAXFDS];
|
|
|
|
|
2001-05-11 01:03:38 +04:00
|
|
|
#define DATA_SIZE 65536
|
|
|
|
|
|
|
|
char data_buffer[DATA_SIZE];
|
2000-10-18 23:06:13 +04:00
|
|
|
|
ChangeLog, hold_inode.c, random_exercise.c:
random_exercise.c: New file which feeds a lot of file creations and
deletions (while leaving the file descriptor open, and then closing
the file descriptor later). This generates lots of fodder for the
orphan list code, as well as for the ext3 journal.
hold_inode.c: New file which holds an inode or a directory open (for
testing orphan list code).
ChangeLog, run_e2fsck, expect.1, expect.2, image.gz, name, expect:
run_e2fsck: Filter out JFS DEBUG messages when comparing e2fsck output.
f_journal: New test case which checks out running the ext3 journal.
f_orphan: New test case which checks clearing the list of orphan
inodes (files and directories).
f_swapfs/expect: Update to reflect new debugfs format for dumping the
blocks of an inode.
2000-08-21 01:48:45 +04:00
|
|
|
void clear_state_array()
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < MAXFDS; i++)
|
|
|
|
state_array[i].state = STATE_CLEAR;
|
|
|
|
}
|
|
|
|
|
|
|
|
int get_random_fd()
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
fd = ((int) random()) % MAXFDS;
|
|
|
|
if (fd > 2)
|
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-11 01:03:38 +04:00
|
|
|
unsigned int get_inode_num(int fd)
|
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
if (fstat(fd, &st) < 0) {
|
|
|
|
perror("fstat");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return st.st_ino;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
ChangeLog, hold_inode.c, random_exercise.c:
random_exercise.c: New file which feeds a lot of file creations and
deletions (while leaving the file descriptor open, and then closing
the file descriptor later). This generates lots of fodder for the
orphan list code, as well as for the ext3 journal.
hold_inode.c: New file which holds an inode or a directory open (for
testing orphan list code).
ChangeLog, run_e2fsck, expect.1, expect.2, image.gz, name, expect:
run_e2fsck: Filter out JFS DEBUG messages when comparing e2fsck output.
f_journal: New test case which checks out running the ext3 journal.
f_orphan: New test case which checks clearing the list of orphan
inodes (files and directories).
f_swapfs/expect: Update to reflect new debugfs format for dumping the
blocks of an inode.
2000-08-21 01:48:45 +04:00
|
|
|
void create_random_file()
|
|
|
|
{
|
|
|
|
char template[16] = "EX.XXXXXX";
|
|
|
|
int fd;
|
2000-10-18 23:06:13 +04:00
|
|
|
int isdir = 0;
|
2001-05-11 01:03:38 +04:00
|
|
|
int size;
|
2008-08-28 07:07:54 +04:00
|
|
|
|
ChangeLog, hold_inode.c, random_exercise.c:
random_exercise.c: New file which feeds a lot of file creations and
deletions (while leaving the file descriptor open, and then closing
the file descriptor later). This generates lots of fodder for the
orphan list code, as well as for the ext3 journal.
hold_inode.c: New file which holds an inode or a directory open (for
testing orphan list code).
ChangeLog, run_e2fsck, expect.1, expect.2, image.gz, name, expect:
run_e2fsck: Filter out JFS DEBUG messages when comparing e2fsck output.
f_journal: New test case which checks out running the ext3 journal.
f_orphan: New test case which checks clearing the list of orphan
inodes (files and directories).
f_swapfs/expect: Update to reflect new debugfs format for dumping the
blocks of an inode.
2000-08-21 01:48:45 +04:00
|
|
|
mktemp(template);
|
2000-10-18 23:06:13 +04:00
|
|
|
isdir = random() & 1;
|
|
|
|
if (isdir) {
|
|
|
|
if (mkdir(template, 0700) < 0)
|
|
|
|
return;
|
|
|
|
fd = open(template, O_RDONLY, 0600);
|
2001-05-11 01:03:38 +04:00
|
|
|
printf("Created temp directory %s, fd = %d\n",
|
|
|
|
template, fd);
|
2000-10-18 23:06:13 +04:00
|
|
|
} else {
|
2008-08-28 07:07:54 +04:00
|
|
|
size = random() & (DATA_SIZE-1);
|
2000-10-18 23:06:13 +04:00
|
|
|
fd = open(template, O_CREAT|O_RDWR, 0600);
|
2001-05-11 01:03:38 +04:00
|
|
|
write(fd, data_buffer, size);
|
|
|
|
printf("Created temp file %s, fd = %d, size=%d\n",
|
|
|
|
template, fd, size);
|
2000-10-18 23:06:13 +04:00
|
|
|
}
|
2001-05-11 01:03:38 +04:00
|
|
|
state_array[fd].isdir = isdir;
|
ChangeLog, hold_inode.c, random_exercise.c:
random_exercise.c: New file which feeds a lot of file creations and
deletions (while leaving the file descriptor open, and then closing
the file descriptor later). This generates lots of fodder for the
orphan list code, as well as for the ext3 journal.
hold_inode.c: New file which holds an inode or a directory open (for
testing orphan list code).
ChangeLog, run_e2fsck, expect.1, expect.2, image.gz, name, expect:
run_e2fsck: Filter out JFS DEBUG messages when comparing e2fsck output.
f_journal: New test case which checks out running the ext3 journal.
f_orphan: New test case which checks clearing the list of orphan
inodes (files and directories).
f_swapfs/expect: Update to reflect new debugfs format for dumping the
blocks of an inode.
2000-08-21 01:48:45 +04:00
|
|
|
if (fd < 0)
|
|
|
|
return;
|
2000-10-18 23:06:13 +04:00
|
|
|
state_array[fd].isdir = isdir;
|
ChangeLog, hold_inode.c, random_exercise.c:
random_exercise.c: New file which feeds a lot of file creations and
deletions (while leaving the file descriptor open, and then closing
the file descriptor later). This generates lots of fodder for the
orphan list code, as well as for the ext3 journal.
hold_inode.c: New file which holds an inode or a directory open (for
testing orphan list code).
ChangeLog, run_e2fsck, expect.1, expect.2, image.gz, name, expect:
run_e2fsck: Filter out JFS DEBUG messages when comparing e2fsck output.
f_journal: New test case which checks out running the ext3 journal.
f_orphan: New test case which checks clearing the list of orphan
inodes (files and directories).
f_swapfs/expect: Update to reflect new debugfs format for dumping the
blocks of an inode.
2000-08-21 01:48:45 +04:00
|
|
|
state_array[fd].state = STATE_CREATED;
|
|
|
|
strcpy(state_array[fd].name, template);
|
|
|
|
}
|
|
|
|
|
2001-05-11 01:03:38 +04:00
|
|
|
void truncate_file(int fd)
|
|
|
|
{
|
|
|
|
int size;
|
|
|
|
|
|
|
|
size = random() & (DATA_SIZE-1);
|
|
|
|
|
|
|
|
if (state_array[fd].isdir)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ftruncate(fd, size);
|
|
|
|
printf("Truncating temp file %s, fd = %d, ino=%u, size=%d\n",
|
|
|
|
state_array[fd].name, fd, get_inode_num(fd), size);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
ChangeLog, hold_inode.c, random_exercise.c:
random_exercise.c: New file which feeds a lot of file creations and
deletions (while leaving the file descriptor open, and then closing
the file descriptor later). This generates lots of fodder for the
orphan list code, as well as for the ext3 journal.
hold_inode.c: New file which holds an inode or a directory open (for
testing orphan list code).
ChangeLog, run_e2fsck, expect.1, expect.2, image.gz, name, expect:
run_e2fsck: Filter out JFS DEBUG messages when comparing e2fsck output.
f_journal: New test case which checks out running the ext3 journal.
f_orphan: New test case which checks clearing the list of orphan
inodes (files and directories).
f_swapfs/expect: Update to reflect new debugfs format for dumping the
blocks of an inode.
2000-08-21 01:48:45 +04:00
|
|
|
void unlink_file(int fd)
|
|
|
|
{
|
|
|
|
char *filename = state_array[fd].name;
|
2008-08-28 07:07:54 +04:00
|
|
|
|
2001-05-11 01:03:38 +04:00
|
|
|
printf("Deleting %s, fd = %d, ino = %u\n", filename, fd,
|
|
|
|
get_inode_num(fd));
|
2000-10-18 23:06:13 +04:00
|
|
|
|
|
|
|
if (state_array[fd].isdir)
|
|
|
|
rmdir(filename);
|
|
|
|
else
|
|
|
|
unlink(filename);
|
ChangeLog, hold_inode.c, random_exercise.c:
random_exercise.c: New file which feeds a lot of file creations and
deletions (while leaving the file descriptor open, and then closing
the file descriptor later). This generates lots of fodder for the
orphan list code, as well as for the ext3 journal.
hold_inode.c: New file which holds an inode or a directory open (for
testing orphan list code).
ChangeLog, run_e2fsck, expect.1, expect.2, image.gz, name, expect:
run_e2fsck: Filter out JFS DEBUG messages when comparing e2fsck output.
f_journal: New test case which checks out running the ext3 journal.
f_orphan: New test case which checks clearing the list of orphan
inodes (files and directories).
f_swapfs/expect: Update to reflect new debugfs format for dumping the
blocks of an inode.
2000-08-21 01:48:45 +04:00
|
|
|
state_array[fd].state = STATE_DELETED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void close_file(int fd)
|
|
|
|
{
|
|
|
|
char *filename = state_array[fd].name;
|
2008-08-28 07:07:54 +04:00
|
|
|
|
2001-05-11 01:03:38 +04:00
|
|
|
printf("Closing %s, fd = %d, ino = %u\n", filename, fd,
|
|
|
|
get_inode_num(fd));
|
2008-08-28 07:07:54 +04:00
|
|
|
|
ChangeLog, hold_inode.c, random_exercise.c:
random_exercise.c: New file which feeds a lot of file creations and
deletions (while leaving the file descriptor open, and then closing
the file descriptor later). This generates lots of fodder for the
orphan list code, as well as for the ext3 journal.
hold_inode.c: New file which holds an inode or a directory open (for
testing orphan list code).
ChangeLog, run_e2fsck, expect.1, expect.2, image.gz, name, expect:
run_e2fsck: Filter out JFS DEBUG messages when comparing e2fsck output.
f_journal: New test case which checks out running the ext3 journal.
f_orphan: New test case which checks clearing the list of orphan
inodes (files and directories).
f_swapfs/expect: Update to reflect new debugfs format for dumping the
blocks of an inode.
2000-08-21 01:48:45 +04:00
|
|
|
close(fd);
|
|
|
|
state_array[fd].state = STATE_CLEAR;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int i, fd;
|
2000-10-18 23:06:13 +04:00
|
|
|
|
|
|
|
memset(data_buffer, 0, sizeof(data_buffer));
|
|
|
|
sprintf(data_buffer, "This is a test file created by the "
|
|
|
|
"random_exerciser program\n");
|
2008-08-28 07:07:54 +04:00
|
|
|
|
ChangeLog, hold_inode.c, random_exercise.c:
random_exercise.c: New file which feeds a lot of file creations and
deletions (while leaving the file descriptor open, and then closing
the file descriptor later). This generates lots of fodder for the
orphan list code, as well as for the ext3 journal.
hold_inode.c: New file which holds an inode or a directory open (for
testing orphan list code).
ChangeLog, run_e2fsck, expect.1, expect.2, image.gz, name, expect:
run_e2fsck: Filter out JFS DEBUG messages when comparing e2fsck output.
f_journal: New test case which checks out running the ext3 journal.
f_orphan: New test case which checks clearing the list of orphan
inodes (files and directories).
f_swapfs/expect: Update to reflect new debugfs format for dumping the
blocks of an inode.
2000-08-21 01:48:45 +04:00
|
|
|
for (i=0; i < 100000; i++) {
|
|
|
|
fd = get_random_fd();
|
|
|
|
switch (state_array[fd].state) {
|
|
|
|
case STATE_CLEAR:
|
|
|
|
create_random_file();
|
|
|
|
break;
|
|
|
|
case STATE_CREATED:
|
2001-05-11 01:03:38 +04:00
|
|
|
if ((state_array[fd].isdir == 0) &&
|
|
|
|
(random() & 2))
|
|
|
|
truncate_file(fd);
|
|
|
|
else
|
|
|
|
unlink_file(fd);
|
ChangeLog, hold_inode.c, random_exercise.c:
random_exercise.c: New file which feeds a lot of file creations and
deletions (while leaving the file descriptor open, and then closing
the file descriptor later). This generates lots of fodder for the
orphan list code, as well as for the ext3 journal.
hold_inode.c: New file which holds an inode or a directory open (for
testing orphan list code).
ChangeLog, run_e2fsck, expect.1, expect.2, image.gz, name, expect:
run_e2fsck: Filter out JFS DEBUG messages when comparing e2fsck output.
f_journal: New test case which checks out running the ext3 journal.
f_orphan: New test case which checks clearing the list of orphan
inodes (files and directories).
f_swapfs/expect: Update to reflect new debugfs format for dumping the
blocks of an inode.
2000-08-21 01:48:45 +04:00
|
|
|
break;
|
|
|
|
case STATE_DELETED:
|
|
|
|
close_file(fd);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|