From 211061b60feaa70c269a9c566e94b554ba781fc5 Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Mon, 18 Apr 2011 14:54:23 +0300 Subject: 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 --- tests/fs-tests/integrity/integck.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) (limited to 'tests') 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; -- cgit v1.2.3