+int open_file(struct thread_data *td, struct fio_file *f, int flags, int perm)
+{
+ if (flags & O_CREAT)
+ f->fd = open(f->file_name, flags, perm);
+ else
+ f->fd = open(f->file_name, flags);
+
+ if (f->fd != -1) {
+ td->nr_open_files++;
+ return 0;
+ }
+
+ return 1;
+}
+
+void close_file(struct thread_data *td, struct fio_file *f)
+{
+ if (f->fd != -1) {
+ close(f->fd);
+ f->fd = -1;
+ td->nr_open_files--;
+ }
+}
+
+/*
+ * Check if the file exists and it's large enough.
+ */
+static int file_ok(struct thread_data *td, struct fio_file *f)
+{
+ struct stat st;
+
+ if (td->filetype != FIO_TYPE_FILE || (td->io_ops->flags & FIO_NULLIO))
+ return 0;
+
+ if (lstat(f->file_name, &st) == -1)
+ return 1;
+
+ /*
+ * if it's a special file, size is always ok for now
+ */
+ if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode))
+ return 0;
+ if (st.st_size < (off_t) f->file_size)
+ return 1;
+
+ return 0;
+}
+