2 * YAFFS: Yet another FFS. A NAND-flash specific file system.
4 * Copyright (C) 2002-2010 Aleph One Ltd.
5 * for Toby Churchill Ltd and Brightstar Engineering
7 * Created by Timothy Manning <timothy@yaffs.net>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
14 #include "linux_test.h"
17 int simulate_power_failure = 1;
19 char message[400]; //this is used for storing print messages.
23 dir_struct *scanned_dir=NULL;
28 while (break_bool!=1){
31 if (x<0 &&(break_bool!=1)){
36 if (x<0 &&(break_bool!=1)){
41 if (x<0 &&(break_bool!=1)){
46 if (x<0 &&(break_bool!=1)){
47 output=symlink_test();
51 if (x<0 &&(break_bool!=1)){
56 if (x<0 &&(break_bool!=1)){
61 if (x<0 &&(break_bool!=1)){
62 scanned_dir=scan_dir();
64 output=remount_test();
65 check_dir(scanned_dir);
66 scanned_dir=NULL; //the scanned dir has been freed in check_dir.
70 //printf("resetting x\n");
71 check_function(output);
78 dir_struct * scan_dir(void)
80 struct dirent *dir_data;
82 dir=malloc(sizeof(dir_struct));
83 memset(dir, NULL, sizeof(dir_struct));
87 open_dir=opendir(ROOT_PATH);
88 dir_data=readdir(open_dir);
90 dir->path_list=linked_list_add_node(HEAD,dir->path_list);
91 dir->path_list->string=malloc(strlen(dir_data->d_name)+1);
92 strcpy(dir->path_list->string,dir_data->d_name);
93 sprintf(message,"opened file: %s\n",dir->path_list->string);
94 print_message(3,message);
95 dir_data=readdir(open_dir);
98 node_print_pointers(dir->path_list);
102 int check_dir(dir_struct *old_dir)
104 dir_struct *new_dir=scan_dir();
105 node *new_list=new_dir->path_list;
106 node *old_list=old_dir->path_list;
108 print_message(3,"checking dir\n");
109 for (;old_list!= NULL;old_list=old_list->next){
111 for (;(new_list=NULL) && (exit_loop !=1);new_list=new_list->next){
112 sprintf(message,"comparing %s and %s\n",old_list->string,new_list->string);
113 print_message(3,message);
114 if (strcmp( new_list->string ,old_list->string)==0){
115 //files match -now compare the modes and contents of the files.
116 //and set the paths to NULL.
119 /*if (new_list->next==NULL){
120 print_message(3,"next is null\n");
125 //failed to find a matching file
126 sprintf(message,"a file has disappeared: %s\n",old_list->string);
127 print_message(3,message);
130 new_list=new_dir->path_list;
133 //now check if there are any old unmatched files
135 //free both data structs
136 delete_linked_list(old_dir->path_list);
137 delete_linked_list(new_dir->path_list);
138 new_dir->path_list=NULL;
139 old_dir->path_list=NULL;
144 int remount_test(void)
147 print_message(3,"\nunmounting\n");
148 output=umount2("/mnt/y",MNT_FORCE);
149 check_function(output);
150 print_message(3,"mounting\n");
151 mount("/dev/mtdblock0","/mnt/y","yaffs2",0,NULL);
152 check_function(output);
158 char string[FILE_NAME_LENGTH+strlen(ROOT_PATH)];
160 strcpy(string,ROOT_PATH);
161 strcat(string,generate_random_string(FILE_NAME_LENGTH));
162 mode = ((S_IREAD|S_IWRITE)&random_int());
163 sprintf(message,"\nmaking directory: %s, with mode %d\n",string,mode);
164 print_message(3,message);
165 output= mkdir(string,mode);
171 char string[FILE_NAME_LENGTH+strlen(ROOT_PATH)];
173 strcpy(string,ROOT_PATH);
174 strcat(string,generate_random_string(FILE_NAME_LENGTH));
176 sprintf(message,"\nremoving directory: %s\n",string);
177 print_message(3,message);
178 output= rmdir(string);
181 int symlink_test(void)
183 char string[FILE_NAME_LENGTH+strlen(ROOT_PATH)];
184 char string2[FILE_NAME_LENGTH+strlen(ROOT_PATH)];
186 strcpy(string,ROOT_PATH);
187 strcat(string,generate_random_string(FILE_NAME_LENGTH));
188 strcpy(string2,ROOT_PATH);
189 strcat(string2,generate_random_string(FILE_NAME_LENGTH));
190 sprintf(message,"\nsymlink from: %s, to %s\n",string,string2);
191 print_message(3,message);
192 output= symlink(string,string2);
195 int rename_test(void)
197 char string[FILE_NAME_LENGTH+strlen(ROOT_PATH)];
198 char string2[FILE_NAME_LENGTH+strlen(ROOT_PATH)];
200 strcpy(string,ROOT_PATH);
201 strcat(string,generate_random_string(FILE_NAME_LENGTH));
202 strcpy(string2,ROOT_PATH);
203 strcat(string2,generate_random_string(FILE_NAME_LENGTH));
204 sprintf(message,"\nrenaming from: %s, to %s\n",string,string2);
205 print_message(3,message);
206 output= rename(string,string2);
211 char string[FILE_NAME_LENGTH+strlen(ROOT_PATH)];
212 char string2[FILE_NAME_LENGTH+strlen(ROOT_PATH)];
214 strcpy(string,ROOT_PATH);
215 strcat(string,generate_random_string(FILE_NAME_LENGTH));
216 strcpy(string2,ROOT_PATH);
217 strcat(string2,generate_random_string(FILE_NAME_LENGTH));
218 sprintf(message,"\nlink from: %s, to %s\n",string,string2);
219 print_message(3,message);
220 output= link(string,string2);
225 char string[FILE_NAME_LENGTH+strlen(ROOT_PATH)];
226 int mode=0,dev=0,output=0;
227 strcpy(string,ROOT_PATH);
228 strcat(string,generate_random_string(FILE_NAME_LENGTH));
229 mode = ((S_IREAD|S_IWRITE)&random_int());
231 sprintf(message,"\nmaking node: %s, with mode %d, dev %d\n",string,mode,dev);
232 print_message(3,message);
233 output= mknod(string,mode,dev);