VirtualBox

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

Last change on this file since 30281 was 30281, checked in by vboxsync, 14 years ago

Runtime: added Darwin support to RTFsQueryType

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 17.2 KB
Line 
1/** @file
2 * IPRT - Filesystem.
3 */
4
5/*
6 * Copyright (C) 2006-2007 Oracle Corporation
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
34RT_C_DECLS_BEGIN
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 inclusively. The
55 * Unix range is bits 0 to 15 (inclusively).
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/** @name Filesystem type IDs. Used by RTFsQueryType. */
183#define RTFS_FS_TYPE_UNKNOWN 0
184#define RTFS_FS_TYPE_EXT 1
185#define RTFS_FS_TYPE_EXT2 2
186#define RTFS_FS_TYPE_EXT3 3
187#define RTFS_FS_TYPE_EXT4 4
188#define RTFS_FS_TYPE_TMPFS 5
189#define RTFS_FS_TYPE_JFS 6
190#define RTFS_FS_TYPE_NFS 7
191#define RTFS_FS_TYPE_HFS 8
192#define RTFS_FS_TYPE_CIFS 9
193#define RTFS_FS_TYPE_FAT 10
194#define RTFS_FS_TYPE_NTFS 11
195#define RTFS_FS_TYPE_ZFS 12
196#define RTFS_FS_TYPE_XFS 13
197#define RTFS_FS_TYPE_AUTOFS 14
198#define RTFS_FS_TYPE_DEVFS 15
199
200
201/**
202 * The available additional information in a RTFSOBJATTR object.
203 */
204typedef enum RTFSOBJATTRADD
205{
206 /** No additional information is available / requested. */
207 RTFSOBJATTRADD_NOTHING = 1,
208 /** The additional unix attributes (RTFSOBJATTR::u::Unix) are available / requested. */
209 RTFSOBJATTRADD_UNIX,
210 /** The additional extended attribute size (RTFSOBJATTR::u::EASize) is available / requested. */
211 RTFSOBJATTRADD_EASIZE,
212 /** The last valid item (inclusive).
213 * The valid range is RTFSOBJATTRADD_NOTHING thru RTFSOBJATTRADD_LAST. */
214 RTFSOBJATTRADD_LAST = RTFSOBJATTRADD_EASIZE,
215
216 /** The usual 32-bit hack. */
217 RTFSOBJATTRADD_32BIT_SIZE_HACK = 0x7fffffff
218} RTFSOBJATTRADD;
219
220
221/**
222 * Filesystem object attributes.
223 */
224#pragma pack(1)
225typedef struct RTFSOBJATTR
226{
227 /** Mode flags (st_mode). RTFS_UNIX_*, RTFS_TYPE_*, and RTFS_DOS_*. */
228 RTFMODE fMode;
229
230 /** The additional attributes available. */
231 RTFSOBJATTRADD enmAdditional;
232
233 /**
234 * Additional attributes.
235 *
236 * Unless explicitly specified to an API, the API can provide additional
237 * data as it is provided by the underlying OS.
238 */
239 union RTFSOBJATTRUNION
240 {
241 /** Additional Unix Attributes
242 * These are available when RTFSOBJATTRADD is set in fUnix.
243 */
244 struct RTFSOBJATTRUNIX
245 {
246 /** The user owning the filesystem object (st_uid).
247 * This field is ~0U if not supported. */
248 RTUID uid;
249
250 /** The group the filesystem object is assigned (st_gid).
251 * This field is ~0U if not supported. */
252 RTGID gid;
253
254 /** Number of hard links to this filesystem object (st_nlink).
255 * This field is 1 if the filesystem doesn't support hardlinking or
256 * the information isn't available.
257 */
258 uint32_t cHardlinks;
259
260 /** The device number of the device which this filesystem object resides on (st_dev).
261 * This field is 0 if this information is not available. */
262 RTDEV INodeIdDevice;
263
264 /** The unique identifier (within the filesystem) of this filesystem object (st_ino).
265 * Together with INodeIdDevice, this field can be used as a OS wide unique id
266 * when both their values are not 0.
267 * This field is 0 if the information is not available. */
268 RTINODE INodeId;
269
270 /** User flags (st_flags).
271 * This field is 0 if this information is not available. */
272 uint32_t fFlags;
273
274 /** The current generation number (st_gen).
275 * This field is 0 if this information is not available. */
276 uint32_t GenerationId;
277
278 /** The device number of a character or block device type object (st_rdev).
279 * This field is 0 if the file isn't of a character or block device type and
280 * when the OS doesn't subscribe to the major+minor device idenfication scheme. */
281 RTDEV Device;
282 } Unix;
283
284 /**
285 * Extended attribute size is available when RTFS_DOS_HAVE_EA_SIZE is set.
286 */
287 struct RTFSOBJATTREASIZE
288 {
289 /** Size of EAs. */
290 RTFOFF cb;
291 } EASize;
292 } u;
293} RTFSOBJATTR;
294#pragma pack()
295/** Pointer to a filesystem object attributes structure. */
296typedef RTFSOBJATTR *PRTFSOBJATTR;
297/** Pointer to a const filesystem object attributes structure. */
298typedef const RTFSOBJATTR *PCRTFSOBJATTR;
299
300
301/**
302 * Filesystem object information structure.
303 *
304 * This is returned by the RTPathQueryInfo(), RTFileQueryInfo() and RTDirRead() APIs.
305 */
306#pragma pack(1)
307typedef struct RTFSOBJINFO
308{
309 /** Logical size (st_size).
310 * For normal files this is the size of the file.
311 * For symbolic links, this is the length of the path name contained
312 * in the symbolic link.
313 * For other objects this fields needs to be specified.
314 */
315 RTFOFF cbObject;
316
317 /** Disk allocation size (st_blocks * DEV_BSIZE). */
318 RTFOFF cbAllocated;
319
320 /** Time of last access (st_atime). */
321 RTTIMESPEC AccessTime;
322
323 /** Time of last data modification (st_mtime). */
324 RTTIMESPEC ModificationTime;
325
326 /** Time of last status change (st_ctime).
327 * If not available this is set to ModificationTime.
328 */
329 RTTIMESPEC ChangeTime;
330
331 /** Time of file birth (st_birthtime).
332 * If not available this is set to ChangeTime.
333 */
334 RTTIMESPEC BirthTime;
335
336 /** Attributes. */
337 RTFSOBJATTR Attr;
338
339} RTFSOBJINFO;
340#pragma pack()
341/** Pointer to a filesystem object information structure. */
342typedef RTFSOBJINFO *PRTFSOBJINFO;
343/** Pointer to a const filesystem object information structure. */
344typedef const RTFSOBJINFO *PCRTFSOBJINFO;
345
346
347#ifdef IN_RING3
348
349/**
350 * Query the sizes of a filesystem.
351 *
352 * @returns iprt status code.
353 * @param pszFsPath Path within the mounted filesystem.
354 * @param pcbTotal Where to store the total filesystem space. (Optional)
355 * @param pcbFree Where to store the remaining free space in the filesystem. (Optional)
356 * @param pcbBlock Where to store the block size. (Optional)
357 * @param pcbSector Where to store the sector size. (Optional)
358 *
359 * @sa RTFileQueryFsSizes
360 */
361RTR3DECL(int) RTFsQuerySizes(const char *pszFsPath, PRTFOFF pcbTotal, RTFOFF *pcbFree,
362 uint32_t *pcbBlock, uint32_t *pcbSector);
363
364/**
365 * Query the mountpoint of a filesystem.
366 *
367 * @returns iprt status code.
368 * @returns VERR_BUFFER_OVERFLOW if cbMountpoint isn't enough.
369 * @param pszFsPath Path within the mounted filesystem.
370 * @param pszMountpoint Where to store the mountpoint path.
371 * @param cbMountpoint Size of the buffer pointed to by pszMountpoint.
372 */
373RTR3DECL(int) RTFsQueryMountpoint(const char *pszFsPath, char *pszMountpoint, size_t cbMountpoint);
374
375/**
376 * Query the label of a filesystem.
377 *
378 * @returns iprt status code.
379 * @returns VERR_BUFFER_OVERFLOW if cbLabel isn't enough.
380 * @param pszFsPath Path within the mounted filesystem.
381 * @param pszLabel Where to store the label.
382 * @param cbLabel Size of the buffer pointed to by pszLabel.
383 */
384RTR3DECL(int) RTFsQueryLabel(const char *pszFsPath, char *pszLabel, size_t cbLabel);
385
386/**
387 * Query the serial number of a filesystem.
388 *
389 * @returns iprt status code.
390 * @param pszFsPath Path within the mounted filesystem.
391 * @param pu32Serial Where to store the serial number.
392 */
393RTR3DECL(int) RTFsQuerySerial(const char *pszFsPath, uint32_t *pu32Serial);
394
395/**
396 * Query the name of the filesystem driver.
397 *
398 * @returns iprt status code.
399 * @returns VERR_BUFFER_OVERFLOW if cbFsDriver isn't enough.
400 * @param pszFsPath Path within the mounted filesystem.
401 * @param pszFsDriver Where to store the filesystem driver name.
402 * @param cbFsDriver Size of the buffer pointed to by pszFsDriver.
403 */
404RTR3DECL(int) RTFsQueryDriver(const char *pszFsPath, char *pszFsDriver, size_t cbFsDriver);
405
406/**
407 * Query the name of the filesystem the file is located on.
408 *
409 * @returns iprt status code.
410 * @param pszFsPath Path within the mounted filesystem.
411 * In case this is a symlink, the file it refers to
412 * is evaluated.
413 * @param pu32Type Where to store the filesystem type.
414 * See RTFS_FS_TYPE_xxx constants.
415 */
416RTR3DECL(int) RTFsQueryType(const char *pszFsPath, uint32_t *pu32Type);
417
418#endif /* IN_RING3 */
419
420/**
421 * Filesystem properties.
422 */
423typedef struct RTFSPROPERTIES
424{
425 /** The maximum size of a filesystem object name.
426 * This does not include the '\\0'. */
427 uint32_t cbMaxComponent;
428
429 /** True if the filesystem is remote.
430 * False if the filesystem is local. */
431 bool fRemote;
432
433 /** True if the filesystem is case sensitive.
434 * False if the filesystem is case insensitive. */
435 bool fCaseSensitive;
436
437 /** True if the filesystem is mounted read only.
438 * False if the filesystem is mounted read write. */
439 bool fReadOnly;
440
441 /** True if the filesystem can encode unicode object names.
442 * False if it can't. */
443 bool fSupportsUnicode;
444
445 /** True if the filesystem is compresses.
446 * False if it isn't or we don't know. */
447 bool fCompressed;
448
449 /** True if the filesystem compresses of individual files.
450 * False if it doesn't or we don't know. */
451 bool fFileCompression;
452
453 /** @todo more? */
454} RTFSPROPERTIES;
455/** Pointer to a filesystem properties structure. */
456typedef RTFSPROPERTIES *PRTFSPROPERTIES;
457
458#ifdef IN_RING3
459
460/**
461 * Query the properties of a mounted filesystem.
462 *
463 * @returns iprt status code.
464 * @param pszFsPath Path within the mounted filesystem.
465 * @param pProperties Where to store the properties.
466 */
467RTR3DECL(int) RTFsQueryProperties(const char *pszFsPath, PRTFSPROPERTIES pProperties);
468
469
470/**
471 * Mountpoint enumerator callback.
472 *
473 * @returns iprt status code. Failure terminates the enumeration.
474 * @param pszMountpoint The mountpoint name.
475 * @param pvUser The user argument.
476 */
477typedef DECLCALLBACK(int) FNRTFSMOUNTPOINTENUM(const char *pszMountpoint, void *pvUser);
478/** Pointer to a FNRTFSMOUNTPOINTENUM(). */
479typedef FNRTFSMOUNTPOINTENUM *PFNRTFSMOUNTPOINTENUM;
480
481/**
482 * Enumerate mount points.
483 *
484 * @returns iprt status code.
485 * @param pfnCallback The callback function.
486 * @param pvUser The user argument to the callback.
487 */
488RTR3DECL(int) RTFsMountpointsEnum(PFNRTFSMOUNTPOINTENUM pfnCallback, void *pvUser);
489
490
491#endif /* IN_RING3 */
492
493/** @} */
494
495RT_C_DECLS_END
496
497#endif /* ___iprt_fs_h */
498
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