relayd: replace uses of block FDs by the fs_handle interface
[lttng-tools.git] / src / common / fs-handle.c
CommitLineData
f5ea0241
JG
1/*
2 * Copyright (C) 2020 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 *
4 * This library is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License as published by the
6 * Free Software Foundation; version 2.1 of the License.
7 *
8 * This library is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
11 * for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this library; if not, write to the Free Software Foundation,
15 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17
f5ea0241 18#include <common/fs-handle-internal.h>
8bb66c3c
JG
19#include <common/fs-handle.h>
20#include <common/readwrite.h>
f5ea0241
JG
21
22LTTNG_HIDDEN
23int fs_handle_get_fd(struct fs_handle *handle)
24{
25 return handle->get_fd(handle);
26}
27
28LTTNG_HIDDEN
29void fs_handle_put_fd(struct fs_handle *handle)
30{
31 return handle->put_fd(handle);
32}
33
34LTTNG_HIDDEN
35int fs_handle_unlink(struct fs_handle *handle)
36{
37 return handle->unlink(handle);
38}
39
40LTTNG_HIDDEN
41int fs_handle_close(struct fs_handle *handle)
42{
43 return handle->close(handle);
44}
8bb66c3c
JG
45
46LTTNG_HIDDEN
47ssize_t fs_handle_read(struct fs_handle *handle, void *buf, size_t count)
48{
49 ssize_t ret;
50 const int fd = fs_handle_get_fd(handle);
51
52 if (fd < 0) {
53 ret = -1;
54 goto end;
55 }
56
57 ret = lttng_read(fd, buf, count);
58 fs_handle_put_fd(handle);
59end:
60 return ret;
61}
62
63LTTNG_HIDDEN
64ssize_t fs_handle_write(struct fs_handle *handle, const void *buf, size_t count)
65{
66 ssize_t ret;
67 const int fd = fs_handle_get_fd(handle);
68
69 if (fd < 0) {
70 ret = -1;
71 goto end;
72 }
73
74 ret = lttng_write(fd, buf, count);
75 fs_handle_put_fd(handle);
76end:
77 return ret;
78}
79
80LTTNG_HIDDEN
81int fs_handle_truncate(struct fs_handle *handle, off_t offset)
82{
83 int ret;
84 const int fd = fs_handle_get_fd(handle);
85
86 if (fd < 0) {
87 ret = -1;
88 goto end;
89 }
90
91 ret = ftruncate(fd, offset);
92 fs_handle_put_fd(handle);
93end:
94 return ret;
95}
96
97LTTNG_HIDDEN
98int fs_handle_seek(struct fs_handle *handle, off_t offset, int whence)
99{
100 int ret;
101 const int fd = fs_handle_get_fd(handle);
102
103 if (fd < 0) {
104 ret = -1;
105 goto end;
106 }
107
108 ret = lseek(fd, offset, whence);
109 fs_handle_put_fd(handle);
110end:
111 return ret;
112}
This page took 0.027205 seconds and 5 git commands to generate.