1 | /** @file
|
---|
2 | * IPRT - Directory Manipulation.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2017 Oracle Corporation
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License (GPL) as published by the Free Software
|
---|
12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | *
|
---|
16 | * The contents of this file may alternatively be used under the terms
|
---|
17 | * of the Common Development and Distribution License Version 1.0
|
---|
18 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
19 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
20 | * CDDL are applicable instead of those of the GPL.
|
---|
21 | *
|
---|
22 | * You may elect to license modified versions of this file under the
|
---|
23 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
24 | */
|
---|
25 |
|
---|
26 | #ifndef ___iprt_dir_h
|
---|
27 | #define ___iprt_dir_h
|
---|
28 |
|
---|
29 | #include <iprt/cdefs.h>
|
---|
30 | #include <iprt/types.h>
|
---|
31 | #include <iprt/fs.h>
|
---|
32 | #include <iprt/symlink.h>
|
---|
33 |
|
---|
34 |
|
---|
35 | RT_C_DECLS_BEGIN
|
---|
36 |
|
---|
37 | /** @defgroup grp_rt_dir RTDir - Directory Manipulation
|
---|
38 | * @ingroup grp_rt
|
---|
39 | * @{
|
---|
40 | */
|
---|
41 |
|
---|
42 | /**
|
---|
43 | * Check for the existence of a directory.
|
---|
44 | *
|
---|
45 | * All symbolic links will be attemped resolved. If that is undesirable, please
|
---|
46 | * use RTPathQueryInfo instead.
|
---|
47 | *
|
---|
48 | * @returns true if exist and is a directory.
|
---|
49 | * @returns false if not exists or isn't a directory.
|
---|
50 | * @param pszPath Path to the directory.
|
---|
51 | */
|
---|
52 | RTDECL(bool) RTDirExists(const char *pszPath);
|
---|
53 |
|
---|
54 | /** @name RTDirCreate flags.
|
---|
55 | * @{ */
|
---|
56 | /** Don't allow symbolic links as part of the path.
|
---|
57 | * @remarks this flag is currently not implemented and will be ignored. */
|
---|
58 | #define RTDIRCREATE_FLAGS_NO_SYMLINKS RT_BIT(0)
|
---|
59 | /** Set the not-content-indexed flag (default). Windows only atm. */
|
---|
60 | #define RTDIRCREATE_FLAGS_NOT_CONTENT_INDEXED_DONT_SET RT_BIT(1)
|
---|
61 | /** Do not set the not-content-indexed flag. Windows only atm. */
|
---|
62 | #define RTDIRCREATE_FLAGS_NOT_CONTENT_INDEXED_DONT_SET RT_BIT(1)
|
---|
63 | /** Ignore errors setting the not-content-indexed flag. Windows only atm. */
|
---|
64 | #define RTDIRCREATE_FLAGS_NOT_CONTENT_INDEXED_NOT_CRITICAL RT_BIT(2)
|
---|
65 | /** @} */
|
---|
66 |
|
---|
67 | /**
|
---|
68 | * Creates a directory.
|
---|
69 | *
|
---|
70 | * @returns iprt status code.
|
---|
71 | * @param pszPath Path to the directory to create.
|
---|
72 | * @param fMode The mode of the new directory.
|
---|
73 | * @param fCreate Create flags, RTDIRCREATE_FLAGS_*.
|
---|
74 | */
|
---|
75 | RTDECL(int) RTDirCreate(const char *pszPath, RTFMODE fMode, uint32_t fCreate);
|
---|
76 |
|
---|
77 | /**
|
---|
78 | * Creates a directory including all parent directories in the path
|
---|
79 | * if they don't exist.
|
---|
80 | *
|
---|
81 | * @returns iprt status code.
|
---|
82 | * @param pszPath Path to the directory to create.
|
---|
83 | * @param fMode The mode of the new directories.
|
---|
84 | */
|
---|
85 | RTDECL(int) RTDirCreateFullPath(const char *pszPath, RTFMODE fMode);
|
---|
86 |
|
---|
87 | /**
|
---|
88 | * Creates a new directory with a unique name using the given template.
|
---|
89 | *
|
---|
90 | * One or more trailing X'es in the template will be replaced by random alpha
|
---|
91 | * numeric characters until a RTDirCreate succeeds or we run out of patience.
|
---|
92 | * For instance:
|
---|
93 | * "/tmp/myprog-XXXXXX"
|
---|
94 | *
|
---|
95 | * As an alternative to trailing X'es, it
|
---|
96 | * is possible to put 3 or more X'es somewhere inside the directory name. In
|
---|
97 | * the following string only the last bunch of X'es will be modified:
|
---|
98 | * "/tmp/myprog-XXX-XXX.tmp"
|
---|
99 | *
|
---|
100 | * @returns iprt status code.
|
---|
101 | * @param pszTemplate The directory name template on input. The actual
|
---|
102 | * directory name on success. Empty string on failure.
|
---|
103 | * @param fMode The mode to create the directory with. Use 0700
|
---|
104 | * unless you have reason not to.
|
---|
105 | */
|
---|
106 | RTDECL(int) RTDirCreateTemp(char *pszTemplate, RTFMODE fMode);
|
---|
107 |
|
---|
108 | /**
|
---|
109 | * Secure version of @a RTDirCreateTemp with a fixed mode of 0700.
|
---|
110 | *
|
---|
111 | * This function behaves in the same way as @a RTDirCreateTemp with two
|
---|
112 | * additional points. Firstly the mode is fixed to 0700. Secondly it will
|
---|
113 | * fail if it is not possible to perform the operation securely. Possible
|
---|
114 | * reasons include that the directory could be removed by another unprivileged
|
---|
115 | * user before it is used (e.g. if is created in a non-sticky /tmp directory)
|
---|
116 | * or that the path contains symbolic links which another unprivileged user
|
---|
117 | * could manipulate; however the exact criteria will be specified on a
|
---|
118 | * platform-by-platform basis as platform support is added.
|
---|
119 | * @see RTPathIsSecure for the current list of criteria.
|
---|
120 | * @returns iprt status code.
|
---|
121 | * @returns VERR_NOT_SUPPORTED if the interface can not be supported on the
|
---|
122 | * current platform at this time.
|
---|
123 | * @returns VERR_INSECURE if the directory could not be created securely.
|
---|
124 | * @param pszTemplate The directory name template on input. The
|
---|
125 | * actual directory name on success. Empty string
|
---|
126 | * on failure.
|
---|
127 | */
|
---|
128 | RTDECL(int) RTDirCreateTempSecure(char *pszTemplate);
|
---|
129 |
|
---|
130 | /**
|
---|
131 | * Creates a new directory with a unique name by appending a number.
|
---|
132 | *
|
---|
133 | * This API differs from RTDirCreateTemp & RTDirCreateTempSecure in that it
|
---|
134 | * first tries to create the directory without any random bits, thus the best
|
---|
135 | * case result will be prettier. It also differs in that it does not take a
|
---|
136 | * template, but is instead given a template description, and will only use
|
---|
137 | * digits for the filling.
|
---|
138 | *
|
---|
139 | * For sake of convenience and debugging , the current implementation
|
---|
140 | * starts at 0 and will increment sequentally for a while before switching to
|
---|
141 | * random numbers.
|
---|
142 | *
|
---|
143 | * On success @a pszPath contains the path created.
|
---|
144 | *
|
---|
145 | * @returns iprt status code.
|
---|
146 | * @param pszPath The path to the directory. On input the base template
|
---|
147 | * name. On successful return, the unique directory we
|
---|
148 | * created.
|
---|
149 | * @param cbSize The size of the pszPath buffer. Needs enough space for
|
---|
150 | * holding the digits and the optional separator.
|
---|
151 | * @param fMode The mode of the new directory.
|
---|
152 | * @param cchDigits How many digits should the number have (zero padded).
|
---|
153 | * @param chSep The separator used between the path and the number. Can
|
---|
154 | * be zero. (optional)
|
---|
155 | */
|
---|
156 | RTDECL(int) RTDirCreateUniqueNumbered(char *pszPath, size_t cbSize, RTFMODE fMode, size_t cchDigits, char chSep);
|
---|
157 |
|
---|
158 | /**
|
---|
159 | * Removes a directory if empty.
|
---|
160 | *
|
---|
161 | * @returns iprt status code.
|
---|
162 | * @param pszPath Path to the directory to remove.
|
---|
163 | */
|
---|
164 | RTDECL(int) RTDirRemove(const char *pszPath);
|
---|
165 |
|
---|
166 | /**
|
---|
167 | * Removes a directory tree recursively.
|
---|
168 | *
|
---|
169 | * @returns iprt status code.
|
---|
170 | * @param pszPath Path to the directory to remove recursively.
|
---|
171 | * @param fFlags Flags, see RTDIRRMREC_F_XXX.
|
---|
172 | *
|
---|
173 | * @remarks This will not work on a root directory.
|
---|
174 | */
|
---|
175 | RTDECL(int) RTDirRemoveRecursive(const char *pszPath, uint32_t fFlags);
|
---|
176 |
|
---|
177 | /** @name RTDirRemoveRecursive flags.
|
---|
178 | * @{ */
|
---|
179 | /** Delete the content of the directory and the directory itself. */
|
---|
180 | #define RTDIRRMREC_F_CONTENT_AND_DIR UINT32_C(0)
|
---|
181 | /** Only delete the content of the directory, omit the directory it self. */
|
---|
182 | #define RTDIRRMREC_F_CONTENT_ONLY RT_BIT_32(0)
|
---|
183 | /** Mask of valid flags. */
|
---|
184 | #define RTDIRRMREC_F_VALID_MASK UINT32_C(0x00000001)
|
---|
185 | /** @} */
|
---|
186 |
|
---|
187 | /**
|
---|
188 | * Flushes the specified directory.
|
---|
189 | *
|
---|
190 | * This API is not implemented on all systems. On some systems it may be
|
---|
191 | * unnecessary if you've already flushed the file. If you really care for your
|
---|
192 | * data and is entering dangerous territories, it doesn't hurt calling it after
|
---|
193 | * flushing and closing the file.
|
---|
194 | *
|
---|
195 | * @returns IPRT status code.
|
---|
196 | * @retval VERR_NOT_IMPLEMENTED must be expected.
|
---|
197 | * @retval VERR_NOT_SUPPORTED must be expected.
|
---|
198 | * @param pszPath Path to the directory.
|
---|
199 | */
|
---|
200 | RTDECL(int) RTDirFlush(const char *pszPath);
|
---|
201 |
|
---|
202 | /**
|
---|
203 | * Flushes the parent directory of the specified file.
|
---|
204 | *
|
---|
205 | * This is just a wrapper around RTDirFlush.
|
---|
206 | *
|
---|
207 | * @returns IPRT status code, see RTDirFlush for details.
|
---|
208 | * @param pszChild Path to the file which parent should be flushed.
|
---|
209 | */
|
---|
210 | RTDECL(int) RTDirFlushParent(const char *pszChild);
|
---|
211 |
|
---|
212 |
|
---|
213 | /** Pointer to an open directory (sort of handle). */
|
---|
214 | typedef struct RTDIR *PRTDIR;
|
---|
215 |
|
---|
216 |
|
---|
217 | /**
|
---|
218 | * Filter option for RTDirOpenFiltered().
|
---|
219 | */
|
---|
220 | typedef enum RTDIRFILTER
|
---|
221 | {
|
---|
222 | /** The usual invalid 0 entry. */
|
---|
223 | RTDIRFILTER_INVALID = 0,
|
---|
224 | /** No filter should be applied (and none was specified). */
|
---|
225 | RTDIRFILTER_NONE,
|
---|
226 | /** The Windows NT filter.
|
---|
227 | * The following wildcard chars: *, ?, <, > and "
|
---|
228 | * The matching is done on the uppercased strings. */
|
---|
229 | RTDIRFILTER_WINNT,
|
---|
230 | /** The UNIX filter.
|
---|
231 | * The following wildcard chars: *, ?, [..]
|
---|
232 | * The matching is done on exact case. */
|
---|
233 | RTDIRFILTER_UNIX,
|
---|
234 | /** The UNIX filter, uppercased matching.
|
---|
235 | * Same as RTDIRFILTER_UNIX except that the strings are uppercased before comparing. */
|
---|
236 | RTDIRFILTER_UNIX_UPCASED,
|
---|
237 |
|
---|
238 | /** The usual full 32-bit value. */
|
---|
239 | RTDIRFILTER_32BIT_HACK = 0x7fffffff
|
---|
240 | } RTDIRFILTER;
|
---|
241 |
|
---|
242 |
|
---|
243 | /**
|
---|
244 | * Directory entry type.
|
---|
245 | *
|
---|
246 | * This is the RTFS_TYPE_MASK stuff shifted down 12 bits and
|
---|
247 | * identical to the BSD/LINUX ABI. See RTFS_TYPE_DIRENTRYTYPE_SHIFT.
|
---|
248 | */
|
---|
249 | typedef enum RTDIRENTRYTYPE
|
---|
250 | {
|
---|
251 | /** Unknown type (DT_UNKNOWN). */
|
---|
252 | RTDIRENTRYTYPE_UNKNOWN = 0,
|
---|
253 | /** Named pipe (fifo) (DT_FIFO). */
|
---|
254 | RTDIRENTRYTYPE_FIFO = 001,
|
---|
255 | /** Character device (DT_CHR). */
|
---|
256 | RTDIRENTRYTYPE_DEV_CHAR = 002,
|
---|
257 | /** Directory (DT_DIR). */
|
---|
258 | RTDIRENTRYTYPE_DIRECTORY = 004,
|
---|
259 | /** Block device (DT_BLK). */
|
---|
260 | RTDIRENTRYTYPE_DEV_BLOCK = 006,
|
---|
261 | /** Regular file (DT_REG). */
|
---|
262 | RTDIRENTRYTYPE_FILE = 010,
|
---|
263 | /** Symbolic link (DT_LNK). */
|
---|
264 | RTDIRENTRYTYPE_SYMLINK = 012,
|
---|
265 | /** Socket (DT_SOCK). */
|
---|
266 | RTDIRENTRYTYPE_SOCKET = 014,
|
---|
267 | /** Whiteout (DT_WHT). */
|
---|
268 | RTDIRENTRYTYPE_WHITEOUT = 016
|
---|
269 | } RTDIRENTRYTYPE;
|
---|
270 |
|
---|
271 |
|
---|
272 | /**
|
---|
273 | * Directory entry.
|
---|
274 | *
|
---|
275 | * This is inspired by the POSIX interfaces.
|
---|
276 | */
|
---|
277 | #pragma pack(1)
|
---|
278 | typedef struct RTDIRENTRY
|
---|
279 | {
|
---|
280 | /** The unique identifier (within the file system) of this file system object (d_ino).
|
---|
281 | *
|
---|
282 | * Together with INodeIdDevice, this field can be used as a OS wide unique id
|
---|
283 | * when both their values are not 0. This field is 0 if the information is not
|
---|
284 | * available. */
|
---|
285 | RTINODE INodeId;
|
---|
286 | /** The entry type. (d_type)
|
---|
287 | * RTDIRENTRYTYPE_UNKNOWN is a common return value here since not all file
|
---|
288 | * systems (or Unixes) stores the type of a directory entry and instead
|
---|
289 | * expects the user to use stat() to get it. So, when you see this you
|
---|
290 | * should use RTDirQueryUnknownType or RTDirQueryUnknownTypeEx to get the type,
|
---|
291 | * or if if you're lazy, use RTDirReadEx. */
|
---|
292 | RTDIRENTRYTYPE enmType;
|
---|
293 | /** The length of the filename, excluding the terminating nul character. */
|
---|
294 | uint16_t cbName;
|
---|
295 | /** The filename. (no path)
|
---|
296 | * Using the pcbDirEntry parameter of RTDirRead makes this field variable in size. */
|
---|
297 | char szName[260];
|
---|
298 | } RTDIRENTRY;
|
---|
299 | #pragma pack()
|
---|
300 | /** Pointer to a directory entry. */
|
---|
301 | typedef RTDIRENTRY *PRTDIRENTRY;
|
---|
302 | /** Pointer to a const directory entry. */
|
---|
303 | typedef RTDIRENTRY const *PCRTDIRENTRY;
|
---|
304 |
|
---|
305 |
|
---|
306 | /**
|
---|
307 | * Directory entry with extended information.
|
---|
308 | *
|
---|
309 | * This is inspired by the PC interfaces.
|
---|
310 | */
|
---|
311 | #pragma pack(1)
|
---|
312 | typedef struct RTDIRENTRYEX
|
---|
313 | {
|
---|
314 | /** Full information about the object. */
|
---|
315 | RTFSOBJINFO Info;
|
---|
316 | /** The length of the short field (number of RTUTF16 entries (not chars)).
|
---|
317 | * It is 16-bit for reasons of alignment. */
|
---|
318 | uint16_t cwcShortName;
|
---|
319 | /** The short name for 8.3 compatibility.
|
---|
320 | * Empty string if not available.
|
---|
321 | * Since the length is a bit tricky for a UTF-8 encoded name, and since this
|
---|
322 | * is practically speaking only a windows thing, it is encoded as UCS-2. */
|
---|
323 | RTUTF16 wszShortName[14];
|
---|
324 | /** The length of the filename. */
|
---|
325 | uint16_t cbName;
|
---|
326 | /** The filename. (no path)
|
---|
327 | * Using the pcbDirEntry parameter of RTDirReadEx makes this field variable in size. */
|
---|
328 | char szName[260];
|
---|
329 | } RTDIRENTRYEX;
|
---|
330 | #pragma pack()
|
---|
331 | /** Pointer to a directory entry. */
|
---|
332 | typedef RTDIRENTRYEX *PRTDIRENTRYEX;
|
---|
333 | /** Pointer to a const directory entry. */
|
---|
334 | typedef RTDIRENTRYEX const *PCRTDIRENTRYEX;
|
---|
335 |
|
---|
336 |
|
---|
337 | /**
|
---|
338 | * Opens a directory.
|
---|
339 | *
|
---|
340 | * @returns iprt status code.
|
---|
341 | * @param ppDir Where to store the open directory pointer.
|
---|
342 | * @param pszPath Path to the directory to open.
|
---|
343 | */
|
---|
344 | RTDECL(int) RTDirOpen(PRTDIR *ppDir, const char *pszPath);
|
---|
345 |
|
---|
346 | /** @name RTDIR_F_XXX - RTDirOpenFiltered flags.
|
---|
347 | * @{ */
|
---|
348 | /** Don't allow symbolic links as part of the path.
|
---|
349 | * @remarks this flag is currently not implemented and will be ignored. */
|
---|
350 | #define RTDIR_F_NO_SYMLINKS RT_BIT_32(0)
|
---|
351 | /** Deny relative opening of anything above this directory. */
|
---|
352 | #define RTDIR_F_DENY_ASCENT RT_BIT_32(1)
|
---|
353 | /** Valid flag mask. */
|
---|
354 | #define RTDIR_F_VALID_MASK UINT32_C(0x00000003)
|
---|
355 | /** @} */
|
---|
356 |
|
---|
357 | /**
|
---|
358 | * Opens a directory with flags and optional filtering.
|
---|
359 | *
|
---|
360 | * @returns iprt status code.
|
---|
361 | * @param ppDir Where to store the open directory pointer.
|
---|
362 | * @param pszPath Path to the directory to search, this must include wildcards.
|
---|
363 | * @param enmFilter The kind of filter to apply. Setting this to RTDIRFILTER_NONE makes
|
---|
364 | * this function behave like RTDirOpen.
|
---|
365 | * @param fFlags Open flags, RTDIR_F_XXX.
|
---|
366 | */
|
---|
367 | RTDECL(int) RTDirOpenFiltered(PRTDIR *ppDir, const char *pszPath, RTDIRFILTER enmFilter, uint32_t fFlags);
|
---|
368 |
|
---|
369 | /**
|
---|
370 | * Closes a directory.
|
---|
371 | *
|
---|
372 | * @returns iprt status code.
|
---|
373 | * @param pDir Pointer to open directory returned by RTDirOpen() or RTDirOpenFiltered().
|
---|
374 | */
|
---|
375 | RTDECL(int) RTDirClose(PRTDIR pDir);
|
---|
376 |
|
---|
377 | /**
|
---|
378 | * Checks if the supplied directory handle is valid.
|
---|
379 | *
|
---|
380 | * @returns true if valid.
|
---|
381 | * @returns false if invalid.
|
---|
382 | * @param hDir The directory handle.
|
---|
383 | */
|
---|
384 | RTDECL(bool) RTDirIsValid(PRTDIR hDir);
|
---|
385 |
|
---|
386 | /**
|
---|
387 | * Reads the next entry in the directory.
|
---|
388 | *
|
---|
389 | * @returns VINF_SUCCESS and data in pDirEntry on success.
|
---|
390 | * @returns VERR_NO_MORE_FILES when the end of the directory has been reached.
|
---|
391 | * @returns VERR_BUFFER_OVERFLOW if the buffer is too small to contain the filename. If
|
---|
392 | * pcbDirEntry is specified it will be updated with the required buffer size.
|
---|
393 | * @returns suitable iprt status code on other errors.
|
---|
394 | *
|
---|
395 | * @param pDir Pointer to the open directory.
|
---|
396 | * @param pDirEntry Where to store the information about the next
|
---|
397 | * directory entry on success.
|
---|
398 | * @param pcbDirEntry Optional parameter used for variable buffer size.
|
---|
399 | *
|
---|
400 | * On input the variable pointed to contains the size of the pDirEntry
|
---|
401 | * structure. This must be at least OFFSET(RTDIRENTRY, szName[2]) bytes.
|
---|
402 | *
|
---|
403 | * On successful output the field is updated to
|
---|
404 | * OFFSET(RTDIRENTRY, szName[pDirEntry->cbName + 1]).
|
---|
405 | *
|
---|
406 | * When the data doesn't fit in the buffer and VERR_BUFFER_OVERFLOW is
|
---|
407 | * returned, this field contains the required buffer size.
|
---|
408 | *
|
---|
409 | * The value is unchanged in all other cases.
|
---|
410 | */
|
---|
411 | RTDECL(int) RTDirRead(PRTDIR pDir, PRTDIRENTRY pDirEntry, size_t *pcbDirEntry);
|
---|
412 |
|
---|
413 | /**
|
---|
414 | * Reads the next entry in the directory returning extended information.
|
---|
415 | *
|
---|
416 | * @returns VINF_SUCCESS and data in pDirEntry on success.
|
---|
417 | * @returns VERR_NO_MORE_FILES when the end of the directory has been reached.
|
---|
418 | * @returns VERR_BUFFER_OVERFLOW if the buffer is too small to contain the filename. If
|
---|
419 | * pcbDirEntry is specified it will be updated with the required buffer size.
|
---|
420 | * @returns suitable iprt status code on other errors.
|
---|
421 | *
|
---|
422 | * @param pDir Pointer to the open directory.
|
---|
423 | * @param pDirEntry Where to store the information about the next
|
---|
424 | * directory entry on success.
|
---|
425 | * @param pcbDirEntry Optional parameter used for variable buffer size.
|
---|
426 | *
|
---|
427 | * On input the variable pointed to contains the size of the pDirEntry
|
---|
428 | * structure. This must be at least OFFSET(RTDIRENTRYEX, szName[2]) bytes.
|
---|
429 | *
|
---|
430 | * On successful output the field is updated to
|
---|
431 | * OFFSET(RTDIRENTRYEX, szName[pDirEntry->cbName + 1]).
|
---|
432 | *
|
---|
433 | * When the data doesn't fit in the buffer and VERR_BUFFER_OVERFLOW is
|
---|
434 | * returned, this field contains the required buffer size.
|
---|
435 | *
|
---|
436 | * The value is unchanged in all other cases.
|
---|
437 | * @param enmAdditionalAttribs
|
---|
438 | * Which set of additional attributes to request.
|
---|
439 | * Use RTFSOBJATTRADD_NOTHING if this doesn't matter.
|
---|
440 | * @param fFlags RTPATH_F_ON_LINK or RTPATH_F_FOLLOW_LINK.
|
---|
441 | */
|
---|
442 | RTDECL(int) RTDirReadEx(PRTDIR pDir, PRTDIRENTRYEX pDirEntry, size_t *pcbDirEntry, RTFSOBJATTRADD enmAdditionalAttribs, uint32_t fFlags);
|
---|
443 |
|
---|
444 | /**
|
---|
445 | * Resolves RTDIRENTRYTYPE_UNKNOWN values returned by RTDirRead.
|
---|
446 | *
|
---|
447 | * @returns IPRT status code (see RTPathQueryInfo).
|
---|
448 | * @param pszComposedName The path to the directory entry. The caller must
|
---|
449 | * compose this, it's NOT sufficient to pass
|
---|
450 | * RTDIRENTRY::szName!
|
---|
451 | * @param fFollowSymlinks Whether to follow symbolic links or not.
|
---|
452 | * @param penmType Pointer to the RTDIRENTRY::enmType member. If this
|
---|
453 | * is not RTDIRENTRYTYPE_UNKNOWN and, if
|
---|
454 | * @a fFollowSymlinks is false, not
|
---|
455 | * RTDIRENTRYTYPE_SYMLINK, the function will return
|
---|
456 | * immediately without doing anything. Otherwise it
|
---|
457 | * will use RTPathQueryInfo to try figure out the
|
---|
458 | * correct value. On failure, this will be unchanged.
|
---|
459 | */
|
---|
460 | RTDECL(int) RTDirQueryUnknownType(const char *pszComposedName, bool fFollowSymlinks, RTDIRENTRYTYPE *penmType);
|
---|
461 |
|
---|
462 | /**
|
---|
463 | * Resolves RTDIRENTRYTYPE_UNKNOWN values returned by RTDirRead, extended
|
---|
464 | * version.
|
---|
465 | *
|
---|
466 | * @returns IPRT status code (see RTPathQueryInfo).
|
---|
467 | * @param pszComposedName The path to the directory entry. The caller must
|
---|
468 | * compose this, it's NOT sufficient to pass
|
---|
469 | * RTDIRENTRY::szName!
|
---|
470 | * @param fFollowSymlinks Whether to follow symbolic links or not.
|
---|
471 | * @param penmType Pointer to the RTDIRENTRY::enmType member or
|
---|
472 | * similar. Will NOT be checked on input.
|
---|
473 | * @param pObjInfo The object info buffer to use with RTPathQueryInfo.
|
---|
474 | */
|
---|
475 | RTDECL(int) RTDirQueryUnknownTypeEx(const char *pszComposedName, bool fFollowSymlinks, RTDIRENTRYTYPE *penmType, PRTFSOBJINFO pObjInfo);
|
---|
476 |
|
---|
477 | /**
|
---|
478 | * Checks if the directory entry returned by RTDirRead is '.', '..' or similar.
|
---|
479 | *
|
---|
480 | * @returns true / false.
|
---|
481 | * @param pDirEntry The directory entry to check.
|
---|
482 | */
|
---|
483 | RTDECL(bool) RTDirEntryIsStdDotLink(PRTDIRENTRY pDirEntry);
|
---|
484 |
|
---|
485 | /**
|
---|
486 | * Checks if the directory entry returned by RTDirReadEx is '.', '..' or
|
---|
487 | * similar.
|
---|
488 | *
|
---|
489 | * @returns true / false.
|
---|
490 | * @param pDirEntryEx The extended directory entry to check.
|
---|
491 | */
|
---|
492 | RTDECL(bool) RTDirEntryExIsStdDotLink(PCRTDIRENTRYEX pDirEntryEx);
|
---|
493 |
|
---|
494 | /**
|
---|
495 | * Renames a file.
|
---|
496 | *
|
---|
497 | * Identical to RTPathRename except that it will ensure that the source is a directory.
|
---|
498 | *
|
---|
499 | * @returns IPRT status code.
|
---|
500 | * @returns VERR_ALREADY_EXISTS if the destination file exists.
|
---|
501 | *
|
---|
502 | * @param pszSrc The path to the source file.
|
---|
503 | * @param pszDst The path to the destination file.
|
---|
504 | * This file will be created.
|
---|
505 | * @param fRename See RTPathRename.
|
---|
506 | */
|
---|
507 | RTDECL(int) RTDirRename(const char *pszSrc, const char *pszDst, unsigned fRename);
|
---|
508 |
|
---|
509 |
|
---|
510 | /**
|
---|
511 | * Query information about an open directory.
|
---|
512 | *
|
---|
513 | * @returns iprt status code.
|
---|
514 | *
|
---|
515 | * @param pDir Pointer to the open directory.
|
---|
516 | * @param pObjInfo Object information structure to be filled on successful return.
|
---|
517 | * @param enmAdditionalAttribs Which set of additional attributes to request.
|
---|
518 | * Use RTFSOBJATTRADD_NOTHING if this doesn't matter.
|
---|
519 | */
|
---|
520 | RTR3DECL(int) RTDirQueryInfo(PRTDIR pDir, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAdditionalAttribs);
|
---|
521 |
|
---|
522 |
|
---|
523 | /**
|
---|
524 | * Changes one or more of the timestamps associated of file system object.
|
---|
525 | *
|
---|
526 | * @returns iprt status code.
|
---|
527 | * @returns VERR_NOT_SUPPORTED is returned if the operation isn't supported by the OS.
|
---|
528 | *
|
---|
529 | * @param pDir Pointer to the open directory.
|
---|
530 | * @param pAccessTime Pointer to the new access time. NULL if not to be changed.
|
---|
531 | * @param pModificationTime Pointer to the new modifcation time. NULL if not to be changed.
|
---|
532 | * @param pChangeTime Pointer to the new change time. NULL if not to be changed.
|
---|
533 | * @param pBirthTime Pointer to the new time of birth. NULL if not to be changed.
|
---|
534 | *
|
---|
535 | * @remark The file system might not implement all these time attributes,
|
---|
536 | * the API will ignore the ones which aren't supported.
|
---|
537 | *
|
---|
538 | * @remark The file system might not implement the time resolution
|
---|
539 | * employed by this interface, the time will be chopped to fit.
|
---|
540 | *
|
---|
541 | * @remark The file system may update the change time even if it's
|
---|
542 | * not specified.
|
---|
543 | *
|
---|
544 | * @remark POSIX can only set Access & Modification and will always set both.
|
---|
545 | */
|
---|
546 | RTR3DECL(int) RTDirSetTimes(PRTDIR pDir, PCRTTIMESPEC pAccessTime, PCRTTIMESPEC pModificationTime,
|
---|
547 | PCRTTIMESPEC pChangeTime, PCRTTIMESPEC pBirthTime);
|
---|
548 |
|
---|
549 |
|
---|
550 | /** @defgroup grp_rt_dir_rel Directory relative APIs
|
---|
551 | *
|
---|
552 | * This group of APIs allows working with paths that are relative to an open
|
---|
553 | * directory, therebye eliminating some classic path related race conditions on
|
---|
554 | * systems with native support for these kinds of operations.
|
---|
555 | *
|
---|
556 | * @{ */
|
---|
557 |
|
---|
558 | /**
|
---|
559 | * Open a file relative to @a hDir.
|
---|
560 | *
|
---|
561 | * @returns IPRT status code.
|
---|
562 | * @param hDir The directory to open relative to.
|
---|
563 | * @param pszRelFilename The relative path to the file.
|
---|
564 | * @param fOpen Open flags, i.e a combination of the RTFILE_O_XXX
|
---|
565 | * defines. The ACCESS, ACTION and DENY flags are
|
---|
566 | * mandatory!
|
---|
567 | * @param phFile Where to store the handle to the opened file.
|
---|
568 | *
|
---|
569 | * @sa RTFileOpen
|
---|
570 | */
|
---|
571 | RTDECL(int) RTDirRelFileOpen(PRTDIR hDir, const char *pszRelFilename, uint64_t fOpen, PRTFILE phFile);
|
---|
572 |
|
---|
573 |
|
---|
574 |
|
---|
575 | /**
|
---|
576 | * Opens a directory relative to @a hDir.
|
---|
577 | *
|
---|
578 | * @returns IPRT status code.
|
---|
579 | * @param hDir The directory to open relative to.
|
---|
580 | * @param pszDir The relative path to the directory to open.
|
---|
581 | * @param phDir Where to store the directory handle.
|
---|
582 | *
|
---|
583 | * @sa RTDirOpen
|
---|
584 | */
|
---|
585 | RTDECL(int) RTDirRelDirOpen(PRTDIR hDir, const char *pszDir, PRTDIR *phDir);
|
---|
586 |
|
---|
587 | /**
|
---|
588 | * Opens a directory relative to @a hDir, with flags and optional filtering.
|
---|
589 | *
|
---|
590 | * @returns IPRT status code.
|
---|
591 | * @param hDir The directory to open relative to.
|
---|
592 | * @param pszDirAndFilter The relative path to the directory to search, this
|
---|
593 | * must include wildcards.
|
---|
594 | * @param enmFilter The kind of filter to apply. Setting this to
|
---|
595 | * RTDIRFILTER_NONE makes this function behave like
|
---|
596 | * RTDirOpen.
|
---|
597 | * @param fFlags Open flags, RTDIR_F_XXX.
|
---|
598 | * @param phDir Where to store the directory handle.
|
---|
599 | *
|
---|
600 | * @sa RTDirOpenFiltered
|
---|
601 | */
|
---|
602 | RTDECL(int) RTDirRelDirOpenFiltered(PRTDIR hDir, const char *pszDirAndFilter, RTDIRFILTER enmFilter,
|
---|
603 | uint32_t fFlags, PRTDIR *phDir);
|
---|
604 |
|
---|
605 | /**
|
---|
606 | * Creates a directory relative to @a hDir.
|
---|
607 | *
|
---|
608 | * @returns IPRT status code.
|
---|
609 | * @param hDir The directory @a pszRelPath is relative to.
|
---|
610 | * @param pszRelPath The relative path to the directory to create.
|
---|
611 | * @param fMode The mode of the new directory.
|
---|
612 | * @param fCreate Create flags, RTDIRCREATE_FLAGS_XXX.
|
---|
613 | *
|
---|
614 | * @sa RTDirCreate
|
---|
615 | */
|
---|
616 | RTDECL(int) RTDirRelDirCreate(PRTDIR hDir, const char *pszRelPath, RTFMODE fMode, uint32_t fCreate);
|
---|
617 |
|
---|
618 | /**
|
---|
619 | * Removes a directory relative to @a hDir if empty.
|
---|
620 | *
|
---|
621 | * @returns IPRT status code.
|
---|
622 | * @param hDir The directory @a pszRelPath is relative to.
|
---|
623 | * @param pszRelPath The relative path to the directory to remove.
|
---|
624 | *
|
---|
625 | * @sa RTDirRemove
|
---|
626 | */
|
---|
627 | RTDECL(int) RTDirRelDirRemove(PRTDIR hDir, const char *pszRelPath);
|
---|
628 |
|
---|
629 |
|
---|
630 | /**
|
---|
631 | * Query information about a file system object relative to @a hDir.
|
---|
632 | *
|
---|
633 | * @returns IPRT status code.
|
---|
634 | * @retval VINF_SUCCESS if the object exists, information returned.
|
---|
635 | * @retval VERR_PATH_NOT_FOUND if any but the last component in the specified
|
---|
636 | * path was not found or was not a directory.
|
---|
637 | * @retval VERR_FILE_NOT_FOUND if the object does not exist (but path to the
|
---|
638 | * parent directory exists).
|
---|
639 | *
|
---|
640 | * @param hDir The directory @a pszRelPath is relative to.
|
---|
641 | * @param pszRelPath The relative path to the file system object.
|
---|
642 | * @param pObjInfo Object information structure to be filled on successful
|
---|
643 | * return.
|
---|
644 | * @param enmAddAttr Which set of additional attributes to request.
|
---|
645 | * Use RTFSOBJATTRADD_NOTHING if this doesn't matter.
|
---|
646 | * @param fFlags RTPATH_F_ON_LINK or RTPATH_F_FOLLOW_LINK.
|
---|
647 | *
|
---|
648 | * @sa RTPathQueryInfoEx
|
---|
649 | */
|
---|
650 | RTDECL(int) RTDirRelPathQueryInfo(PRTDIR hDir, const char *pszRelPath, PRTFSOBJINFO pObjInfo,
|
---|
651 | RTFSOBJATTRADD enmAddAttr, uint32_t fFlags);
|
---|
652 |
|
---|
653 | /**
|
---|
654 | * Changes the mode flags of a file system object relative to @a hDir.
|
---|
655 | *
|
---|
656 | * The API requires at least one of the mode flag sets (Unix/Dos) to
|
---|
657 | * be set. The type is ignored.
|
---|
658 | *
|
---|
659 | * @returns IPRT status code.
|
---|
660 | * @param hDir The directory @a pszRelPath is relative to.
|
---|
661 | * @param pszRelPath The relative path to the file system object.
|
---|
662 | * @param fMode The new file mode, see @ref grp_rt_fs for details.
|
---|
663 | * @param fFlags RTPATH_F_ON_LINK or RTPATH_F_FOLLOW_LINK.
|
---|
664 | *
|
---|
665 | * @sa RTPathSetMode
|
---|
666 | */
|
---|
667 | RTDECL(int) RTDirRelPathSetMode(PRTDIR hDir, const char *pszRelPath, RTFMODE fMode, uint32_t fFlags);
|
---|
668 |
|
---|
669 | /**
|
---|
670 | * Changes one or more of the timestamps associated of file system object
|
---|
671 | * relative to @a hDir.
|
---|
672 | *
|
---|
673 | * @returns IPRT status code.
|
---|
674 | * @param hDir The directory @a pszRelPath is relative to.
|
---|
675 | * @param pszRelPath The relative path to the file system object.
|
---|
676 | * @param pAccessTime Pointer to the new access time.
|
---|
677 | * @param pModificationTime Pointer to the new modification time.
|
---|
678 | * @param pChangeTime Pointer to the new change time. NULL if not to be changed.
|
---|
679 | * @param pBirthTime Pointer to the new time of birth. NULL if not to be changed.
|
---|
680 | * @param fFlags RTPATH_F_ON_LINK or RTPATH_F_FOLLOW_LINK.
|
---|
681 | *
|
---|
682 | * @remark The file system might not implement all these time attributes,
|
---|
683 | * the API will ignore the ones which aren't supported.
|
---|
684 | *
|
---|
685 | * @remark The file system might not implement the time resolution
|
---|
686 | * employed by this interface, the time will be chopped to fit.
|
---|
687 | *
|
---|
688 | * @remark The file system may update the change time even if it's
|
---|
689 | * not specified.
|
---|
690 | *
|
---|
691 | * @remark POSIX can only set Access & Modification and will always set both.
|
---|
692 | *
|
---|
693 | * @sa RTPathSetTimesEx
|
---|
694 | */
|
---|
695 | RTDECL(int) RTDirRelPathSetTimes(PRTDIR hDir, const char *pszRelPath, PCRTTIMESPEC pAccessTime, PCRTTIMESPEC pModificationTime,
|
---|
696 | PCRTTIMESPEC pChangeTime, PCRTTIMESPEC pBirthTime, uint32_t fFlags);
|
---|
697 |
|
---|
698 | /**
|
---|
699 | * Changes the owner and/or group of a file system object relative to @a hDir.
|
---|
700 | *
|
---|
701 | * @returns IPRT status code.
|
---|
702 | * @param hDir The directory @a pszRelPath is relative to.
|
---|
703 | * @param pszRelPath The relative path to the file system object.
|
---|
704 | * @param uid The new file owner user id. Pass NIL_RTUID to leave
|
---|
705 | * this unchanged.
|
---|
706 | * @param gid The new group id. Pass NIL_RTGID to leave this
|
---|
707 | * unchanged.
|
---|
708 | * @param fFlags RTPATH_F_ON_LINK or RTPATH_F_FOLLOW_LINK.
|
---|
709 | *
|
---|
710 | * @sa RTPathSetOwnerEx
|
---|
711 | */
|
---|
712 | RTDECL(int) RTDirRelPathSetOwner(PRTDIR hDir, const char *pszRelPath, uint32_t uid, uint32_t gid, uint32_t fFlags);
|
---|
713 |
|
---|
714 | /**
|
---|
715 | * Renames a directory relative path within a filesystem.
|
---|
716 | *
|
---|
717 | * This will rename symbolic links. If RTPATHRENAME_FLAGS_REPLACE is used and
|
---|
718 | * pszDst is a symbolic link, it will be replaced and not its target.
|
---|
719 | *
|
---|
720 | * @returns IPRT status code.
|
---|
721 | * @param hDirSrc The directory the source path is relative to.
|
---|
722 | * @param pszSrc The source path, relative to @a hDirSrc.
|
---|
723 | * @param hDirSrc The directory the destination path is relative to.
|
---|
724 | * @param pszDst The destination path, relative to @a hDirDst.
|
---|
725 | * @param fRename Rename flags, RTPATHRENAME_FLAGS_XXX.
|
---|
726 | *
|
---|
727 | * @sa RTPathRename
|
---|
728 | */
|
---|
729 | RTDECL(int) RTDirRelPathRename(PRTDIR hDirSrc, const char *pszSrc, PRTDIR hDirDst, const char *pszDst, unsigned fRename);
|
---|
730 |
|
---|
731 | /**
|
---|
732 | * Removes the last component of the directory relative path.
|
---|
733 | *
|
---|
734 | * @returns IPRT status code.
|
---|
735 | * @param hDir The directory @a pszRelPath is relative to.
|
---|
736 | * @param pszRelPath The relative path to the file system object.
|
---|
737 | * @param fUnlink Unlink flags, RTPATHUNLINK_FLAGS_XXX.
|
---|
738 | *
|
---|
739 | * @sa RTPathUnlink
|
---|
740 | */
|
---|
741 | RTDECL(int) RTDirRelPathUnlink(PRTDIR hDir, const char *pszRelPath, uint32_t fUnlink);
|
---|
742 |
|
---|
743 |
|
---|
744 |
|
---|
745 | /**
|
---|
746 | * Creates a symbolic link (@a pszSymlink) relative to @a hDir targeting @a
|
---|
747 | * pszTarget.
|
---|
748 | *
|
---|
749 | * @returns IPRT status code.
|
---|
750 | * @param hDir The directory @a pszSymlink is relative to.
|
---|
751 | * @param pszSymlink The relative path of the symbolic link.
|
---|
752 | * @param pszTarget The path to the symbolic link target. This is
|
---|
753 | * relative to @a pszSymlink or an absolute path.
|
---|
754 | * @param enmType The symbolic link type. For Windows compatability
|
---|
755 | * it is very important to set this correctly. When
|
---|
756 | * RTSYMLINKTYPE_UNKNOWN is used, the API will try
|
---|
757 | * make a guess and may attempt query information
|
---|
758 | * about @a pszTarget in the process.
|
---|
759 | * @param fCreate Create flags, RTSYMLINKCREATE_FLAGS_XXX.
|
---|
760 | *
|
---|
761 | * @sa RTSymlinkCreate
|
---|
762 | */
|
---|
763 | RTDECL(int) RTDirRelSymlinkCreate(PRTDIR hDir, const char *pszSymlink, const char *pszTarget,
|
---|
764 | RTSYMLINKTYPE enmType, uint32_t fCreate);
|
---|
765 |
|
---|
766 | /**
|
---|
767 | * Read the symlink target relative to @a hDir.
|
---|
768 | *
|
---|
769 | * @returns IPRT status code.
|
---|
770 | * @retval VERR_NOT_SYMLINK if @a pszSymlink does not specify a symbolic link.
|
---|
771 | * @retval VERR_BUFFER_OVERFLOW if the link is larger than @a cbTarget. The
|
---|
772 | * buffer will contain what all we managed to read, fully terminated
|
---|
773 | * if @a cbTarget > 0.
|
---|
774 | *
|
---|
775 | * @param hDir The directory @a pszSymlink is relative to.
|
---|
776 | * @param pszSymlink The relative path to the symbolic link that should
|
---|
777 | * be read.
|
---|
778 | * @param pszTarget The target buffer.
|
---|
779 | * @param cbTarget The size of the target buffer.
|
---|
780 | * @param fRead Read flags, RTSYMLINKREAD_FLAGS_XXX.
|
---|
781 | *
|
---|
782 | * @sa RTSymlinkRead
|
---|
783 | */
|
---|
784 | RTDECL(int) RTDirRelSymlinkRead(PRTDIR hDir, const char *pszSymlink, char *pszTarget, size_t cbTarget, uint32_t fRead);
|
---|
785 |
|
---|
786 | /** @} */
|
---|
787 |
|
---|
788 |
|
---|
789 | /** @} */
|
---|
790 |
|
---|
791 | RT_C_DECLS_END
|
---|
792 |
|
---|
793 | #endif
|
---|
794 |
|
---|