1 | /** @file
|
---|
2 | * innotek Portable Runtime - Directory Manipulation.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2007 innotek GmbH
|
---|
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 | #ifdef IN_RING3
|
---|
32 | # include <iprt/fs.h>
|
---|
33 | #endif
|
---|
34 |
|
---|
35 |
|
---|
36 | __BEGIN_DECLS
|
---|
37 |
|
---|
38 | /** @defgroup grp_rt_dir RTDir - Directory Manipulation
|
---|
39 | * @ingroup grp_rt
|
---|
40 | * @{
|
---|
41 | */
|
---|
42 |
|
---|
43 | #ifdef IN_RING3
|
---|
44 |
|
---|
45 | /**
|
---|
46 | * Check for the existence of a directory.
|
---|
47 | *
|
---|
48 | * @returns true if exist and is a directory.
|
---|
49 | * @returns flase if exists or isn't a directory.
|
---|
50 | * @param pszPath Path to the directory.
|
---|
51 | */
|
---|
52 | RTDECL(bool) RTDirExists(const char *pszPath);
|
---|
53 |
|
---|
54 | /**
|
---|
55 | * Creates a directory.
|
---|
56 | *
|
---|
57 | * @returns iprt status code.
|
---|
58 | * @param pszPath Path to the directory to create.
|
---|
59 | * @param fMode The mode of the new directory.
|
---|
60 | */
|
---|
61 | RTDECL(int) RTDirCreate(const char *pszPath, RTFMODE fMode);
|
---|
62 |
|
---|
63 | /**
|
---|
64 | * Creates a directory including all parent directories in the path
|
---|
65 | * if they don't exist.
|
---|
66 | *
|
---|
67 | * @returns iprt status code.
|
---|
68 | * @param pszPath Path to the directory to create.
|
---|
69 | * @param fMode The mode of the new directories.
|
---|
70 | */
|
---|
71 | RTDECL(int) RTDirCreateFullPath(const char *pszPath, RTFMODE fMode);
|
---|
72 |
|
---|
73 | /**
|
---|
74 | * Removes a directory.
|
---|
75 | *
|
---|
76 | * @returns iprt status code.
|
---|
77 | * @param pszPath Path to the directory to remove.
|
---|
78 | */
|
---|
79 | RTDECL(int) RTDirRemove(const char *pszPath);
|
---|
80 |
|
---|
81 |
|
---|
82 | /** Pointer to an open directory (sort of handle). */
|
---|
83 | typedef struct RTDIR *PRTDIR;
|
---|
84 |
|
---|
85 |
|
---|
86 | /**
|
---|
87 | * Filter option for RTDirOpenFiltered().
|
---|
88 | */
|
---|
89 | typedef enum RTDIRFILTER
|
---|
90 | {
|
---|
91 | /** The usual invalid 0 entry. */
|
---|
92 | RTDIRFILTER_INVALID = 0,
|
---|
93 | /** No filter should be applied (and none was specified). */
|
---|
94 | RTDIRFILTER_NONE,
|
---|
95 | /** The Windows NT filter.
|
---|
96 | * The following wildcard chars: *, ?, <, > and "
|
---|
97 | * The matching is done on the uppercased strings. */
|
---|
98 | RTDIRFILTER_WINNT,
|
---|
99 | /** The UNIX filter.
|
---|
100 | * The following wildcard chars: *, ?, [..]
|
---|
101 | * The matching is done on exact case. */
|
---|
102 | RTDIRFILTER_UNIX,
|
---|
103 | /** The UNIX filter, uppercased matching.
|
---|
104 | * Same as RTDIRFILTER_UNIX except that the strings are uppercased before comparing. */
|
---|
105 | RTDIRFILTER_UNIX_UPCASED,
|
---|
106 |
|
---|
107 | /** The usual full 32-bit value. */
|
---|
108 | RTDIRFILTER_32BIT_HACK = 0x7fffffff
|
---|
109 | } RTDIRFILTER;
|
---|
110 |
|
---|
111 |
|
---|
112 | /**
|
---|
113 | * Directory entry type.
|
---|
114 | *
|
---|
115 | * This is the RTFS_TYPE_MASK stuff shifted down 12 bits and
|
---|
116 | * identical to the BSD/LINUX ABI.
|
---|
117 | */
|
---|
118 | typedef enum RTDIRENTRYTYPE
|
---|
119 | {
|
---|
120 | /** Unknown type (DT_UNKNOWN). */
|
---|
121 | RTDIRENTRYTYPE_UNKNOWN = 0,
|
---|
122 | /** Named pipe (fifo) (DT_FIFO). */
|
---|
123 | RTDIRENTRYTYPE_FIFO = 001,
|
---|
124 | /** Character device (DT_CHR). */
|
---|
125 | RTDIRENTRYTYPE_DEV_CHAR = 002,
|
---|
126 | /** Directory (DT_DIR). */
|
---|
127 | RTDIRENTRYTYPE_DIRECTORY = 004,
|
---|
128 | /** Block device (DT_BLK). */
|
---|
129 | RTDIRENTRYTYPE_DEV_BLOCK = 006,
|
---|
130 | /** Regular file (DT_REG). */
|
---|
131 | RTDIRENTRYTYPE_FILE = 010,
|
---|
132 | /** Symbolic link (DT_LNK). */
|
---|
133 | RTDIRENTRYTYPE_SYMLINK = 012,
|
---|
134 | /** Socket (DT_SOCK). */
|
---|
135 | RTDIRENTRYTYPE_SOCKET = 014,
|
---|
136 | /** Whiteout (DT_WHT). */
|
---|
137 | RTDIRENTRYTYPE_WHITEOUT = 016
|
---|
138 | } RTDIRENTRYTYPE;
|
---|
139 |
|
---|
140 |
|
---|
141 | /**
|
---|
142 | * Directory entry.
|
---|
143 | *
|
---|
144 | * This is inspired by the POSIX interfaces.
|
---|
145 | */
|
---|
146 | #pragma pack(1)
|
---|
147 | typedef struct RTDIRENTRY
|
---|
148 | {
|
---|
149 | /** The unique identifier (within the file system) of this file system object (d_ino).
|
---|
150 | * Together with INodeIdDevice, this field can be used as a OS wide unique id
|
---|
151 | * when both their values are not 0.
|
---|
152 | * This field is 0 if the information is not available. */
|
---|
153 | RTINODE INodeId;
|
---|
154 | /** The entry type. (d_type) */
|
---|
155 | RTDIRENTRYTYPE enmType;
|
---|
156 | /** The length of the filename. */
|
---|
157 | uint16_t cbName;
|
---|
158 | /** The filename. (no path)
|
---|
159 | * Using the pcbDirEntry parameter of RTDirRead makes this field variable in size. */
|
---|
160 | char szName[260];
|
---|
161 | } RTDIRENTRY;
|
---|
162 | #pragma pack()
|
---|
163 | /** Pointer to a directory entry. */
|
---|
164 | typedef RTDIRENTRY *PRTDIRENTRY;
|
---|
165 |
|
---|
166 |
|
---|
167 | /**
|
---|
168 | * Directory entry with extended information.
|
---|
169 | *
|
---|
170 | * This is inspired by the PC interfaces.
|
---|
171 | */
|
---|
172 | #pragma pack(1)
|
---|
173 | typedef struct RTDIRENTRYEX
|
---|
174 | {
|
---|
175 | /** Full information about the object. */
|
---|
176 | RTFSOBJINFO Info;
|
---|
177 | /** The length of the short field (number of RTUCS2 chars).
|
---|
178 | * It is 16-bit for reasons of alignment. */
|
---|
179 | uint16_t cucShortName;
|
---|
180 | /** The short name for 8.3 compatability.
|
---|
181 | * Empty string if not available.
|
---|
182 | * Since the length is a bit tricky for a UTF-8 encoded name, and since this
|
---|
183 | * is practically speaking only a windows thing, it is encoded as UCS-2. */
|
---|
184 | RTUCS2 uszShortName[14];
|
---|
185 | /** The length of the filename. */
|
---|
186 | uint16_t cbName;
|
---|
187 | /** The filename. (no path)
|
---|
188 | * Using the pcbDirEntry parameter of RTDirReadEx makes this field variable in size. */
|
---|
189 | char szName[260];
|
---|
190 | } RTDIRENTRYEX;
|
---|
191 | #pragma pack()
|
---|
192 | /** Pointer to a directory entry. */
|
---|
193 | typedef RTDIRENTRYEX *PRTDIRENTRYEX;
|
---|
194 |
|
---|
195 |
|
---|
196 | /**
|
---|
197 | * Opens a directory.
|
---|
198 | *
|
---|
199 | * @returns iprt status code.
|
---|
200 | * @param ppDir Where to store the open directory pointer.
|
---|
201 | * @param pszPath Path to the directory to open.
|
---|
202 | */
|
---|
203 | RTDECL(int) RTDirOpen(PRTDIR *ppDir, const char *pszPath);
|
---|
204 |
|
---|
205 | /**
|
---|
206 | * Opens a directory filtering the entries using dos style wildcards.
|
---|
207 | *
|
---|
208 | * @returns iprt status code.
|
---|
209 | * @param ppDir Where to store the open directory pointer.
|
---|
210 | * @param pszPath Path to the directory to search, this must include wildcards.
|
---|
211 | * @param enmFilter The kind of filter to apply. Setting this to RTDIRFILTER_NONE makes
|
---|
212 | * this function behave like RTDirOpen.
|
---|
213 | */
|
---|
214 | RTDECL(int) RTDirOpenFiltered(PRTDIR *ppDir, const char *pszPath, RTDIRFILTER enmFilter);
|
---|
215 |
|
---|
216 | /**
|
---|
217 | * Closes a directory.
|
---|
218 | *
|
---|
219 | * @returns iprt status code.
|
---|
220 | * @param pDir Pointer to open directory returned by RTDirOpen() or RTDirOpenFiltered().
|
---|
221 | */
|
---|
222 | RTDECL(int) RTDirClose(PRTDIR pDir);
|
---|
223 |
|
---|
224 | /**
|
---|
225 | * Reads the next entry in the directory.
|
---|
226 | *
|
---|
227 | * @returns VINF_SUCCESS and data in pDirEntry on success.
|
---|
228 | * @returns VERR_NO_MORE_FILES when the end of the directory has been reached.
|
---|
229 | * @returns VERR_BUFFER_OVERFLOW if the buffer is too small to contain the filename. If
|
---|
230 | * pcbDirEntry is specified it will be updated with the required buffer size.
|
---|
231 | * @returns suitable iprt status code on other errors.
|
---|
232 | *
|
---|
233 | * @param pDir Pointer to the open directory.
|
---|
234 | * @param pDirEntry Where to store the information about the next
|
---|
235 | * directory entry on success.
|
---|
236 | * @param pcbDirEntry Optional parameter used for variable buffer size.
|
---|
237 | *
|
---|
238 | * On input the variable pointed to contains the size of the pDirEntry
|
---|
239 | * structure. This must be at least OFFSET(RTDIRENTRY, szName[2]) bytes.
|
---|
240 | *
|
---|
241 | * On successful output the field is updated to
|
---|
242 | * OFFSET(RTDIRENTRY, szName[pDirEntry->cbName + 1]).
|
---|
243 | *
|
---|
244 | * When the data doesn't fit in the buffer and VERR_BUFFER_OVERFLOW is
|
---|
245 | * returned, this field contains the required buffer size.
|
---|
246 | *
|
---|
247 | * The value is unchanged in all other cases.
|
---|
248 | */
|
---|
249 | RTDECL(int) RTDirRead(PRTDIR pDir, PRTDIRENTRY pDirEntry, unsigned *pcbDirEntry);
|
---|
250 |
|
---|
251 | /**
|
---|
252 | * Reads the next entry in the directory returning extended information.
|
---|
253 | *
|
---|
254 | * @returns VINF_SUCCESS and data in pDirEntry on success.
|
---|
255 | * @returns VERR_NO_MORE_FILES when the end of the directory has been reached.
|
---|
256 | * @returns VERR_BUFFER_OVERFLOW if the buffer is too small to contain the filename. If
|
---|
257 | * pcbDirEntry is specified it will be updated with the required buffer size.
|
---|
258 | * @returns suitable iprt status code on other errors.
|
---|
259 | *
|
---|
260 | * @param pDir Pointer to the open directory.
|
---|
261 | * @param pDirEntry Where to store the information about the next
|
---|
262 | * directory entry on success.
|
---|
263 | * @param pcbDirEntry Optional parameter used for variable buffer size.
|
---|
264 | *
|
---|
265 | * On input the variable pointed to contains the size of the pDirEntry
|
---|
266 | * structure. This must be at least OFFSET(RTDIRENTRYEX, szName[2]) bytes.
|
---|
267 | *
|
---|
268 | * On successful output the field is updated to
|
---|
269 | * OFFSET(RTDIRENTRYEX, szName[pDirEntry->cbName + 1]).
|
---|
270 | *
|
---|
271 | * When the data doesn't fit in the buffer and VERR_BUFFER_OVERFLOW is
|
---|
272 | * returned, this field contains the required buffer size.
|
---|
273 | *
|
---|
274 | * The value is unchanged in all other cases.
|
---|
275 | * @param enmAdditionalAttribs
|
---|
276 | * Which set of additional attributes to request.
|
---|
277 | * Use RTFSOBJATTRADD_NOTHING if this doesn't matter.
|
---|
278 | */
|
---|
279 | RTDECL(int) RTDirReadEx(PRTDIR pDir, PRTDIRENTRYEX pDirEntry, unsigned *pcbDirEntry, RTFSOBJATTRADD enmAdditionalAttribs);
|
---|
280 |
|
---|
281 |
|
---|
282 | /**
|
---|
283 | * Renames a file.
|
---|
284 | *
|
---|
285 | * Identical to RTPathRename except that it will ensure that the source is a directory.
|
---|
286 | *
|
---|
287 | * @returns IPRT status code.
|
---|
288 | * @returns VERR_ALREADY_EXISTS if the destination file exists.
|
---|
289 | *
|
---|
290 | * @param pszSrc The path to the source file.
|
---|
291 | * @param pszDst The path to the destination file.
|
---|
292 | * This file will be created.
|
---|
293 | * @param fRename See RTPathRename.
|
---|
294 | */
|
---|
295 | RTDECL(int) RTDirRename(const char *pszSrc, const char *pszDst, unsigned fRename);
|
---|
296 |
|
---|
297 |
|
---|
298 | /**
|
---|
299 | * Query information about an open directory.
|
---|
300 | *
|
---|
301 | * @returns iprt status code.
|
---|
302 | *
|
---|
303 | * @param pDir Pointer to the open directory.
|
---|
304 | * @param pObjInfo Object information structure to be filled on successful return.
|
---|
305 | * @param enmAdditionalAttribs Which set of additional attributes to request.
|
---|
306 | * Use RTFSOBJATTRADD_NOTHING if this doesn't matter.
|
---|
307 | */
|
---|
308 | RTR3DECL(int) RTDirQueryInfo(PRTDIR pDir, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAdditionalAttribs);
|
---|
309 |
|
---|
310 |
|
---|
311 | /**
|
---|
312 | * Changes one or more of the timestamps associated of file system object.
|
---|
313 | *
|
---|
314 | * @returns iprt status code.
|
---|
315 | * @returns VERR_NOT_SUPPORTED is returned if the operation isn't supported by the OS.
|
---|
316 | *
|
---|
317 | * @param pDir Pointer to the open directory.
|
---|
318 | * @param pAccessTime Pointer to the new access time. NULL if not to be changed.
|
---|
319 | * @param pModificationTime Pointer to the new modifcation time. NULL if not to be changed.
|
---|
320 | * @param pChangeTime Pointer to the new change time. NULL if not to be changed.
|
---|
321 | * @param pBirthTime Pointer to the new time of birth. NULL if not to be changed.
|
---|
322 | *
|
---|
323 | * @remark The file system might not implement all these time attributes,
|
---|
324 | * the API will ignore the ones which aren't supported.
|
---|
325 | *
|
---|
326 | * @remark The file system might not implement the time resolution
|
---|
327 | * employed by this interface, the time will be chopped to fit.
|
---|
328 | *
|
---|
329 | * @remark The file system may update the change time even if it's
|
---|
330 | * not specified.
|
---|
331 | *
|
---|
332 | * @remark POSIX can only set Access & Modification and will always set both.
|
---|
333 | */
|
---|
334 | RTR3DECL(int) RTDirSetTimes(PRTDIR pDir, PCRTTIMESPEC pAccessTime, PCRTTIMESPEC pModificationTime,
|
---|
335 | PCRTTIMESPEC pChangeTime, PCRTTIMESPEC pBirthTime);
|
---|
336 |
|
---|
337 | #endif /* IN_RING3 */
|
---|
338 | /** @} */
|
---|
339 |
|
---|
340 | __END_DECLS
|
---|
341 |
|
---|
342 | #endif
|
---|
343 |
|
---|