| 1 | /* $Id: dvm.h 106061 2024-09-16 14:03:52Z vboxsync $ */
|
|---|
| 2 | /** @file
|
|---|
| 3 | * IPRT - Disk Volume Management Internals.
|
|---|
| 4 | */
|
|---|
| 5 |
|
|---|
| 6 | /*
|
|---|
| 7 | * Copyright (C) 2006-2024 Oracle and/or its affiliates.
|
|---|
| 8 | *
|
|---|
| 9 | * This file is part of VirtualBox base platform packages, as
|
|---|
| 10 | * available from https://www.virtualbox.org.
|
|---|
| 11 | *
|
|---|
| 12 | * This program is free software; you can redistribute it and/or
|
|---|
| 13 | * modify it under the terms of the GNU General Public License
|
|---|
| 14 | * as published by the Free Software Foundation, in version 3 of the
|
|---|
| 15 | * License.
|
|---|
| 16 | *
|
|---|
| 17 | * This program is distributed in the hope that it will be useful, but
|
|---|
| 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|---|
| 20 | * General Public License for more details.
|
|---|
| 21 | *
|
|---|
| 22 | * You should have received a copy of the GNU General Public License
|
|---|
| 23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
|---|
| 24 | *
|
|---|
| 25 | * The contents of this file may alternatively be used under the terms
|
|---|
| 26 | * of the Common Development and Distribution License Version 1.0
|
|---|
| 27 | * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
|---|
| 28 | * in the VirtualBox distribution, in which case the provisions of the
|
|---|
| 29 | * CDDL are applicable instead of those of the GPL.
|
|---|
| 30 | *
|
|---|
| 31 | * You may elect to license modified versions of this file under the
|
|---|
| 32 | * terms and conditions of either the GPL or the CDDL or both.
|
|---|
| 33 | *
|
|---|
| 34 | * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
|---|
| 35 | */
|
|---|
| 36 |
|
|---|
| 37 | #ifndef IPRT_INCLUDED_INTERNAL_dvm_h
|
|---|
| 38 | #define IPRT_INCLUDED_INTERNAL_dvm_h
|
|---|
| 39 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
|---|
| 40 | # pragma once
|
|---|
| 41 | #endif
|
|---|
| 42 |
|
|---|
| 43 | #include <iprt/types.h>
|
|---|
| 44 | #include <iprt/err.h>
|
|---|
| 45 | #include <iprt/assert.h>
|
|---|
| 46 | #include <iprt/vfs.h>
|
|---|
| 47 | #include "internal/magics.h"
|
|---|
| 48 |
|
|---|
| 49 | RT_C_DECLS_BEGIN
|
|---|
| 50 |
|
|---|
| 51 | /** Format specific volume manager handle. */
|
|---|
| 52 | typedef struct RTDVMFMTINTERNAL *RTDVMFMT;
|
|---|
| 53 | /** Pointer to a format specific volume manager handle. */
|
|---|
| 54 | typedef RTDVMFMT *PRTDVMFMT;
|
|---|
| 55 | /** NIL volume manager handle. */
|
|---|
| 56 | #define NIL_RTDVMFMT ((RTDVMFMT)~0)
|
|---|
| 57 |
|
|---|
| 58 | /** Format specific volume data handle. */
|
|---|
| 59 | typedef struct RTDVMVOLUMEFMTINTERNAL *RTDVMVOLUMEFMT;
|
|---|
| 60 | /** Pointer to a format specific volume data handle. */
|
|---|
| 61 | typedef RTDVMVOLUMEFMT *PRTDVMVOLUMEFMT;
|
|---|
| 62 | /** NIL volume handle. */
|
|---|
| 63 | #define NIL_RTDVMVOLUMEFMT ((RTDVMVOLUMEFMT)~0)
|
|---|
| 64 |
|
|---|
| 65 | /**
|
|---|
| 66 | * Disk descriptor.
|
|---|
| 67 | */
|
|---|
| 68 | typedef struct RTDVMDISK
|
|---|
| 69 | {
|
|---|
| 70 | /** Size of the disk in bytes. */
|
|---|
| 71 | uint64_t cbDisk;
|
|---|
| 72 | /** Sector size. */
|
|---|
| 73 | uint64_t cbSector;
|
|---|
| 74 | /** The VFS file handle if backed by such. */
|
|---|
| 75 | RTVFSFILE hVfsFile;
|
|---|
| 76 | } RTDVMDISK;
|
|---|
| 77 | /** Pointer to a disk descriptor. */
|
|---|
| 78 | typedef RTDVMDISK *PRTDVMDISK;
|
|---|
| 79 | /** Pointer to a const descriptor. */
|
|---|
| 80 | typedef const RTDVMDISK *PCRTDVMDISK;
|
|---|
| 81 |
|
|---|
| 82 | /** Score to indicate that the backend can't handle the format at all */
|
|---|
| 83 | #define RTDVM_MATCH_SCORE_UNSUPPORTED 0
|
|---|
| 84 | /** Score to indicate that a backend supports the format
|
|---|
| 85 | * but there can be other backends. */
|
|---|
| 86 | #define RTDVM_MATCH_SCORE_SUPPORTED (UINT32_MAX/2)
|
|---|
| 87 | /** Score to indicate a perfect match. */
|
|---|
| 88 | #define RTDVM_MATCH_SCORE_PERFECT UINT32_MAX
|
|---|
| 89 |
|
|---|
| 90 | /**
|
|---|
| 91 | * Volume format operations.
|
|---|
| 92 | */
|
|---|
| 93 | typedef struct RTDVMFMTOPS
|
|---|
| 94 | {
|
|---|
| 95 | /** Name of the format. */
|
|---|
| 96 | const char *pszFmt;
|
|---|
| 97 | /** The format type. */
|
|---|
| 98 | RTDVMFORMATTYPE enmFormat;
|
|---|
| 99 |
|
|---|
| 100 | /**
|
|---|
| 101 | * Probes the given disk for known structures.
|
|---|
| 102 | *
|
|---|
| 103 | * @returns IPRT status code.
|
|---|
| 104 | * @param pDisk Disk descriptor.
|
|---|
| 105 | * @param puScore Where to store the match score on success.
|
|---|
| 106 | */
|
|---|
| 107 | DECLCALLBACKMEMBER(int, pfnProbe,(PCRTDVMDISK pDisk, uint32_t *puScore));
|
|---|
| 108 |
|
|---|
| 109 | /**
|
|---|
| 110 | * Opens the format to set up all structures.
|
|---|
| 111 | *
|
|---|
| 112 | * @returns IPRT status code.
|
|---|
| 113 | * @param pDisk The disk descriptor.
|
|---|
| 114 | * @param phVolMgrFmt Where to store the volume format data on success.
|
|---|
| 115 | */
|
|---|
| 116 | DECLCALLBACKMEMBER(int, pfnOpen,(PCRTDVMDISK pDisk, PRTDVMFMT phVolMgrFmt));
|
|---|
| 117 |
|
|---|
| 118 | /**
|
|---|
| 119 | * Initializes a new volume map.
|
|---|
| 120 | *
|
|---|
| 121 | * @returns IPRT status code.
|
|---|
| 122 | * @param pDisk The disk descriptor.
|
|---|
| 123 | * @param phVolMgrFmt Where to store the volume format data on success.
|
|---|
| 124 | */
|
|---|
| 125 | DECLCALLBACKMEMBER(int, pfnInitialize,(PCRTDVMDISK pDisk, PRTDVMFMT phVolMgrFmt));
|
|---|
| 126 |
|
|---|
| 127 | /**
|
|---|
| 128 | * Closes the volume format.
|
|---|
| 129 | *
|
|---|
| 130 | * @param hVolMgrFmt The format specific volume manager handle.
|
|---|
| 131 | */
|
|---|
| 132 | DECLCALLBACKMEMBER(void, pfnClose,(RTDVMFMT hVolMgrFmt));
|
|---|
| 133 |
|
|---|
| 134 | /**
|
|---|
| 135 | * Returns whether the given range is in use by the volume manager.
|
|---|
| 136 | *
|
|---|
| 137 | * @returns IPRT status code.
|
|---|
| 138 | * @param hVolMgrFmt The format specific volume manager handle.
|
|---|
| 139 | * @param offStart Start offset of the range.
|
|---|
| 140 | * @param cbRange Size of the range to check in bytes.
|
|---|
| 141 | * @param pfUsed Where to store whether the range is in use by the
|
|---|
| 142 | * volume manager.
|
|---|
| 143 | */
|
|---|
| 144 | DECLCALLBACKMEMBER(int, pfnQueryRangeUse,(RTDVMFMT hVolMgrFmt,
|
|---|
| 145 | uint64_t off, uint64_t cbRange,
|
|---|
| 146 | bool *pfUsed));
|
|---|
| 147 |
|
|---|
| 148 | /**
|
|---|
| 149 | * Optional: Query the uuid of the current disk if applicable.
|
|---|
| 150 | *
|
|---|
| 151 | * @returns IPRT status code.
|
|---|
| 152 | * @retval VERR_NOT_SUPPORTED if the partition scheme doesn't do UUIDs.
|
|---|
| 153 | * @param hVolMgrFmt The format specific volume manager handle.
|
|---|
| 154 | * @param pUuid Where to return the UUID.
|
|---|
| 155 | */
|
|---|
| 156 | DECLCALLBACKMEMBER(int, pfnQueryDiskUuid,(RTDVMFMT hVolMgrFmt, PRTUUID pUuid));
|
|---|
| 157 |
|
|---|
| 158 | /**
|
|---|
| 159 | * Gets the number of valid volumes in the map.
|
|---|
| 160 | *
|
|---|
| 161 | * @returns Number of valid volumes in the map or UINT32_MAX on failure.
|
|---|
| 162 | * @param hVolMgrFmt The format specific volume manager handle.
|
|---|
| 163 | */
|
|---|
| 164 | DECLCALLBACKMEMBER(uint32_t, pfnGetValidVolumes,(RTDVMFMT hVolMgrFmt));
|
|---|
| 165 |
|
|---|
| 166 | /**
|
|---|
| 167 | * Gets the maximum number of volumes the map can have.
|
|---|
| 168 | *
|
|---|
| 169 | * @returns Maximum number of volumes in the map or 0 on failure.
|
|---|
| 170 | * @param hVolMgrFmt The format specific volume manager handle.
|
|---|
| 171 | */
|
|---|
| 172 | DECLCALLBACKMEMBER(uint32_t, pfnGetMaxVolumes,(RTDVMFMT hVolMgrFmt));
|
|---|
| 173 |
|
|---|
| 174 | /**
|
|---|
| 175 | * Get the first valid volume from a map.
|
|---|
| 176 | *
|
|---|
| 177 | * @returns IPRT status code.
|
|---|
| 178 | * @param hVolMgrFmt The format specific volume manager handle.
|
|---|
| 179 | * @param phVolFmt Where to store the volume handle to the first volume
|
|---|
| 180 | * on success.
|
|---|
| 181 | */
|
|---|
| 182 | DECLCALLBACKMEMBER(int, pfnQueryFirstVolume,(RTDVMFMT hVolMgrFmt, PRTDVMVOLUMEFMT phVolFmt));
|
|---|
| 183 |
|
|---|
| 184 | /**
|
|---|
| 185 | * Get the first valid volume from a map.
|
|---|
| 186 | *
|
|---|
| 187 | * @returns IPRT status code.
|
|---|
| 188 | * @param hVolMgrFmt The format specific volume manager handle.
|
|---|
| 189 | * @param hVolFmt The current volume.
|
|---|
| 190 | * @param phVolFmtNext Where to store the handle to the format specific
|
|---|
| 191 | * volume data of the next volume on success.
|
|---|
| 192 | */
|
|---|
| 193 | DECLCALLBACKMEMBER(int, pfnQueryNextVolume,(RTDVMFMT hVolMgrFmt, RTDVMVOLUMEFMT hVolFmt, PRTDVMVOLUMEFMT phVolFmtNext));
|
|---|
| 194 |
|
|---|
| 195 | /**
|
|---|
| 196 | * Query the partition table locations.
|
|---|
| 197 | *
|
|---|
| 198 | * @returns IPRT status code.
|
|---|
| 199 | * @retval VERR_BUFFER_OVERFLOW if the table is too small, @a *pcActual will be
|
|---|
| 200 | * set to the required size.
|
|---|
| 201 | * @retval VERR_BUFFER_UNDERFLOW if the table is too big and @a pcActual is
|
|---|
| 202 | * NULL.
|
|---|
| 203 | * @param hVolMgrFmt The format specific volume manager handle.
|
|---|
| 204 | * @param fFlags Flags, see RTDVMMAPQTABLOC_F_XXX.
|
|---|
| 205 | * @param paLocations Where to return the info. Ignored if @a cLocations
|
|---|
| 206 | * is zero, then only @a pcActual matters.
|
|---|
| 207 | * @param cLocations The size of @a paLocations in items.
|
|---|
| 208 | * @param pcActual Where to return the actual number of locations, or
|
|---|
| 209 | * on VERR_BUFFER_OVERFLOW the necessary table size.
|
|---|
| 210 | * Optional, when not specified the cLocations value
|
|---|
| 211 | * must match exactly or it fails with
|
|---|
| 212 | * VERR_BUFFER_UNDERFLOW.
|
|---|
| 213 | * @sa RTDvmMapQueryTableLocations
|
|---|
| 214 | */
|
|---|
| 215 | DECLCALLBACKMEMBER(int, pfnQueryTableLocations,(RTDVMFMT hVolMgrFmt, uint32_t fFlags, PRTDVMTABLELOCATION paLocations,
|
|---|
| 216 | size_t cLocations, size_t *pcActual));
|
|---|
| 217 |
|
|---|
| 218 | /**
|
|---|
| 219 | * Closes a volume handle.
|
|---|
| 220 | *
|
|---|
| 221 | * @param hVolFmt The format specific volume handle.
|
|---|
| 222 | */
|
|---|
| 223 | DECLCALLBACKMEMBER(void, pfnVolumeClose,(RTDVMVOLUMEFMT hVolFmt));
|
|---|
| 224 |
|
|---|
| 225 | /**
|
|---|
| 226 | * Gets the size of the given volume.
|
|---|
| 227 | *
|
|---|
| 228 | * @returns Size of the volume in bytes or 0 on failure.
|
|---|
| 229 | * @param hVolFmt The format specific volume handle.
|
|---|
| 230 | */
|
|---|
| 231 | DECLCALLBACKMEMBER(uint64_t, pfnVolumeGetSize,(RTDVMVOLUMEFMT hVolFmt));
|
|---|
| 232 |
|
|---|
| 233 | /**
|
|---|
| 234 | * Queries the name of the given volume.
|
|---|
| 235 | *
|
|---|
| 236 | * @returns IPRT status code.
|
|---|
| 237 | * @param hVolFmt The format specific volume handle.
|
|---|
| 238 | * @param ppszVolname Where to store the name of the volume on success.
|
|---|
| 239 | */
|
|---|
| 240 | DECLCALLBACKMEMBER(int, pfnVolumeQueryName,(RTDVMVOLUMEFMT hVolFmt, char **ppszVolName));
|
|---|
| 241 |
|
|---|
| 242 | /**
|
|---|
| 243 | * Get the type of the given volume.
|
|---|
| 244 | *
|
|---|
| 245 | * @returns The volume type on success, DVMVOLTYPE_INVALID if hVol is invalid.
|
|---|
| 246 | * @param hVolFmt The format specific volume handle.
|
|---|
| 247 | */
|
|---|
| 248 | DECLCALLBACKMEMBER(RTDVMVOLTYPE, pfnVolumeGetType,(RTDVMVOLUMEFMT hVolFmt));
|
|---|
| 249 |
|
|---|
| 250 | /**
|
|---|
| 251 | * Get the flags of the given volume.
|
|---|
| 252 | *
|
|---|
| 253 | * @returns The volume flags or UINT64_MAX on failure.
|
|---|
| 254 | * @param hVolFmt The format specific volume handle.
|
|---|
| 255 | */
|
|---|
| 256 | DECLCALLBACKMEMBER(uint64_t, pfnVolumeGetFlags,(RTDVMVOLUMEFMT hVolFmt));
|
|---|
| 257 |
|
|---|
| 258 | /**
|
|---|
| 259 | * Queries the range of the given volume on the underyling medium.
|
|---|
| 260 | *
|
|---|
| 261 | * @returns IPRT status code.
|
|---|
| 262 | * @param hVolFmt The format specific volume handle.
|
|---|
| 263 | * @param poffStart Where to store the start byte offset on the
|
|---|
| 264 | * underlying medium.
|
|---|
| 265 | * @param poffLast Where to store the last byte offset on the
|
|---|
| 266 | * underlying medium (inclusive).
|
|---|
| 267 | */
|
|---|
| 268 | DECLCALLBACKMEMBER(int, pfnVolumeQueryRange,(RTDVMVOLUMEFMT hVolFmt, uint64_t *poffStart, uint64_t *poffLast));
|
|---|
| 269 |
|
|---|
| 270 | /**
|
|---|
| 271 | * Returns whether the supplied range is at least partially intersecting
|
|---|
| 272 | * with the given volume.
|
|---|
| 273 | *
|
|---|
| 274 | * @returns whether the range intersects with the volume.
|
|---|
| 275 | * @param hVolFmt The format specific volume handle.
|
|---|
| 276 | * @param offStart Start offset of the range.
|
|---|
| 277 | * @param cbRange Size of the range to check in bytes.
|
|---|
| 278 | * @param poffVol Where to store the offset of the range from the
|
|---|
| 279 | * start of the volume if true is returned.
|
|---|
| 280 | * @param pcbIntersect Where to store the number of bytes intersecting
|
|---|
| 281 | * with the range if true is returned.
|
|---|
| 282 | */
|
|---|
| 283 | DECLCALLBACKMEMBER(bool, pfnVolumeIsRangeIntersecting,(RTDVMVOLUMEFMT hVolFmt,
|
|---|
| 284 | uint64_t offStart, size_t cbRange,
|
|---|
| 285 | uint64_t *poffVol,
|
|---|
| 286 | uint64_t *pcbIntersect));
|
|---|
| 287 |
|
|---|
| 288 | /**
|
|---|
| 289 | * Queries the range of the partition table the volume belongs to on the underlying medium.
|
|---|
| 290 | *
|
|---|
| 291 | * @returns IPRT status code.
|
|---|
| 292 | * @param hVolFmt The format specific volume handle.
|
|---|
| 293 | * @param poffTable Where to return the byte offset on the underlying
|
|---|
| 294 | * media of the (partition/volume/whatever) table.
|
|---|
| 295 | * @param pcbTable Where to return the table size in bytes. This
|
|---|
| 296 | * typically includes alignment padding.
|
|---|
| 297 | * @sa RTDvmVolumeQueryTableLocation
|
|---|
| 298 | */
|
|---|
| 299 | DECLCALLBACKMEMBER(int, pfnVolumeQueryTableLocation,(RTDVMVOLUMEFMT hVolFmt, uint64_t *poffStart, uint64_t *poffLast));
|
|---|
| 300 |
|
|---|
| 301 | /**
|
|---|
| 302 | * Gets the tiven index for the specified volume.
|
|---|
| 303 | *
|
|---|
| 304 | * @returns The requested index. UINT32_MAX on failure.
|
|---|
| 305 | * @param hVolFmt The format specific volume handle.
|
|---|
| 306 | * @param enmIndex The index to get. Never RTDVMVOLIDX_HOST.
|
|---|
| 307 | * @sa RTDvmVolumeGetIndex
|
|---|
| 308 | */
|
|---|
| 309 | DECLCALLBACKMEMBER(uint32_t, pfnVolumeGetIndex,(RTDVMVOLUMEFMT hVolFmt, RTDVMVOLIDX enmIndex));
|
|---|
| 310 |
|
|---|
| 311 | /**
|
|---|
| 312 | * Query a generic volume property.
|
|---|
| 313 | *
|
|---|
| 314 | * This is an extensible interface for retriving mostly format specific
|
|---|
| 315 | * information, or information that's not commonly used. (It's modelled after
|
|---|
| 316 | * RTLdrQueryPropEx.)
|
|---|
| 317 | *
|
|---|
| 318 | * @returns IPRT status code.
|
|---|
| 319 | * @retval VERR_NOT_SUPPORTED if the property query isn't supported (either all
|
|---|
| 320 | * or that specific property). The caller must handle this result.
|
|---|
| 321 | * @retval VERR_NOT_FOUND is currently not returned, but intended for cases
|
|---|
| 322 | * where it wasn't present in the tables.
|
|---|
| 323 | * @retval VERR_INVALID_FUNCTION if the @a enmProperty value is wrong.
|
|---|
| 324 | * @retval VERR_INVALID_PARAMETER if the fixed buffer size is wrong. Correct
|
|---|
| 325 | * size in @a *pcbBuf.
|
|---|
| 326 | * @retval VERR_BUFFER_OVERFLOW if the property doesn't have a fixed size
|
|---|
| 327 | * buffer and the buffer isn't big enough. Correct size in @a *pcbBuf.
|
|---|
| 328 | * @retval VERR_INVALID_HANDLE if the handle is invalid.
|
|---|
| 329 | *
|
|---|
| 330 | * @param hVolFmt Handle to the volume.
|
|---|
| 331 | * @param enmProperty The property to query.
|
|---|
| 332 | * @param pvBuf Pointer to the input / output buffer. In most cases
|
|---|
| 333 | * it's only used for returning data.
|
|---|
| 334 | * @param cbBuf The size of the buffer. This is validated by the common
|
|---|
| 335 | * code for all fixed typed & sized properties. The
|
|---|
| 336 | * interger properties may have several supported sizes, in
|
|---|
| 337 | * which case the user value is passed along as-is but it
|
|---|
| 338 | * is okay to return a smaller amount of data. The common
|
|---|
| 339 | * code will make upcast the data.
|
|---|
| 340 | * @param pcbBuf Where to return the amount of data returned. This must
|
|---|
| 341 | * be set even for fixed type/sized data.
|
|---|
| 342 | * @sa RTDvmVolumeQueryProp, RTDvmVolumeGetPropU64
|
|---|
| 343 | */
|
|---|
| 344 | DECLCALLBACKMEMBER(int, pfnVolumeQueryProp,(RTDVMVOLUMEFMT hVolFmt, RTDVMVOLPROP enmProperty,
|
|---|
| 345 | void *pvBuf, size_t cbBuf, size_t *pcbBuf));
|
|---|
| 346 |
|
|---|
| 347 | /**
|
|---|
| 348 | * Read data from the given volume.
|
|---|
| 349 | *
|
|---|
| 350 | * @returns IPRT status code.
|
|---|
| 351 | * @param hVolFmt The format specific volume handle.
|
|---|
| 352 | * @param off Where to start reading from.
|
|---|
| 353 | * @param pvBuf Where to store the read data.
|
|---|
| 354 | * @param cbRead How many bytes to read.
|
|---|
| 355 | */
|
|---|
| 356 | DECLCALLBACKMEMBER(int, pfnVolumeRead,(RTDVMVOLUMEFMT hVolFmt, uint64_t off, void *pvBuf, size_t cbRead));
|
|---|
| 357 |
|
|---|
| 358 | /**
|
|---|
| 359 | * Write data to the given volume.
|
|---|
| 360 | *
|
|---|
| 361 | * @returns IPRT status code.
|
|---|
| 362 | * @param hVolFmt The format specific volume handle.
|
|---|
| 363 | * @param off Where to start writing to.
|
|---|
| 364 | * @param pvBuf The data to write.
|
|---|
| 365 | * @param cbWrite How many bytes to write.
|
|---|
| 366 | */
|
|---|
| 367 | DECLCALLBACKMEMBER(int, pfnVolumeWrite,(RTDVMVOLUMEFMT hVolFmt, uint64_t off, const void *pvBuf, size_t cbWrite));
|
|---|
| 368 |
|
|---|
| 369 | } RTDVMFMTOPS;
|
|---|
| 370 | /** Pointer to a DVM ops table. */
|
|---|
| 371 | typedef RTDVMFMTOPS *PRTDVMFMTOPS;
|
|---|
| 372 | /** Pointer to a const DVM ops table. */
|
|---|
| 373 | typedef const RTDVMFMTOPS *PCRTDVMFMTOPS;
|
|---|
| 374 |
|
|---|
| 375 | /** Checks whether a range is intersecting. */
|
|---|
| 376 | #define RTDVM_RANGE_IS_INTERSECTING(start, size, off) ( (start) <= (off) && ((start) + (size)) > (off) )
|
|---|
| 377 |
|
|---|
| 378 | /** Converts a LBA number to the byte offset. */
|
|---|
| 379 | #define RTDVM_LBA2BYTE(lba, disk) ((lba) * (disk)->cbSector)
|
|---|
| 380 | /** Converts a Byte offset to the LBA number. */
|
|---|
| 381 | #define RTDVM_BYTE2LBA(off, disk) ((off) / (disk)->cbSector)
|
|---|
| 382 |
|
|---|
| 383 | /**
|
|---|
| 384 | * Returns the number of sectors in the disk.
|
|---|
| 385 | *
|
|---|
| 386 | * @returns Number of sectors.
|
|---|
| 387 | * @param pDisk The disk descriptor.
|
|---|
| 388 | */
|
|---|
| 389 | DECLINLINE(uint64_t) rtDvmDiskGetSectors(PCRTDVMDISK pDisk)
|
|---|
| 390 | {
|
|---|
| 391 | return pDisk->cbDisk / pDisk->cbSector;
|
|---|
| 392 | }
|
|---|
| 393 |
|
|---|
| 394 | /**
|
|---|
| 395 | * Read from the disk at the given offset.
|
|---|
| 396 | *
|
|---|
| 397 | * @returns IPRT status code.
|
|---|
| 398 | * @param pDisk The disk descriptor to read from.
|
|---|
| 399 | * @param off Start offset.
|
|---|
| 400 | * @param pvBuf Destination buffer.
|
|---|
| 401 | * @param cbRead How much to read.
|
|---|
| 402 | * @sa rtDvmDiskReadUnaligned
|
|---|
| 403 | */
|
|---|
| 404 | DECLINLINE(int) rtDvmDiskRead(PCRTDVMDISK pDisk, uint64_t off, void *pvBuf, size_t cbRead)
|
|---|
| 405 | {
|
|---|
| 406 | AssertPtrReturn(pDisk, VERR_INVALID_POINTER);
|
|---|
| 407 | AssertPtrReturn(pvBuf, VERR_INVALID_POINTER);
|
|---|
| 408 | AssertReturn(cbRead > 0, VERR_INVALID_PARAMETER);
|
|---|
| 409 | AssertReturn(off + cbRead <= pDisk->cbDisk, VERR_INVALID_PARAMETER);
|
|---|
| 410 |
|
|---|
| 411 | /* Use RTVfsFileReadAt if these triggers: */
|
|---|
| 412 | Assert(!(cbRead % pDisk->cbSector));
|
|---|
| 413 | Assert(!(off % pDisk->cbSector));
|
|---|
| 414 |
|
|---|
| 415 | return RTVfsFileReadAt(pDisk->hVfsFile, off, pvBuf, cbRead, NULL /*pcbRead*/);
|
|---|
| 416 | }
|
|---|
| 417 |
|
|---|
| 418 | DECLHIDDEN(int) rtDvmDiskReadUnaligned(PCRTDVMDISK pDisk, uint64_t off, void *pvBuf, size_t cbRead);
|
|---|
| 419 |
|
|---|
| 420 | /**
|
|---|
| 421 | * Write to the disk at the given offset.
|
|---|
| 422 | *
|
|---|
| 423 | * @returns IPRT status code.
|
|---|
| 424 | * @param pDisk The disk descriptor to write to.
|
|---|
| 425 | * @param off Start offset.
|
|---|
| 426 | * @param pvBuf Source buffer.
|
|---|
| 427 | * @param cbWrite How much to write.
|
|---|
| 428 | */
|
|---|
| 429 | DECLINLINE(int) rtDvmDiskWrite(PCRTDVMDISK pDisk, uint64_t off, const void *pvBuf, size_t cbWrite)
|
|---|
| 430 | {
|
|---|
| 431 | AssertPtrReturn(pDisk, VERR_INVALID_POINTER);
|
|---|
| 432 | AssertPtrReturn(pvBuf, VERR_INVALID_POINTER);
|
|---|
| 433 | AssertReturn(cbWrite > 0, VERR_INVALID_PARAMETER);
|
|---|
| 434 | AssertReturn(off + cbWrite <= pDisk->cbDisk, VERR_INVALID_PARAMETER);
|
|---|
| 435 |
|
|---|
| 436 | /* Write RTVfsFileReadAt if these triggers: */
|
|---|
| 437 | Assert(!(cbWrite % pDisk->cbSector));
|
|---|
| 438 | Assert(!(off % pDisk->cbSector));
|
|---|
| 439 |
|
|---|
| 440 | return RTVfsFileWriteAt(pDisk->hVfsFile, off, pvBuf, cbWrite, NULL /*pcbWritten*/);
|
|---|
| 441 | }
|
|---|
| 442 |
|
|---|
| 443 | extern DECL_HIDDEN_DATA(const RTDVMFMTOPS) g_rtDvmFmtMbr;
|
|---|
| 444 | extern DECL_HIDDEN_DATA(const RTDVMFMTOPS) g_rtDvmFmtGpt;
|
|---|
| 445 | extern DECL_HIDDEN_DATA(const RTDVMFMTOPS) g_rtDvmFmtBsdLbl;
|
|---|
| 446 |
|
|---|
| 447 | RT_C_DECLS_END
|
|---|
| 448 |
|
|---|
| 449 | #endif /* !IPRT_INCLUDED_INTERNAL_dvm_h */
|
|---|
| 450 |
|
|---|