VirtualBox

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

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

*: scm --fix-header-guard-endif

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