]> www.infradead.org Git - mtd-utils.git/commitdiff
fs-tests: integck: make file_open return error on failure
authorArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Mon, 18 Apr 2011 11:47:45 +0000 (14:47 +0300)
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Fri, 22 Apr 2011 11:29:52 +0000 (14:29 +0300)
Make 'file_open()' return an error to the caller if it fails to open
the file.

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

index c3c38135b7e7b32c25c5cf113993fe80a184793c..3498c760d6661582356b6ad3e0142b62e465eb4a 100644 (file)
@@ -738,7 +738,7 @@ static void file_info_display(struct file_info *file)
        normsg("    ============================================");
 }
 
-static struct fd_info *file_open(struct file_info *file)
+static int file_open(struct file_info *file)
 {
        int fd, flags = O_RDWR;
        char *path;
@@ -747,9 +747,14 @@ static struct fd_info *file_open(struct file_info *file)
        if (random_no(100) == 1)
                flags |= O_SYNC;
        fd = open(path, flags);
-       CHECK(fd != -1);
+       if (fd == -1) {
+               pcv("cannot open file %s", path);
+               free(path);
+               return -1;
+       }
        free(path);
-       return add_fd(file, fd);
+       add_fd(file, fd);
+       return 0;
 }
 
 /*
@@ -1884,20 +1889,15 @@ static int operate_on_dir(struct dir_info *dir);
 static int operate_on_file(struct file_info *file)
 {
        /* Try to keep at least 10 files open */
-       if (open_files_count < 10) {
-               file_open(file);
-               return 0;
-       }
+       if (open_files_count < 10)
+               return file_open(file);
        /* Try to keep about 20 files open */
-       if (open_files_count < 20 && random_no(2) == 0) {
-               file_open(file);
-               return 0;
-       }
+       if (open_files_count < 20 && random_no(2) == 0)
+               return file_open(file);
        /* Try to keep up to 40 files open */
-       if (open_files_count < 40 && random_no(20) == 0) {
-               file_open(file);
-               return 0;
-       }
+       if (open_files_count < 40 && random_no(20) == 0)
+               return file_open(file);
+
        /* Occasionly truncate */
        if (shrink && random_no(100) == 0) {
                file_truncate_file(file);