VirtualBox

source: vbox/trunk/src/VBox/Runtime/include/internal/dvm.h@ 39550

Last change on this file since 39550 was 37270, checked in by vboxsync, 14 years ago

IPRT/Dvm: Commit BSD disklabel support.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.5 KB
Line 
1/* $Id: dvm.h 37270 2011-05-30 21:25:42Z vboxsync $ */
2/** @file
3 * IPRT - Disk Volume Management Internals.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27#ifndef ___internal_dvm_h
28#define ___internal_dvm_h
29
30#include <iprt/types.h>
31#include <iprt/err.h>
32#include <iprt/assert.h>
33#include "internal/magics.h"
34
35RT_C_DECLS_BEGIN
36
37/** Format specific volume manager handle. */
38typedef struct RTDVMFMTINTERNAL *RTDVMFMT;
39/** Pointer to a format specific volume manager handle. */
40typedef RTDVMFMT *PRTDVMFMT;
41/** NIL volume manager handle. */
42#define NIL_RTDVMFMT ((RTDVMFMT)~0)
43
44/** Format specific volume data handle. */
45typedef struct RTDVMVOLUMEFMTINTERNAL *RTDVMVOLUMEFMT;
46/** Pointer to a format specific volume data handle. */
47typedef RTDVMVOLUMEFMT *PRTDVMVOLUMEFMT;
48/** NIL volume handle. */
49#define NIL_RTDVMVOLUMEFMT ((RTDVMVOLUMEFMT)~0)
50
51/**
52 * Disk descriptor.
53 */
54typedef struct RTDVMDISK
55{
56 /** Size of the disk in bytes. */
57 uint64_t cbDisk;
58 /** Sector size. */
59 uint64_t cbSector;
60 /** Read callback */
61 PFNDVMREAD pfnRead;
62 /** Write callback. */
63 PFNDVMWRITE pfnWrite;
64 /** Opaque user data. */
65 void *pvUser;
66} RTDVMDISK;
67/** Pointer to a disk descriptor. */
68typedef RTDVMDISK *PRTDVMDISK;
69/** Pointer to a const descriptor. */
70typedef const RTDVMDISK *PCRTDVMDISK;
71
72/** Score to indicate that the backend can't handle the format at all */
73#define RTDVM_MATCH_SCORE_UNSUPPORTED 0
74/** Score to indicate that a backend supports the format
75 * but there can be other backends. */
76#define RTDVM_MATCH_SCORE_SUPPORTED (UINT32_MAX/2)
77/** Score to indicate a perfect match. */
78#define RTDVM_MATCH_SCORE_PERFECT UINT32_MAX
79
80/**
81 * Volume format operations.
82 */
83typedef struct RTDVMFMTOPS
84{
85 /** Name of the format. */
86 const char *pcszFmt;
87
88 /**
89 * Probes the given disk for known structures.
90 *
91 * @returns IPRT status code.
92 * @param pDisk Disk descriptor.
93 * @param puScore Where to store the match score on success.
94 */
95 DECLCALLBACKMEMBER(int, pfnProbe)(PCRTDVMDISK pDisk, uint32_t *puScore);
96
97 /**
98 * Opens the format to set up all structures.
99 *
100 * @returns IPRT status code.
101 * @param pDisk The disk descriptor.
102 * @param phVolMgrFmt Where to store the volume format data on success.
103 */
104 DECLCALLBACKMEMBER(int, pfnOpen)(PCRTDVMDISK pDisk, PRTDVMFMT phVolMgrFmt);
105
106 /**
107 * Initializes a new volume map.
108 *
109 * @returns IPRT status code.
110 * @param pDisk The disk descriptor.
111 * @param phVolMgrFmt Where to store the volume format data on success.
112 */
113 DECLCALLBACKMEMBER(int, pfnInitialize)(PCRTDVMDISK pDisk, PRTDVMFMT phVolMgrFmt);
114
115 /**
116 * Closes the volume format.
117 *
118 * @returns nothing.
119 * @param hVolMgrFmt The format specific volume manager handle.
120 */
121 DECLCALLBACKMEMBER(void, pfnClose)(RTDVMFMT hVolMgrFmt);
122
123 /**
124 * Gets the number of valid volumes in the map.
125 *
126 * @returns Number of valid volumes in the map or UINT32_MAX on failure.
127 * @param hVolMgrFmt The format specific volume manager handle.
128 */
129 DECLCALLBACKMEMBER(uint32_t, pfnGetValidVolumes)(RTDVMFMT hVolMgrFmt);
130
131 /**
132 * Gets the maximum number of volumes the map can have.
133 *
134 * @returns Maximum number of volumes in the map or 0 on failure.
135 * @param hVolMgrFmt The format specific volume manager handle.
136 */
137 DECLCALLBACKMEMBER(uint32_t, pfnGetMaxVolumes)(RTDVMFMT hVolMgrFmt);
138
139 /**
140 * Get the first valid volume from a map.
141 *
142 * @returns IPRT status code.
143 * @param hVolMgrFmt The format specific volume manager handle.
144 * @param phVolFmt Where to store the volume handle to the first volume
145 * on success.
146 */
147 DECLCALLBACKMEMBER(int, pfnQueryFirstVolume)(RTDVMFMT hVolMgrFmt, PRTDVMVOLUMEFMT phVolFmt);
148
149 /**
150 * Get the first valid volume from a map.
151 *
152 * @returns IPRT status code.
153 * @param hVolMgrFmt The format specific volume manager handle.
154 * @param hVolFmt The current volume.
155 * @param phVolFmtNext Where to store the handle to the format specific
156 * volume data of the next volume on success.
157 */
158 DECLCALLBACKMEMBER(int, pfnQueryNextVolume)(RTDVMFMT hVolMgrFmt, RTDVMVOLUMEFMT hVolFmt, PRTDVMVOLUMEFMT phVolFmtNext);
159
160 /**
161 * Closes a volume handle.
162 *
163 * @returns nothing.
164 * @param hVolFmt The format specific volume handle.
165 */
166 DECLCALLBACKMEMBER(void, pfnVolumeClose)(RTDVMVOLUMEFMT hVolFmt);
167
168 /**
169 * Gets the size of the given volume.
170 *
171 * @returns Size of the volume in bytes or 0 on failure.
172 * @param hVolFmt The format specific volume handle.
173 */
174 DECLCALLBACKMEMBER(uint64_t, pfnVolumeGetSize)(RTDVMVOLUMEFMT hVolFmt);
175
176 /**
177 * Queries the name of the given volume.
178 *
179 * @returns IPRT status code.
180 * @param hVolFmt The format specific volume handle.
181 * @param ppszVolname Where to store the name of the volume on success.
182 */
183 DECLCALLBACKMEMBER(int, pfnVolumeQueryName)(RTDVMVOLUMEFMT hVolFmt, char **ppszVolName);
184
185 /**
186 * Get the type of the given volume.
187 *
188 * @returns The volume type on success, DVMVOLTYPE_INVALID if hVol is invalid.
189 * @param hVolFmt The format specific volume handle.
190 */
191 DECLCALLBACKMEMBER(RTDVMVOLTYPE, pfnVolumeGetType)(RTDVMVOLUMEFMT hVolFmt);
192
193 /**
194 * Get the flags of the given volume.
195 *
196 * @returns The volume flags or UINT64_MAX on failure.
197 * @param hVolFmt The format specific volume handle.
198 */
199 DECLCALLBACKMEMBER(uint64_t, pfnVolumeGetFlags)(RTDVMVOLUMEFMT hVolFmt);
200
201 /**
202 * Read data from the given volume.
203 *
204 * @returns IPRT status code.
205 * @param hVolFmt The format specific volume handle.
206 * @param off Where to start reading from.
207 * @param pvBuf Where to store the read data.
208 * @param cbRead How many bytes to read.
209 */
210 DECLCALLBACKMEMBER(int, pfnVolumeRead)(RTDVMVOLUMEFMT hVolFmt, uint64_t off, void *pvBuf, size_t cbRead);
211
212 /**
213 * Write data to the given volume.
214 *
215 * @returns IPRT status code.
216 * @param hVolFmt The format specific volume handle.
217 * @param off Where to start writing to.
218 * @param pvBuf The data to write.
219 * @param cbWrite How many bytes to write.
220 */
221 DECLCALLBACKMEMBER(int, pfnVolumeWrite)(RTDVMVOLUMEFMT hVolFmt, uint64_t off, const void *pvBuf, size_t cbWrite);
222
223} RTDVMFMTOPS;
224/** Pointer to a DVM ops table. */
225typedef RTDVMFMTOPS *PRTDVMFMTOPS;
226/** Pointer to a const DVM ops table. */
227typedef const RTDVMFMTOPS *PCRTDVMFMTOPS;
228
229/** Converts a LBA number to the byte offset. */
230#define RTDVM_LBA2BYTE(lba, disk) ((lba) * (disk)->cbSector)
231/** Converts a Byte offset to the LBA number. */
232#define RTDVM_BYTE2LBA(off, disk) ((off) / (disk)->cbSector)
233
234/**
235 * Returns the number of sectors in the disk.
236 *
237 * @returns Number of sectors.
238 * @param pDisk The disk descriptor.
239 */
240DECLINLINE(uint64_t) rtDvmDiskGetSectors(PCRTDVMDISK pDisk)
241{
242 return pDisk->cbDisk / pDisk->cbSector;
243}
244
245/**
246 * Read from the disk at the given offset.
247 *
248 * @returns IPRT status code.
249 * @param pDisk The disk descriptor to read from.
250 * @param off Start offset.
251 * @param pvBuf Destination buffer.
252 * @param cbRead How much to read.
253 */
254DECLINLINE(int) rtDvmDiskRead(PCRTDVMDISK pDisk, uint64_t off, void *pvBuf, size_t cbRead)
255{
256 AssertPtrReturn(pDisk, VERR_INVALID_POINTER);
257 AssertPtrReturn(pvBuf, VERR_INVALID_POINTER);
258 AssertReturn(cbRead > 0, VERR_INVALID_PARAMETER);
259 AssertReturn(off + cbRead <= pDisk->cbDisk, VERR_INVALID_PARAMETER);
260
261 return pDisk->pfnRead(pDisk->pvUser, off, pvBuf, cbRead);
262}
263
264/**
265 * Write to the disk at the given offset.
266 *
267 * @returns IPRT status code.
268 * @param pDisk The disk descriptor to write to.
269 * @param off Start offset.
270 * @param pvBuf Source buffer.
271 * @param cbWrite How much to write.
272 */
273DECLINLINE(int) rtDvmDiskWrite(PCRTDVMDISK pDisk, uint64_t off, const void *pvBuf, size_t cbWrite)
274{
275 AssertPtrReturn(pDisk, VERR_INVALID_POINTER);
276 AssertPtrReturn(pvBuf, VERR_INVALID_POINTER);
277 AssertReturn(cbWrite > 0, VERR_INVALID_PARAMETER);
278 AssertReturn(off + cbWrite <= pDisk->cbDisk, VERR_INVALID_PARAMETER);
279
280 return pDisk->pfnWrite(pDisk->pvUser, off, pvBuf, cbWrite);
281}
282
283RT_C_DECLS_END
284
285#endif
286
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