]> www.infradead.org Git - mtd-utils.git/commitdiff
fs-tests: integck: make directory checking work
authorArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Wed, 25 May 2011 15:22:51 +0000 (18:22 +0300)
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Fri, 27 May 2011 12:55:07 +0000 (15:55 +0300)
This patch makes the directory checking in case of power cut emulation
actually work. There were many bugs. Basically, we cannot rely on anything
unless the directory is marked as clean.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
tests/fs-tests/integrity/integck.c

index 437922e85095912c37e7b07ca5d0c6b27e038ce0..748b6cb330a60f671229a6f9e630af05bcd095cc 100644 (file)
@@ -1702,65 +1702,54 @@ static void dir_check(struct dir_info *dir)
        int link_count = 2; /* Parent and dot */
        struct stat st;
 
-       /* Create an array of entries */
-       sz = sizeof(struct dir_entry_info *);
-       n = dir->number_of_entries;
-       entry_array = malloc(sz * n);
-       CHECK(entry_array != NULL);
-
-       entry = dir->first;
-       p = entry_array;
-       while (entry) {
-               *p++ = entry;
-               entry->checked = 0;
-               entry = entry->next;
-       }
+       path = dir_path(dir->parent, dir->entry->name);
 
-       /* Sort it by name */
-       qsort(entry_array, n, sz, sort_comp);
+       if (!args.power_cut_mode || dir->clean) {
+               v("checking dir %s", path);
 
-       /* Go through directory on file system checking entries match */
-       path = dir_path(dir->parent, dir->entry->name);
+               /* Create an array of entries */
+               sz = sizeof(struct dir_entry_info *);
+               n = dir->number_of_entries;
+               entry_array = malloc(sz * n);
+               CHECK(entry_array != NULL);
 
-       v("checking dir %s", path);
+               entry = dir->first;
+               p = entry_array;
+               while (entry) {
+                       *p++ = entry;
+                       entry->checked = 0;
+                       entry = entry->next;
+               }
 
-       d = opendir(path);
-       if (!d) {
-               if (args.power_cut_mode && !dir->clean)
-                       /*
-                        * We are doing power cut testing and the directory
-                        * was not synchronized, which means it might not
-                        * exist.
-                        */
-                       return;
+               /* Sort it by name */
+               qsort(entry_array, n, sz, sort_comp);
 
-               errmsg("cannot open directory %s", path);
-               CHECK(0);
-       }
+               /* Go through directory on file system checking entries match */
+               d = opendir(path);
+               if (!d) {
+                       errmsg("cannot open directory %s", path);
+                       CHECK(0);
+               }
 
-       for (;;) {
-               errno = 0;
-               ent = readdir(d);
-               if (ent) {
-                       if (strcmp(".",ent->d_name) != 0 &&
-                                       strcmp("..",ent->d_name) != 0) {
-                               dir_entry_check(entry_array, n, ent);
-                               checked += 1;
+               for (;;) {
+                       errno = 0;
+                       ent = readdir(d);
+                       if (ent) {
+                               if (strcmp(".",ent->d_name) != 0 &&
+                                               strcmp("..",ent->d_name) != 0) {
+                                       dir_entry_check(entry_array, n, ent);
+                                       checked += 1;
+                               }
+                       } else {
+                               CHECK(errno == 0);
+                               break;
                        }
-               } else {
-                       CHECK(errno == 0);
-                       break;
                }
-       }
-       CHECK(closedir(d) == 0);
+               free(entry_array);
+               CHECK(closedir(d) == 0);
 
-       /*
-        * In power cut mode the file-system may miss some directory entries
-        * because it is possible that they have not reached the media by the
-        * time of the emulated power cut.
-        */
-       if (!args.power_cut_mode || dir->clean)
                CHECK(checked == dir->number_of_entries);
+       }
 
        /* Now check each entry */
        entry = dir->first;
@@ -1777,15 +1766,15 @@ static void dir_check(struct dir_info *dir)
                entry = entry->next;
        }
 
-       CHECK(stat(path, &st) == 0);
-
-       if (link_count != st.st_nlink) {
-               errmsg("calculated link count %d, FS reports %d for dir %s",
-                      link_count, (int)st.st_nlink, path);
-               CHECK(0);
+       if (!args.power_cut_mode || dir->clean) {
+               CHECK(stat(path, &st) == 0);
+               if (link_count != st.st_nlink) {
+                       errmsg("calculated link count %d, FS reports %d for dir %s",
+                              link_count, (int)st.st_nlink, path);
+                       CHECK(0);
+               }
        }
 
-       free(entry_array);
        free(path);
 }