1 | /** @file
|
---|
2 | * IPRT Disk Volume Management API (DVM).
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2011-2024 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_rt_dvm IPRT Disk Volume Management
|
---|
48 | * @ingroup grp_rt
|
---|
49 | * @{
|
---|
50 | */
|
---|
51 |
|
---|
52 | /**
|
---|
53 | * Volume type.
|
---|
54 | * Comparable to the FS type in MBR partition maps
|
---|
55 | * or the partition type GUIDs in GPT tables.
|
---|
56 | */
|
---|
57 | typedef enum RTDVMVOLTYPE
|
---|
58 | {
|
---|
59 | /** Invalid. */
|
---|
60 | RTDVMVOLTYPE_INVALID = 0,
|
---|
61 | /** Unknown. */
|
---|
62 | RTDVMVOLTYPE_UNKNOWN,
|
---|
63 | /** Volume hosts a NTFS filesystem. */
|
---|
64 | RTDVMVOLTYPE_NTFS,
|
---|
65 | /** Volume hosts a FAT12 filesystem. */
|
---|
66 | RTDVMVOLTYPE_FAT12,
|
---|
67 | /** Volume hosts a FAT16 filesystem. */
|
---|
68 | RTDVMVOLTYPE_FAT16,
|
---|
69 | /** Volume hosts a FAT32 filesystem. */
|
---|
70 | RTDVMVOLTYPE_FAT32,
|
---|
71 |
|
---|
72 | /** EFI system partition (c12a7328-f81f-11d2-ba4b-00a0c93ec93b). */
|
---|
73 | RTDVMVOLTYPE_EFI_SYSTEM,
|
---|
74 |
|
---|
75 | /** Volume hosts a Mac OS X HFS or HFS+ filesystem. */
|
---|
76 | RTDVMVOLTYPE_DARWIN_HFS,
|
---|
77 | /** Volume hosts a Mac OS X APFS filesystem. */
|
---|
78 | RTDVMVOLTYPE_DARWIN_APFS,
|
---|
79 |
|
---|
80 | /** Volume hosts a Linux swap. */
|
---|
81 | RTDVMVOLTYPE_LINUX_SWAP,
|
---|
82 | /** Volume hosts a Linux filesystem. */
|
---|
83 | RTDVMVOLTYPE_LINUX_NATIVE,
|
---|
84 | /** Volume hosts a Linux LVM. */
|
---|
85 | RTDVMVOLTYPE_LINUX_LVM,
|
---|
86 | /** Volume hosts a Linux SoftRaid. */
|
---|
87 | RTDVMVOLTYPE_LINUX_SOFTRAID,
|
---|
88 |
|
---|
89 | /** Volume hosts a FreeBSD disklabel. */
|
---|
90 | RTDVMVOLTYPE_FREEBSD,
|
---|
91 | /** Volume hosts a NetBSD disklabel. */
|
---|
92 | RTDVMVOLTYPE_NETBSD,
|
---|
93 | /** Volume hosts a OpenBSD disklabel. */
|
---|
94 | RTDVMVOLTYPE_OPENBSD,
|
---|
95 | /** Volume hosts a Solaris volume. */
|
---|
96 | RTDVMVOLTYPE_SOLARIS,
|
---|
97 |
|
---|
98 | /** Volume hosts a Windows basic data partition . */
|
---|
99 | RTDVMVOLTYPE_WIN_BASIC,
|
---|
100 | /** Volume hosts a Microsoft reserved partition (MSR). */
|
---|
101 | RTDVMVOLTYPE_WIN_MSR,
|
---|
102 | /** Volume hosts a Windows logical disk manager (LDM) metadata partition. */
|
---|
103 | RTDVMVOLTYPE_WIN_LDM_META,
|
---|
104 | /** Volume hosts a Windows logical disk manager (LDM) data partition. */
|
---|
105 | RTDVMVOLTYPE_WIN_LDM_DATA,
|
---|
106 | /** Volume hosts a Windows recovery partition. */
|
---|
107 | RTDVMVOLTYPE_WIN_RECOVERY,
|
---|
108 | /** Volume hosts a storage spaces partition. */
|
---|
109 | RTDVMVOLTYPE_WIN_STORAGE_SPACES,
|
---|
110 |
|
---|
111 | /** Volume hosts an IBM general parallel file system (GPFS). */
|
---|
112 | RTDVMVOLTYPE_IBM_GPFS,
|
---|
113 |
|
---|
114 | /** OS/2 (Arca Noae) type 1 partition. */
|
---|
115 | RTDVMVOLTYPE_ARCA_OS2,
|
---|
116 |
|
---|
117 | /** End of the valid values. */
|
---|
118 | RTDVMVOLTYPE_END,
|
---|
119 | /** Usual 32bit hack. */
|
---|
120 | RTDVMVOLTYPE_32BIT_HACK = 0x7fffffff
|
---|
121 | } RTDVMVOLTYPE;
|
---|
122 |
|
---|
123 | /** @defgroup grp_dvm_flags Flags used by RTDvmCreate.
|
---|
124 | * @{ */
|
---|
125 | /** DVM flags - Blocks are always marked as unused if the volume has
|
---|
126 | * no block status callback set.
|
---|
127 | * The default is to mark them as used. */
|
---|
128 | #define DVM_FLAGS_NO_STATUS_CALLBACK_MARK_AS_UNUSED RT_BIT_32(0)
|
---|
129 | /** DVM flags - Space which is unused in the map will be marked as used
|
---|
130 | * when calling RTDvmMapQueryBlockStatus(). */
|
---|
131 | #define DVM_FLAGS_UNUSED_SPACE_MARK_AS_USED RT_BIT_32(1)
|
---|
132 | /** Mask of all valid flags. */
|
---|
133 | #define DVM_FLAGS_VALID_MASK UINT32_C(0x00000003)
|
---|
134 | /** @} */
|
---|
135 |
|
---|
136 |
|
---|
137 | /** @defgroup grp_dvm_vol_flags Volume flags used by RTDvmVolumeGetFlags().
|
---|
138 | * @{ */
|
---|
139 | /** Volume flags - Volume is bootable. */
|
---|
140 | #define DVMVOLUME_FLAGS_BOOTABLE RT_BIT_64(0)
|
---|
141 | /** Volume flags - Volume is active. */
|
---|
142 | #define DVMVOLUME_FLAGS_ACTIVE RT_BIT_64(1)
|
---|
143 | /** Volume is contiguous on the underlying medium and RTDvmVolumeQueryRange(). */
|
---|
144 | #define DVMVOLUME_F_CONTIGUOUS RT_BIT_64(2)
|
---|
145 | /** @} */
|
---|
146 |
|
---|
147 | /** A handle to a volume manager. */
|
---|
148 | typedef struct RTDVMINTERNAL *RTDVM;
|
---|
149 | /** A pointer to a volume manager handle. */
|
---|
150 | typedef RTDVM *PRTDVM;
|
---|
151 | /** NIL volume manager handle. */
|
---|
152 | #define NIL_RTDVM ((RTDVM)~0)
|
---|
153 |
|
---|
154 | /** A handle to a volume in a volume map. */
|
---|
155 | typedef struct RTDVMVOLUMEINTERNAL *RTDVMVOLUME;
|
---|
156 | /** A pointer to a volume handle. */
|
---|
157 | typedef RTDVMVOLUME *PRTDVMVOLUME;
|
---|
158 | /** NIL volume handle. */
|
---|
159 | #define NIL_RTDVMVOLUME ((RTDVMVOLUME)~0)
|
---|
160 |
|
---|
161 | /**
|
---|
162 | * Callback for querying the block allocation status of a volume.
|
---|
163 | *
|
---|
164 | * @returns IPRT status code.
|
---|
165 | * @param pvUser Opaque user data passed when setting the callback.
|
---|
166 | * @param off Offset relative to the start of the volume.
|
---|
167 | * @param cb Range to check in bytes.
|
---|
168 | * @param pfAllocated Where to store the allocation status on success.
|
---|
169 | */
|
---|
170 | typedef DECLCALLBACKTYPE(int, FNDVMVOLUMEQUERYBLOCKSTATUS,(void *pvUser, uint64_t off, uint64_t cb, bool *pfAllocated));
|
---|
171 | /** Pointer to a query block allocation status callback. */
|
---|
172 | typedef FNDVMVOLUMEQUERYBLOCKSTATUS *PFNDVMVOLUMEQUERYBLOCKSTATUS;
|
---|
173 |
|
---|
174 | /**
|
---|
175 | * Create a new volume manager.
|
---|
176 | *
|
---|
177 | * @returns IPRT status.
|
---|
178 | * @param phVolMgr Where to store the handle to the volume manager on
|
---|
179 | * success.
|
---|
180 | * @param hVfsFile The disk/container/whatever.
|
---|
181 | * @param cbSector Size of one sector in bytes.
|
---|
182 | * @param fFlags Combination of RTDVM_FLAGS_*
|
---|
183 | */
|
---|
184 | RTDECL(int) RTDvmCreate(PRTDVM phVolMgr, RTVFSFILE hVfsFile, uint32_t cbSector, uint32_t fFlags);
|
---|
185 |
|
---|
186 | /**
|
---|
187 | * Retain a given volume manager.
|
---|
188 | *
|
---|
189 | * @returns New reference count on success, UINT32_MAX on failure.
|
---|
190 | * @param hVolMgr The volume manager to retain.
|
---|
191 | */
|
---|
192 | RTDECL(uint32_t) RTDvmRetain(RTDVM hVolMgr);
|
---|
193 |
|
---|
194 | /**
|
---|
195 | * Releases a given volume manager.
|
---|
196 | *
|
---|
197 | * @returns New reference count on success (0 if closed), UINT32_MAX on failure.
|
---|
198 | * @param hVolMgr The volume manager to release.
|
---|
199 | */
|
---|
200 | RTDECL(uint32_t) RTDvmRelease(RTDVM hVolMgr);
|
---|
201 |
|
---|
202 | /**
|
---|
203 | * Probes the underyling disk for the best volume manager format handler
|
---|
204 | * and opens it.
|
---|
205 | *
|
---|
206 | * @returns IPRT status code.
|
---|
207 | * @retval VERR_NOT_FOUND if no backend can handle the volume map on the disk.
|
---|
208 | * @param hVolMgr The volume manager handle.
|
---|
209 | */
|
---|
210 | RTDECL(int) RTDvmMapOpen(RTDVM hVolMgr);
|
---|
211 |
|
---|
212 | /**
|
---|
213 | * Initializes a new volume map using the given format handler.
|
---|
214 | *
|
---|
215 | * @returns IPRT status code.
|
---|
216 | * @param hVolMgr The volume manager handle.
|
---|
217 | * @param pszFmt The format to use for the new map.
|
---|
218 | */
|
---|
219 | RTDECL(int) RTDvmMapInitialize(RTDVM hVolMgr, const char *pszFmt);
|
---|
220 |
|
---|
221 | /**
|
---|
222 | * Gets the name of the currently used format of the disk map.
|
---|
223 | *
|
---|
224 | * @returns Name of the format.
|
---|
225 | * @param hVolMgr The volume manager handle.
|
---|
226 | */
|
---|
227 | RTDECL(const char *) RTDvmMapGetFormatName(RTDVM hVolMgr);
|
---|
228 |
|
---|
229 | /**
|
---|
230 | * DVM format types.
|
---|
231 | */
|
---|
232 | typedef enum RTDVMFORMATTYPE
|
---|
233 | {
|
---|
234 | /** Invalid zero value. */
|
---|
235 | RTDVMFORMATTYPE_INVALID = 0,
|
---|
236 | /** Master boot record. */
|
---|
237 | RTDVMFORMATTYPE_MBR,
|
---|
238 | /** GUID partition table. */
|
---|
239 | RTDVMFORMATTYPE_GPT,
|
---|
240 | /** BSD labels. */
|
---|
241 | RTDVMFORMATTYPE_BSD_LABEL,
|
---|
242 | /** End of valid values. */
|
---|
243 | RTDVMFORMATTYPE_END,
|
---|
244 | /** 32-bit type size hack. */
|
---|
245 | RTDVMFORMATTYPE_32BIT_HACK = 0x7fffffff
|
---|
246 | } RTDVMFORMATTYPE;
|
---|
247 |
|
---|
248 | /**
|
---|
249 | * Gets the format type of the current disk map.
|
---|
250 | *
|
---|
251 | * @returns Format type. RTDVMFORMATTYPE_INVALID on invalid input.
|
---|
252 | * @param hVolMgr The volume manager handle.
|
---|
253 | */
|
---|
254 | RTDECL(RTDVMFORMATTYPE) RTDvmMapGetFormatType(RTDVM hVolMgr);
|
---|
255 |
|
---|
256 | /**
|
---|
257 | * Gets the UUID of the disk if applicable.
|
---|
258 | *
|
---|
259 | * Disks using the MBR format may return the 32-bit disk identity in the
|
---|
260 | * u32TimeLow field and set the rest to zero.
|
---|
261 | *
|
---|
262 | * @returns IPRT status code.
|
---|
263 | * @retval VERR_NOT_SUPPORTED if the partition scheme doesn't do UUIDs.
|
---|
264 | * @retval VINF_NOT_SUPPORTED if non-UUID disk ID is returned.
|
---|
265 | * @param hVolMgr The volume manager handle.
|
---|
266 | * @param pUuid Where to return the UUID.
|
---|
267 | *
|
---|
268 | * @todo It's quite possible this should be turned into a map-level edition of
|
---|
269 | * RTDvmVolumeQueryProp...
|
---|
270 | */
|
---|
271 | RTDECL(int) RTDvmMapQueryDiskUuid(RTDVM hVolMgr, PRTUUID pUuid);
|
---|
272 |
|
---|
273 | /**
|
---|
274 | * Gets the number of valid partitions in the map.
|
---|
275 | *
|
---|
276 | * @returns The number of valid volumes in the map or UINT32_MAX on failure.
|
---|
277 | * @param hVolMgr The volume manager handle.
|
---|
278 | */
|
---|
279 | RTDECL(uint32_t) RTDvmMapGetValidVolumes(RTDVM hVolMgr);
|
---|
280 |
|
---|
281 | /**
|
---|
282 | * Gets the maximum number of partitions the map can hold.
|
---|
283 | *
|
---|
284 | * @returns The maximum number of volumes in the map or UINT32_MAX on failure.
|
---|
285 | * @param hVolMgr The volume manager handle.
|
---|
286 | */
|
---|
287 | RTDECL(uint32_t) RTDvmMapGetMaxVolumes(RTDVM hVolMgr);
|
---|
288 |
|
---|
289 | /**
|
---|
290 | * Get the first valid volume from a map.
|
---|
291 | *
|
---|
292 | * @returns IPRT status code.
|
---|
293 | * @param hVolMgr The volume manager handle.
|
---|
294 | * @param phVol Where to store the handle to the first volume on
|
---|
295 | * success. Release with RTDvmVolumeRelease().
|
---|
296 | */
|
---|
297 | RTDECL(int) RTDvmMapQueryFirstVolume(RTDVM hVolMgr, PRTDVMVOLUME phVol);
|
---|
298 |
|
---|
299 | /**
|
---|
300 | * Get the first valid volume from a map.
|
---|
301 | *
|
---|
302 | * @returns IPRT status code.
|
---|
303 | * @param hVolMgr The volume manager handle.
|
---|
304 | * @param hVol Handle of the current volume.
|
---|
305 | * @param phVolNext Where to store the handle to the next volume on
|
---|
306 | * success. Release with RTDvmVolumeRelease().
|
---|
307 | */
|
---|
308 | RTDECL(int) RTDvmMapQueryNextVolume(RTDVM hVolMgr, RTDVMVOLUME hVol, PRTDVMVOLUME phVolNext);
|
---|
309 |
|
---|
310 | /**
|
---|
311 | * Returns whether the given block on the disk is in use.
|
---|
312 | *
|
---|
313 | * @returns IPRT status code.
|
---|
314 | * @param hVolMgr The volume manager handle.
|
---|
315 | * @param off The start offset to check for.
|
---|
316 | * @param cb The range in bytes to check.
|
---|
317 | * @param pfAllocated Where to store the in-use status on success.
|
---|
318 | *
|
---|
319 | * @remark This method will return true even if a part of the range is not in use.
|
---|
320 | */
|
---|
321 | RTDECL(int) RTDvmMapQueryBlockStatus(RTDVM hVolMgr, uint64_t off, uint64_t cb, bool *pfAllocated);
|
---|
322 |
|
---|
323 | /**
|
---|
324 | * Partition/map table location information.
|
---|
325 | * @sa RTDvmMapQueryTableLocations
|
---|
326 | */
|
---|
327 | typedef struct RTDVMTABLELOCATION
|
---|
328 | {
|
---|
329 | /** The byte offset on the underlying media. */
|
---|
330 | uint64_t off;
|
---|
331 | /** The table size in bytes. */
|
---|
332 | uint64_t cb;
|
---|
333 | /** Number of padding bytes / free space between the actual table and
|
---|
334 | * first partition. */
|
---|
335 | uint64_t cbPadding;
|
---|
336 | } RTDVMTABLELOCATION;
|
---|
337 | /** Pointer to partition table location info. */
|
---|
338 | typedef RTDVMTABLELOCATION *PRTDVMTABLELOCATION;
|
---|
339 | /** Pointer to const partition table location info. */
|
---|
340 | typedef RTDVMTABLELOCATION const *PCRTDVMTABLELOCATION;
|
---|
341 |
|
---|
342 |
|
---|
343 | /** @name RTDVMMAPQTABLOC_F_XXX - Flags for RTDvmMapQueryTableLocations
|
---|
344 | * @{ */
|
---|
345 | /** Make sure GPT includes the protective MBR. */
|
---|
346 | #define RTDVMMAPQTABLOC_F_INCLUDE_LEGACY RT_BIT_32(0)
|
---|
347 | /** Valid flags. */
|
---|
348 | #define RTDVMMAPQTABLOC_F_VALID_MASK UINT32_C(1)
|
---|
349 | /** @} */
|
---|
350 |
|
---|
351 | /**
|
---|
352 | * Query the partition table locations.
|
---|
353 | *
|
---|
354 | * @returns IPRT status code.
|
---|
355 | * @retval VERR_BUFFER_OVERFLOW if the table is too small, @a *pcActual will be
|
---|
356 | * set to the required size.
|
---|
357 | * @retval VERR_BUFFER_UNDERFLOW if the table is too big and @a pcActual is
|
---|
358 | * NULL.
|
---|
359 | * @param hVolMgr The volume manager handle.
|
---|
360 | * @param fFlags Flags, see RTDVMMAPQTABLOC_F_XXX.
|
---|
361 | * @param paLocations Where to return the info. This can be NULL if @a
|
---|
362 | * cLocations is zero and @a pcActual is given.
|
---|
363 | * @param cLocations The size of @a paLocations in items.
|
---|
364 | * @param pcActual Where to return the actual number of locations, or
|
---|
365 | * on VERR_BUFFER_OVERFLOW the necessary table size.
|
---|
366 | * Optional, when not specified the cLocations value
|
---|
367 | * must match exactly or it fails with
|
---|
368 | * VERR_BUFFER_UNDERFLOW.
|
---|
369 | */
|
---|
370 | RTDECL(int) RTDvmMapQueryTableLocations(RTDVM hVolMgr, uint32_t fFlags,
|
---|
371 | PRTDVMTABLELOCATION paLocations, size_t cLocations, size_t *pcActual);
|
---|
372 |
|
---|
373 | /**
|
---|
374 | * Retains a valid volume handle.
|
---|
375 | *
|
---|
376 | * @returns New reference count on success, UINT32_MAX on failure.
|
---|
377 | * @param hVol The volume to retain.
|
---|
378 | */
|
---|
379 | RTDECL(uint32_t) RTDvmVolumeRetain(RTDVMVOLUME hVol);
|
---|
380 |
|
---|
381 | /**
|
---|
382 | * Releases a valid volume handle.
|
---|
383 | *
|
---|
384 | * @returns New reference count on success (0 if closed), UINT32_MAX on failure.
|
---|
385 | * @param hVol The volume to release.
|
---|
386 | */
|
---|
387 | RTDECL(uint32_t) RTDvmVolumeRelease(RTDVMVOLUME hVol);
|
---|
388 |
|
---|
389 | /**
|
---|
390 | * Sets the callback to query the block allocation status for a volume.
|
---|
391 | * This overwrites any other callback set previously.
|
---|
392 | *
|
---|
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 |
|
---|