From: Jens Axboe Date: Wed, 26 Mar 2008 08:17:55 +0000 (+0100) Subject: Check directory if filename= option includes dir name X-Git-Tag: fio-1.20-rc4~9^2~6 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=921c766ffda25c6ac23e34a616595da3ed3f27e8 Check directory if filename= option includes dir name Signed-off-by: Jens Axboe --- diff --git a/options.c b/options.c index f05b786b..5626da79 100644 --- a/options.c +++ b/options.c @@ -5,6 +5,7 @@ #include #include #include +#include #include "fio.h" #include "parse.h" @@ -269,6 +270,30 @@ static int str_fst_cb(void *data, const char *str) return 0; } +static int check_dir(struct thread_data *td, char *fname) +{ + char file[PATH_MAX], *dir; + struct stat sb; + + strcpy(file, fname); + dir = dirname(file); + + if (lstat(dir, &sb) < 0) { + int ret = errno; + + log_err("fio: %s is not a directory\n", dir); + td_verror(td, ret, "lstat"); + return 1; + } + + if (!S_ISDIR(sb.st_mode)) { + log_err("fio: %s is not a directory\n", dir); + return 1; + } + + return 0; +} + static int str_filename_cb(void *data, const char *input) { struct thread_data *td = data; @@ -285,6 +310,10 @@ static int str_filename_cb(void *data, const char *input) while ((fname = strsep(&str, ":")) != NULL) { if (!strlen(fname)) break; + if (check_dir(td, fname)) { + free(p); + return 1; + } add_file(td, fname); td->o.nr_files++; } @@ -299,8 +328,10 @@ static int str_directory_cb(void *data, const char fio_unused *str) struct stat sb; if (lstat(td->o.directory, &sb) < 0) { + int ret = errno; + log_err("fio: %s is not a directory\n", td->o.directory); - td_verror(td, errno, "lstat"); + td_verror(td, ret, "lstat"); return 1; } if (!S_ISDIR(sb.st_mode)) {