summaryrefslogtreecommitdiff
path: root/ioreplay/src/vfd.h
blob: fd0c4fbf65d3ad8afc6c896808e71827c68be262 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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