VirtualBox

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

Last change on this file since 20067 was 20067, checked in by vboxsync, 16 years ago

Runtime: accident

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