VirtualBox

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

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

iprt/dir.h: RTDIRENTRY clearification

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.1 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_UNKNOWN is a legal return value here and
160 * should be expected by the user. */
161 RTDIRENTRYTYPE enmType;
162 /** The length of the filename. */
163 uint16_t cbName;
164 /** The filename. (no path)
165 * Using the pcbDirEntry parameter of RTDirRead makes this field variable in size. */
166 char szName[260];
167} RTDIRENTRY;
168#pragma pack()
169/** Pointer to a directory entry. */
170typedef RTDIRENTRY *PRTDIRENTRY;
171
172
173/**
174 * Directory entry with extended information.
175 *
176 * This is inspired by the PC interfaces.
177 */
178#pragma pack(1)
179typedef struct RTDIRENTRYEX
180{
181 /** Full information about the object. */
182 RTFSOBJINFO Info;
183 /** The length of the short field (number of RTUTF16 entries (not chars)).
184 * It is 16-bit for reasons of alignment. */
185 uint16_t cwcShortName;
186 /** The short name for 8.3 compatability.
187 * Empty string if not available.
188 * Since the length is a bit tricky for a UTF-8 encoded name, and since this
189 * is practically speaking only a windows thing, it is encoded as UCS-2. */
190 RTUTF16 wszShortName[14];
191 /** The length of the filename. */
192 uint16_t cbName;
193 /** The filename. (no path)
194 * Using the pcbDirEntry parameter of RTDirReadEx makes this field variable in size. */
195 char szName[260];
196} RTDIRENTRYEX;
197#pragma pack()
198/** Pointer to a directory entry. */
199typedef RTDIRENTRYEX *PRTDIRENTRYEX;
200
201
202/**
203 * Opens a directory.
204 *
205 * @returns iprt status code.
206 * @param ppDir Where to store the open directory pointer.
207 * @param pszPath Path to the directory to open.
208 */
209RTDECL(int) RTDirOpen(PRTDIR *ppDir, const char *pszPath);
210
211/**
212 * Opens a directory filtering the entries using dos style wildcards.
213 *
214 * @returns iprt status code.
215 * @param ppDir Where to store the open directory pointer.
216 * @param pszPath Path to the directory to search, this must include wildcards.
217 * @param enmFilter The kind of filter to apply. Setting this to RTDIRFILTER_NONE makes
218 * this function behave like RTDirOpen.
219 */
220RTDECL(int) RTDirOpenFiltered(PRTDIR *ppDir, const char *pszPath, RTDIRFILTER enmFilter);
221
222/**
223 * Closes a directory.
224 *
225 * @returns iprt status code.
226 * @param pDir Pointer to open directory returned by RTDirOpen() or RTDirOpenFiltered().
227 */
228RTDECL(int) RTDirClose(PRTDIR pDir);
229
230/**
231 * Reads the next entry in the directory.
232 *
233 * @returns VINF_SUCCESS and data in pDirEntry on success.
234 * @returns VERR_NO_MORE_FILES when the end of the directory has been reached.
235 * @returns VERR_BUFFER_OVERFLOW if the buffer is too small to contain the filename. If
236 * pcbDirEntry is specified it will be updated with the required buffer size.
237 * @returns suitable iprt status code on other errors.
238 *
239 * @param pDir Pointer to the open directory.
240 * @param pDirEntry Where to store the information about the next
241 * directory entry on success.
242 * @param pcbDirEntry Optional parameter used for variable buffer size.
243 *
244 * On input the variable pointed to contains the size of the pDirEntry
245 * structure. This must be at least OFFSET(RTDIRENTRY, szName[2]) bytes.
246 *
247 * On successful output the field is updated to
248 * OFFSET(RTDIRENTRY, szName[pDirEntry->cbName + 1]).
249 *
250 * When the data doesn't fit in the buffer and VERR_BUFFER_OVERFLOW is
251 * returned, this field contains the required buffer size.
252 *
253 * The value is unchanged in all other cases.
254 */
255RTDECL(int) RTDirRead(PRTDIR pDir, PRTDIRENTRY pDirEntry, unsigned *pcbDirEntry);
256
257/**
258 * Reads the next entry in the directory returning extended information.
259 *
260 * @returns VINF_SUCCESS and data in pDirEntry on success.
261 * @returns VERR_NO_MORE_FILES when the end of the directory has been reached.
262 * @returns VERR_BUFFER_OVERFLOW if the buffer is too small to contain the filename. If
263 * pcbDirEntry is specified it will be updated with the required buffer size.
264 * @returns suitable iprt status code on other errors.
265 *
266 * @param pDir Pointer to the open directory.
267 * @param pDirEntry Where to store the information about the next
268 * directory entry on success.
269 * @param pcbDirEntry Optional parameter used for variable buffer size.
270 *
271 * On input the variable pointed to contains the size of the pDirEntry
272 * structure. This must be at least OFFSET(RTDIRENTRYEX, szName[2]) bytes.
273 *
274 * On successful output the field is updated to
275 * OFFSET(RTDIRENTRYEX, szName[pDirEntry->cbName + 1]).
276 *
277 * When the data doesn't fit in the buffer and VERR_BUFFER_OVERFLOW is
278 * returned, this field contains the required buffer size.
279 *
280 * The value is unchanged in all other cases.
281 * @param enmAdditionalAttribs
282 * Which set of additional attributes to request.
283 * Use RTFSOBJATTRADD_NOTHING if this doesn't matter.
284 */
285RTDECL(int) RTDirReadEx(PRTDIR pDir, PRTDIRENTRYEX pDirEntry, unsigned *pcbDirEntry, RTFSOBJATTRADD enmAdditionalAttribs);
286
287
288/**
289 * Renames a file.
290 *
291 * Identical to RTPathRename except that it will ensure that the source is a directory.
292 *
293 * @returns IPRT status code.
294 * @returns VERR_ALREADY_EXISTS if the destination file exists.
295 *
296 * @param pszSrc The path to the source file.
297 * @param pszDst The path to the destination file.
298 * This file will be created.
299 * @param fRename See RTPathRename.
300 */
301RTDECL(int) RTDirRename(const char *pszSrc, const char *pszDst, unsigned fRename);
302
303
304/**
305 * Query information about an open directory.
306 *
307 * @returns iprt status code.
308 *
309 * @param pDir Pointer to the open directory.
310 * @param pObjInfo Object information structure to be filled on successful return.
311 * @param enmAdditionalAttribs Which set of additional attributes to request.
312 * Use RTFSOBJATTRADD_NOTHING if this doesn't matter.
313 */
314RTR3DECL(int) RTDirQueryInfo(PRTDIR pDir, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAdditionalAttribs);
315
316
317/**
318 * Changes one or more of the timestamps associated of file system object.
319 *
320 * @returns iprt status code.
321 * @returns VERR_NOT_SUPPORTED is returned if the operation isn't supported by the OS.
322 *
323 * @param pDir Pointer to the open directory.
324 * @param pAccessTime Pointer to the new access time. NULL if not to be changed.
325 * @param pModificationTime Pointer to the new modifcation time. NULL if not to be changed.
326 * @param pChangeTime Pointer to the new change time. NULL if not to be changed.
327 * @param pBirthTime Pointer to the new time of birth. NULL if not to be changed.
328 *
329 * @remark The file system might not implement all these time attributes,
330 * the API will ignore the ones which aren't supported.
331 *
332 * @remark The file system might not implement the time resolution
333 * employed by this interface, the time will be chopped to fit.
334 *
335 * @remark The file system may update the change time even if it's
336 * not specified.
337 *
338 * @remark POSIX can only set Access & Modification and will always set both.
339 */
340RTR3DECL(int) RTDirSetTimes(PRTDIR pDir, PCRTTIMESPEC pAccessTime, PCRTTIMESPEC pModificationTime,
341 PCRTTIMESPEC pChangeTime, PCRTTIMESPEC pBirthTime);
342
343#endif /* IN_RING3 */
344/** @} */
345
346__END_DECLS
347
348#endif
349
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