Add a copy method to lttng_directory_handle
[lttng-tools.git] / src / common / compat / directory-handle.h
1 /*
2 * Copyright (C) 2019 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2 only,
6 * as published by the Free Software Foundation.
7 *
8 * This program 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 General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 */
17
18 #ifndef _COMPAT_DIRECTORY_HANDLE_H
19 #define _COMPAT_DIRECTORY_HANDLE_H
20
21 #include <common/macros.h>
22 #include <common/credentials.h>
23
24 /*
25 * Some platforms, such as Solaris 10, do not support directory file descriptors
26 * and their associated functions (*at(...)), which are defined in POSIX.2008.
27 *
28 * This wrapper provides a handle that is either a copy of a directory's path
29 * or a directory file descriptors, depending on the platform's capabilities.
30 */
31 #ifdef COMPAT_DIRFD
32 struct lttng_directory_handle {
33 int dirfd;
34 };
35 #else
36 struct lttng_directory_handle {
37 char *base_path;
38 };
39 #endif
40
41 /*
42 * Initialize a directory handle to the provided path. Passing a NULL path
43 * returns a handle to the current working directory. The working directory
44 * is not sampled; it will be accessed at the time of use of the functions
45 * of this API.
46 *
47 * An initialized directory handle must be finalized using
48 * lttng_directory_handle_fini().
49 */
50 LTTNG_HIDDEN
51 int lttng_directory_handle_init(struct lttng_directory_handle *handle,
52 const char *path);
53
54 LTTNG_HIDDEN
55 int lttng_directory_handle_init_from_dirfd(
56 struct lttng_directory_handle *handle, int dirfd);
57
58 /*
59 * Copy a directory handle.
60 */
61 LTTNG_HIDDEN
62 int lttng_directory_handle_copy(const struct lttng_directory_handle *handle,
63 struct lttng_directory_handle *new_copy);
64
65 /*
66 * Release the resources of a directory handle.
67 */
68 LTTNG_HIDDEN
69 void lttng_directory_handle_fini(struct lttng_directory_handle *handle);
70
71 /*
72 * Create a subdirectory relative to a directory handle.
73 */
74 LTTNG_HIDDEN
75 int lttng_directory_handle_create_subdirectory(
76 const struct lttng_directory_handle *handle,
77 const char *subdirectory,
78 mode_t mode);
79
80 /*
81 * Create a subdirectory relative to a directory handle
82 * as a given user.
83 */
84 LTTNG_HIDDEN
85 int lttng_directory_handle_create_subdirectory_as_user(
86 const struct lttng_directory_handle *handle,
87 const char *subdirectory,
88 mode_t mode, const struct lttng_credentials *creds);
89
90 /*
91 * Recursively create a directory relative to a directory handle.
92 */
93 LTTNG_HIDDEN
94 int lttng_directory_handle_create_subdirectory_recursive(
95 const struct lttng_directory_handle *handle,
96 const char *subdirectory_path,
97 mode_t mode);
98
99 /*
100 * Recursively create a directory relative to a directory handle
101 * as a given user.
102 */
103 LTTNG_HIDDEN
104 int lttng_directory_handle_create_subdirectory_recursive_as_user(
105 const struct lttng_directory_handle *handle,
106 const char *subdirectory_path,
107 mode_t mode, const struct lttng_credentials *creds);
108
109 #endif /* _COMPAT_PATH_HANDLE_H */
This page took 0.031618 seconds and 5 git commands to generate.