2
* innotek Portable Runtime - Directory Manipulation.
6
* Copyright (C) 2006-2007 innotek GmbH
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 as published by the Free Software Foundation,
12
* in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
13
* distribution. VirtualBox OSE is distributed in the hope that it will
14
* be useful, but WITHOUT ANY WARRANTY of any kind.
20
#include <iprt/cdefs.h>
21
#include <iprt/types.h>
29
/** @defgroup grp_rt_dir RTDir - Directory Manipulation
37
* Check for the existence of a directory.
39
* @returns true if exist and is a directory.
40
* @returns flase if exists or isn't a directory.
41
* @param pszPath Path to the directory.
43
RTDECL(bool) RTDirExists(const char *pszPath);
46
* Creates a directory.
48
* @returns iprt status code.
49
* @param pszPath Path to the directory to create.
50
* @param fMode The mode of the new directory.
52
RTDECL(int) RTDirCreate(const char *pszPath, RTFMODE fMode);
55
* Creates a directory including all parent directories in the path
56
* if they don't exist.
58
* @returns iprt status code.
59
* @param pszPath Path to the directory to create.
60
* @param fMode The mode of the new directories.
62
RTDECL(int) RTDirCreateFullPath(const char *pszPath, RTFMODE fMode);
65
* Removes a directory.
67
* @returns iprt status code.
68
* @param pszPath Path to the directory to remove.
70
RTDECL(int) RTDirRemove(const char *pszPath);
73
/** Pointer to an open directory (sort of handle). */
74
typedef struct RTDIR *PRTDIR;
78
* Filter option for RTDirOpenFiltered().
80
typedef enum RTDIRFILTER
82
/** The usual invalid 0 entry. */
83
RTDIRFILTER_INVALID = 0,
84
/** No filter should be applied (and none was specified). */
86
/** The Windows NT filter.
87
* The following wildcard chars: *, ?, <, > and "
88
* The matching is done on the uppercased strings. */
91
* The following wildcard chars: *, ?, [..]
92
* The matching is done on exact case. */
94
/** The UNIX filter, uppercased matching.
95
* Same as RTDIRFILTER_UNIX except that the strings are uppercased before comparing. */
96
RTDIRFILTER_UNIX_UPCASED,
98
/** The usual full 32-bit value. */
99
RTDIRFILTER_32BIT_HACK = 0x7fffffff
104
* Directory entry type.
106
* This is the RTFS_TYPE_MASK stuff shifted down 12 bits and
107
* identical to the BSD/LINUX ABI.
109
typedef enum RTDIRENTRYTYPE
111
/** Unknown type (DT_UNKNOWN). */
112
RTDIRENTRYTYPE_UNKNOWN = 0,
113
/** Named pipe (fifo) (DT_FIFO). */
114
RTDIRENTRYTYPE_FIFO = 001,
115
/** Character device (DT_CHR). */
116
RTDIRENTRYTYPE_DEV_CHAR = 002,
117
/** Directory (DT_DIR). */
118
RTDIRENTRYTYPE_DIRECTORY = 004,
119
/** Block device (DT_BLK). */
120
RTDIRENTRYTYPE_DEV_BLOCK = 006,
121
/** Regular file (DT_REG). */
122
RTDIRENTRYTYPE_FILE = 010,
123
/** Symbolic link (DT_LNK). */
124
RTDIRENTRYTYPE_SYMLINK = 012,
125
/** Socket (DT_SOCK). */
126
RTDIRENTRYTYPE_SOCKET = 014,
127
/** Whiteout (DT_WHT). */
128
RTDIRENTRYTYPE_WHITEOUT = 016
135
* This is inspired by the POSIX interfaces.
138
typedef struct RTDIRENTRY
140
/** The unique identifier (within the file system) of this file system object (d_ino).
141
* Together with INodeIdDevice, this field can be used as a OS wide unique id
142
* when both their values are not 0.
143
* This field is 0 if the information is not available. */
145
/** The entry type. (d_type) */
146
RTDIRENTRYTYPE enmType;
147
/** The length of the filename. */
149
/** The filename. (no path)
150
* Using the pcbDirEntry parameter of RTDirRead makes this field variable in size. */
154
/** Pointer to a directory entry. */
155
typedef RTDIRENTRY *PRTDIRENTRY;
159
* Directory entry with extended information.
161
* This is inspired by the PC interfaces.
164
typedef struct RTDIRENTRYEX
166
/** Full information about the object. */
168
/** The length of the short field (number of RTUCS2 chars).
169
* It is 16-bit for reasons of alignment. */
170
uint16_t cucShortName;
171
/** The short name for 8.3 compatability.
172
* Empty string if not available.
173
* Since the length is a bit tricky for a UTF-8 encoded name, and since this
174
* is practically speaking only a windows thing, it is encoded as UCS-2. */
175
RTUCS2 uszShortName[14];
176
/** The length of the filename. */
178
/** The filename. (no path)
179
* Using the pcbDirEntry parameter of RTDirReadEx makes this field variable in size. */
183
/** Pointer to a directory entry. */
184
typedef RTDIRENTRYEX *PRTDIRENTRYEX;
190
* @returns iprt status code.
191
* @param ppDir Where to store the open directory pointer.
192
* @param pszPath Path to the directory to open.
194
RTDECL(int) RTDirOpen(PRTDIR *ppDir, const char *pszPath);
197
* Opens a directory filtering the entries using dos style wildcards.
199
* @returns iprt status code.
200
* @param ppDir Where to store the open directory pointer.
201
* @param pszPath Path to the directory to search, this must include wildcards.
202
* @param enmFilter The kind of filter to apply. Setting this to RTDIRFILTER_NONE makes
203
* this function behave like RTDirOpen.
205
RTDECL(int) RTDirOpenFiltered(PRTDIR *ppDir, const char *pszPath, RTDIRFILTER enmFilter);
208
* Closes a directory.
210
* @returns iprt status code.
211
* @param pDir Pointer to open directory returned by RTDirOpen() or RTDirOpenFiltered().
213
RTDECL(int) RTDirClose(PRTDIR pDir);
216
* Reads the next entry in the directory.
218
* @returns VINF_SUCCESS and data in pDirEntry on success.
219
* @returns VERR_NO_MORE_FILES when the end of the directory has been reached.
220
* @returns VERR_BUFFER_OVERFLOW if the buffer is too small to contain the filename. If
221
* pcbDirEntry is specified it will be updated with the required buffer size.
222
* @returns suitable iprt status code on other errors.
224
* @param pDir Pointer to the open directory.
225
* @param pDirEntry Where to store the information about the next
226
* directory entry on success.
227
* @param pcbDirEntry Optional parameter used for variable buffer size.
229
* On input the variable pointed to contains the size of the pDirEntry
230
* structure. This must be at least OFFSET(RTDIRENTRY, szName[2]) bytes.
232
* On successful output the field is updated to
233
* OFFSET(RTDIRENTRY, szName[pDirEntry->cbName + 1]).
235
* When the data doesn't fit in the buffer and VERR_BUFFER_OVERFLOW is
236
* returned, this field contains the required buffer size.
238
* The value is unchanged in all other cases.
240
RTDECL(int) RTDirRead(PRTDIR pDir, PRTDIRENTRY pDirEntry, unsigned *pcbDirEntry);
243
* Reads the next entry in the directory returning extended information.
245
* @returns VINF_SUCCESS and data in pDirEntry on success.
246
* @returns VERR_NO_MORE_FILES when the end of the directory has been reached.
247
* @returns VERR_BUFFER_OVERFLOW if the buffer is too small to contain the filename. If
248
* pcbDirEntry is specified it will be updated with the required buffer size.
249
* @returns suitable iprt status code on other errors.
251
* @param pDir Pointer to the open directory.
252
* @param pDirEntry Where to store the information about the next
253
* directory entry on success.
254
* @param pcbDirEntry Optional parameter used for variable buffer size.
256
* On input the variable pointed to contains the size of the pDirEntry
257
* structure. This must be at least OFFSET(RTDIRENTRYEX, szName[2]) bytes.
259
* On successful output the field is updated to
260
* OFFSET(RTDIRENTRYEX, szName[pDirEntry->cbName + 1]).
262
* When the data doesn't fit in the buffer and VERR_BUFFER_OVERFLOW is
263
* returned, this field contains the required buffer size.
265
* The value is unchanged in all other cases.
266
* @param enmAdditionalAttribs
267
* Which set of additional attributes to request.
268
* Use RTFSOBJATTRADD_NOTHING if this doesn't matter.
270
RTDECL(int) RTDirReadEx(PRTDIR pDir, PRTDIRENTRYEX pDirEntry, unsigned *pcbDirEntry, RTFSOBJATTRADD enmAdditionalAttribs);
276
* Identical to RTPathRename except that it will ensure that the source is a directory.
278
* @returns IPRT status code.
279
* @returns VERR_ALREADY_EXISTS if the destination file exists.
281
* @param pszSrc The path to the source file.
282
* @param pszDst The path to the destination file.
283
* This file will be created.
284
* @param fRename See RTPathRename.
286
RTDECL(int) RTDirRename(const char *pszSrc, const char *pszDst, unsigned fRename);
290
* Query information about an open directory.
292
* @returns iprt status code.
294
* @param pDir Pointer to the open directory.
295
* @param pObjInfo Object information structure to be filled on successful return.
296
* @param enmAdditionalAttribs Which set of additional attributes to request.
297
* Use RTFSOBJATTRADD_NOTHING if this doesn't matter.
299
RTR3DECL(int) RTDirQueryInfo(PRTDIR pDir, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAdditionalAttribs);
303
* Changes one or more of the timestamps associated of file system object.
305
* @returns iprt status code.
306
* @returns VERR_NOT_SUPPORTED is returned if the operation isn't supported by the OS.
308
* @param pDir Pointer to the open directory.
309
* @param pAccessTime Pointer to the new access time. NULL if not to be changed.
310
* @param pModificationTime Pointer to the new modifcation time. NULL if not to be changed.
311
* @param pChangeTime Pointer to the new change time. NULL if not to be changed.
312
* @param pBirthTime Pointer to the new time of birth. NULL if not to be changed.
314
* @remark The file system might not implement all these time attributes,
315
* the API will ignore the ones which aren't supported.
317
* @remark The file system might not implement the time resolution
318
* employed by this interface, the time will be chopped to fit.
320
* @remark The file system may update the change time even if it's
323
* @remark POSIX can only set Access & Modification and will always set both.
325
RTR3DECL(int) RTDirSetTimes(PRTDIR pDir, PCRTTIMESPEC pAccessTime, PCRTTIMESPEC pModificationTime,
326
PCRTTIMESPEC pChangeTime, PCRTTIMESPEC pBirthTime);
328
#endif /* IN_RING3 */