VirtualBox

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

Last change on this file since 69617 was 69617, checked in by vboxsync, 7 years ago

dvm.h: build fix

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