Allow ':' in filenames
authorJens Axboe <jens.axboe@oracle.com>
Tue, 4 Aug 2009 07:51:48 +0000 (09:51 +0200)
committerJens Axboe <jens.axboe@oracle.com>
Tue, 4 Aug 2009 07:51:48 +0000 (09:51 +0200)
You can now use '\' to escape a colon in a filename.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
HOWTO
options.c

diff --git a/HOWTO b/HOWTO
index dc70ab6693688e4078713abd0292bb8036915035..aec00e84e548f1c9d65952e73803d8fcb5df53e9 100644 (file)
--- a/HOWTO
+++ b/HOWTO
@@ -243,8 +243,11 @@ filename=str       Fio normally makes up a filename based on the job name,
                can specify a number of files by separating the names with a
                ':' colon. So if you wanted a job to open /dev/sda and /dev/sdb
                as the two working files, you would use
                can specify a number of files by separating the names with a
                ':' colon. So if you wanted a job to open /dev/sda and /dev/sdb
                as the two working files, you would use
-               filename=/dev/sda:/dev/sdb. '-' is a reserved name, meaning
-               stdin or stdout. Which of the two depends on the read/write
+               filename=/dev/sda:/dev/sdb. If the wanted filename does need to
+               include a colon, then escape that with a '\' character. For
+               instance, if the filename is "/dev/dsk/foo@3,0:c", then you would
+               use filename="/dev/dsk/foo@3,0\:c". '-' is a reserved name,
+               meaning stdin or stdout. Which of the two depends on the read/write
                direction set.
 
 opendir=str    Tell fio to recursively add any file it can find in this
                direction set.
 
 opendir=str    Tell fio to recursively add any file it can find in this
index 6941af0e8d9efa91e1a7a0d67152e9266322432f..b7262a7ff4eefb3be41413308e8a88374a27b863 100644 (file)
--- a/options.c
+++ b/options.c
@@ -449,6 +449,52 @@ static int check_dir(struct thread_data *td, char *fname)
        return 0;
 }
 
        return 0;
 }
 
+/*
+ * Return next file in the string. Files are separated with ':'. If the ':'
+ * is escaped with a '\', then that ':' is part of the filename and does not
+ * indicate a new file.
+ */
+static char *get_next_file_name(char **ptr)
+{
+       char *str = *ptr;
+       char *p, *start;
+
+       if (!str || !strlen(str))
+               return NULL;
+
+       start = str;
+       do {
+               /*
+                * No colon, we are done
+                */
+               p = strchr(str, ':');
+               if (!p) {
+                       *ptr = NULL;
+                       break;
+               }
+
+               /*
+                * We got a colon, but it's the first character. Skip and
+                * continue
+                */
+               if (p == start) {
+                       str = ++start;
+                       continue;
+               }
+
+               if (*(p - 1) != '\\') {
+                       *p = '\0';
+                       *ptr = p + 1;
+                       break;
+               }
+
+               memmove(p - 1, p, strlen(p) + 1);
+               str = p;
+       } while (1);
+
+       return start;
+}
+
 static int str_filename_cb(void *data, const char *input)
 {
        struct thread_data *td = data;
 static int str_filename_cb(void *data, const char *input)
 {
        struct thread_data *td = data;
@@ -462,7 +508,7 @@ static int str_filename_cb(void *data, const char *input)
        if (!td->files_index)
                td->o.nr_files = 0;
 
        if (!td->files_index)
                td->o.nr_files = 0;
 
-       while ((fname = strsep(&str, ":")) != NULL) {
+       while ((fname = get_next_file_name(&str)) != NULL) {
                if (!strlen(fname))
                        break;
                if (check_dir(td, fname)) {
                if (!strlen(fname))
                        break;
                if (check_dir(td, fname)) {