summaryrefslogtreecommitdiff
path: root/ioreplay/src/vfd.h
diff options
context:
space:
mode:
authorPaul Bütow <pbuetow@mimecast.com>2018-03-01 11:21:26 +0000
committerPaul Bütow <pbuetow@mimecast.com>2018-03-01 11:21:26 +0000
commit56f8cdff9aaa9bf00c5dc9441a7569374f2cbafb (patch)
treeb5b440b504b9879e241733fa38d19089fb3377b2 /ioreplay/src/vfd.h
initial commit0.1
Diffstat (limited to 'ioreplay/src/vfd.h')
-rw-r--r--ioreplay/src/vfd.h77
1 files changed, 77 insertions, 0 deletions
diff --git a/ioreplay/src/vfd.h b/ioreplay/src/vfd.h
new file mode 100644
index 0000000..fd0c4fb
--- /dev/null
+++ b/ioreplay/src/vfd.h
@@ -0,0 +1,77 @@
+// Copyright 2018 Mimecast Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef VFD_H
+#define VFD_H
+
+#include "opcodes.h"
+#include "defaults.h"
+
+/**
+ * @brief The virtual file descriptor definition
+ *
+ * A virtual file descriptor represents a file descriptor from ioreplay's
+ * point of view and is being used in various ways to simulate the real I/O
+ * protocolled to the .capture/.replay files.
+ *
+ * Generally speaking I/O replay maps the real FD numbers (the ones logged to
+ * the .capture file) to virtual FD numbers (a uniqe FD number for every open
+ * to increase concurrency).
+ */
+typedef struct vfd_s_ {
+ int fd; /**< the real fd */
+ DIR *dirfd; /**< The real dirfd */
+ long mapped_fd; /**< The mapped fd (virtual fd) */
+ char *path; /**< The file path belonging to that fd */
+ bool free_path; /**< True if path has to be freed or not */
+ unsigned long offset; /**< The current virtual file offset in bytes */
+ int debug; /**< Used for debugging purposes only */
+} vfd_s;
+
+/**
+ * @brief Creates a new virtual file descriptor object
+ *
+ * @param fd The file descriptor
+ * @param mapped_fd The mapped file descriptor
+ * @param path The path name
+ * @return The new fd object
+ */
+vfd_s* vfd_new(const int fd, const long mapped_fd, char *path);
+
+/**
+ * @brief Updates the virtfd object
+ *
+ * @param vfd The virtfd object
+ * @param fd The (real) file descriptor
+ * @param mapped_fd The mapped (virtual) file descriptor
+ * @param path The path name
+ * @return The new fd object
+ */
+void vfd_update(vfd_s *vfd, const int fd, const long mapped_fd, char *path);
+
+/**
+ * @brief Destroys a file descriptor object
+ *
+ * @param vfd The file descriptor object
+ */
+void vfd_destroy(vfd_s *vfd);
+
+/**
+ * @brief Prints the virtual file descriptor
+ * @param vfd The virtual file descriptor
+ */
+void vfd_print(vfd_s *vfd);
+
+#endif // VFD_H
+