GuestHost/installation/VBoxWinDrvInst.cpp: Try harder if DiInstallDriverW() returns...
[vbox.git] / include / iprt / dir.h
bloba568a84cf119c1b44934ff040ebe79c38a736304
1 /** @file
2 * IPRT - Directory Manipulation.
3 */
5 /*
6 * Copyright (C) 2006-2024 Oracle and/or its affiliates.
8 * This file is part of VirtualBox base platform packages, as
9 * available from https://www.virtualbox.org.
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation, in version 3 of the
14 * License.
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 * The contents of this file may alternatively be used under the terms
25 * of the Common Development and Distribution License Version 1.0
26 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
27 * in the VirtualBox distribution, in which case the provisions of the
28 * CDDL are applicable instead of those of the GPL.
30 * You may elect to license modified versions of this file under the
31 * terms and conditions of either the GPL or the CDDL or both.
33 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
36 #ifndef IPRT_INCLUDED_dir_h
37 #define IPRT_INCLUDED_dir_h
38 #ifndef RT_WITHOUT_PRAGMA_ONCE
39 # pragma once
40 #endif
42 #include <iprt/cdefs.h>
43 #include <iprt/types.h>
44 #include <iprt/fs.h>
45 #include <iprt/symlink.h>
48 RT_C_DECLS_BEGIN
50 /** @defgroup grp_rt_dir RTDir - Directory Manipulation
51 * @ingroup grp_rt
52 * @{
55 /**
56 * Check for the existence of a directory.
58 * All symbolic links will be attemped resolved. If that is undesirable, please
59 * use RTPathQueryInfo instead.
61 * @returns true if exist and is a directory.
62 * @returns false if not exists or isn't a directory.
63 * @param pszPath Path to the directory.
65 RTDECL(bool) RTDirExists(const char *pszPath);
67 /** @name RTDirCreate flags.
68 * @{ */
69 /** Don't allow symbolic links as part of the path.
70 * @remarks this flag is currently not implemented and will be ignored. */
71 #define RTDIRCREATE_FLAGS_NO_SYMLINKS RT_BIT(0)
72 /** Set the not-content-indexed flag (default). Windows only atm. */
73 #define RTDIRCREATE_FLAGS_NOT_CONTENT_INDEXED_DONT_SET RT_BIT(1)
74 /** Do not set the not-content-indexed flag. Windows only atm. */
75 #define RTDIRCREATE_FLAGS_NOT_CONTENT_INDEXED_SET UINT32_C(0)
76 /** Ignore errors setting the not-content-indexed flag. Windows only atm. */
77 #define RTDIRCREATE_FLAGS_NOT_CONTENT_INDEXED_NOT_CRITICAL RT_BIT(2)
78 /** Ignore umask when applying the mode. */
79 #define RTDIRCREATE_FLAGS_IGNORE_UMASK RT_BIT(3)
80 /** Valid mask. */
81 #define RTDIRCREATE_FLAGS_VALID_MASK UINT32_C(0x0000000f)
82 /** @} */
84 /**
85 * Creates a directory.
87 * @returns iprt status code.
88 * @param pszPath Path to the directory to create.
89 * @param fMode The mode of the new directory.
90 * @param fCreate Create flags, RTDIRCREATE_FLAGS_*.
92 RTDECL(int) RTDirCreate(const char *pszPath, RTFMODE fMode, uint32_t fCreate);
94 /**
95 * Creates a directory including all non-existing parent directories.
97 * @returns iprt status code.
98 * @param pszPath Path to the directory to create.
99 * @param fMode The mode of the new directories.
101 RTDECL(int) RTDirCreateFullPath(const char *pszPath, RTFMODE fMode);
104 * Creates a directory including all non-existing parent directories.
106 * @returns iprt status code.
107 * @param pszPath Path to the directory to create.
108 * @param fMode The mode of the new directories.
109 * @param fFlags Create flags, RTDIRCREATE_FLAGS_*.
111 RTDECL(int) RTDirCreateFullPathEx(const char *pszPath, RTFMODE fMode, uint32_t fFlags);
114 * Creates a new directory with a unique name using the given template.
116 * One or more trailing X'es in the template will be replaced by random alpha
117 * numeric characters until a RTDirCreate succeeds or we run out of patience.
118 * For instance:
119 * "/tmp/myprog-XXXXXX"
121 * As an alternative to trailing X'es, it
122 * is possible to put 3 or more X'es somewhere inside the directory name. In
123 * the following string only the last bunch of X'es will be modified:
124 * "/tmp/myprog-XXX-XXX.tmp"
126 * @returns iprt status code.
127 * @param pszTemplate The directory name template on input. The actual
128 * directory name on success. Empty string on failure.
129 * @param fMode The mode to create the directory with. Use 0700
130 * unless you have reason not to.
132 RTDECL(int) RTDirCreateTemp(char *pszTemplate, RTFMODE fMode);
135 * Secure version of @a RTDirCreateTemp with a fixed mode of 0700.
137 * This function behaves in the same way as @a RTDirCreateTemp with two
138 * additional points. Firstly the mode is fixed to 0700. Secondly it will
139 * fail if it is not possible to perform the operation securely. Possible
140 * reasons include that the directory could be removed by another unprivileged
141 * user before it is used (e.g. if is created in a non-sticky /tmp directory)
142 * or that the path contains symbolic links which another unprivileged user
143 * could manipulate; however the exact criteria will be specified on a
144 * platform-by-platform basis as platform support is added.
145 * @see RTPathIsSecure for the current list of criteria.
146 * @returns iprt status code.
147 * @returns VERR_NOT_SUPPORTED if the interface can not be supported on the
148 * current platform at this time.
149 * @returns VERR_INSECURE if the directory could not be created securely.
150 * @param pszTemplate The directory name template on input. The
151 * actual directory name on success. Empty string
152 * on failure.
154 RTDECL(int) RTDirCreateTempSecure(char *pszTemplate);
157 * Creates a new directory with a unique name by appending a number.
159 * This API differs from RTDirCreateTemp & RTDirCreateTempSecure in that it
160 * first tries to create the directory without any random bits, thus the best
161 * case result will be prettier. It also differs in that it does not take a
162 * template, but is instead given a template description, and will only use
163 * digits for the filling.
165 * For sake of convenience and debugging , the current implementation
166 * starts at 0 and will increment sequentally for a while before switching to
167 * random numbers.
169 * On success @a pszPath contains the path created.
171 * @returns iprt status code.
172 * @param pszPath The path to the directory. On input the base template
173 * name. On successful return, the unique directory we
174 * created.
175 * @param cbSize The size of the pszPath buffer. Needs enough space for
176 * holding the digits and the optional separator.
177 * @param fMode The mode of the new directory.
178 * @param cchDigits How many digits should the number have (zero padded).
179 * @param chSep The separator used between the path and the number. Can
180 * be zero. (optional)
182 RTDECL(int) RTDirCreateUniqueNumbered(char *pszPath, size_t cbSize, RTFMODE fMode, size_t cchDigits, char chSep);
185 * Removes a directory if empty.
187 * @returns iprt status code.
188 * @param pszPath Path to the directory to remove.
190 RTDECL(int) RTDirRemove(const char *pszPath);
193 * Removes a directory tree recursively.
195 * @returns iprt status code.
196 * @param pszPath Path to the directory to remove recursively.
197 * @param fFlags Flags, see RTDIRRMREC_F_XXX.
199 * @remarks This will not work on a root directory.
201 RTDECL(int) RTDirRemoveRecursive(const char *pszPath, uint32_t fFlags);
203 /** @name RTDirRemoveRecursive flags.
204 * @{ */
205 /** Delete the content of the directory and the directory itself. */
206 #define RTDIRRMREC_F_CONTENT_AND_DIR UINT32_C(0)
207 /** Only delete the content of the directory, omit the directory it self. */
208 #define RTDIRRMREC_F_CONTENT_ONLY RT_BIT_32(0)
209 /** Long path hack: Don't apply RTPathAbs to the path. */
210 #define RTDIRRMREC_F_NO_ABS_PATH RT_BIT_32(1)
211 /** Mask of valid flags. */
212 #define RTDIRRMREC_F_VALID_MASK UINT32_C(0x00000003)
213 /** @} */
216 * Flushes the specified directory.
218 * This API is not implemented on all systems. On some systems it may be
219 * unnecessary if you've already flushed the file. If you really care for your
220 * data and is entering dangerous territories, it doesn't hurt calling it after
221 * flushing and closing the file.
223 * @returns IPRT status code.
224 * @retval VERR_NOT_IMPLEMENTED must be expected.
225 * @retval VERR_NOT_SUPPORTED must be expected.
226 * @param pszPath Path to the directory.
228 RTDECL(int) RTDirFlush(const char *pszPath);
231 * Flushes the parent directory of the specified file.
233 * This is just a wrapper around RTDirFlush.
235 * @returns IPRT status code, see RTDirFlush for details.
236 * @param pszChild Path to the file which parent should be flushed.
238 RTDECL(int) RTDirFlushParent(const char *pszChild);
243 * Filter option for RTDirOpenFiltered().
245 typedef enum RTDIRFILTER
247 /** The usual invalid 0 entry. */
248 RTDIRFILTER_INVALID = 0,
249 /** No filter should be applied (and none was specified). */
250 RTDIRFILTER_NONE,
251 /** The Windows NT filter.
252 * The following wildcard chars: *, ?, <, > and "
253 * The matching is done on the uppercased strings. */
254 RTDIRFILTER_WINNT,
255 /** The UNIX filter.
256 * The following wildcard chars: *, ?, [..]
257 * The matching is done on exact case. */
258 RTDIRFILTER_UNIX,
259 /** The UNIX filter, uppercased matching.
260 * Same as RTDIRFILTER_UNIX except that the strings are uppercased before comparing. */
261 RTDIRFILTER_UNIX_UPCASED,
263 /** The usual full 32-bit value. */
264 RTDIRFILTER_32BIT_HACK = 0x7fffffff
265 } RTDIRFILTER;
269 * Directory entry type.
271 * This is the RTFS_TYPE_MASK stuff shifted down 12 bits and
272 * identical to the BSD/LINUX ABI. See RTFS_TYPE_DIRENTRYTYPE_SHIFT.
274 typedef enum RTDIRENTRYTYPE
276 /** Unknown type (DT_UNKNOWN). */
277 RTDIRENTRYTYPE_UNKNOWN = 0,
278 /** Named pipe (fifo) (DT_FIFO). */
279 RTDIRENTRYTYPE_FIFO = 001,
280 /** Character device (DT_CHR). */
281 RTDIRENTRYTYPE_DEV_CHAR = 002,
282 /** Directory (DT_DIR). */
283 RTDIRENTRYTYPE_DIRECTORY = 004,
284 /** Block device (DT_BLK). */
285 RTDIRENTRYTYPE_DEV_BLOCK = 006,
286 /** Regular file (DT_REG). */
287 RTDIRENTRYTYPE_FILE = 010,
288 /** Symbolic link (DT_LNK). */
289 RTDIRENTRYTYPE_SYMLINK = 012,
290 /** Socket (DT_SOCK). */
291 RTDIRENTRYTYPE_SOCKET = 014,
292 /** Whiteout (DT_WHT). */
293 RTDIRENTRYTYPE_WHITEOUT = 016
294 } RTDIRENTRYTYPE;
298 * Directory entry.
300 * This is inspired by the POSIX interfaces.
302 #pragma pack(1)
303 typedef struct RTDIRENTRY
305 /** The unique identifier (within the file system) of this file system object (d_ino).
307 * Together with INodeIdDevice, this field can be used as a OS wide unique id
308 * when both their values are not 0. This field is 0 if the information is not
309 * available. */
310 RTINODE INodeId;
311 /** The entry type. (d_type)
313 * @warning RTDIRENTRYTYPE_UNKNOWN is a common return value here since not all
314 * file systems (or Unixes) stores the type of a directory entry and
315 * instead expects the user to use stat() to get it. So, when you see
316 * this you should use RTDirQueryUnknownType or RTDirQueryUnknownTypeEx
317 * to get the type, or if if you're lazy, use RTDirReadEx.
319 RTDIRENTRYTYPE enmType;
320 /** The length of the filename, excluding the terminating nul character. */
321 uint16_t cbName;
322 /** The filename. (no path)
323 * Using the pcbDirEntry parameter of RTDirRead makes this field variable in size. */
324 char szName[260];
325 } RTDIRENTRY;
326 #pragma pack()
327 /** Pointer to a directory entry. */
328 typedef RTDIRENTRY *PRTDIRENTRY;
329 /** Pointer to a const directory entry. */
330 typedef RTDIRENTRY const *PCRTDIRENTRY;
334 * Directory entry with extended information.
336 * This is inspired by the PC interfaces.
338 #pragma pack(1)
339 typedef struct RTDIRENTRYEX
341 /** Full information about the object. */
342 RTFSOBJINFO Info;
343 /** The length of the short field (number of RTUTF16 entries (not chars)).
344 * It is 16-bit for reasons of alignment. */
345 uint16_t cwcShortName;
346 /** The short name for 8.3 compatibility.
347 * Empty string if not available.
348 * Since the length is a bit tricky for a UTF-8 encoded name, and since this
349 * is practically speaking only a windows thing, it is encoded as UCS-2. */
350 RTUTF16 wszShortName[14];
351 /** The length of the filename. */
352 uint16_t cbName;
353 /** The filename. (no path)
354 * Using the pcbDirEntry parameter of RTDirReadEx makes this field variable in size. */
355 char szName[260];
356 } RTDIRENTRYEX;
357 #pragma pack()
358 /** Pointer to a directory entry. */
359 typedef RTDIRENTRYEX *PRTDIRENTRYEX;
360 /** Pointer to a const directory entry. */
361 typedef RTDIRENTRYEX const *PCRTDIRENTRYEX;
365 * Opens a directory.
367 * @returns iprt status code.
368 * @param phDir Where to store the open directory handle.
369 * @param pszPath Path to the directory to open.
371 RTDECL(int) RTDirOpen(RTDIR *phDir, const char *pszPath);
373 /** @name RTDIR_F_XXX - RTDirOpenFiltered flags.
374 * @{ */
375 /** Don't allow symbolic links as part of the path.
376 * @remarks this flag is currently not implemented and will be ignored. */
377 #define RTDIR_F_NO_SYMLINKS RT_BIT_32(0)
378 /** Deny relative opening of anything above this directory. */
379 #define RTDIR_F_DENY_ASCENT RT_BIT_32(1)
380 /** Don't follow symbolic links in the final component. */
381 #define RTDIR_F_NO_FOLLOW RT_BIT_32(2)
382 /** Long path hack: Don't apply RTPathAbs to the path. */
383 #define RTDIR_F_NO_ABS_PATH RT_BIT_32(3)
384 /** Valid flag mask. */
385 #define RTDIR_F_VALID_MASK UINT32_C(0x0000000f)
386 /** @} */
389 * Opens a directory with flags and optional filtering.
391 * @returns IPRT status code.
392 * @retval VERR_IS_A_SYMLINK if RTDIR_F_NO_FOLLOW is set, @a enmFilter is
393 * RTDIRFILTER_NONE and @a pszPath points to a symbolic link and does
394 * not end with a slash. Note that on Windows this does not apply to
395 * file symlinks, only directory symlinks, for the file variant
396 * VERR_NOT_A_DIRECTORY will be returned.
398 * @param phDir Where to store the open directory handle.
399 * @param pszPath Path to the directory to search, this must include wildcards.
400 * @param enmFilter The kind of filter to apply. Setting this to RTDIRFILTER_NONE makes
401 * this function behave like RTDirOpen.
402 * @param fFlags Open flags, RTDIR_F_XXX.
405 RTDECL(int) RTDirOpenFiltered(RTDIR *phDir, const char *pszPath, RTDIRFILTER enmFilter, uint32_t fFlags);
408 * Closes a directory.
410 * @returns iprt status code.
411 * @param hDir Handle to open directory returned by RTDirOpen() or
412 * RTDirOpenFiltered().
414 RTDECL(int) RTDirClose(RTDIR hDir);
417 * Checks if the supplied directory handle is valid.
419 * @returns true if valid.
420 * @returns false if invalid.
421 * @param hDir The directory handle.
423 RTDECL(bool) RTDirIsValid(RTDIR hDir);
426 * Reads the next entry in the directory.
428 * @returns VINF_SUCCESS and data in pDirEntry on success.
429 * @returns VERR_NO_MORE_FILES when the end of the directory has been reached.
430 * @returns VERR_BUFFER_OVERFLOW if the buffer is too small to contain the filename. If
431 * pcbDirEntry is specified it will be updated with the required buffer size.
432 * @returns suitable iprt status code on other errors.
434 * @param hDir Handle to the open directory.
435 * @param pDirEntry Where to store the information about the next
436 * directory entry on success.
437 * @param pcbDirEntry Optional parameter used for variable buffer size.
439 * On input the variable pointed to contains the size of the pDirEntry
440 * structure. This must be at least OFFSET(RTDIRENTRY, szName[2]) bytes.
442 * On successful output the field is updated to
443 * OFFSET(RTDIRENTRY, szName[pDirEntry->cbName + 1]).
445 * When the data doesn't fit in the buffer and VERR_BUFFER_OVERFLOW is
446 * returned, this field contains the required buffer size.
448 * The value is unchanged in all other cases.
450 RTDECL(int) RTDirRead(RTDIR hDir, PRTDIRENTRY pDirEntry, size_t *pcbDirEntry);
453 * Reads the next entry in the directory returning extended information.
455 * @returns VINF_SUCCESS and data in pDirEntry on success.
456 * @returns VERR_NO_MORE_FILES when the end of the directory has been reached.
457 * @returns VERR_BUFFER_OVERFLOW if the buffer is too small to contain the filename. If
458 * pcbDirEntry is specified it will be updated with the required buffer size.
459 * @returns suitable iprt status code on other errors.
461 * @param hDir Handle to the open directory.
462 * @param pDirEntry Where to store the information about the next
463 * directory entry on success.
464 * @param pcbDirEntry Optional parameter used for variable buffer size.
466 * On input the variable pointed to contains the size of the pDirEntry
467 * structure. This must be at least OFFSET(RTDIRENTRYEX, szName[2]) bytes.
469 * On successful output the field is updated to
470 * OFFSET(RTDIRENTRYEX, szName[pDirEntry->cbName + 1]).
472 * When the data doesn't fit in the buffer and VERR_BUFFER_OVERFLOW is
473 * returned, this field contains the required buffer size.
475 * The value is unchanged in all other cases.
476 * @param enmAdditionalAttribs
477 * Which set of additional attributes to request.
478 * Use RTFSOBJATTRADD_NOTHING if this doesn't matter.
479 * @param fFlags RTPATH_F_ON_LINK or RTPATH_F_FOLLOW_LINK.
481 RTDECL(int) RTDirReadEx(RTDIR hDir, PRTDIRENTRYEX pDirEntry, size_t *pcbDirEntry, RTFSOBJATTRADD enmAdditionalAttribs, uint32_t fFlags);
484 * Wrapper around RTDirReadEx that does the directory entry buffer handling.
486 * Call RTDirReadExAFree to free the buffers allocated by this function.
488 * @returns IPRT status code, see RTDirReadEx() for details.
490 * @param hDir Handle to the open directory.
491 * @param ppDirEntry Pointer to the directory entry pointer. Initialize this
492 * to NULL before the first call.
493 * @param pcbDirEntry Where the API caches the allocation size. Set this to
494 * zero before the first call.
495 * @param enmAddAttr See RTDirReadEx.
496 * @param fFlags See RTDirReadEx.
498 RTDECL(int) RTDirReadExA(RTDIR hDir, PRTDIRENTRYEX *ppDirEntry, size_t *pcbDirEntry, RTFSOBJATTRADD enmAddAttr, uint32_t fFlags);
501 * Frees the buffer allocated by RTDirReadExA.
503 * @param ppDirEntry Pointer to the directory entry pointer.
504 * @param pcbDirEntry Where the API caches the allocation size.
506 RTDECL(void) RTDirReadExAFree(PRTDIRENTRYEX *ppDirEntry, size_t *pcbDirEntry);
509 * Resolves RTDIRENTRYTYPE_UNKNOWN values returned by RTDirRead.
511 * @returns IPRT status code (see RTPathQueryInfo).
512 * @param pszComposedName The path to the directory entry. The caller must
513 * compose this, it's NOT sufficient to pass
514 * RTDIRENTRY::szName!
515 * @param fFollowSymlinks Whether to follow symbolic links or not.
516 * @param penmType Pointer to the RTDIRENTRY::enmType member. If this
517 * is not RTDIRENTRYTYPE_UNKNOWN and, if
518 * @a fFollowSymlinks is false, not
519 * RTDIRENTRYTYPE_SYMLINK, the function will return
520 * immediately without doing anything. Otherwise it
521 * will use RTPathQueryInfo to try figure out the
522 * correct value. On failure, this will be unchanged.
524 RTDECL(int) RTDirQueryUnknownType(const char *pszComposedName, bool fFollowSymlinks, RTDIRENTRYTYPE *penmType);
527 * Resolves RTDIRENTRYTYPE_UNKNOWN values returned by RTDirRead, extended
528 * version.
530 * @returns IPRT status code (see RTPathQueryInfo).
531 * @param pszComposedName The path to the directory entry. The caller must
532 * compose this, it's NOT sufficient to pass
533 * RTDIRENTRY::szName!
534 * @param fFollowSymlinks Whether to follow symbolic links or not.
535 * @param penmType Pointer to the RTDIRENTRY::enmType member or
536 * similar. Will NOT be checked on input.
537 * @param pObjInfo The object info buffer to use with RTPathQueryInfo.
539 RTDECL(int) RTDirQueryUnknownTypeEx(const char *pszComposedName, bool fFollowSymlinks, RTDIRENTRYTYPE *penmType, PRTFSOBJINFO pObjInfo);
542 * Checks if the directory entry returned by RTDirRead is '.', '..' or similar.
544 * @returns true / false.
545 * @param pDirEntry The directory entry to check.
547 RTDECL(bool) RTDirEntryIsStdDotLink(PRTDIRENTRY pDirEntry);
550 * Checks if the directory entry returned by RTDirReadEx is '.', '..' or
551 * similar.
553 * @returns true / false.
554 * @param pDirEntryEx The extended directory entry to check.
556 RTDECL(bool) RTDirEntryExIsStdDotLink(PCRTDIRENTRYEX pDirEntryEx);
559 * Rewind and restart the directory reading.
561 * @returns IRPT status code.
562 * @param hDir The directory handle to rewind.
564 RTDECL(int) RTDirRewind(RTDIR hDir);
567 * Renames a file.
569 * Identical to RTPathRename except that it will ensure that the source is a directory.
571 * @returns IPRT status code.
572 * @returns VERR_ALREADY_EXISTS if the destination file exists.
574 * @param pszSrc The path to the source file.
575 * @param pszDst The path to the destination file.
576 * This file will be created.
577 * @param fRename See RTPathRename.
579 RTDECL(int) RTDirRename(const char *pszSrc, const char *pszDst, unsigned fRename);
583 * Query information about an open directory.
585 * @returns iprt status code.
587 * @param hDir Handle to the open directory.
588 * @param pObjInfo Object information structure to be filled on successful return.
589 * @param enmAdditionalAttribs Which set of additional attributes to request.
590 * Use RTFSOBJATTRADD_NOTHING if this doesn't matter.
592 RTR3DECL(int) RTDirQueryInfo(RTDIR hDir, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAdditionalAttribs);
596 * Changes one or more of the timestamps associated of file system object.
598 * @returns iprt status code.
599 * @returns VERR_NOT_SUPPORTED is returned if the operation isn't supported by the OS.
601 * @param hDir Handle to the open directory.
602 * @param pAccessTime Pointer to the new access time. NULL if not to be changed.
603 * @param pModificationTime Pointer to the new modifcation time. NULL if not to be changed.
604 * @param pChangeTime Pointer to the new change time. NULL if not to be changed.
605 * @param pBirthTime Pointer to the new time of birth. NULL if not to be changed.
607 * @remark The file system might not implement all these time attributes,
608 * the API will ignore the ones which aren't supported.
610 * @remark The file system might not implement the time resolution
611 * employed by this interface, the time will be chopped to fit.
613 * @remark The file system may update the change time even if it's
614 * not specified.
616 * @remark POSIX can only set Access & Modification and will always set both.
618 RTR3DECL(int) RTDirSetTimes(RTDIR hDir, PCRTTIMESPEC pAccessTime, PCRTTIMESPEC pModificationTime,
619 PCRTTIMESPEC pChangeTime, PCRTTIMESPEC pBirthTime);
623 * Changes the mode flags of an open directory.
625 * The API requires at least one of the mode flag sets (Unix/Dos) to
626 * be set. The type is ignored.
628 * @returns iprt status code.
629 * @param hDir Handle to the open directory.
630 * @param fMode The new file mode, see @ref grp_rt_fs for details.
632 RTDECL(int) RTDirSetMode(RTDIR hDir, RTFMODE fMode);
635 /** @defgroup grp_rt_dir_rel Directory relative APIs
637 * This group of APIs allows working with paths that are relative to an open
638 * directory, therebye eliminating some classic path related race conditions on
639 * systems with native support for these kinds of operations.
641 * On NT (Windows) there is native support for addressing files, directories and
642 * stuff _below_ the open directory. It is not possible to go upwards
643 * (hDir:../../grandparent), at least not with NTFS, forcing us to use the
644 * directory path as a fallback and opening us to potential races.
646 * On most unix-like systems here is now native support for all of this.
648 * @{ */
651 * Open a file relative to @a hDir.
653 * @returns IPRT status code.
654 * @param hDir The directory to open relative to.
655 * @param pszRelFilename The relative path to the file.
656 * @param fOpen Open flags, i.e a combination of the RTFILE_O_XXX
657 * defines. The ACCESS, ACTION and DENY flags are
658 * mandatory!
659 * @param phFile Where to store the handle to the opened file.
661 * @sa RTFileOpen
663 RTDECL(int) RTDirRelFileOpen(RTDIR hDir, const char *pszRelFilename, uint64_t fOpen, PRTFILE phFile);
668 * Opens a directory relative to @a hDir.
670 * @returns IPRT status code.
671 * @param hDir The directory to open relative to.
672 * @param pszDir The relative path to the directory to open.
673 * @param phDir Where to store the directory handle.
675 * @sa RTDirOpen
677 RTDECL(int) RTDirRelDirOpen(RTDIR hDir, const char *pszDir, RTDIR *phDir);
680 * Opens a directory relative to @a hDir, with flags and optional filtering.
682 * @returns IPRT status code.
683 * @retval VERR_IS_A_SYMLINK if RTDIR_F_NO_FOLLOW is set, @a enmFilter is
684 * RTDIRFILTER_NONE and @a pszPath points to a symbolic link and does
685 * not end with a slash. Note that on Windows this does not apply to
686 * file symlinks, only directory symlinks, for the file variant
687 * VERR_NOT_A_DIRECTORY will be returned.
689 * @param hDir The directory to open relative to.
690 * @param pszDirAndFilter The relative path to the directory to search, this
691 * must include wildcards.
692 * @param enmFilter The kind of filter to apply. Setting this to
693 * RTDIRFILTER_NONE makes this function behave like
694 * RTDirOpen.
695 * @param fFlags Open flags, RTDIR_F_XXX.
696 * @param phDir Where to store the directory handle.
698 * @sa RTDirOpenFiltered
700 RTDECL(int) RTDirRelDirOpenFiltered(RTDIR hDir, const char *pszDirAndFilter, RTDIRFILTER enmFilter,
701 uint32_t fFlags, RTDIR *phDir);
704 * Creates a directory relative to @a hDir.
706 * @returns IPRT status code.
707 * @param hDir The directory @a pszRelPath is relative to.
708 * @param pszRelPath The relative path to the directory to create.
709 * @param fMode The mode of the new directory.
710 * @param fCreate Create flags, RTDIRCREATE_FLAGS_XXX.
711 * @param phSubDir Where to return the handle of the created directory.
712 * Optional.
714 * @sa RTDirCreate
716 RTDECL(int) RTDirRelDirCreate(RTDIR hDir, const char *pszRelPath, RTFMODE fMode, uint32_t fCreate, RTDIR *phSubDir);
719 * Removes a directory relative to @a hDir if empty.
721 * @returns IPRT status code.
722 * @param hDir The directory @a pszRelPath is relative to.
723 * @param pszRelPath The relative path to the directory to remove.
725 * @sa RTDirRemove
727 RTDECL(int) RTDirRelDirRemove(RTDIR hDir, const char *pszRelPath);
731 * Query information about a file system object relative to @a hDir.
733 * @returns IPRT status code.
734 * @retval VINF_SUCCESS if the object exists, information returned.
735 * @retval VERR_PATH_NOT_FOUND if any but the last component in the specified
736 * path was not found or was not a directory.
737 * @retval VERR_FILE_NOT_FOUND if the object does not exist (but path to the
738 * parent directory exists).
740 * @param hDir The directory @a pszRelPath is relative to.
741 * @param pszRelPath The relative path to the file system object.
742 * @param pObjInfo Object information structure to be filled on successful
743 * return.
744 * @param enmAddAttr Which set of additional attributes to request.
745 * Use RTFSOBJATTRADD_NOTHING if this doesn't matter.
746 * @param fFlags RTPATH_F_ON_LINK or RTPATH_F_FOLLOW_LINK.
748 * @sa RTPathQueryInfoEx
750 RTDECL(int) RTDirRelPathQueryInfo(RTDIR hDir, const char *pszRelPath, PRTFSOBJINFO pObjInfo,
751 RTFSOBJATTRADD enmAddAttr, uint32_t fFlags);
754 * Changes the mode flags of a file system object relative to @a hDir.
756 * The API requires at least one of the mode flag sets (Unix/Dos) to
757 * be set. The type is ignored.
759 * @returns IPRT status code.
760 * @param hDir The directory @a pszRelPath is relative to.
761 * @param pszRelPath The relative path to the file system object.
762 * @param fMode The new file mode, see @ref grp_rt_fs for details.
763 * @param fFlags RTPATH_F_ON_LINK or RTPATH_F_FOLLOW_LINK.
765 * @sa RTPathSetMode
767 RTDECL(int) RTDirRelPathSetMode(RTDIR hDir, const char *pszRelPath, RTFMODE fMode, uint32_t fFlags);
770 * Changes one or more of the timestamps associated of file system object
771 * relative to @a hDir.
773 * @returns IPRT status code.
774 * @param hDir The directory @a pszRelPath is relative to.
775 * @param pszRelPath The relative path to the file system object.
776 * @param pAccessTime Pointer to the new access time.
777 * @param pModificationTime Pointer to the new modification time.
778 * @param pChangeTime Pointer to the new change time. NULL if not to be changed.
779 * @param pBirthTime Pointer to the new time of birth. NULL if not to be changed.
780 * @param fFlags RTPATH_F_ON_LINK or RTPATH_F_FOLLOW_LINK.
782 * @remark The file system might not implement all these time attributes,
783 * the API will ignore the ones which aren't supported.
785 * @remark The file system might not implement the time resolution
786 * employed by this interface, the time will be chopped to fit.
788 * @remark The file system may update the change time even if it's
789 * not specified.
791 * @remark POSIX can only set Access & Modification and will always set both.
793 * @sa RTPathSetTimesEx
795 RTDECL(int) RTDirRelPathSetTimes(RTDIR hDir, const char *pszRelPath, PCRTTIMESPEC pAccessTime, PCRTTIMESPEC pModificationTime,
796 PCRTTIMESPEC pChangeTime, PCRTTIMESPEC pBirthTime, uint32_t fFlags);
799 * Changes the owner and/or group of a file system object relative to @a hDir.
801 * @returns IPRT status code.
802 * @param hDir The directory @a pszRelPath is relative to.
803 * @param pszRelPath The relative path to the file system object.
804 * @param uid The new file owner user id. Pass NIL_RTUID to leave
805 * this unchanged.
806 * @param gid The new group id. Pass NIL_RTGID to leave this
807 * unchanged.
808 * @param fFlags RTPATH_F_ON_LINK or RTPATH_F_FOLLOW_LINK.
810 * @sa RTPathSetOwnerEx
812 RTDECL(int) RTDirRelPathSetOwner(RTDIR hDir, const char *pszRelPath, uint32_t uid, uint32_t gid, uint32_t fFlags);
815 * Renames a directory relative path within a filesystem.
817 * This will rename symbolic links. If RTPATHRENAME_FLAGS_REPLACE is used and
818 * pszDst is a symbolic link, it will be replaced and not its target.
820 * @returns IPRT status code.
821 * @param hDirSrc The directory the source path is relative to.
822 * @param pszSrc The source path, relative to @a hDirSrc.
823 * @param hDirDst The directory the destination path is relative to.
824 * @param pszDst The destination path, relative to @a hDirDst.
825 * @param fRename Rename flags, RTPATHRENAME_FLAGS_XXX.
827 * @sa RTPathRename
829 RTDECL(int) RTDirRelPathRename(RTDIR hDirSrc, const char *pszSrc, RTDIR hDirDst, const char *pszDst, unsigned fRename);
832 * Removes the last component of the directory relative path.
834 * @returns IPRT status code.
835 * @param hDir The directory @a pszRelPath is relative to.
836 * @param pszRelPath The relative path to the file system object.
837 * @param fUnlink Unlink flags, RTPATHUNLINK_FLAGS_XXX.
839 * @sa RTPathUnlink
841 RTDECL(int) RTDirRelPathUnlink(RTDIR hDir, const char *pszRelPath, uint32_t fUnlink);
846 * Creates a symbolic link (@a pszSymlink) relative to @a hDir targeting @a
847 * pszTarget.
849 * @returns IPRT status code.
850 * @param hDir The directory @a pszSymlink is relative to.
851 * @param pszSymlink The relative path of the symbolic link.
852 * @param pszTarget The path to the symbolic link target. This is
853 * relative to @a pszSymlink or an absolute path.
854 * @param enmType The symbolic link type. For Windows compatability
855 * it is very important to set this correctly. When
856 * RTSYMLINKTYPE_UNKNOWN is used, the API will try
857 * make a guess and may attempt query information
858 * about @a pszTarget in the process.
859 * @param fCreate Create flags, RTSYMLINKCREATE_FLAGS_XXX.
861 * @sa RTSymlinkCreate
863 RTDECL(int) RTDirRelSymlinkCreate(RTDIR hDir, const char *pszSymlink, const char *pszTarget,
864 RTSYMLINKTYPE enmType, uint32_t fCreate);
867 * Read the symlink target relative to @a hDir.
869 * @returns IPRT status code.
870 * @retval VERR_NOT_SYMLINK if @a pszSymlink does not specify a symbolic link.
871 * @retval VERR_BUFFER_OVERFLOW if the link is larger than @a cbTarget. The
872 * buffer will contain what all we managed to read, fully terminated
873 * if @a cbTarget > 0.
875 * @param hDir The directory @a pszSymlink is relative to.
876 * @param pszSymlink The relative path to the symbolic link that should
877 * be read.
878 * @param pszTarget The target buffer.
879 * @param cbTarget The size of the target buffer.
880 * @param fRead Read flags, RTSYMLINKREAD_FLAGS_XXX.
882 * @sa RTSymlinkRead
884 RTDECL(int) RTDirRelSymlinkRead(RTDIR hDir, const char *pszSymlink, char *pszTarget, size_t cbTarget, uint32_t fRead);
886 /** @} */
889 /** @} */
891 RT_C_DECLS_END
893 #endif /* !IPRT_INCLUDED_dir_h */