VirtualBox

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

Last change on this file since 69759 was 69759, checked in by vboxsync, 7 years ago

RTDIRENTRY::enmType: Make the warning more visible as such.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 32.6 KB
Line 
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
35RT_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 */
52RTDECL(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_SET UINT32_C(0)
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/** Valid mask. */
66#define RTDIRCREATE_FLAGS_VALID_MASK UINT32_C(0x00000007)
67/** @} */
68
69/**
70 * Creates a directory.
71 *
72 * @returns iprt status code.
73 * @param pszPath Path to the directory to create.
74 * @param fMode The mode of the new directory.
75 * @param fCreate Create flags, RTDIRCREATE_FLAGS_*.
76 */
77RTDECL(int) RTDirCreate(const char *pszPath, RTFMODE fMode, uint32_t fCreate);
78
79/**
80 * Creates a directory including all parent directories in the path
81 * if they don't exist.
82 *
83 * @returns iprt status code.
84 * @param pszPath Path to the directory to create.
85 * @param fMode The mode of the new directories.
86 */
87RTDECL(int) RTDirCreateFullPath(const char *pszPath, RTFMODE fMode);
88
89/**
90 * Creates a new directory with a unique name using the given template.
91 *
92 * One or more trailing X'es in the template will be replaced by random alpha
93 * numeric characters until a RTDirCreate succeeds or we run out of patience.
94 * For instance:
95 * "/tmp/myprog-XXXXXX"
96 *
97 * As an alternative to trailing X'es, it
98 * is possible to put 3 or more X'es somewhere inside the directory name. In
99 * the following string only the last bunch of X'es will be modified:
100 * "/tmp/myprog-XXX-XXX.tmp"
101 *
102 * @returns iprt status code.
103 * @param pszTemplate The directory name template on input. The actual
104 * directory name on success. Empty string on failure.
105 * @param fMode The mode to create the directory with. Use 0700
106 * unless you have reason not to.
107 */
108RTDECL(int) RTDirCreateTemp(char *pszTemplate, RTFMODE fMode);
109
110/**
111 * Secure version of @a RTDirCreateTemp with a fixed mode of 0700.
112 *
113 * This function behaves in the same way as @a RTDirCreateTemp with two
114 * additional points. Firstly the mode is fixed to 0700. Secondly it will
115 * fail if it is not possible to perform the operation securely. Possible
116 * reasons include that the directory could be removed by another unprivileged
117 * user before it is used (e.g. if is created in a non-sticky /tmp directory)
118 * or that the path contains symbolic links which another unprivileged user
119 * could manipulate; however the exact criteria will be specified on a
120 * platform-by-platform basis as platform support is added.
121 * @see RTPathIsSecure for the current list of criteria.
122 * @returns iprt status code.
123 * @returns VERR_NOT_SUPPORTED if the interface can not be supported on the
124 * current platform at this time.
125 * @returns VERR_INSECURE if the directory could not be created securely.
126 * @param pszTemplate The directory name template on input. The
127 * actual directory name on success. Empty string
128 * on failure.
129 */
130RTDECL(int) RTDirCreateTempSecure(char *pszTemplate);
131
132/**
133 * Creates a new directory with a unique name by appending a number.
134 *
135 * This API differs from RTDirCreateTemp & RTDirCreateTempSecure in that it
136 * first tries to create the directory without any random bits, thus the best
137 * case result will be prettier. It also differs in that it does not take a
138 * template, but is instead given a template description, and will only use
139 * digits for the filling.
140 *
141 * For sake of convenience and debugging , the current implementation
142 * starts at 0 and will increment sequentally for a while before switching to
143 * random numbers.
144 *
145 * On success @a pszPath contains the path created.
146 *
147 * @returns iprt status code.
148 * @param pszPath The path to the directory. On input the base template
149 * name. On successful return, the unique directory we
150 * created.
151 * @param cbSize The size of the pszPath buffer. Needs enough space for
152 * holding the digits and the optional separator.
153 * @param fMode The mode of the new directory.
154 * @param cchDigits How many digits should the number have (zero padded).
155 * @param chSep The separator used between the path and the number. Can
156 * be zero. (optional)
157 */
158RTDECL(int) RTDirCreateUniqueNumbered(char *pszPath, size_t cbSize, RTFMODE fMode, size_t cchDigits, char chSep);
159
160/**
161 * Removes a directory if empty.
162 *
163 * @returns iprt status code.
164 * @param pszPath Path to the directory to remove.
165 */
166RTDECL(int) RTDirRemove(const char *pszPath);
167
168/**
169 * Removes a directory tree recursively.
170 *
171 * @returns iprt status code.
172 * @param pszPath Path to the directory to remove recursively.
173 * @param fFlags Flags, see RTDIRRMREC_F_XXX.
174 *
175 * @remarks This will not work on a root directory.
176 */
177RTDECL(int) RTDirRemoveRecursive(const char *pszPath, uint32_t fFlags);
178
179/** @name RTDirRemoveRecursive flags.
180 * @{ */
181/** Delete the content of the directory and the directory itself. */
182#define RTDIRRMREC_F_CONTENT_AND_DIR UINT32_C(0)
183/** Only delete the content of the directory, omit the directory it self. */
184#define RTDIRRMREC_F_CONTENT_ONLY RT_BIT_32(0)
185/** Mask of valid flags. */
186#define RTDIRRMREC_F_VALID_MASK UINT32_C(0x00000001)
187/** @} */
188
189/**
190 * Flushes the specified directory.
191 *
192 * This API is not implemented on all systems. On some systems it may be
193 * unnecessary if you've already flushed the file. If you really care for your
194 * data and is entering dangerous territories, it doesn't hurt calling it after
195 * flushing and closing the file.
196 *
197 * @returns IPRT status code.
198 * @retval VERR_NOT_IMPLEMENTED must be expected.
199 * @retval VERR_NOT_SUPPORTED must be expected.
200 * @param pszPath Path to the directory.
201 */
202RTDECL(int) RTDirFlush(const char *pszPath);
203
204/**
205 * Flushes the parent directory of the specified file.
206 *
207 * This is just a wrapper around RTDirFlush.
208 *
209 * @returns IPRT status code, see RTDirFlush for details.
210 * @param pszChild Path to the file which parent should be flushed.
211 */
212RTDECL(int) RTDirFlushParent(const char *pszChild);
213
214
215/** Open directory handle. */
216typedef struct RTDIRINTERNAL *RTDIR;
217/** NIL open directory handle. */
218#define NIL_RTDIR ((RTDIR)0)
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/** Valid flag mask. */
360#define RTDIR_F_VALID_MASK UINT32_C(0x00000003)
361/** @} */
362
363/**
364 * Opens a directory with flags and optional filtering.
365 *
366 * @returns iprt status code.
367 * @param phDir Where to store the open directory handle.
368 * @param pszPath Path to the directory to search, this must include wildcards.
369 * @param enmFilter The kind of filter to apply. Setting this to RTDIRFILTER_NONE makes
370 * this function behave like RTDirOpen.
371 * @param fFlags Open flags, RTDIR_F_XXX.
372 */
373RTDECL(int) RTDirOpenFiltered(RTDIR *phDir, const char *pszPath, RTDIRFILTER enmFilter, uint32_t fFlags);
374
375/**
376 * Closes a directory.
377 *
378 * @returns iprt status code.
379 * @param hDir Handle to open directory returned by RTDirOpen() or
380 * RTDirOpenFiltered().
381 */
382RTDECL(int) RTDirClose(RTDIR hDir);
383
384/**
385 * Checks if the supplied directory handle is valid.
386 *
387 * @returns true if valid.
388 * @returns false if invalid.
389 * @param hDir The directory handle.
390 */
391RTDECL(bool) RTDirIsValid(RTDIR hDir);
392
393/**
394 * Reads the next entry in the directory.
395 *
396 * @returns VINF_SUCCESS and data in pDirEntry on success.
397 * @returns VERR_NO_MORE_FILES when the end of the directory has been reached.
398 * @returns VERR_BUFFER_OVERFLOW if the buffer is too small to contain the filename. If
399 * pcbDirEntry is specified it will be updated with the required buffer size.
400 * @returns suitable iprt status code on other errors.
401 *
402 * @param hDir Handle to the open directory.
403 * @param pDirEntry Where to store the information about the next
404 * directory entry on success.
405 * @param pcbDirEntry Optional parameter used for variable buffer size.
406 *
407 * On input the variable pointed to contains the size of the pDirEntry
408 * structure. This must be at least OFFSET(RTDIRENTRY, szName[2]) bytes.
409 *
410 * On successful output the field is updated to
411 * OFFSET(RTDIRENTRY, szName[pDirEntry->cbName + 1]).
412 *
413 * When the data doesn't fit in the buffer and VERR_BUFFER_OVERFLOW is
414 * returned, this field contains the required buffer size.
415 *
416 * The value is unchanged in all other cases.
417 */
418RTDECL(int) RTDirRead(RTDIR hDir, PRTDIRENTRY pDirEntry, size_t *pcbDirEntry);
419
420/**
421 * Reads the next entry in the directory returning extended information.
422 *
423 * @returns VINF_SUCCESS and data in pDirEntry on success.
424 * @returns VERR_NO_MORE_FILES when the end of the directory has been reached.
425 * @returns VERR_BUFFER_OVERFLOW if the buffer is too small to contain the filename. If
426 * pcbDirEntry is specified it will be updated with the required buffer size.
427 * @returns suitable iprt status code on other errors.
428 *
429 * @param hDir Handle to the open directory.
430 * @param pDirEntry Where to store the information about the next
431 * directory entry on success.
432 * @param pcbDirEntry Optional parameter used for variable buffer size.
433 *
434 * On input the variable pointed to contains the size of the pDirEntry
435 * structure. This must be at least OFFSET(RTDIRENTRYEX, szName[2]) bytes.
436 *
437 * On successful output the field is updated to
438 * OFFSET(RTDIRENTRYEX, szName[pDirEntry->cbName + 1]).
439 *
440 * When the data doesn't fit in the buffer and VERR_BUFFER_OVERFLOW is
441 * returned, this field contains the required buffer size.
442 *
443 * The value is unchanged in all other cases.
444 * @param enmAdditionalAttribs
445 * Which set of additional attributes to request.
446 * Use RTFSOBJATTRADD_NOTHING if this doesn't matter.
447 * @param fFlags RTPATH_F_ON_LINK or RTPATH_F_FOLLOW_LINK.
448 */
449RTDECL(int) RTDirReadEx(RTDIR hDir, PRTDIRENTRYEX pDirEntry, size_t *pcbDirEntry, RTFSOBJATTRADD enmAdditionalAttribs, uint32_t fFlags);
450
451/**
452 * Wrapper around RTDirReadEx that does the directory entry buffer handling.
453 *
454 * Call RTDirReadExAFree to free the buffers allocated by this function.
455 *
456 * @returns IPRT status code, see RTDirReadEx() for details.
457 *
458 * @param hDir Handle to the open directory.
459 * @param ppDirEntry Pointer to the directory entry pointer. Initialize this
460 * to NULL before the first call.
461 * @param pcbDirEntry Where the API caches the allocation size. Set this to
462 * zero before the first call.
463 * @param enmAddAttr See RTDirReadEx.
464 * @param fFlags See RTDirReadEx.
465 */
466RTDECL(int) RTDirReadExA(RTDIR hDir, PRTDIRENTRYEX *ppDirEntry, size_t *pcbDirEntry, RTFSOBJATTRADD enmAddAttr, uint32_t fFlags);
467
468/**
469 * Frees the buffer allocated by RTDirReadExA.
470 *
471 * @param ppDirEntry Pointer to the directory entry pointer.
472 * @param pcbDirEntry Where the API caches the allocation size.
473 */
474RTDECL(void) RTDirReadExAFree(PRTDIRENTRYEX *ppDirEntry, size_t *pcbDirEntry);
475
476/**
477 * Resolves RTDIRENTRYTYPE_UNKNOWN values returned by RTDirRead.
478 *
479 * @returns IPRT status code (see RTPathQueryInfo).
480 * @param pszComposedName The path to the directory entry. The caller must
481 * compose this, it's NOT sufficient to pass
482 * RTDIRENTRY::szName!
483 * @param fFollowSymlinks Whether to follow symbolic links or not.
484 * @param penmType Pointer to the RTDIRENTRY::enmType member. If this
485 * is not RTDIRENTRYTYPE_UNKNOWN and, if
486 * @a fFollowSymlinks is false, not
487 * RTDIRENTRYTYPE_SYMLINK, the function will return
488 * immediately without doing anything. Otherwise it
489 * will use RTPathQueryInfo to try figure out the
490 * correct value. On failure, this will be unchanged.
491 */
492RTDECL(int) RTDirQueryUnknownType(const char *pszComposedName, bool fFollowSymlinks, RTDIRENTRYTYPE *penmType);
493
494/**
495 * Resolves RTDIRENTRYTYPE_UNKNOWN values returned by RTDirRead, extended
496 * version.
497 *
498 * @returns IPRT status code (see RTPathQueryInfo).
499 * @param pszComposedName The path to the directory entry. The caller must
500 * compose this, it's NOT sufficient to pass
501 * RTDIRENTRY::szName!
502 * @param fFollowSymlinks Whether to follow symbolic links or not.
503 * @param penmType Pointer to the RTDIRENTRY::enmType member or
504 * similar. Will NOT be checked on input.
505 * @param pObjInfo The object info buffer to use with RTPathQueryInfo.
506 */
507RTDECL(int) RTDirQueryUnknownTypeEx(const char *pszComposedName, bool fFollowSymlinks, RTDIRENTRYTYPE *penmType, PRTFSOBJINFO pObjInfo);
508
509/**
510 * Checks if the directory entry returned by RTDirRead is '.', '..' or similar.
511 *
512 * @returns true / false.
513 * @param pDirEntry The directory entry to check.
514 */
515RTDECL(bool) RTDirEntryIsStdDotLink(PRTDIRENTRY pDirEntry);
516
517/**
518 * Checks if the directory entry returned by RTDirReadEx is '.', '..' or
519 * similar.
520 *
521 * @returns true / false.
522 * @param pDirEntryEx The extended directory entry to check.
523 */
524RTDECL(bool) RTDirEntryExIsStdDotLink(PCRTDIRENTRYEX pDirEntryEx);
525
526/**
527 * Renames a file.
528 *
529 * Identical to RTPathRename except that it will ensure that the source is a directory.
530 *
531 * @returns IPRT status code.
532 * @returns VERR_ALREADY_EXISTS if the destination file exists.
533 *
534 * @param pszSrc The path to the source file.
535 * @param pszDst The path to the destination file.
536 * This file will be created.
537 * @param fRename See RTPathRename.
538 */
539RTDECL(int) RTDirRename(const char *pszSrc, const char *pszDst, unsigned fRename);
540
541
542/**
543 * Query information about an open directory.
544 *
545 * @returns iprt status code.
546 *
547 * @param hDir Handle to the open directory.
548 * @param pObjInfo Object information structure to be filled on successful return.
549 * @param enmAdditionalAttribs Which set of additional attributes to request.
550 * Use RTFSOBJATTRADD_NOTHING if this doesn't matter.
551 */
552RTR3DECL(int) RTDirQueryInfo(RTDIR hDir, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAdditionalAttribs);
553
554
555/**
556 * Changes one or more of the timestamps associated of file system object.
557 *
558 * @returns iprt status code.
559 * @returns VERR_NOT_SUPPORTED is returned if the operation isn't supported by the OS.
560 *
561 * @param hDir Handle to the open directory.
562 * @param pAccessTime Pointer to the new access time. NULL if not to be changed.
563 * @param pModificationTime Pointer to the new modifcation time. NULL if not to be changed.
564 * @param pChangeTime Pointer to the new change time. NULL if not to be changed.
565 * @param pBirthTime Pointer to the new time of birth. NULL if not to be changed.
566 *
567 * @remark The file system might not implement all these time attributes,
568 * the API will ignore the ones which aren't supported.
569 *
570 * @remark The file system might not implement the time resolution
571 * employed by this interface, the time will be chopped to fit.
572 *
573 * @remark The file system may update the change time even if it's
574 * not specified.
575 *
576 * @remark POSIX can only set Access & Modification and will always set both.
577 */
578RTR3DECL(int) RTDirSetTimes(RTDIR hDir, PCRTTIMESPEC pAccessTime, PCRTTIMESPEC pModificationTime,
579 PCRTTIMESPEC pChangeTime, PCRTTIMESPEC pBirthTime);
580
581
582/** @defgroup grp_rt_dir_rel Directory relative APIs
583 *
584 * This group of APIs allows working with paths that are relative to an open
585 * directory, therebye eliminating some classic path related race conditions on
586 * systems with native support for these kinds of operations.
587 *
588 * On NT (Windows) there is native support for addressing files, directories and
589 * stuff _below_ the open directory. It is not possible to go upwards
590 * (hDir:../../grandparent), at least not with NTFS, forcing us to use the
591 * directory path as a fallback and opening us to potential races.
592 *
593 * On most unix-like systems here is now native support for all of this.
594 *
595 * @{ */
596
597/**
598 * Open a file relative to @a hDir.
599 *
600 * @returns IPRT status code.
601 * @param hDir The directory to open relative to.
602 * @param pszRelFilename The relative path to the file.
603 * @param fOpen Open flags, i.e a combination of the RTFILE_O_XXX
604 * defines. The ACCESS, ACTION and DENY flags are
605 * mandatory!
606 * @param phFile Where to store the handle to the opened file.
607 *
608 * @sa RTFileOpen
609 */
610RTDECL(int) RTDirRelFileOpen(RTDIR hDir, const char *pszRelFilename, uint64_t fOpen, PRTFILE phFile);
611
612
613
614/**
615 * Opens a directory relative to @a hDir.
616 *
617 * @returns IPRT status code.
618 * @param hDir The directory to open relative to.
619 * @param pszDir The relative path to the directory to open.
620 * @param phDir Where to store the directory handle.
621 *
622 * @sa RTDirOpen
623 */
624RTDECL(int) RTDirRelDirOpen(RTDIR hDir, const char *pszDir, RTDIR *phDir);
625
626/**
627 * Opens a directory relative to @a hDir, with flags and optional filtering.
628 *
629 * @returns IPRT status code.
630 * @param hDir The directory to open relative to.
631 * @param pszDirAndFilter The relative path to the directory to search, this
632 * must include wildcards.
633 * @param enmFilter The kind of filter to apply. Setting this to
634 * RTDIRFILTER_NONE makes this function behave like
635 * RTDirOpen.
636 * @param fFlags Open flags, RTDIR_F_XXX.
637 * @param phDir Where to store the directory handle.
638 *
639 * @sa RTDirOpenFiltered
640 */
641RTDECL(int) RTDirRelDirOpenFiltered(RTDIR hDir, const char *pszDirAndFilter, RTDIRFILTER enmFilter,
642 uint32_t fFlags, RTDIR *phDir);
643
644/**
645 * Creates a directory relative to @a hDir.
646 *
647 * @returns IPRT status code.
648 * @param hDir The directory @a pszRelPath is relative to.
649 * @param pszRelPath The relative path to the directory to create.
650 * @param fMode The mode of the new directory.
651 * @param fCreate Create flags, RTDIRCREATE_FLAGS_XXX.
652 * @param phSubDir Where to return the handle of the created directory.
653 * Optional.
654 *
655 * @sa RTDirCreate
656 */
657RTDECL(int) RTDirRelDirCreate(RTDIR hDir, const char *pszRelPath, RTFMODE fMode, uint32_t fCreate, RTDIR *phSubDir);
658
659/**
660 * Removes a directory relative to @a hDir if empty.
661 *
662 * @returns IPRT status code.
663 * @param hDir The directory @a pszRelPath is relative to.
664 * @param pszRelPath The relative path to the directory to remove.
665 *
666 * @sa RTDirRemove
667 */
668RTDECL(int) RTDirRelDirRemove(RTDIR hDir, const char *pszRelPath);
669
670
671/**
672 * Query information about a file system object relative to @a hDir.
673 *
674 * @returns IPRT status code.
675 * @retval VINF_SUCCESS if the object exists, information returned.
676 * @retval VERR_PATH_NOT_FOUND if any but the last component in the specified
677 * path was not found or was not a directory.
678 * @retval VERR_FILE_NOT_FOUND if the object does not exist (but path to the
679 * parent directory exists).
680 *
681 * @param hDir The directory @a pszRelPath is relative to.
682 * @param pszRelPath The relative path to the file system object.
683 * @param pObjInfo Object information structure to be filled on successful
684 * return.
685 * @param enmAddAttr Which set of additional attributes to request.
686 * Use RTFSOBJATTRADD_NOTHING if this doesn't matter.
687 * @param fFlags RTPATH_F_ON_LINK or RTPATH_F_FOLLOW_LINK.
688 *
689 * @sa RTPathQueryInfoEx
690 */
691RTDECL(int) RTDirRelPathQueryInfo(RTDIR hDir, const char *pszRelPath, PRTFSOBJINFO pObjInfo,
692 RTFSOBJATTRADD enmAddAttr, uint32_t fFlags);
693
694/**
695 * Changes the mode flags of a file system object relative to @a hDir.
696 *
697 * The API requires at least one of the mode flag sets (Unix/Dos) to
698 * be set. The type is ignored.
699 *
700 * @returns IPRT status code.
701 * @param hDir The directory @a pszRelPath is relative to.
702 * @param pszRelPath The relative path to the file system object.
703 * @param fMode The new file mode, see @ref grp_rt_fs for details.
704 * @param fFlags RTPATH_F_ON_LINK or RTPATH_F_FOLLOW_LINK.
705 *
706 * @sa RTPathSetMode
707 */
708RTDECL(int) RTDirRelPathSetMode(RTDIR hDir, const char *pszRelPath, RTFMODE fMode, uint32_t fFlags);
709
710/**
711 * Changes one or more of the timestamps associated of file system object
712 * relative to @a hDir.
713 *
714 * @returns IPRT status code.
715 * @param hDir The directory @a pszRelPath is relative to.
716 * @param pszRelPath The relative path to the file system object.
717 * @param pAccessTime Pointer to the new access time.
718 * @param pModificationTime Pointer to the new modification time.
719 * @param pChangeTime Pointer to the new change time. NULL if not to be changed.
720 * @param pBirthTime Pointer to the new time of birth. NULL if not to be changed.
721 * @param fFlags RTPATH_F_ON_LINK or RTPATH_F_FOLLOW_LINK.
722 *
723 * @remark The file system might not implement all these time attributes,
724 * the API will ignore the ones which aren't supported.
725 *
726 * @remark The file system might not implement the time resolution
727 * employed by this interface, the time will be chopped to fit.
728 *
729 * @remark The file system may update the change time even if it's
730 * not specified.
731 *
732 * @remark POSIX can only set Access & Modification and will always set both.
733 *
734 * @sa RTPathSetTimesEx
735 */
736RTDECL(int) RTDirRelPathSetTimes(RTDIR hDir, const char *pszRelPath, PCRTTIMESPEC pAccessTime, PCRTTIMESPEC pModificationTime,
737 PCRTTIMESPEC pChangeTime, PCRTTIMESPEC pBirthTime, uint32_t fFlags);
738
739/**
740 * Changes the owner and/or group of a file system object relative to @a hDir.
741 *
742 * @returns IPRT status code.
743 * @param hDir The directory @a pszRelPath is relative to.
744 * @param pszRelPath The relative path to the file system object.
745 * @param uid The new file owner user id. Pass NIL_RTUID to leave
746 * this unchanged.
747 * @param gid The new group id. Pass NIL_RTGID to leave this
748 * unchanged.
749 * @param fFlags RTPATH_F_ON_LINK or RTPATH_F_FOLLOW_LINK.
750 *
751 * @sa RTPathSetOwnerEx
752 */
753RTDECL(int) RTDirRelPathSetOwner(RTDIR hDir, const char *pszRelPath, uint32_t uid, uint32_t gid, uint32_t fFlags);
754
755/**
756 * Renames a directory relative path within a filesystem.
757 *
758 * This will rename symbolic links. If RTPATHRENAME_FLAGS_REPLACE is used and
759 * pszDst is a symbolic link, it will be replaced and not its target.
760 *
761 * @returns IPRT status code.
762 * @param hDirSrc The directory the source path is relative to.
763 * @param pszSrc The source path, relative to @a hDirSrc.
764 * @param hDirDst The directory the destination path is relative to.
765 * @param pszDst The destination path, relative to @a hDirDst.
766 * @param fRename Rename flags, RTPATHRENAME_FLAGS_XXX.
767 *
768 * @sa RTPathRename
769 */
770RTDECL(int) RTDirRelPathRename(RTDIR hDirSrc, const char *pszSrc, RTDIR hDirDst, const char *pszDst, unsigned fRename);
771
772/**
773 * Removes the last component of the directory relative path.
774 *
775 * @returns IPRT status code.
776 * @param hDir The directory @a pszRelPath is relative to.
777 * @param pszRelPath The relative path to the file system object.
778 * @param fUnlink Unlink flags, RTPATHUNLINK_FLAGS_XXX.
779 *
780 * @sa RTPathUnlink
781 */
782RTDECL(int) RTDirRelPathUnlink(RTDIR hDir, const char *pszRelPath, uint32_t fUnlink);
783
784
785
786/**
787 * Creates a symbolic link (@a pszSymlink) relative to @a hDir targeting @a
788 * pszTarget.
789 *
790 * @returns IPRT status code.
791 * @param hDir The directory @a pszSymlink is relative to.
792 * @param pszSymlink The relative path of the symbolic link.
793 * @param pszTarget The path to the symbolic link target. This is
794 * relative to @a pszSymlink or an absolute path.
795 * @param enmType The symbolic link type. For Windows compatability
796 * it is very important to set this correctly. When
797 * RTSYMLINKTYPE_UNKNOWN is used, the API will try
798 * make a guess and may attempt query information
799 * about @a pszTarget in the process.
800 * @param fCreate Create flags, RTSYMLINKCREATE_FLAGS_XXX.
801 *
802 * @sa RTSymlinkCreate
803 */
804RTDECL(int) RTDirRelSymlinkCreate(RTDIR hDir, const char *pszSymlink, const char *pszTarget,
805 RTSYMLINKTYPE enmType, uint32_t fCreate);
806
807/**
808 * Read the symlink target relative to @a hDir.
809 *
810 * @returns IPRT status code.
811 * @retval VERR_NOT_SYMLINK if @a pszSymlink does not specify a symbolic link.
812 * @retval VERR_BUFFER_OVERFLOW if the link is larger than @a cbTarget. The
813 * buffer will contain what all we managed to read, fully terminated
814 * if @a cbTarget > 0.
815 *
816 * @param hDir The directory @a pszSymlink is relative to.
817 * @param pszSymlink The relative path to the symbolic link that should
818 * be read.
819 * @param pszTarget The target buffer.
820 * @param cbTarget The size of the target buffer.
821 * @param fRead Read flags, RTSYMLINKREAD_FLAGS_XXX.
822 *
823 * @sa RTSymlinkRead
824 */
825RTDECL(int) RTDirRelSymlinkRead(RTDIR hDir, const char *pszSymlink, char *pszTarget, size_t cbTarget, uint32_t fRead);
826
827/** @} */
828
829
830/** @} */
831
832RT_C_DECLS_END
833
834#endif
835
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