2 * Copyright (C) 2019 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
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.
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
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.
18 #ifndef _COMPAT_DIRECTORY_HANDLE_H
19 #define _COMPAT_DIRECTORY_HANDLE_H
21 #include <common/macros.h>
22 #include <common/credentials.h>
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.
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.
32 struct lttng_directory_handle
{
37 int lttng_directory_handle_get_dirfd(
38 const struct lttng_directory_handle
*handle
)
44 struct lttng_directory_handle
{
50 * Initialize a directory handle to the provided path. Passing a NULL path
51 * returns a handle to the current working directory.
53 * An initialized directory handle must be finalized using
54 * lttng_directory_handle_fini().
57 int lttng_directory_handle_init(struct lttng_directory_handle
*handle
,
61 * Initialize a new directory handle to a path relative to an existing handle.
63 * The provided path must already exist. Note that the creation of a
64 * subdirectory and the creation of a handle are kept as separate operations
65 * to highlight the fact that there is an inherent race between the creation of
66 * a directory and the creation of a handle to it.
68 * Passing a NULL path effectively copies the original handle.
70 * An initialized directory handle must be finalized using
71 * lttng_directory_handle_fini().
74 int lttng_directory_handle_init_from_handle(
75 struct lttng_directory_handle
*new_handle
,
77 const struct lttng_directory_handle
*handle
);
80 * Initialize a new directory handle from an existing directory fd.
82 * The new directory handle assumes the ownership of the directory fd.
83 * Note that this method should only be used in very specific cases, such as
84 * re-creating a directory handle from a dirfd passed over a unix socket.
86 * An initialized directory handle must be finalized using
87 * lttng_directory_handle_fini().
90 int lttng_directory_handle_init_from_dirfd(
91 struct lttng_directory_handle
*handle
, int dirfd
);
94 * Copy a directory handle.
97 int lttng_directory_handle_copy(const struct lttng_directory_handle
*handle
,
98 struct lttng_directory_handle
*new_copy
);
101 * Move a directory handle. The original directory handle may no longer be
102 * used after this call. This call cannot fail; directly assign the
103 * return value to the new directory handle.
105 * It is safe (but unnecessary) to call lttng_directory_handle_fini on the
109 struct lttng_directory_handle
110 lttng_directory_handle_move(struct lttng_directory_handle
*original
);
113 * Release the resources of a directory handle.
116 void lttng_directory_handle_fini(struct lttng_directory_handle
*handle
);
119 * Create a subdirectory relative to a directory handle.
122 int lttng_directory_handle_create_subdirectory(
123 const struct lttng_directory_handle
*handle
,
124 const char *subdirectory
,
128 * Create a subdirectory relative to a directory handle
132 int lttng_directory_handle_create_subdirectory_as_user(
133 const struct lttng_directory_handle
*handle
,
134 const char *subdirectory
,
135 mode_t mode
, const struct lttng_credentials
*creds
);
138 * Recursively create a directory relative to a directory handle.
141 int lttng_directory_handle_create_subdirectory_recursive(
142 const struct lttng_directory_handle
*handle
,
143 const char *subdirectory_path
,
147 * Recursively create a directory relative to a directory handle
151 int lttng_directory_handle_create_subdirectory_recursive_as_user(
152 const struct lttng_directory_handle
*handle
,
153 const char *subdirectory_path
,
154 mode_t mode
, const struct lttng_credentials
*creds
);
156 #endif /* _COMPAT_PATH_HANDLE_H */
This page took 0.050756 seconds and 4 git commands to generate.