diff options
author | Artem Bityutskiy <Artem.Bityutskiy@nokia.com> | 2011-04-18 14:54:23 +0300 |
---|---|---|
committer | Artem Bityutskiy <Artem.Bityutskiy@nokia.com> | 2011-04-22 14:29:52 +0300 |
commit | 211061b60feaa70c269a9c566e94b554ba781fc5 (patch) | |
tree | cb8281ecc961bff5bc46b0ed02aa6168dad4c0d9 /tests | |
parent | e9daefff43ef95c7a3b79122d172c04f4d086927 (diff) |
fs-tests: integck: make file_truncate_file return error
Teach 'file_truncate_file()' return an error to the caller if it fails
to open the file or to truncate it.
Additionally, check the error code from 'open()' in other places.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/fs-tests/integrity/integck.c | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/tests/fs-tests/integrity/integck.c b/tests/fs-tests/integrity/integck.c index 3498c76..79c1020 100644 --- a/tests/fs-tests/integrity/integck.c +++ b/tests/fs-tests/integrity/integck.c @@ -993,7 +993,11 @@ static int file_mmap_write(struct file_info *file) /* Open it */ path = dir_path(file->links->parent, file->links->name); fd = open(path, O_RDWR); - CHECK(fd != -1); + if (fd == -1) { + pcv("cannot open file %s to do mmap", path); + free(path); + return -1; + } /* mmap it */ addr = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, offs); @@ -1090,7 +1094,11 @@ static int file_write_file(struct file_info *file) path = dir_path(file->links->parent, file->links->name); fd = open(path, O_WRONLY); - CHECK(fd != -1); + if (fd == -1) { + pcv("cannot open file %s for writing", path); + free(path); + return -1; + } ret = file_write(file, fd); CHECK(close(fd) == 0); free(path); @@ -1146,17 +1154,23 @@ static int file_truncate(struct file_info *file, int fd) return 0; } -static void file_truncate_file(struct file_info *file) +static int file_truncate_file(struct file_info *file) { int fd; char *path; + int ret; path = dir_path(file->links->parent, file->links->name); fd = open(path, O_WRONLY); - CHECK(fd != -1); - file_truncate(file, fd); - CHECK(close(fd) == 0); + if (fd == -1) { + pcv("cannot open file %s to truncate", path); + free(path); + return -1; + } free(path); + ret = file_truncate(file, fd); + CHECK(close(fd) == 0); + return ret; } static void file_close(struct fd_info *fdi) @@ -1899,12 +1913,11 @@ static int operate_on_file(struct file_info *file) return file_open(file); /* Occasionly truncate */ - if (shrink && random_no(100) == 0) { - file_truncate_file(file); - return 0; - } + if (shrink && random_no(100) == 0) + return file_truncate_file(file); /* Mostly just write */ - file_write_file(file); + if (file_write_file(file) != 0) + return -1; /* Once in a while check it too */ if (random_no(100) == 1) { int fd = -2; |