VirtualBox

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

Last change on this file since 8245 was 8245, checked in by vboxsync, 17 years ago

rebranding: IPRT files again.

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