fbdc19179e594aa358ec12564b46cdc7aae999fc
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
{
36 struct lttng_directory_handle
{
42 * Initialize a directory handle to the provided path. Passing a NULL path
43 * returns a handle to the current working directory.
45 * An initialized directory handle must be finalized using
46 * lttng_directory_handle_fini().
49 int lttng_directory_handle_init(struct lttng_directory_handle
*handle
,
53 * Initialize a new directory handle to a path relative to an existing handle.
55 * The provided path must already exist. Note that the creation of a
56 * subdirectory and the creation of a handle are kept as separate operations
57 * to highlight the fact that there is an inherent race between the creation of
58 * a directory and the creation of a handle to it.
60 * Passing a NULL path effectively copies the original handle.
62 * An initialized directory handle must be finalized using
63 * lttng_directory_handle_fini().
66 int lttng_directory_handle_init_from_handle(
67 struct lttng_directory_handle
*new_handle
,
69 const struct lttng_directory_handle
*handle
);
72 * Initialize a new directory handle from an existing directory fd.
74 * The new directory handle assumes the ownership of the directory fd.
75 * Note that this method should only be used in very specific cases, such as
76 * re-creating a directory handle from a dirfd passed over a unix socket.
78 * An initialized directory handle must be finalized using
79 * lttng_directory_handle_fini().
82 int lttng_directory_handle_init_from_dirfd(
83 struct lttng_directory_handle
*handle
, int dirfd
);
86 * Copy a directory handle.
89 int lttng_directory_handle_copy(const struct lttng_directory_handle
*handle
,
90 struct lttng_directory_handle
*new_copy
);
93 * Move a directory handle. The original directory handle may no longer be
94 * used after this call. This call cannot fail; directly assign the
95 * return value to the new directory handle.
97 * It is safe (but unnecessary) to call lttng_directory_handle_fini on the
101 struct lttng_directory_handle
102 lttng_directory_handle_move(struct lttng_directory_handle
*original
);
105 * Release the resources of a directory handle.
108 void lttng_directory_handle_fini(struct lttng_directory_handle
*handle
);
111 * Create a subdirectory relative to a directory handle.
114 int lttng_directory_handle_create_subdirectory(
115 const struct lttng_directory_handle
*handle
,
116 const char *subdirectory
,
120 * Create a subdirectory relative to a directory handle
124 int lttng_directory_handle_create_subdirectory_as_user(
125 const struct lttng_directory_handle
*handle
,
126 const char *subdirectory
,
127 mode_t mode
, const struct lttng_credentials
*creds
);
130 * Recursively create a directory relative to a directory handle.
133 int lttng_directory_handle_create_subdirectory_recursive(
134 const struct lttng_directory_handle
*handle
,
135 const char *subdirectory_path
,
139 * Recursively create a directory relative to a directory handle
143 int lttng_directory_handle_create_subdirectory_recursive_as_user(
144 const struct lttng_directory_handle
*handle
,
145 const char *subdirectory_path
,
146 mode_t mode
, const struct lttng_credentials
*creds
);
148 #endif /* _COMPAT_PATH_HANDLE_H */
This page took 0.031778 seconds and 3 git commands to generate.