VirtualBox

source: vbox/trunk/include/iprt/dir.h@ 78561

Last change on this file since 78561 was 78186, checked in by vboxsync, 6 years ago

IPRT,FsPerf: Added RTDIR_F_NO_ABS_PATH and RTDIRRMREC_F_NO_ABS_PATH to help FsPerf work below PATH_MAX on linux. bugref:9172

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette