1 | /** @file
|
---|
2 | * IPRT Disk Volume Management API (DVM).
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2011-2022 Oracle and/or its affiliates.
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox base platform packages, as
|
---|
9 | * available from https://www.virtualbox.org.
|
---|
10 | *
|
---|
11 | * This program is free software; you can redistribute it and/or
|
---|
12 | * modify it under the terms of the GNU General Public License
|
---|
13 | * as published by the Free Software Foundation, in version 3 of the
|
---|
14 | * License.
|
---|
15 | *
|
---|
16 | * This program is distributed in the hope that it will be useful, but
|
---|
17 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
19 | * General Public License for more details.
|
---|
20 | *
|
---|
21 | * You should have received a copy of the GNU General Public License
|
---|
22 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
23 | *
|
---|
24 | * The contents of this file may alternatively be used under the terms
|
---|
25 | * of the Common Development and Distribution License Version 1.0
|
---|
26 | * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
27 | * in the VirtualBox distribution, in which case the provisions of the
|
---|
28 | * CDDL are applicable instead of those of the GPL.
|
---|
29 | *
|
---|
30 | * You may elect to license modified versions of this file under the
|
---|
31 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
32 | *
|
---|
33 | * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
34 | */
|
---|
35 |
|
---|
36 | #ifndef IPRT_INCLUDED_dvm_h
|
---|
37 | #define IPRT_INCLUDED_dvm_h
|
---|
38 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
39 | # pragma once
|
---|
40 | #endif
|
---|
41 |
|
---|
42 | #include <iprt/types.h>
|
---|
43 |
|
---|
44 | RT_C_DECLS_BEGIN
|
---|
45 |
|
---|
46 |
|
---|
47 | /** @defgroup grp_dvm IPRT Disk Volume Management
|
---|
48 | * @{
|
---|
49 | */
|
---|
50 |
|
---|
51 | /**
|
---|
52 | * Volume type.
|
---|
53 | * Comparable to the FS type in MBR partition maps
|
---|
54 | * or the partition type GUIDs in GPT tables.
|
---|
55 | */
|
---|
56 | typedef enum RTDVMVOLTYPE
|
---|
57 | {
|
---|
58 | /** Invalid. */
|
---|
59 | RTDVMVOLTYPE_INVALID = 0,
|
---|
60 | /** Unknown. */
|
---|
61 | RTDVMVOLTYPE_UNKNOWN,
|
---|
62 | /** Volume hosts a NTFS filesystem. */
|
---|
63 | RTDVMVOLTYPE_NTFS,
|
---|
64 | /** Volume hosts a FAT12 filesystem. */
|
---|
65 | RTDVMVOLTYPE_FAT12,
|
---|
66 | /** Volume hosts a FAT16 filesystem. */
|
---|
67 | RTDVMVOLTYPE_FAT16,
|
---|
68 | /** Volume hosts a FAT32 filesystem. */
|
---|
69 | RTDVMVOLTYPE_FAT32,
|
---|
70 |
|
---|
71 | /** EFI system partition (c12a7328-f81f-11d2-ba4b-00a0c93ec93b). */
|
---|
72 | RTDVMVOLTYPE_EFI_SYSTEM,
|
---|
73 |
|
---|
74 | /** Volume hosts a Mac OS X HFS or HFS+ filesystem. */
|
---|
75 | RTDVMVOLTYPE_DARWIN_HFS,
|
---|
76 | /** Volume hosts a Mac OS X APFS filesystem. */
|
---|
77 | RTDVMVOLTYPE_DARWIN_APFS,
|
---|
78 |
|
---|
79 | /** Volume hosts a Linux swap. */
|
---|
80 | RTDVMVOLTYPE_LINUX_SWAP,
|
---|
81 | /** Volume hosts a Linux filesystem. */
|
---|
82 | RTDVMVOLTYPE_LINUX_NATIVE,
|
---|
83 | /** Volume hosts a Linux LVM. */
|
---|
84 | RTDVMVOLTYPE_LINUX_LVM,
|
---|
85 | /** Volume hosts a Linux SoftRaid. */
|
---|
86 | RTDVMVOLTYPE_LINUX_SOFTRAID,
|
---|
87 |
|
---|
88 | /** Volume hosts a FreeBSD disklabel. */
|
---|
89 | RTDVMVOLTYPE_FREEBSD,
|
---|
90 | /** Volume hosts a NetBSD disklabel. */
|
---|
91 | RTDVMVOLTYPE_NETBSD,
|
---|
92 | /** Volume hosts a OpenBSD disklabel. */
|
---|
93 | RTDVMVOLTYPE_OPENBSD,
|
---|
94 | /** Volume hosts a Solaris volume. */
|
---|
95 | RTDVMVOLTYPE_SOLARIS,
|
---|
96 |
|
---|
97 | /** Volume hosts a Windows basic data partition . */
|
---|
98 | RTDVMVOLTYPE_WIN_BASIC,
|
---|
99 | /** Volume hosts a Microsoft reserved partition (MSR). */
|
---|
100 | RTDVMVOLTYPE_WIN_MSR,
|
---|
101 | /** Volume hosts a Windows logical disk manager (LDM) metadata partition. */
|
---|
102 | RTDVMVOLTYPE_WIN_LDM_META,
|
---|
103 | /** Volume hosts a Windows logical disk manager (LDM) data partition. */
|
---|
104 | RTDVMVOLTYPE_WIN_LDM_DATA,
|
---|
105 | /** Volume hosts a Windows recovery partition. */
|
---|
106 | RTDVMVOLTYPE_WIN_RECOVERY,
|
---|
107 | /** Volume hosts a storage spaces partition. */
|
---|
108 | RTDVMVOLTYPE_WIN_STORAGE_SPACES,
|
---|
109 |
|
---|
110 | /** Volume hosts an IBM general parallel file system (GPFS). */
|
---|
111 | RTDVMVOLTYPE_IBM_GPFS,
|
---|
112 |
|
---|
113 | /** OS/2 (Arca Noae) type 1 partition. */
|
---|
114 | RTDVMVOLTYPE_ARCA_OS2,
|
---|
115 |
|
---|
116 | /** End of the valid values. */
|
---|
117 | RTDVMVOLTYPE_END,
|
---|
118 | /** Usual 32bit hack. */
|
---|
119 | RTDVMVOLTYPE_32BIT_HACK = 0x7fffffff
|
---|
120 | } RTDVMVOLTYPE;
|
---|
121 |
|
---|
122 | /** @defgroup grp_dvm_flags Flags used by RTDvmCreate.
|
---|
123 | * @{ */
|
---|
124 | /** DVM flags - Blocks are always marked as unused if the volume has
|
---|
125 | * no block status callback set.
|
---|
126 | * The default is to mark them as used. */
|
---|
127 | #define DVM_FLAGS_NO_STATUS_CALLBACK_MARK_AS_UNUSED RT_BIT_32(0)
|
---|
128 | /** DVM flags - Space which is unused in the map will be marked as used
|
---|
129 | * when calling RTDvmMapQueryBlockStatus(). */
|
---|
130 | #define DVM_FLAGS_UNUSED_SPACE_MARK_AS_USED RT_BIT_32(1)
|
---|
131 | /** Mask of all valid flags. */
|
---|
132 | #define DVM_FLAGS_VALID_MASK UINT32_C(0x00000003)
|
---|
133 | /** @} */
|
---|
134 |
|
---|
135 |
|
---|
136 | /** @defgroup grp_dvm_vol_flags Volume flags used by RTDvmVolumeGetFlags().
|
---|
137 | * @{ */
|
---|
138 | /** Volume flags - Volume is bootable. */
|
---|
139 | #define DVMVOLUME_FLAGS_BOOTABLE RT_BIT_64(0)
|
---|
140 | /** Volume flags - Volume is active. */
|
---|
141 | #define DVMVOLUME_FLAGS_ACTIVE RT_BIT_64(1)
|
---|
142 | /** Volume is contiguous on the underlying medium and RTDvmVolumeQueryRange(). */
|
---|
143 | #define DVMVOLUME_F_CONTIGUOUS RT_BIT_64(2)
|
---|
144 | /** @} */
|
---|
145 |
|
---|
146 | /** A handle to a volume manager. */
|
---|
147 | typedef struct RTDVMINTERNAL *RTDVM;
|
---|
148 | /** A pointer to a volume manager handle. */
|
---|
149 | typedef RTDVM *PRTDVM;
|
---|
150 | /** NIL volume manager handle. */
|
---|
151 | #define NIL_RTDVM ((RTDVM)~0)
|
---|
152 |
|
---|
153 | /** A handle to a volume in a volume map. */
|
---|
154 | typedef struct RTDVMVOLUMEINTERNAL *RTDVMVOLUME;
|
---|
155 | /** A pointer to a volume handle. */
|
---|
156 | typedef RTDVMVOLUME *PRTDVMVOLUME;
|
---|
157 | /** NIL volume handle. */
|
---|
158 | #define NIL_RTDVMVOLUME ((RTDVMVOLUME)~0)
|
---|
159 |
|
---|
160 | /**
|
---|
161 | * Callback for querying the block allocation status of a volume.
|
---|
162 | *
|
---|
163 | * @returns IPRT status code.
|
---|
164 | * @param pvUser Opaque user data passed when setting the callback.
|
---|
165 | * @param off Offset relative to the start of the volume.
|
---|
166 | * @param cb Range to check in bytes.
|
---|
167 | * @param pfAllocated Where to store the allocation status on success.
|
---|
168 | */
|
---|
169 | typedef DECLCALLBACKTYPE(int, FNDVMVOLUMEQUERYBLOCKSTATUS,(void *pvUser, uint64_t off, uint64_t cb, bool *pfAllocated));
|
---|
170 | /** Pointer to a query block allocation status callback. */
|
---|
171 | typedef FNDVMVOLUMEQUERYBLOCKSTATUS *PFNDVMVOLUMEQUERYBLOCKSTATUS;
|
---|
172 |
|
---|
173 | /**
|
---|
174 | * Create a new volume manager.
|
---|
175 | *
|
---|
176 | * @returns IPRT status.
|
---|
177 | * @param phVolMgr Where to store the handle to the volume manager on
|
---|
178 | * success.
|
---|
179 | * @param hVfsFile The disk/container/whatever.
|
---|
180 | * @param cbSector Size of one sector in bytes.
|
---|
181 | * @param fFlags Combination of RTDVM_FLAGS_*
|
---|
182 | */
|
---|
183 | RTDECL(int) RTDvmCreate(PRTDVM phVolMgr, RTVFSFILE hVfsFile, uint32_t cbSector, uint32_t fFlags);
|
---|
184 |
|
---|
185 | /**
|
---|
186 | * Retain a given volume manager.
|
---|
187 | *
|
---|
188 | * @returns New reference count on success, UINT32_MAX on failure.
|
---|
189 | * @param hVolMgr The volume manager to retain.
|
---|
190 | */
|
---|
191 | RTDECL(uint32_t) RTDvmRetain(RTDVM hVolMgr);
|
---|
192 |
|
---|
193 | /**
|
---|
194 | * Releases a given volume manager.
|
---|
195 | *
|
---|
196 | * @returns New reference count on success (0 if closed), UINT32_MAX on failure.
|
---|
197 | * @param hVolMgr The volume manager to release.
|
---|
198 | */
|
---|
199 | RTDECL(uint32_t) RTDvmRelease(RTDVM hVolMgr);
|
---|
200 |
|
---|
201 | /**
|
---|
202 | * Probes the underyling disk for the best volume manager format handler
|
---|
203 | * and opens it.
|
---|
204 | *
|
---|
205 | * @returns IPRT status code.
|
---|
206 | * @retval VERR_NOT_FOUND if no backend can handle the volume map on the disk.
|
---|
207 | * @param hVolMgr The volume manager handle.
|
---|
208 | */
|
---|
209 | RTDECL(int) RTDvmMapOpen(RTDVM hVolMgr);
|
---|
210 |
|
---|
211 | /**
|
---|
212 | * Initializes a new volume map using the given format handler.
|
---|
213 | *
|
---|
214 | * @returns IPRT status code.
|
---|
215 | * @param hVolMgr The volume manager handle.
|
---|
216 | * @param pszFmt The format to use for the new map.
|
---|
217 | */
|
---|
218 | RTDECL(int) RTDvmMapInitialize(RTDVM hVolMgr, const char *pszFmt);
|
---|
219 |
|
---|
220 | /**
|
---|
221 | * Gets the name of the currently used format of the disk map.
|
---|
222 | *
|
---|
223 | * @returns Name of the format.
|
---|
224 | * @param hVolMgr The volume manager handle.
|
---|
225 | */
|
---|
226 | RTDECL(const char *) RTDvmMapGetFormatName(RTDVM hVolMgr);
|
---|
227 |
|
---|
228 | /**
|
---|
229 | * DVM format types.
|
---|
230 | */
|
---|
231 | typedef enum RTDVMFORMATTYPE
|
---|
232 | {
|
---|
233 | /** Invalid zero value. */
|
---|
234 | RTDVMFORMATTYPE_INVALID = 0,
|
---|
235 | /** Master boot record. */
|
---|
236 | RTDVMFORMATTYPE_MBR,
|
---|
237 | /** GUID partition table. */
|
---|
238 | RTDVMFORMATTYPE_GPT,
|
---|
239 | /** BSD labels. */
|
---|
240 | RTDVMFORMATTYPE_BSD_LABEL,
|
---|
241 | /** End of valid values. */
|
---|
242 | RTDVMFORMATTYPE_END,
|
---|
243 | /** 32-bit type size hack. */
|
---|
244 | RTDVMFORMATTYPE_32BIT_HACK = 0x7fffffff
|
---|
245 | } RTDVMFORMATTYPE;
|
---|
246 |
|
---|
247 | /**
|
---|
248 | * Gets the format type of the current disk map.
|
---|
249 | *
|
---|
250 | * @returns Format type. RTDVMFORMATTYPE_INVALID on invalid input.
|
---|
251 | * @param hVolMgr The volume manager handle.
|
---|
252 | */
|
---|
253 | RTDECL(RTDVMFORMATTYPE) RTDvmMapGetFormatType(RTDVM hVolMgr);
|
---|
254 |
|
---|
255 | /**
|
---|
256 | * Gets the UUID of the disk if applicable.
|
---|
257 | *
|
---|
258 | * Disks using the MBR format may return the 32-bit disk identity in the
|
---|
259 | * u32TimeLow field and set the rest to zero.
|
---|
260 | *
|
---|
261 | * @returns IPRT status code.
|
---|
262 | * @retval VERR_NOT_SUPPORTED if the partition scheme doesn't do UUIDs.
|
---|
263 | * @retval VINF_NOT_SUPPORTED if non-UUID disk ID is returned.
|
---|
264 | * @param hVolMgr The volume manager handle.
|
---|
265 | * @param pUuid Where to return the UUID.
|
---|
266 | *
|
---|
267 | * @todo It's quite possible this should be turned into a map-level edition of
|
---|
268 | * RTDvmVolumeQueryProp...
|
---|
269 | */
|
---|
270 | RTDECL(int) RTDvmMapQueryDiskUuid(RTDVM hVolMgr, PRTUUID pUuid);
|
---|
271 |
|
---|
272 | /**
|
---|
273 | * Gets the number of valid partitions in the map.
|
---|
274 | *
|
---|
275 | * @returns The number of valid volumes in the map or UINT32_MAX on failure.
|
---|
276 | * @param hVolMgr The volume manager handle.
|
---|
277 | */
|
---|
278 | RTDECL(uint32_t) RTDvmMapGetValidVolumes(RTDVM hVolMgr);
|
---|
279 |
|
---|
280 | /**
|
---|
281 | * Gets the maximum number of partitions the map can hold.
|
---|
282 | *
|
---|
283 | * @returns The maximum number of volumes in the map or UINT32_MAX on failure.
|
---|
284 | * @param hVolMgr The volume manager handle.
|
---|
285 | */
|
---|
286 | RTDECL(uint32_t) RTDvmMapGetMaxVolumes(RTDVM hVolMgr);
|
---|
287 |
|
---|
288 | /**
|
---|
289 | * Get the first valid volume from a map.
|
---|
290 | *
|
---|
291 | * @returns IPRT status code.
|
---|
292 | * @param hVolMgr The volume manager handle.
|
---|
293 | * @param phVol Where to store the handle to the first volume on
|
---|
294 | * success. Release with RTDvmVolumeRelease().
|
---|
295 | */
|
---|
296 | RTDECL(int) RTDvmMapQueryFirstVolume(RTDVM hVolMgr, PRTDVMVOLUME phVol);
|
---|
297 |
|
---|
298 | /**
|
---|
299 | * Get the first valid volume from a map.
|
---|
300 | *
|
---|
301 | * @returns IPRT status code.
|
---|
302 | * @param hVolMgr The volume manager handle.
|
---|
303 | * @param hVol Handle of the current volume.
|
---|
304 | * @param phVolNext Where to store the handle to the next volume on
|
---|
305 | * success. Release with RTDvmVolumeRelease().
|
---|
306 | */
|
---|
307 | RTDECL(int) RTDvmMapQueryNextVolume(RTDVM hVolMgr, RTDVMVOLUME hVol, PRTDVMVOLUME phVolNext);
|
---|
308 |
|
---|
309 | /**
|
---|
310 | * Returns whether the given block on the disk is in use.
|
---|
311 | *
|
---|
312 | * @returns IPRT status code.
|
---|
313 | * @param hVolMgr The volume manager handle.
|
---|
314 | * @param off The start offset to check for.
|
---|
315 | * @param cb The range in bytes to check.
|
---|
316 | * @param pfAllocated Where to store the in-use status on success.
|
---|
317 | *
|
---|
318 | * @remark This method will return true even if a part of the range is not in use.
|
---|
319 | */
|
---|
320 | RTDECL(int) RTDvmMapQueryBlockStatus(RTDVM hVolMgr, uint64_t off, uint64_t cb, bool *pfAllocated);
|
---|
321 |
|
---|
322 | /**
|
---|
323 | * Partition/map table location information.
|
---|
324 | * @sa RTDvmMapQueryTableLocations
|
---|
325 | */
|
---|
326 | typedef struct RTDVMTABLELOCATION
|
---|
327 | {
|
---|
328 | /** The byte offset on the underlying media. */
|
---|
329 | uint64_t off;
|
---|
330 | /** The table size in bytes. */
|
---|
331 | uint64_t cb;
|
---|
332 | /** Number of padding bytes / free space between the actual table and
|
---|
333 | * first partition. */
|
---|
334 | uint64_t cbPadding;
|
---|
335 | } RTDVMTABLELOCATION;
|
---|
336 | /** Pointer to partition table location info. */
|
---|
337 | typedef RTDVMTABLELOCATION *PRTDVMTABLELOCATION;
|
---|
338 | /** Pointer to const partition table location info. */
|
---|
339 | typedef RTDVMTABLELOCATION const *PCRTDVMTABLELOCATION;
|
---|
340 |
|
---|
341 |
|
---|
342 | /** @name RTDVMMAPQTABLOC_F_XXX - Flags for RTDvmMapQueryTableLocations
|
---|
343 | * @{ */
|
---|
344 | /** Make sure GPT includes the protective MBR. */
|
---|
345 | #define RTDVMMAPQTABLOC_F_INCLUDE_LEGACY RT_BIT_32(0)
|
---|
346 | /** Valid flags. */
|
---|
347 | #define RTDVMMAPQTABLOC_F_VALID_MASK UINT32_C(1)
|
---|
348 | /** @} */
|
---|
349 |
|
---|
350 | /**
|
---|
351 | * Query the partition table locations.
|
---|
352 | *
|
---|
353 | * @returns IPRT status code.
|
---|
354 | * @retval VERR_BUFFER_OVERFLOW if the table is too small, @a *pcActual will be
|
---|
355 | * set to the required size.
|
---|
356 | * @retval VERR_BUFFER_UNDERFLOW if the table is too big and @a pcActual is
|
---|
357 | * NULL.
|
---|
358 | * @param hVolMgr The volume manager handle.
|
---|
359 | * @param fFlags Flags, see RTDVMMAPQTABLOC_F_XXX.
|
---|
360 | * @param paLocations Where to return the info. This can be NULL if @a
|
---|
361 | * cLocations is zero and @a pcActual is given.
|
---|
362 | * @param cLocations The size of @a paLocations in items.
|
---|
363 | * @param pcActual Where to return the actual number of locations, or
|
---|
364 | * on VERR_BUFFER_OVERFLOW the necessary table size.
|
---|
365 | * Optional, when not specified the cLocations value
|
---|
366 | * must match exactly or it fails with
|
---|
367 | * VERR_BUFFER_UNDERFLOW.
|
---|
368 | */
|
---|
369 | RTDECL(int) RTDvmMapQueryTableLocations(RTDVM hVolMgr, uint32_t fFlags,
|
---|
370 | PRTDVMTABLELOCATION paLocations, size_t cLocations, size_t *pcActual);
|
---|
371 |
|
---|
372 | /**
|
---|
373 | * Retains a valid volume handle.
|
---|
374 | *
|
---|
375 | * @returns New reference count on success, UINT32_MAX on failure.
|
---|
376 | * @param hVol The volume to retain.
|
---|
377 | */
|
---|
378 | RTDECL(uint32_t) RTDvmVolumeRetain(RTDVMVOLUME hVol);
|
---|
379 |
|
---|
380 | /**
|
---|
381 | * Releases a valid volume handle.
|
---|
382 | *
|
---|
383 | * @returns New reference count on success (0 if closed), UINT32_MAX on failure.
|
---|
384 | * @param hVol The volume to release.
|
---|
385 | */
|
---|
386 | RTDECL(uint32_t) RTDvmVolumeRelease(RTDVMVOLUME hVol);
|
---|
387 |
|
---|
388 | /**
|
---|
389 | * Sets the callback to query the block allocation status for a volume.
|
---|
390 | * This overwrites any other callback set previously.
|
---|
391 | *
|
---|
392 | * @returns nothing.
|
---|
393 | * @param hVol The volume handle.
|
---|
394 | * @param pfnQueryBlockStatus The callback to set. Can be NULL to disable
|
---|
395 | * a previous callback.
|
---|
396 | * @param pvUser Opaque user data passed in the callback.
|
---|
397 | */
|
---|
398 | RTDECL(void) RTDvmVolumeSetQueryBlockStatusCallback(RTDVMVOLUME hVol,
|
---|
399 | PFNDVMVOLUMEQUERYBLOCKSTATUS pfnQueryBlockStatus,
|
---|
400 | void *pvUser);
|
---|
401 |
|
---|
402 | /**
|
---|
403 | * Get the size of a volume in bytes.
|
---|
404 | *
|
---|
405 | * @returns Size of the volume in bytes or 0 on failure.
|
---|
406 | * @param hVol The volume handle.
|
---|
407 | */
|
---|
408 | RTDECL(uint64_t) RTDvmVolumeGetSize(RTDVMVOLUME hVol);
|
---|
409 |
|
---|
410 | /**
|
---|
411 | * Gets the name of the volume if supported.
|
---|
412 | *
|
---|
413 | * @returns IPRT status code.
|
---|
414 | * @param hVol The volume handle.
|
---|
415 | * @param ppszVolName Where to store the name of the volume on success.
|
---|
416 | * The string must be freed with RTStrFree().
|
---|
417 | */
|
---|
418 | RTDECL(int) RTDvmVolumeQueryName(RTDVMVOLUME hVol, char **ppszVolName);
|
---|
419 |
|
---|
420 | /**
|
---|
421 | * Get the volume type of the volume if supported.
|
---|
422 | *
|
---|
423 | * @returns The volume type on success, DVMVOLTYPE_INVALID if hVol is invalid.
|
---|
424 | * @param hVol The volume handle.
|
---|
425 | */
|
---|
426 | RTDECL(RTDVMVOLTYPE) RTDvmVolumeGetType(RTDVMVOLUME hVol);
|
---|
427 |
|
---|
428 | /**
|
---|
429 | * Get the volume flags of the volume if supported.
|
---|
430 | *
|
---|
431 | * @returns The volume flags or UINT64_MAX on failure.
|
---|
432 | * @param hVol The volume handle.
|
---|
433 | */
|
---|
434 | RTDECL(uint64_t) RTDvmVolumeGetFlags(RTDVMVOLUME hVol);
|
---|
435 |
|
---|
436 | /**
|
---|
437 | * Queries the range of the given volume on the underlying medium.
|
---|
438 | *
|
---|
439 | * @returns IPRT status code.
|
---|
440 | * @retval VERR_NOT_SUPPORTED if the DVMVOLUME_F_CONTIGUOUS flag is not returned by RTDvmVolumeGetFlags().
|
---|
441 | * @param hVol The volume handle.
|
---|
442 | * @param poffStart Where to store the start offset in bytes on the underlying medium.
|
---|
443 | * @param poffLast Where to store the last offset in bytes on the underlying medium (inclusive).
|
---|
444 | */
|
---|
445 | RTDECL(int) RTDvmVolumeQueryRange(RTDVMVOLUME hVol, uint64_t *poffStart, uint64_t *poffLast);
|
---|
446 |
|
---|
447 | /**
|
---|
448 | * Returns the partition/whatever table location of the volume.
|
---|
449 | *
|
---|
450 | * For volume format with a single table, like GPT and BSD-labels, it will
|
---|
451 | * return the location of that table. Though for GPT, the fake MBR will not be
|
---|
452 | * included.
|
---|
453 | *
|
---|
454 | * For logical (extended) MBR-style volumes, this will return the location of
|
---|
455 | * the extended partition table. For primary volumes the MBR location is
|
---|
456 | * returned. The special MBR case is why this operation is done on the volume
|
---|
457 | * rather than the volume manager.
|
---|
458 | *
|
---|
459 | * Using RTDvmVolumeGetIndex with RTDVMVOLIDX_IN_PART_TABLE should get you
|
---|
460 | * the index in the table returned by this function.
|
---|
461 | *
|
---|
462 | * @returns IPRT status code.
|
---|
463 | * @param hVol The volume handle.
|
---|
464 | * @param poffTable Where to return the byte offset on the underlying
|
---|
465 | * media of the (partition/volume/whatever) table.
|
---|
466 | * @param pcbTable Where to return the table size in bytes. (This does
|
---|
467 | * not include any alignment padding or such, just
|
---|
468 | * padding up to sector/block size.)
|
---|
469 | */
|
---|
470 | RTDECL(int) RTDvmVolumeQueryTableLocation(RTDVMVOLUME hVol, uint64_t *poffTable, uint64_t *pcbTable);
|
---|
471 |
|
---|
472 | /**
|
---|
473 | * RTDvmVolumeGetIndex indexes.
|
---|
474 | */
|
---|
475 | typedef enum RTDVMVOLIDX
|
---|
476 | {
|
---|
477 | /** Invalid zero value. */
|
---|
478 | RTDVMVOLIDX_INVALID = 0,
|
---|
479 | /** Index matching the host's volume numbering.
|
---|
480 | * This is a pseudo index, that gets translated to one of the others depending
|
---|
481 | * on which host we're running on. */
|
---|
482 | RTDVMVOLIDX_HOST,
|
---|
483 | /** Only consider user visible ones, i.e. don't count MBR extended partition
|
---|
484 | * entries and such like. */
|
---|
485 | RTDVMVOLIDX_USER_VISIBLE,
|
---|
486 | /** Index when all volumes, user visible, hidden, special, whatever ones are
|
---|
487 | * included.
|
---|
488 | *
|
---|
489 | * For MBR this is 1-based index where all primary entires are included whether
|
---|
490 | * in use or not. Only non-empty entries in extended tables are counted, though
|
---|
491 | * the forward link is included. */
|
---|
492 | RTDVMVOLIDX_ALL,
|
---|
493 | /** The raw index within the partition/volume/whatever table. This have a kind
|
---|
494 | * of special meaning to MBR, where there are multiple tables. */
|
---|
495 | RTDVMVOLIDX_IN_TABLE,
|
---|
496 | /** Follows the linux /dev/sdaX convention as closely as absolutely possible. */
|
---|
497 | RTDVMVOLIDX_LINUX,
|
---|
498 | /** End of valid indexes. */
|
---|
499 | RTDVMVOLIDX_END,
|
---|
500 | /** Make sure the type is 32-bit. */
|
---|
501 | RTDVMVOLIDX_32BIT_HACK = 0x7fffffff
|
---|
502 | } RTDVMVOLIDX;
|
---|
503 |
|
---|
504 | /**
|
---|
505 | * Gets the tiven index for the specified volume.
|
---|
506 | *
|
---|
507 | * @returns The requested index, UINT32_MAX on failure.
|
---|
508 | * @param hVol The volume handle.
|
---|
509 | * @param enmIndex Which kind of index to get for the volume.
|
---|
510 | */
|
---|
511 | RTDECL(uint32_t) RTDvmVolumeGetIndex(RTDVMVOLUME hVol, RTDVMVOLIDX enmIndex);
|
---|
512 |
|
---|
513 | /**
|
---|
514 | * Volume properties queriable via RTDvmVolumeQueryProp.
|
---|
515 | *
|
---|
516 | * @note Integer values can typically be queried in multiple sizes. This is
|
---|
517 | * handled by the frontend code. The format specific backends only
|
---|
518 | * have to handle the smallest allowed size.
|
---|
519 | */
|
---|
520 | typedef enum RTDVMVOLPROP
|
---|
521 | {
|
---|
522 | /** Customary invalid zero value. */
|
---|
523 | RTDVMVOLPROP_INVALID = 0,
|
---|
524 | /** unsigned[16,32,64]: MBR first cylinder (0-based, CHS). */
|
---|
525 | RTDVMVOLPROP_MBR_FIRST_CYLINDER,
|
---|
526 | /** unsigned[8,16,32,64]: MBR first head (0-based, CHS). */
|
---|
527 | RTDVMVOLPROP_MBR_FIRST_HEAD,
|
---|
528 | /** unsigned[8,16,32,64]: MBR first sector (1-based, CHS). */
|
---|
529 | RTDVMVOLPROP_MBR_FIRST_SECTOR,
|
---|
530 | /** unsigned[16,32,64]: MBR last cylinder (0-based, CHS). */
|
---|
531 | RTDVMVOLPROP_MBR_LAST_CYLINDER,
|
---|
532 | /** unsigned[8,16,32,64]: MBR last head (0-based, CHS). */
|
---|
533 | RTDVMVOLPROP_MBR_LAST_HEAD,
|
---|
534 | /** unsigned[8,16,32,64]: MBR last sector (1-based, CHS). */
|
---|
535 | RTDVMVOLPROP_MBR_LAST_SECTOR,
|
---|
536 | /** unsigned[8,16,32,64]: MBR partition type. */
|
---|
537 | RTDVMVOLPROP_MBR_TYPE,
|
---|
538 | /** RTUUID: GPT volume type. */
|
---|
539 | RTDVMVOLPROP_GPT_TYPE,
|
---|
540 | /** RTUUID: GPT volume UUID. */
|
---|
541 | RTDVMVOLPROP_GPT_UUID,
|
---|
542 | /** End of valid values. */
|
---|
543 | RTDVMVOLPROP_END,
|
---|
544 | /** Make sure the type is 32-bit. */
|
---|
545 | RTDVMVOLPROP_32BIT_HACK = 0x7fffffff
|
---|
546 | } RTDVMVOLPROP;
|
---|
547 |
|
---|
548 | /**
|
---|
549 | * Query a generic volume property.
|
---|
550 | *
|
---|
551 | * This is an extensible interface for retrieving mostly format specific
|
---|
552 | * information, or information that's not commonly used. (It's modeled after
|
---|
553 | * RTLdrQueryPropEx.)
|
---|
554 | *
|
---|
555 | * @returns IPRT status code.
|
---|
556 | * @retval VERR_NOT_SUPPORTED if the property query isn't supported (either all
|
---|
557 | * or that specific property). The caller must handle this result.
|
---|
558 | * @retval VERR_NOT_FOUND is currently not returned, but intended for cases
|
---|
559 | * where it wasn't present in the tables.
|
---|
560 | * @retval VERR_INVALID_FUNCTION if the @a enmProperty value is wrong.
|
---|
561 | * @retval VERR_INVALID_PARAMETER if the fixed buffer size is wrong. Correct
|
---|
562 | * size in @a *pcbBuf.
|
---|
563 | * @retval VERR_BUFFER_OVERFLOW if the property doesn't have a fixed size
|
---|
564 | * buffer and the buffer isn't big enough. Correct size in @a *pcbBuf.
|
---|
565 | * @retval VERR_INVALID_HANDLE if the handle is invalid.
|
---|
566 | * @param hVol Handle to the volume.
|
---|
567 | * @param enmProperty The property to query.
|
---|
568 | * @param pvBuf Pointer to the input / output buffer. In most cases
|
---|
569 | * it's only used for returning data.
|
---|
570 | * @param cbBuf The size of the buffer.
|
---|
571 | * @param pcbBuf Where to return the amount of data returned. On
|
---|
572 | * buffer size errors, this is set to the correct size.
|
---|
573 | * Optional.
|
---|
574 | * @sa RTDvmVolumeGetPropU64
|
---|
575 | */
|
---|
576 | RTDECL(int) RTDvmVolumeQueryProp(RTDVMVOLUME hVol, RTDVMVOLPROP enmProperty, void *pvBuf, size_t cbBuf, size_t *pcbBuf);
|
---|
577 |
|
---|
578 | /**
|
---|
579 | * Wrapper around RTDvmVolumeQueryProp for simplifying getting unimportant
|
---|
580 | * integer properties.
|
---|
581 | *
|
---|
582 | * @returns The property value if supported and found, the default value if not.
|
---|
583 | * Errors other than VERR_NOT_SUPPORTED and VERR_NOT_FOUND are
|
---|
584 | * asserted.
|
---|
585 | * @param hVol Handle to the volume.
|
---|
586 | * @param enmProperty The property to query.
|
---|
587 | * @param uDefault The value to return on error.
|
---|
588 | * @sa RTDvmVolumeQueryProp
|
---|
589 | */
|
---|
590 | RTDECL(uint64_t) RTDvmVolumeGetPropU64(RTDVMVOLUME hVol, RTDVMVOLPROP enmProperty, uint64_t uDefault);
|
---|
591 |
|
---|
592 | /**
|
---|
593 | * Reads data from the given volume.
|
---|
594 | *
|
---|
595 | * @returns IPRT status code.
|
---|
596 | * @param hVol The volume handle.
|
---|
597 | * @param off Where to start reading from - 0 is the beginning of
|
---|
598 | * the volume.
|
---|
599 | * @param pvBuf Where to store the read data.
|
---|
600 | * @param cbRead How many bytes to read.
|
---|
601 | */
|
---|
602 | RTDECL(int) RTDvmVolumeRead(RTDVMVOLUME hVol, uint64_t off, void *pvBuf, size_t cbRead);
|
---|
603 |
|
---|
604 | /**
|
---|
605 | * Writes data to the given volume.
|
---|
606 | *
|
---|
607 | * @returns IPRT status code.
|
---|
608 | * @param hVol The volume handle.
|
---|
609 | * @param off Where to start writing to - 0 is the beginning of
|
---|
610 | * the volume.
|
---|
611 | * @param pvBuf The data to write.
|
---|
612 | * @param cbWrite How many bytes to write.
|
---|
613 | */
|
---|
614 | RTDECL(int) RTDvmVolumeWrite(RTDVMVOLUME hVol, uint64_t off, const void *pvBuf, size_t cbWrite);
|
---|
615 |
|
---|
616 | /**
|
---|
617 | * Returns the description of a given volume type.
|
---|
618 | *
|
---|
619 | * @returns The description of the type.
|
---|
620 | * @param enmVolType The volume type.
|
---|
621 | */
|
---|
622 | RTDECL(const char *) RTDvmVolumeTypeGetDescr(RTDVMVOLTYPE enmVolType);
|
---|
623 |
|
---|
624 | /**
|
---|
625 | * Creates an VFS file from a volume handle.
|
---|
626 | *
|
---|
627 | * @returns IPRT status code.
|
---|
628 | * @param hVol The volume handle.
|
---|
629 | * @param fOpen RTFILE_O_XXX.
|
---|
630 | * @param phVfsFileOut Where to store the VFS file handle on success.
|
---|
631 | */
|
---|
632 | RTDECL(int) RTDvmVolumeCreateVfsFile(RTDVMVOLUME hVol, uint64_t fOpen, PRTVFSFILE phVfsFileOut);
|
---|
633 |
|
---|
634 | RT_C_DECLS_END
|
---|
635 |
|
---|
636 | /** @} */
|
---|
637 |
|
---|
638 | #endif /* !IPRT_INCLUDED_dvm_h */
|
---|
639 |
|
---|