VirtualBox

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

Last change on this file since 46252 was 44529, checked in by vboxsync, 12 years ago

header (C) fixes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.7 KB
Line 
1/** @file
2 * IPRT Disk Volume Management API (DVM).
3 */
4
5/*
6 * Copyright (C) 2011-2012 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_MASK (DVM_FLAGS_NO_STATUS_CALLBACK_MARK_AS_UNUSED | DVM_FLAGS_UNUSED_SPACE_MARK_AS_USED)
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 to read data from the underlying medium.
117 *
118 * @returns IPRT status code.
119 * @param pvUser Opaque user data passed on creation.
120 * @param off Offset to start reading from.
121 * @param pvBuf Where to store the read data.
122 * @param cbRead How many bytes to read.
123 */
124typedef DECLCALLBACK(int) FNDVMREAD(void *pvUser, uint64_t off, void *pvBuf, size_t cbRead);
125/** Pointer to a read callback. */
126typedef FNDVMREAD *PFNDVMREAD;
127
128/**
129 * Callback to write data to the underlying medium.
130 *
131 * @returns IPRT status code.
132 * @param pvUser Opaque user data passed on creation.
133 * @param off Offset to start writing to.
134 * @param pvBuf The data to write.
135 * @param cbRead How many bytes to write.
136 */
137typedef DECLCALLBACK(int) FNDVMWRITE(void *pvUser, uint64_t off, const void *pvBuf, size_t cbWrite);
138/** Pointer to a read callback. */
139typedef FNDVMWRITE *PFNDVMWRITE;
140
141/**
142 * Callback for querying the block allocation status of a volume.
143 *
144 * @returns IPRT status code.
145 * @param pvUser Opaque user data passed when setting the callback.
146 * @param off Offset relative to the start of the volume.
147 * @param cb Range to check in bytes.
148 * @param pfAllocated Where to store the allocation status on success.
149 */
150typedef DECLCALLBACK(int) FNDVMVOLUMEQUERYBLOCKSTATUS(void *pvUser, uint64_t off,
151 uint64_t cb, bool *pfAllocated);
152/** Pointer to a query block allocation status callback. */
153typedef FNDVMVOLUMEQUERYBLOCKSTATUS *PFNDVMVOLUMEQUERYBLOCKSTATUS;
154
155/**
156 * Create a new volume manager.
157 *
158 * @returns IPRT status.
159 * @param phVolMgr Where to store the handle to the volume manager on
160 * success.
161 * @param pfnRead Read callback for the underlying
162 * disk/container/whatever.
163 * @param pfnWrite Write callback for the underlying
164 * disk/container/whatever.
165 * @param cbDisk Size of the underlying disk in bytes.
166 * @param cbSector Size of one sector in bytes.
167 * @param fFlags Combination of RTDVM_FLAGS_*
168 * @param pvUser Opaque user data passed to the callbacks.
169 */
170RTDECL(int) RTDvmCreate(PRTDVM phVolMgr, PFNDVMREAD pfnRead,
171 PFNDVMWRITE pfnWrite, uint64_t cbDisk,
172 uint64_t cbSector, uint32_t fFlags,
173 void *pvUser);
174
175/**
176 * Retain a given volume manager.
177 *
178 * @returns New reference count on success, UINT32_MAX on failure.
179 * @param hVolMgr The volume manager to retain.
180 */
181RTDECL(uint32_t) RTDvmRetain(RTDVM hVolMgr);
182
183/**
184 * Releases a given volume manager.
185 *
186 * @returns New reference count on success (0 if closed), UINT32_MAX on failure.
187 * @param hVolMgr The volume manager to release.
188 */
189RTDECL(uint32_t) RTDvmRelease(RTDVM hVolMgr);
190
191/**
192 * Probes the underyling disk for the best volume manager format handler
193 * and opens it.
194 *
195 * @returns IPRT status code.
196 * @retval VERR_NOT_FOUND if no backend can handle the volume map on the disk.
197 * @param hVolMgr The volume manager handle.
198 */
199RTDECL(int) RTDvmMapOpen(RTDVM hVolMgr);
200
201/**
202 * Initializes a new volume map using the given format handler.
203 *
204 * @returns IPRT status code.
205 * @param hVolMgr The volume manager handle.
206 * @param pszFmt The format to use for the new map.
207 */
208RTDECL(int) RTDvmMapInitialize(RTDVM hVolMgr, const char *pszFmt);
209
210/**
211 * Gets the currently used format of the disk map.
212 *
213 * @returns Name of the format.
214 * @param hVolMgr The volume manager handle.
215 */
216RTDECL(const char *) RTDvmMapGetFormat(RTDVM hVolMgr);
217
218/**
219 * Gets the number of valid partitions in the map.
220 *
221 * @returns The number of valid volumes in the map or UINT32_MAX on failure.
222 * @param hVolMgr The volume manager handle.
223 */
224RTDECL(uint32_t) RTDvmMapGetValidVolumes(RTDVM hVolMgr);
225
226/**
227 * Gets the maximum number of partitions the map can hold.
228 *
229 * @returns The maximum number of volumes in the map or UINT32_MAX on failure.
230 * @param hVolMgr The volume manager handle.
231 */
232RTDECL(uint32_t) RTDvmMapGetMaxVolumes(RTDVM hVolMgr);
233
234/**
235 * Get the first valid volume from a map.
236 *
237 * @returns IPRT status code.
238 * @param hVolMgr The volume manager handle.
239 * @param phVol Where to store the handle to the first volume on
240 * success. Release with RTDvmVolumeRelease().
241 */
242RTDECL(int) RTDvmMapQueryFirstVolume(RTDVM hVolMgr, PRTDVMVOLUME phVol);
243
244/**
245 * Get the first valid volume from a map.
246 *
247 * @returns IPRT status code.
248 * @param hVolMgr The volume manager handle.
249 * @param hVol Handle of the current volume.
250 * @param phVolNext Where to store the handle to the next volume on
251 * success. Release with RTDvmVolumeRelease().
252 */
253RTDECL(int) RTDvmMapQueryNextVolume(RTDVM hVolMgr, RTDVMVOLUME hVol, PRTDVMVOLUME phVolNext);
254
255/**
256 * Returns whether the given block on the disk is in use.
257 *
258 * @returns IPRT status code.
259 * @param hVolMgr The volume manager handler.
260 * @param off The start offset to check for.
261 * @param cb The range in bytes to check.
262 * @param pfAllocated Where to store the status on success.
263 *
264 * @remark This method will return true even if a part of the range is not in use.
265 */
266RTDECL(int) RTDvmMapQueryBlockStatus(RTDVM hVolMgr, uint64_t off, uint64_t cb,
267 bool *pfAllocated);
268
269/**
270 * Retains a valid volume handle.
271 *
272 * @returns New reference count on success, UINT32_MAX on failure.
273 * @param hVol The volume to retain.
274 */
275RTDECL(uint32_t) RTDvmVolumeRetain(RTDVMVOLUME hVol);
276
277/**
278 * Releases a valid volume handle.
279 *
280 * @returns New reference count on success (0 if closed), UINT32_MAX on failure.
281 * @param hVol The volume to release.
282 */
283RTDECL(uint32_t) RTDvmVolumeRelease(RTDVMVOLUME hVol);
284
285/**
286 * Sets the callback to query the block allocation status for a volume.
287 * This overwrites any other callback set previously.
288 *
289 * @returns nothing.
290 * @param hVol The volume handle.
291 * @param pfnQueryBlockStatus The callback to set. Can be NULL to disable
292 * a previous callback.
293 * @param pvUser Opaque user data passed in the callback.
294 */
295RTDECL(void) RTDvmVolumeSetQueryBlockStatusCallback(RTDVMVOLUME hVol,
296 PFNDVMVOLUMEQUERYBLOCKSTATUS pfnQueryBlockStatus,
297 void *pvUser);
298
299/**
300 * Get the size of a volume in bytes.
301 *
302 * @returns Size of the volume in bytes or 0 on failure.
303 * @param hVol The volume handle.
304 */
305RTDECL(uint64_t) RTDvmVolumeGetSize(RTDVMVOLUME hVol);
306
307/**
308 * Gets the name of the volume if supported.
309 *
310 * @returns IPRT status code.
311 * @param hVol The volume handle.
312 * @param ppszVolName Where to store the name of the volume on success.
313 * The string must be freed with RTStrFree().
314 */
315RTDECL(int) RTDvmVolumeQueryName(RTDVMVOLUME hVol, char **ppszVolName);
316
317/**
318 * Get the volume type of the volume if supported.
319 *
320 * @returns The volume type on success, DVMVOLTYPE_INVALID if hVol is invalid.
321 * @param hVol The volume handle.
322 */
323RTDECL(RTDVMVOLTYPE) RTDvmVolumeGetType(RTDVMVOLUME hVol);
324
325/**
326 * Get the volume flags of the volume if supported.
327 *
328 * @returns The volume flags or UINT64_MAX on failure.
329 * @param hVol The volume handle.
330 */
331RTDECL(uint64_t) RTDvmVolumeGetFlags(RTDVMVOLUME hVol);
332
333/**
334 * Reads data from the given volume.
335 *
336 * @returns IPRT status code.
337 * @param hVol The volume handle.
338 * @param off Where to start reading from - 0 is the beginning of
339 * the volume.
340 * @param pvBuf Where to store the read data.
341 * @param cbRead How many bytes to read.
342 */
343RTDECL(int) RTDvmVolumeRead(RTDVMVOLUME hVol, uint64_t off, void *pvBuf, size_t cbRead);
344
345/**
346 * Writes data to the given volume.
347 *
348 * @returns IPRT status code.
349 * @param hVol The volume handle.
350 * @param off Where to start writing to - 0 is the beginning of
351 * the volume.
352 * @param pvBuf The data to write.
353 * @param cbWrite How many bytes to write.
354 */
355RTDECL(int) RTDvmVolumeWrite(RTDVMVOLUME hVol, uint64_t off, const void *pvBuf, size_t cbWrite);
356
357/**
358 * Returns the description of a given volume type.
359 *
360 * @returns The description of the type.
361 * @param enmVolType The volume type.
362 */
363RTDECL(const char *) RTDvmVolumeTypeGetDescr(RTDVMVOLTYPE enmVolType);
364
365/**
366 * Creates an VFS file from a volume handle.
367 *
368 * @returns IPRT status code.
369 * @param hVol The volume handle.
370 * @param phVfsFileOut Where to store the VFS file handle on success.
371 */
372RTDECL(int) RTDvmVolumeCreateVfsFile(RTDVMVOLUME hVol, PRTVFSFILE phVfsFileOut);
373
374RT_C_DECLS_END
375
376/** @} */
377
378#endif
379
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