VirtualBox

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

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

Runtime/RTDvm: Add flag to indicate that a volume is contiguous on the underlying medium and add method to query start and end offset of the volume

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 13.8 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 RTDvmVolumeGetFlags().
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/** Volume is contiguous on the underlying medium and RTDvmVolumeQueryRange(). */
130#define DVMVOLUME_F_CONTIGUOUS RT_BIT_64(2)
131/** @} */
132
133/** A handle to a volume manager. */
134typedef struct RTDVMINTERNAL *RTDVM;
135/** A pointer to a volume manager handle. */
136typedef RTDVM *PRTDVM;
137/** NIL volume manager handle. */
138#define NIL_RTDVM ((RTDVM)~0)
139
140/** A handle to a volume in a volume map. */
141typedef struct RTDVMVOLUMEINTERNAL *RTDVMVOLUME;
142/** A pointer to a volume handle. */
143typedef RTDVMVOLUME *PRTDVMVOLUME;
144/** NIL volume handle. */
145#define NIL_RTDVMVOLUME ((RTDVMVOLUME)~0)
146
147/**
148 * Callback for querying the block allocation status of a volume.
149 *
150 * @returns IPRT status code.
151 * @param pvUser Opaque user data passed when setting the callback.
152 * @param off Offset relative to the start of the volume.
153 * @param cb Range to check in bytes.
154 * @param pfAllocated Where to store the allocation status on success.
155 */
156typedef DECLCALLBACK(int) FNDVMVOLUMEQUERYBLOCKSTATUS(void *pvUser, uint64_t off,
157 uint64_t cb, bool *pfAllocated);
158/** Pointer to a query block allocation status callback. */
159typedef FNDVMVOLUMEQUERYBLOCKSTATUS *PFNDVMVOLUMEQUERYBLOCKSTATUS;
160
161/**
162 * Create a new volume manager.
163 *
164 * @returns IPRT status.
165 * @param phVolMgr Where to store the handle to the volume manager on
166 * success.
167 * @param hVfsFile The disk/container/whatever.
168 * @param cbSector Size of one sector in bytes.
169 * @param fFlags Combination of RTDVM_FLAGS_*
170 */
171RTDECL(int) RTDvmCreate(PRTDVM phVolMgr, RTVFSFILE hVfsFile, uint32_t cbSector, uint32_t fFlags);
172
173/**
174 * Retain a given volume manager.
175 *
176 * @returns New reference count on success, UINT32_MAX on failure.
177 * @param hVolMgr The volume manager to retain.
178 */
179RTDECL(uint32_t) RTDvmRetain(RTDVM hVolMgr);
180
181/**
182 * Releases a given volume manager.
183 *
184 * @returns New reference count on success (0 if closed), UINT32_MAX on failure.
185 * @param hVolMgr The volume manager to release.
186 */
187RTDECL(uint32_t) RTDvmRelease(RTDVM hVolMgr);
188
189/**
190 * Probes the underyling disk for the best volume manager format handler
191 * and opens it.
192 *
193 * @returns IPRT status code.
194 * @retval VERR_NOT_FOUND if no backend can handle the volume map on the disk.
195 * @param hVolMgr The volume manager handle.
196 */
197RTDECL(int) RTDvmMapOpen(RTDVM hVolMgr);
198
199/**
200 * Initializes a new volume map using the given format handler.
201 *
202 * @returns IPRT status code.
203 * @param hVolMgr The volume manager handle.
204 * @param pszFmt The format to use for the new map.
205 */
206RTDECL(int) RTDvmMapInitialize(RTDVM hVolMgr, const char *pszFmt);
207
208/**
209 * Gets the name of the currently used format of the disk map.
210 *
211 * @returns Name of the format.
212 * @param hVolMgr The volume manager handle.
213 */
214RTDECL(const char *) RTDvmMapGetFormatName(RTDVM hVolMgr);
215
216/**
217 * DVM format types.
218 */
219typedef enum RTDVMFORMATTYPE
220{
221 /** Invalid zero value. */
222 RTDVMFORMATTYPE_INVALID = 0,
223 /** Master boot record. */
224 RTDVMFORMATTYPE_MBR,
225 /** GUID partition table. */
226 RTDVMFORMATTYPE_GPT,
227 /** BSD labels. */
228 RTDVMFORMATTYPE_BSD_LABEL,
229 /** End of valid values. */
230 RTDVMFORMATTYPE_END,
231 /** 32-bit type size hack. */
232 RTDVMFORMATTYPE_32BIT_HACK = 0x7fffffff
233} RTDVMFORMATTYPE;
234
235/**
236 * Gets the format type of the current disk map.
237 *
238 * @returns Format type. RTDVMFORMATTYPE_INVALID on invalid input.
239 * @param hVolMgr The volume manager handle.
240 */
241RTDECL(RTDVMFORMATTYPE) RTDvmMapGetFormatType(RTDVM hVolMgr);
242
243/**
244 * Gets the number of valid partitions in the map.
245 *
246 * @returns The number of valid volumes in the map or UINT32_MAX on failure.
247 * @param hVolMgr The volume manager handle.
248 */
249RTDECL(uint32_t) RTDvmMapGetValidVolumes(RTDVM hVolMgr);
250
251/**
252 * Gets the maximum number of partitions the map can hold.
253 *
254 * @returns The maximum number of volumes in the map or UINT32_MAX on failure.
255 * @param hVolMgr The volume manager handle.
256 */
257RTDECL(uint32_t) RTDvmMapGetMaxVolumes(RTDVM hVolMgr);
258
259/**
260 * Get the first valid volume from a map.
261 *
262 * @returns IPRT status code.
263 * @param hVolMgr The volume manager handle.
264 * @param phVol Where to store the handle to the first volume on
265 * success. Release with RTDvmVolumeRelease().
266 */
267RTDECL(int) RTDvmMapQueryFirstVolume(RTDVM hVolMgr, PRTDVMVOLUME phVol);
268
269/**
270 * Get the first valid volume from a map.
271 *
272 * @returns IPRT status code.
273 * @param hVolMgr The volume manager handle.
274 * @param hVol Handle of the current volume.
275 * @param phVolNext Where to store the handle to the next volume on
276 * success. Release with RTDvmVolumeRelease().
277 */
278RTDECL(int) RTDvmMapQueryNextVolume(RTDVM hVolMgr, RTDVMVOLUME hVol, PRTDVMVOLUME phVolNext);
279
280/**
281 * Returns whether the given block on the disk is in use.
282 *
283 * @returns IPRT status code.
284 * @param hVolMgr The volume manager handler.
285 * @param off The start offset to check for.
286 * @param cb The range in bytes to check.
287 * @param pfAllocated Where to store the in-use status on success.
288 *
289 * @remark This method will return true even if a part of the range is not in use.
290 */
291RTDECL(int) RTDvmMapQueryBlockStatus(RTDVM hVolMgr, uint64_t off, uint64_t cb, bool *pfAllocated);
292
293/**
294 * Retains a valid volume handle.
295 *
296 * @returns New reference count on success, UINT32_MAX on failure.
297 * @param hVol The volume to retain.
298 */
299RTDECL(uint32_t) RTDvmVolumeRetain(RTDVMVOLUME hVol);
300
301/**
302 * Releases a valid volume handle.
303 *
304 * @returns New reference count on success (0 if closed), UINT32_MAX on failure.
305 * @param hVol The volume to release.
306 */
307RTDECL(uint32_t) RTDvmVolumeRelease(RTDVMVOLUME hVol);
308
309/**
310 * Sets the callback to query the block allocation status for a volume.
311 * This overwrites any other callback set previously.
312 *
313 * @returns nothing.
314 * @param hVol The volume handle.
315 * @param pfnQueryBlockStatus The callback to set. Can be NULL to disable
316 * a previous callback.
317 * @param pvUser Opaque user data passed in the callback.
318 */
319RTDECL(void) RTDvmVolumeSetQueryBlockStatusCallback(RTDVMVOLUME hVol,
320 PFNDVMVOLUMEQUERYBLOCKSTATUS pfnQueryBlockStatus,
321 void *pvUser);
322
323/**
324 * Get the size of a volume in bytes.
325 *
326 * @returns Size of the volume in bytes or 0 on failure.
327 * @param hVol The volume handle.
328 */
329RTDECL(uint64_t) RTDvmVolumeGetSize(RTDVMVOLUME hVol);
330
331/**
332 * Gets the name of the volume if supported.
333 *
334 * @returns IPRT status code.
335 * @param hVol The volume handle.
336 * @param ppszVolName Where to store the name of the volume on success.
337 * The string must be freed with RTStrFree().
338 */
339RTDECL(int) RTDvmVolumeQueryName(RTDVMVOLUME hVol, char **ppszVolName);
340
341/**
342 * Get the volume type of the volume if supported.
343 *
344 * @returns The volume type on success, DVMVOLTYPE_INVALID if hVol is invalid.
345 * @param hVol The volume handle.
346 */
347RTDECL(RTDVMVOLTYPE) RTDvmVolumeGetType(RTDVMVOLUME hVol);
348
349/**
350 * Get the volume flags of the volume if supported.
351 *
352 * @returns The volume flags or UINT64_MAX on failure.
353 * @param hVol The volume handle.
354 */
355RTDECL(uint64_t) RTDvmVolumeGetFlags(RTDVMVOLUME hVol);
356
357/**
358 * Queries the range of the given volume on the underyling medium.
359 *
360 * @returns IPRT status code.
361 * @retval VERR_NOT_SUPPORTED if the DVMVOLUME_F_CONTIGUOUS flag is not returned by RTDvmVolumeGetFlags().
362 * @param hVol The volume handle.
363 * @param poffStart Where to store the start offset in bytes on the underlying medium.
364 * @param poffEnd Where to store the end offset in bytes on the underlying medium (inclusive).
365 */
366RTDECL(int) RTDvmVolumeQueryRange(RTDVMVOLUME hVol, uint64_t *poffStart, uint64_t *poffEnd);
367
368/**
369 * Reads data from the given volume.
370 *
371 * @returns IPRT status code.
372 * @param hVol The volume handle.
373 * @param off Where to start reading from - 0 is the beginning of
374 * the volume.
375 * @param pvBuf Where to store the read data.
376 * @param cbRead How many bytes to read.
377 */
378RTDECL(int) RTDvmVolumeRead(RTDVMVOLUME hVol, uint64_t off, void *pvBuf, size_t cbRead);
379
380/**
381 * Writes data to the given volume.
382 *
383 * @returns IPRT status code.
384 * @param hVol The volume handle.
385 * @param off Where to start writing to - 0 is the beginning of
386 * the volume.
387 * @param pvBuf The data to write.
388 * @param cbWrite How many bytes to write.
389 */
390RTDECL(int) RTDvmVolumeWrite(RTDVMVOLUME hVol, uint64_t off, const void *pvBuf, size_t cbWrite);
391
392/**
393 * Returns the description of a given volume type.
394 *
395 * @returns The description of the type.
396 * @param enmVolType The volume type.
397 */
398RTDECL(const char *) RTDvmVolumeTypeGetDescr(RTDVMVOLTYPE enmVolType);
399
400/**
401 * Creates an VFS file from a volume handle.
402 *
403 * @returns IPRT status code.
404 * @param hVol The volume handle.
405 * @param fOpen RTFILE_O_XXX.
406 * @param phVfsFileOut Where to store the VFS file handle on success.
407 */
408RTDECL(int) RTDvmVolumeCreateVfsFile(RTDVMVOLUME hVol, uint64_t fOpen, PRTVFSFILE phVfsFileOut);
409
410RT_C_DECLS_END
411
412/** @} */
413
414#endif /* !IPRT_INCLUDED_dvm_h */
415
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle
ContactPrivacy/Do Not Sell My InfoTerms of Use