+
+static void get_file_type(struct fio_file *f)
+{
+ struct stat sb;
+
+ f->filetype = FIO_TYPE_FILE;
+
+ if (!lstat(f->file_name, &sb)) {
+ if (S_ISBLK(sb.st_mode))
+ f->filetype = FIO_TYPE_BD;
+ else if (S_ISCHR(sb.st_mode))
+ f->filetype = FIO_TYPE_CHAR;
+ }
+}
+
+void add_file(struct thread_data *td, const char *fname)
+{
+ int cur_files = td->open_files;
+ struct fio_file *f;
+
+ td->files = realloc(td->files, (cur_files + 1) * sizeof(*f));
+
+ f = &td->files[cur_files];
+ memset(f, 0, sizeof(*f));
+ f->fd = -1;
+ f->file_name = strdup(fname);
+
+ get_file_type(f);
+
+ td->open_files++;
+ if (f->filetype == FIO_TYPE_FILE)
+ td->nr_normal_files++;
+}
+
+void get_file(struct fio_file *f)
+{
+ f->references++;
+}
+
+void put_file(struct thread_data *td, struct fio_file *f)
+{
+ if (!(f->flags & FIO_FILE_OPEN))
+ return;
+
+ assert(f->references);
+ if (--f->references)
+ return;
+
+ if (td->io_ops->close_file)
+ td->io_ops->close_file(td, f);
+ td->nr_open_files--;
+ f->flags &= ~FIO_FILE_OPEN;
+}