VirtualBox

source: vbox/trunk/include/iprt/dvm.h@ 73460

Last change on this file since 73460 was 73156, checked in by vboxsync, 6 years ago

IPRT/DVM: Added more GUID and partition types. The VFS directory enum now returns symlink objects with the partition name linking to volXX when a name is present (there can be duplicates).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 13.0 KB
Line 
1/** @file
2 * IPRT Disk Volume Management API (DVM).
3 */
4
5/*
6 * Copyright (C) 2011-2017 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_dvm_h
27#define ___iprt_dvm_h
28
29#include <iprt/types.h>
30
31RT_C_DECLS_BEGIN
32
33
34/** @defgroup grp_dvm IPRT Disk Volume Management
35 * @{
36 */
37
38/**
39 * Volume type.
40 * Comparable to the FS type in MBR partition maps
41 * or the partition type GUIDs in GPT tables.
42 */
43typedef enum RTDVMVOLTYPE
44{
45 /** Invalid. */
46 RTDVMVOLTYPE_INVALID = 0,
47 /** Unknown. */
48 RTDVMVOLTYPE_UNKNOWN,
49 /** Volume hosts a NTFS filesystem. */
50 RTDVMVOLTYPE_NTFS,
51 /** Volume hosts a FAT12 filesystem. */
52 RTDVMVOLTYPE_FAT12,
53 /** Volume hosts a FAT16 filesystem. */
54 RTDVMVOLTYPE_FAT16,
55 /** Volume hosts a FAT32 filesystem. */
56 RTDVMVOLTYPE_FAT32,
57
58 /** EFI system partition (c12a7328-f81f-11d2-ba4b-00a0c93ec93b). */
59 RTDVMVOLTYPE_EFI_SYSTEM,
60
61 /** Volume hosts a Mac OS X HFS or HFS+ filesystem. */
62 RTDVMVOLTYPE_DARWIN_HFS,
63 /** Volume hosts a Mac OS X APFS filesystem. */
64 RTDVMVOLTYPE_DARWIN_APFS,
65
66 /** Volume hosts a Linux swap. */
67 RTDVMVOLTYPE_LINUX_SWAP,
68 /** Volume hosts a Linux filesystem. */
69 RTDVMVOLTYPE_LINUX_NATIVE,
70 /** Volume hosts a Linux LVM. */
71 RTDVMVOLTYPE_LINUX_LVM,
72 /** Volume hosts a Linux SoftRaid. */
73 RTDVMVOLTYPE_LINUX_SOFTRAID,
74
75 /** Volume hosts a FreeBSD disklabel. */
76 RTDVMVOLTYPE_FREEBSD,
77 /** Volume hosts a NetBSD disklabel. */
78 RTDVMVOLTYPE_NETBSD,
79 /** Volume hosts a OpenBSD disklabel. */
80 RTDVMVOLTYPE_OPENBSD,
81 /** Volume hosts a Solaris volume. */
82 RTDVMVOLTYPE_SOLARIS,
83
84 /** Volume hosts a Windows basic data partition . */
85 RTDVMVOLTYPE_WIN_BASIC,
86 /** Volume hosts a Microsoft reserved partition (MSR). */
87 RTDVMVOLTYPE_WIN_MSR,
88 /** Volume hosts a Windows logical disk manager (LDM) metadata partition. */
89 RTDVMVOLTYPE_WIN_LDM_META,
90 /** Volume hosts a Windows logical disk manager (LDM) data partition. */
91 RTDVMVOLTYPE_WIN_LDM_DATA,
92 /** Volume hosts a Windows recovery partition. */
93 RTDVMVOLTYPE_WIN_RECOVERY,
94 /** Volume hosts a storage spaces partition. */
95 RTDVMVOLTYPE_WIN_STORAGE_SPACES,
96
97 /** Volume hosts an IBM general parallel file system (GPFS). */
98 RTDVMVOLTYPE_IBM_GPFS,
99
100 /** End of the valid values. */
101 RTDVMVOLTYPE_END,
102 /** Usual 32bit hack. */
103 RTDVMVOLTYPE_32BIT_HACK = 0x7fffffff
104} RTDVMVOLTYPE;
105
106/** @defgroup grp_dvm_flags Flags used by RTDvmCreate.
107 * @{ */
108/** DVM flags - Blocks are always marked as unused if the volume has
109 * no block status callback set.
110 * The default is to mark them as used. */
111#define DVM_FLAGS_NO_STATUS_CALLBACK_MARK_AS_UNUSED RT_BIT_32(0)
112/** DVM flags - Space which is unused in the map will be marked as used
113 * when calling RTDvmMapQueryBlockStatus(). */
114#define DVM_FLAGS_UNUSED_SPACE_MARK_AS_USED RT_BIT_32(1)
115/** Mask of all valid flags. */
116#define DVM_FLAGS_VALID_MASK UINT32_C(0x00000003)
117/** @} */
118
119
120/** @defgroup grp_dvm_vol_flags Volume flags used by DVMVolumeGetFlags.
121 * @{ */
122/** Volume flags - Volume is bootable. */
123#define DVMVOLUME_FLAGS_BOOTABLE RT_BIT_64(0)
124/** Volume flags - Volume is active. */
125#define DVMVOLUME_FLAGS_ACTIVE RT_BIT_64(1)
126/** @} */
127
128/** A handle to a volume manager. */
129typedef struct RTDVMINTERNAL *RTDVM;
130/** A pointer to a volume manager handle. */
131typedef RTDVM *PRTDVM;
132/** NIL volume manager handle. */
133#define NIL_RTDVM ((RTDVM)~0)
134
135/** A handle to a volume in a volume map. */
136typedef struct RTDVMVOLUMEINTERNAL *RTDVMVOLUME;
137/** A pointer to a volume handle. */
138typedef RTDVMVOLUME *PRTDVMVOLUME;
139/** NIL volume handle. */
140#define NIL_RTDVMVOLUME ((RTDVMVOLUME)~0)
141
142/**
143 * Callback for querying the block allocation status of a volume.
144 *
145 * @returns IPRT status code.
146 * @param pvUser Opaque user data passed when setting the callback.
147 * @param off Offset relative to the start of the volume.
148 * @param cb Range to check in bytes.
149 * @param pfAllocated Where to store the allocation status on success.
150 */
151typedef DECLCALLBACK(int) FNDVMVOLUMEQUERYBLOCKSTATUS(void *pvUser, uint64_t off,
152 uint64_t cb, bool *pfAllocated);
153/** Pointer to a query block allocation status callback. */
154typedef FNDVMVOLUMEQUERYBLOCKSTATUS *PFNDVMVOLUMEQUERYBLOCKSTATUS;
155
156/**
157 * Create a new volume manager.
158 *
159 * @returns IPRT status.
160 * @param phVolMgr Where to store the handle to the volume manager on
161 * success.
162 * @param hVfsFile The disk/container/whatever.
163 * @param cbSector Size of one sector in bytes.
164 * @param fFlags Combination of RTDVM_FLAGS_*
165 */
166RTDECL(int) RTDvmCreate(PRTDVM phVolMgr, RTVFSFILE hVfsFile, uint32_t cbSector, uint32_t fFlags);
167
168/**
169 * Retain a given volume manager.
170 *
171 * @returns New reference count on success, UINT32_MAX on failure.
172 * @param hVolMgr The volume manager to retain.
173 */
174RTDECL(uint32_t) RTDvmRetain(RTDVM hVolMgr);
175
176/**
177 * Releases a given volume manager.
178 *
179 * @returns New reference count on success (0 if closed), UINT32_MAX on failure.
180 * @param hVolMgr The volume manager to release.
181 */
182RTDECL(uint32_t) RTDvmRelease(RTDVM hVolMgr);
183
184/**
185 * Probes the underyling disk for the best volume manager format handler
186 * and opens it.
187 *
188 * @returns IPRT status code.
189 * @retval VERR_NOT_FOUND if no backend can handle the volume map on the disk.
190 * @param hVolMgr The volume manager handle.
191 */
192RTDECL(int) RTDvmMapOpen(RTDVM hVolMgr);
193
194/**
195 * Initializes a new volume map using the given format handler.
196 *
197 * @returns IPRT status code.
198 * @param hVolMgr The volume manager handle.
199 * @param pszFmt The format to use for the new map.
200 */
201RTDECL(int) RTDvmMapInitialize(RTDVM hVolMgr, const char *pszFmt);
202
203/**
204 * Gets the name of the currently used format of the disk map.
205 *
206 * @returns Name of the format.
207 * @param hVolMgr The volume manager handle.
208 */
209RTDECL(const char *) RTDvmMapGetFormatName(RTDVM hVolMgr);
210
211/**
212 * DVM format types.
213 */
214typedef enum RTDVMFORMATTYPE
215{
216 /** Invalid zero value. */
217 RTDVMFORMATTYPE_INVALID = 0,
218 /** Master boot record. */
219 RTDVMFORMATTYPE_MBR,
220 /** GUID partition table. */
221 RTDVMFORMATTYPE_GPT,
222 /** BSD labels. */
223 RTDVMFORMATTYPE_BSD_LABLE,
224 /** End of valid values. */
225 RTDVMFORMATTYPE_END,
226 /** 32-bit type size hack. */
227 RTDVMFORMATTYPE_32BIT_HACK = 0x7fffffff
228} RTDVMFORMATTYPE;
229
230/**
231 * Gets the format type of the current disk map.
232 *
233 * @returns Format type. RTDVMFORMATTYPE_INVALID on invalid input.
234 * @param hVolMgr The volume manager handle.
235 */
236RTDECL(RTDVMFORMATTYPE) RTDvmMapGetFormatType(RTDVM hVolMgr);
237
238/**
239 * Gets the number of valid partitions in the map.
240 *
241 * @returns The number of valid volumes in the map or UINT32_MAX on failure.
242 * @param hVolMgr The volume manager handle.
243 */
244RTDECL(uint32_t) RTDvmMapGetValidVolumes(RTDVM hVolMgr);
245
246/**
247 * Gets the maximum number of partitions the map can hold.
248 *
249 * @returns The maximum number of volumes in the map or UINT32_MAX on failure.
250 * @param hVolMgr The volume manager handle.
251 */
252RTDECL(uint32_t) RTDvmMapGetMaxVolumes(RTDVM hVolMgr);
253
254/**
255 * Get the first valid volume from a map.
256 *
257 * @returns IPRT status code.
258 * @param hVolMgr The volume manager handle.
259 * @param phVol Where to store the handle to the first volume on
260 * success. Release with RTDvmVolumeRelease().
261 */
262RTDECL(int) RTDvmMapQueryFirstVolume(RTDVM hVolMgr, PRTDVMVOLUME phVol);
263
264/**
265 * Get the first valid volume from a map.
266 *
267 * @returns IPRT status code.
268 * @param hVolMgr The volume manager handle.
269 * @param hVol Handle of the current volume.
270 * @param phVolNext Where to store the handle to the next volume on
271 * success. Release with RTDvmVolumeRelease().
272 */
273RTDECL(int) RTDvmMapQueryNextVolume(RTDVM hVolMgr, RTDVMVOLUME hVol, PRTDVMVOLUME phVolNext);
274
275/**
276 * Returns whether the given block on the disk is in use.
277 *
278 * @returns IPRT status code.
279 * @param hVolMgr The volume manager handler.
280 * @param off The start offset to check for.
281 * @param cb The range in bytes to check.
282 * @param pfAllocated Where to store the in-use status on success.
283 *
284 * @remark This method will return true even if a part of the range is not in use.
285 */
286RTDECL(int) RTDvmMapQueryBlockStatus(RTDVM hVolMgr, uint64_t off, uint64_t cb, bool *pfAllocated);
287
288/**
289 * Retains a valid volume handle.
290 *
291 * @returns New reference count on success, UINT32_MAX on failure.
292 * @param hVol The volume to retain.
293 */
294RTDECL(uint32_t) RTDvmVolumeRetain(RTDVMVOLUME hVol);
295
296/**
297 * Releases a valid volume handle.
298 *
299 * @returns New reference count on success (0 if closed), UINT32_MAX on failure.
300 * @param hVol The volume to release.
301 */
302RTDECL(uint32_t) RTDvmVolumeRelease(RTDVMVOLUME hVol);
303
304/**
305 * Sets the callback to query the block allocation status for a volume.
306 * This overwrites any other callback set previously.
307 *
308 * @returns nothing.
309 * @param hVol The volume handle.
310 * @param pfnQueryBlockStatus The callback to set. Can be NULL to disable
311 * a previous callback.
312 * @param pvUser Opaque user data passed in the callback.
313 */
314RTDECL(void) RTDvmVolumeSetQueryBlockStatusCallback(RTDVMVOLUME hVol,
315 PFNDVMVOLUMEQUERYBLOCKSTATUS pfnQueryBlockStatus,
316 void *pvUser);
317
318/**
319 * Get the size of a volume in bytes.
320 *
321 * @returns Size of the volume in bytes or 0 on failure.
322 * @param hVol The volume handle.
323 */
324RTDECL(uint64_t) RTDvmVolumeGetSize(RTDVMVOLUME hVol);
325
326/**
327 * Gets the name of the volume if supported.
328 *
329 * @returns IPRT status code.
330 * @param hVol The volume handle.
331 * @param ppszVolName Where to store the name of the volume on success.
332 * The string must be freed with RTStrFree().
333 */
334RTDECL(int) RTDvmVolumeQueryName(RTDVMVOLUME hVol, char **ppszVolName);
335
336/**
337 * Get the volume type of the volume if supported.
338 *
339 * @returns The volume type on success, DVMVOLTYPE_INVALID if hVol is invalid.
340 * @param hVol The volume handle.
341 */
342RTDECL(RTDVMVOLTYPE) RTDvmVolumeGetType(RTDVMVOLUME hVol);
343
344/**
345 * Get the volume flags of the volume if supported.
346 *
347 * @returns The volume flags or UINT64_MAX on failure.
348 * @param hVol The volume handle.
349 */
350RTDECL(uint64_t) RTDvmVolumeGetFlags(RTDVMVOLUME hVol);
351
352/**
353 * Reads data from the given volume.
354 *
355 * @returns IPRT status code.
356 * @param hVol The volume handle.
357 * @param off Where to start reading from - 0 is the beginning of
358 * the volume.
359 * @param pvBuf Where to store the read data.
360 * @param cbRead How many bytes to read.
361 */
362RTDECL(int) RTDvmVolumeRead(RTDVMVOLUME hVol, uint64_t off, void *pvBuf, size_t cbRead);
363
364/**
365 * Writes data to the given volume.
366 *
367 * @returns IPRT status code.
368 * @param hVol The volume handle.
369 * @param off Where to start writing to - 0 is the beginning of
370 * the volume.
371 * @param pvBuf The data to write.
372 * @param cbWrite How many bytes to write.
373 */
374RTDECL(int) RTDvmVolumeWrite(RTDVMVOLUME hVol, uint64_t off, const void *pvBuf, size_t cbWrite);
375
376/**
377 * Returns the description of a given volume type.
378 *
379 * @returns The description of the type.
380 * @param enmVolType The volume type.
381 */
382RTDECL(const char *) RTDvmVolumeTypeGetDescr(RTDVMVOLTYPE enmVolType);
383
384/**
385 * Creates an VFS file from a volume handle.
386 *
387 * @returns IPRT status code.
388 * @param hVol The volume handle.
389 * @param fOpen RTFILE_O_XXX.
390 * @param phVfsFileOut Where to store the VFS file handle on success.
391 */
392RTDECL(int) RTDvmVolumeCreateVfsFile(RTDVMVOLUME hVol, uint64_t fOpen, PRTVFSFILE phVfsFileOut);
393
394RT_C_DECLS_END
395
396/** @} */
397
398#endif
399
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