VirtualBox

source: vbox/trunk/include/iprt/fs.h@ 7329

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

The Giant CDDL Dual-License Header Change.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 16.0 KB
Line 
1/** @file
2 * innotek Portable Runtime - Filesystem.
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_fs_h
27#define ___iprt_fs_h
28
29#include <iprt/cdefs.h>
30#include <iprt/types.h>
31#include <iprt/time.h>
32
33
34__BEGIN_DECLS
35
36/** @defgroup grp_rt_fs RTFs - Filesystem and Volume
37 * @ingroup grp_rt
38 * @{
39 */
40
41
42/** @name Filesystem Object Mode Flags.
43 *
44 * There are two sets of flags: the unix mode flags and the dos
45 * attributes.
46 *
47 * APIs returning mode flags will provide both sets.
48 *
49 * When specifying mode flags to any API at least one of
50 * them must be given. If one set is missing the API will
51 * synthesize it from the one given if it requires it.
52 *
53 * Both sets match their x86 ABIs, the DOS/NT one is simply shifted
54 * up 16 bits. The DOS/NT range is bits 16 to 31 inclusivly. The
55 * Unix range is bits 0 to 15 (inclusivly).
56 *
57 * @{
58 */
59
60/** Set user id on execution (S_ISUID). */
61#define RTFS_UNIX_ISUID 0004000U
62/** Set group id on execution (S_ISGID). */
63#define RTFS_UNIX_ISGID 0002000U
64/** Sticky bit (S_ISVTX / S_ISTXT). */
65#define RTFS_UNIX_ISTXT 0001000U
66
67/** Owner RWX mask (S_IRWXU). */
68#define RTFS_UNIX_IRWXU 0000700U
69/** Owner readable (S_IRUSR). */
70#define RTFS_UNIX_IRUSR 0000400U
71/** Owner writable (S_IWUSR). */
72#define RTFS_UNIX_IWUSR 0000200U
73/** Owner executable (S_IXUSR). */
74#define RTFS_UNIX_IXUSR 0000100U
75
76/** Group RWX mask (S_IRWXG). */
77#define RTFS_UNIX_IRWXG 0000070U
78/** Group readable (S_IRGRP). */
79#define RTFS_UNIX_IRGRP 0000040U
80/** Group writable (S_IWGRP). */
81#define RTFS_UNIX_IWGRP 0000020U
82/** Group executable (S_IXGRP). */
83#define RTFS_UNIX_IXGRP 0000010U
84
85/** Other RWX mask (S_IRWXO). */
86#define RTFS_UNIX_IRWXO 0000007U
87/** Other readable (S_IROTH). */
88#define RTFS_UNIX_IROTH 0000004U
89/** Other writable (S_IWOTH). */
90#define RTFS_UNIX_IWOTH 0000002U
91/** Other executable (S_IXOTH). */
92#define RTFS_UNIX_IXOTH 0000001U
93
94/** Named pipe (fifo) (S_IFIFO). */
95#define RTFS_TYPE_FIFO 0010000U
96/** Character device (S_IFCHR). */
97#define RTFS_TYPE_DEV_CHAR 0020000U
98/** Directory (S_IFDIR). */
99#define RTFS_TYPE_DIRECTORY 0040000U
100/** Block device (S_IFBLK). */
101#define RTFS_TYPE_DEV_BLOCK 0060000U
102/** Regular file (S_IFREG). */
103#define RTFS_TYPE_FILE 0100000U
104/** Symbolic link (S_IFLNK). */
105#define RTFS_TYPE_SYMLINK 0120000U
106/** Socket (S_IFSOCK). */
107#define RTFS_TYPE_SOCKET 0140000U
108/** Whiteout (S_IFWHT). */
109#define RTFS_TYPE_WHITEOUT 0160000U
110/** Type mask (S_IFMT). */
111#define RTFS_TYPE_MASK 0170000U
112
113/** Unix attribute mask. */
114#define RTFS_UNIX_MASK 0xffffU
115/** The mask of all the NT, OS/2 and DOS attributes. */
116#define RTFS_DOS_MASK (0x7fffU << RTFS_DOS_SHIFT)
117
118/** The shift value. */
119#define RTFS_DOS_SHIFT 16
120/** The mask of the OS/2 and DOS attributes. */
121#define RTFS_DOS_MASK_OS2 (0x003fU << RTFS_DOS_SHIFT)
122/** The mask of the NT attributes. */
123#define RTFS_DOS_MASK_NT (0x7fffU << RTFS_DOS_SHIFT)
124
125/** Readonly object. */
126#define RTFS_DOS_READONLY (0x0001U << RTFS_DOS_SHIFT)
127/** Hidden object. */
128#define RTFS_DOS_HIDDEN (0x0002U << RTFS_DOS_SHIFT)
129/** System object. */
130#define RTFS_DOS_SYSTEM (0x0004U << RTFS_DOS_SHIFT)
131/** Directory. */
132#define RTFS_DOS_DIRECTORY (0x0010U << RTFS_DOS_SHIFT)
133/** Archived object.
134 * This bit is set by the filesystem after each modification of a file. */
135#define RTFS_DOS_ARCHIVED (0x0020U << RTFS_DOS_SHIFT)
136/** Undocumented / Reserved, used to be the FAT volume label. */
137#define RTFS_DOS_NT_DEVICE (0x0040U << RTFS_DOS_SHIFT)
138/** Normal object, no other attribute set (NT). */
139#define RTFS_DOS_NT_NORMAL (0x0080U << RTFS_DOS_SHIFT)
140/** Temporary object (NT). */
141#define RTFS_DOS_NT_TEMPORARY (0x0100U << RTFS_DOS_SHIFT)
142/** Sparse file (NT). */
143#define RTFS_DOS_NT_SPARSE_FILE (0x0200U << RTFS_DOS_SHIFT)
144/** Reparse point (NT). */
145#define RTFS_DOS_NT_REPARSE_POINT (0x0400U << RTFS_DOS_SHIFT)
146/** Compressed object (NT).
147 * For a directory, compression is the default for new files. */
148#define RTFS_DOS_NT_COMPRESSED (0x0800U << RTFS_DOS_SHIFT)
149/** Physically offline data (NT).
150 * MSDN say, don't mess with this one. */
151#define RTFS_DOS_NT_OFFLINE (0x1000U << RTFS_DOS_SHIFT)
152/** Not content indexed by the content indexing service (NT). */
153#define RTFS_DOS_NT_NOT_CONTENT_INDEXED (0x2000U << RTFS_DOS_SHIFT)
154/** Encryped object (NT).
155 * For a directory, encrypted is the default for new files. */
156#define RTFS_DOS_NT_ENCRYPTED (0x4000U << RTFS_DOS_SHIFT)
157
158/** @} */
159
160
161/** @name Filesystem Object Type Predicates.
162 * @{ */
163/** Checks the mode flags indicate a named pipe (fifo) (S_ISFIFO). */
164#define RTFS_IS_FIFO(fMode) ( ((fMode) & RTFS_TYPE_MASK) == RTFS_TYPE_FIFO )
165/** Checks the mode flags indicate a character device (S_ISCHR). */
166#define RTFS_IS_DEV_CHAR(fMode) ( ((fMode) & RTFS_TYPE_MASK) == RTFS_TYPE_DEV_CHAR )
167/** Checks the mode flags indicate a directory (S_ISDIR). */
168#define RTFS_IS_DIRECTORY(fMode) ( ((fMode) & RTFS_TYPE_MASK) == RTFS_TYPE_DIRECTORY )
169/** Checks the mode flags indicate a block device (S_ISBLK). */
170#define RTFS_IS_DEV_BLOCK(fMode) ( ((fMode) & RTFS_TYPE_MASK) == RTFS_TYPE_DEV_BLOCK )
171/** Checks the mode flags indicate a regular file (S_ISREG). */
172#define RTFS_IS_FILE(fMode) ( ((fMode) & RTFS_TYPE_MASK) == RTFS_TYPE_FILE )
173/** Checks the mode flags indicate a symbolic link (S_ISLNK). */
174#define RTFS_IS_SYMLINK(fMode) ( ((fMode) & RTFS_TYPE_MASK) == RTFS_TYPE_SYMLINK )
175/** Checks the mode flags indicate a socket (S_ISSOCK). */
176#define RTFS_IS_SOCKET(fMode) ( ((fMode) & RTFS_TYPE_MASK) == RTFS_TYPE_SOCKET )
177/** Checks the mode flags indicate a whiteout (S_ISWHT). */
178#define RTFS_IS_WHITEOUT(fMode) ( ((fMode) & RTFS_TYPE_MASK) == RTFS_TYPE_WHITEOUT )
179/** @} */
180
181
182/**
183 * The available additional information in a RTFSOBJATTR object.
184 */
185typedef enum RTFSOBJATTRADD
186{
187 /** No additional information is available / requested. */
188 RTFSOBJATTRADD_NOTHING = 1,
189 /** The additional unix attributes (RTFSOBJATTR::u::Unix) are available / requested. */
190 RTFSOBJATTRADD_UNIX,
191 /** The additional extended attribute size (RTFSOBJATTR::u::EASize) is available / requested. */
192 RTFSOBJATTRADD_EASIZE,
193 /** The last valid item (inclusive).
194 * The valid range is RTFSOBJATTRADD_NOTHING thru RTFSOBJATTRADD_LAST. */
195 RTFSOBJATTRADD_LAST = RTFSOBJATTRADD_EASIZE,
196
197 /** The usual 32-bit hack. */
198 RTFSOBJATTRADD_32BIT_SIZE_HACK = 0x7fffffff
199} RTFSOBJATTRADD;
200
201
202/**
203 * Filesystem object attributes.
204 */
205#pragma pack(1)
206typedef struct RTFSOBJATTR
207{
208 /** Mode flags (st_mode). RTFS_UNIX_*, RTFS_TYPE_*, and RTFS_DOS_*. */
209 RTFMODE fMode;
210
211 /** The additional attributes available. */
212 RTFSOBJATTRADD enmAdditional;
213
214 /**
215 * Additional attributes.
216 *
217 * Unless explicitly specified to an API, the API can provide additional
218 * data as it is provided by the underlying OS.
219 */
220 union RTFSOBJATTRUNION
221 {
222 /** Additional Unix Attributes
223 * These are available when RTFSOBJATTRADD is set in fUnix.
224 */
225 struct RTFSOBJATTRUNIX
226 {
227 /** The user owning the filesystem object (st_uid).
228 * This field is ~0U if not supported. */
229 RTUID uid;
230
231 /** The group the filesystem object is assigned (st_gid).
232 * This field is ~0U if not supported. */
233 RTGID gid;
234
235 /** Number of hard links to this filesystem object (st_nlink).
236 * This field is 1 if the filesystem doesn't support hardlinking or
237 * the information isn't available.
238 */
239 uint32_t cHardlinks;
240
241 /** The device number of the device which this filesystem object resides on (st_dev).
242 * This field is 0 if this information is not available. */
243 RTDEV INodeIdDevice;
244
245 /** The unique identifier (within the filesystem) of this filesystem object (st_ino).
246 * Together with INodeIdDevice, this field can be used as a OS wide unique id
247 * when both their values are not 0.
248 * This field is 0 if the information is not available. */
249 RTINODE INodeId;
250
251 /** User flags (st_flags).
252 * This field is 0 if this information is not available. */
253 uint32_t fFlags;
254
255 /** The current generation number (st_gen).
256 * This field is 0 if this information is not available. */
257 uint32_t GenerationId;
258
259 /** The device number of a character or block device type object (st_rdev).
260 * This field is 0 if the file isn't of a character or block device type and
261 * when the OS doesn't subscribe to the major+minor device idenfication scheme. */
262 RTDEV Device;
263 } Unix;
264
265 /**
266 * Extended attribute size is available when RTFS_DOS_HAVE_EA_SIZE is set.
267 */
268 struct RTFSOBJATTREASIZE
269 {
270 /** Size of EAs. */
271 RTFOFF cb;
272 } EASize;
273 } u;
274} RTFSOBJATTR;
275#pragma pack()
276/** Pointer to a filesystem object attributes structure. */
277typedef RTFSOBJATTR *PRTFSOBJATTR;
278/** Pointer to a const filesystem object attributes structure. */
279typedef const RTFSOBJATTR *PCRTFSOBJATTR;
280
281
282/**
283 * Filesystem object information structure.
284 *
285 * This is returned by the RTPathQueryInfo(), RTFileQueryInfo() and RTDirRead() APIs.
286 */
287#pragma pack(1)
288typedef struct RTFSOBJINFO
289{
290 /** Logical size (st_size).
291 * For normal files this is the size of the file.
292 * For symbolic links, this is the length of the path name contained
293 * in the symbolic link.
294 * For other objects this fields needs to be specified.
295 */
296 RTFOFF cbObject;
297
298 /** Disk allocation size (st_blocks * DEV_BSIZE). */
299 RTFOFF cbAllocated;
300
301 /** Time of last access (st_atime). */
302 RTTIMESPEC AccessTime;
303
304 /** Time of last data modification (st_mtime). */
305 RTTIMESPEC ModificationTime;
306
307 /** Time of last status change (st_ctime).
308 * If not available this is set to ModificationTime.
309 */
310 RTTIMESPEC ChangeTime;
311
312 /** Time of file birth (st_birthtime).
313 * If not available this is set to ChangeTime.
314 */
315 RTTIMESPEC BirthTime;
316
317 /** Attributes. */
318 RTFSOBJATTR Attr;
319
320} RTFSOBJINFO;
321#pragma pack()
322/** Pointer to a filesystem object information structure. */
323typedef RTFSOBJINFO *PRTFSOBJINFO;
324/** Pointer to a const filesystem object information structure. */
325typedef const RTFSOBJINFO *PCRTFSOBJINFO;
326
327
328#ifdef IN_RING3
329
330/**
331 * Query the sizes of a filesystem.
332 *
333 * @returns iprt status code.
334 * @param pszFsPath Path within the mounted filesystem.
335 * @param pcbTotal Where to store the total filesystem space. (Optional)
336 * @param pcbFree Where to store the remaining free space in the filesystem. (Optional)
337 * @param pcbBlock Where to store the block size. (Optional)
338 * @param pcbSector Where to store the sector size. (Optional)
339 */
340RTR3DECL(int) RTFsQuerySizes(const char *pszFsPath, PRTFOFF pcbTotal, RTFOFF *pcbFree,
341 uint32_t *pcbBlock, uint32_t *pcbSector);
342
343/**
344 * Query the mountpoint of a filesystem.
345 *
346 * @returns iprt status code.
347 * @returns VERR_BUFFER_OVERFLOW if cbMountpoint isn't enough.
348 * @param pszFsPath Path within the mounted filesystem.
349 * @param pszMountpoint Where to store the mountpoint path.
350 * @param cbMountpoint Size of the buffer pointed to by pszMountpoint.
351 */
352RTR3DECL(int) RTFsQueryMountpoint(const char *pszFsPath, char *pszMountpoint, size_t cbMountpoint);
353
354/**
355 * Query the label of a filesystem.
356 *
357 * @returns iprt status code.
358 * @returns VERR_BUFFER_OVERFLOW if cbLabel isn't enough.
359 * @param pszFsPath Path within the mounted filesystem.
360 * @param pszLabel Where to store the label.
361 * @param cbLabel Size of the buffer pointed to by pszLabel.
362 */
363RTR3DECL(int) RTFsQueryLabel(const char *pszFsPath, char *pszLabel, size_t cbLabel);
364
365/**
366 * Query the serial number of a filesystem.
367 *
368 * @returns iprt status code.
369 * @param pszFsPath Path within the mounted filesystem.
370 * @param pu32Serial Where to store the serial number.
371 */
372RTR3DECL(int) RTFsQuerySerial(const char *pszFsPath, uint32_t *pu32Serial);
373
374/**
375 * Query the name of the filesystem driver.
376 *
377 * @returns iprt status code.
378 * @returns VERR_BUFFER_OVERFLOW if cbFsDriver isn't enough.
379 * @param pszFsPath Path within the mounted filesystem.
380 * @param pszFsDriver Where to store the filesystem driver name.
381 * @param cbFsDriver Size of the buffer pointed to by pszFsDriver.
382 */
383RTR3DECL(int) RTFsQueryDriver(const char *pszFsPath, char *pszFsDriver, size_t cbFsDriver);
384
385#endif /* IN_RING3 */
386
387/**
388 * Filesystem properties.
389 */
390typedef struct RTFSPROPERTIES
391{
392 /** The maximum size of a filesystem object name.
393 * This does not include the '\\0'. */
394 uint32_t cbMaxComponent;
395
396 /** True if the filesystem is remote.
397 * False if the filesystem is local. */
398 bool fRemote;
399
400 /** True if the filesystem is case sensitive.
401 * False if the filesystem is case insensitive. */
402 bool fCaseSensitive;
403
404 /** True if the filesystem is mounted read only.
405 * False if the filesystem is mounted read write. */
406 bool fReadOnly;
407
408 /** True if the filesystem can encode unicode object names.
409 * False if it can't. */
410 bool fSupportsUnicode;
411
412 /** True if the filesystem is compresses.
413 * False if it isn't or we don't know. */
414 bool fCompressed;
415
416 /** True if the filesystem compresses of individual files.
417 * False if it doesn't or we don't know. */
418 bool fFileCompression;
419
420 /** @todo more? */
421} RTFSPROPERTIES;
422/** Pointer to a filesystem properties structure. */
423typedef RTFSPROPERTIES *PRTFSPROPERTIES;
424
425#ifdef IN_RING3
426
427/**
428 * Query the properties of a mounted filesystem.
429 *
430 * @returns iprt status code.
431 * @param pszFsPath Path within the mounted filesystem.
432 * @param pProperties Where to store the properties.
433 */
434RTR3DECL(int) RTFsQueryProperties(const char *pszFsPath, PRTFSPROPERTIES pProperties);
435
436
437/**
438 * Mountpoint enumerator callback.
439 *
440 * @returns iprt status code. Failure terminates the enumeration.
441 * @param pszMountpoint The mountpoint name.
442 * @param pvUser The user argument.
443 */
444typedef DECLCALLBACK(int) FNRTFSMOUNTPOINTENUM(const char *pszMountpoint, void *pvUser);
445/** Pointer to a FNRTFSMOUNTPOINTENUM(). */
446typedef FNRTFSMOUNTPOINTENUM *PFNRTFSMOUNTPOINTENUM;
447
448/**
449 * Enumerate mount points.
450 *
451 * @returns iprt status code.
452 * @param pfnCallback The callback function.
453 * @param pvUser The user argument to the callback.
454 */
455RTR3DECL(int) RTFsMountpointsEnum(PFNRTFSMOUNTPOINTENUM pfnCallback, void *pvUser);
456
457
458#endif /* IN_RING3 */
459
460/** @} */
461
462__END_DECLS
463
464#endif /* ___iprt_fs_h */
465
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