1 | /** @file
|
---|
2 | *
|
---|
3 | * VBox HDD container test utility, memory disk/file.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2011-2023 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 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 | #ifndef VBOX_INCLUDED_SRC_testcase_VDMemDisk_h
|
---|
29 | #define VBOX_INCLUDED_SRC_testcase_VDMemDisk_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | #include <iprt/sg.h>
|
---|
35 |
|
---|
36 | /** Handle to the a memory disk. */
|
---|
37 | typedef struct VDMEMDISK *PVDMEMDISK;
|
---|
38 | /** Pointer to a memory disk handle. */
|
---|
39 | typedef PVDMEMDISK *PPVDMEMDISK;
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * Creates a new memory disk with the given size.
|
---|
43 | *
|
---|
44 | * @returns VBOX status code.
|
---|
45 | *
|
---|
46 | * @param ppMemDisk Where to store the memory disk handle.
|
---|
47 | * @param cbSize Size of the disk if it is fixed.
|
---|
48 | * If 0 the disk grows when it is written to
|
---|
49 | * and the size can be changed with
|
---|
50 | * VDMemDiskSetSize().
|
---|
51 | */
|
---|
52 | int VDMemDiskCreate(PPVDMEMDISK ppMemDisk, uint64_t cbSize);
|
---|
53 |
|
---|
54 | /**
|
---|
55 | * Destroys a memory disk.
|
---|
56 | *
|
---|
57 | * @param pMemDisk The memory disk to destroy.
|
---|
58 | */
|
---|
59 | void VDMemDiskDestroy(PVDMEMDISK pMemDisk);
|
---|
60 |
|
---|
61 | /**
|
---|
62 | * Writes the specified amount of data from the S/G buffer at
|
---|
63 | * the given offset.
|
---|
64 | *
|
---|
65 | * @returns VBox status code.
|
---|
66 | *
|
---|
67 | * @param pMemDisk The memory disk handle.
|
---|
68 | * @param off Where to start writing to.
|
---|
69 | * @param cbWrite How many bytes to write.
|
---|
70 | * @param pSgBuf The S/G buffer to write from.
|
---|
71 | */
|
---|
72 | int VDMemDiskWrite(PVDMEMDISK pMemDisk, uint64_t off, size_t cbWrite, PRTSGBUF pSgBuf);
|
---|
73 |
|
---|
74 | /**
|
---|
75 | * Reads the specified amount of data into the S/G buffer
|
---|
76 | * starting from the given offset.
|
---|
77 | *
|
---|
78 | * @returns VBox status code.
|
---|
79 | *
|
---|
80 | * @param pMemDisk The memory disk handle.
|
---|
81 | * @param off Where to start reading from.
|
---|
82 | * @param cbRead The amount of bytes to read.
|
---|
83 | * @param pSgBuf The S/G buffer to read into.
|
---|
84 | */
|
---|
85 | int VDMemDiskRead(PVDMEMDISK pMemDisk, uint64_t off, size_t cbRead, PRTSGBUF pSgBuf);
|
---|
86 |
|
---|
87 | /**
|
---|
88 | * Sets the size of the memory disk.
|
---|
89 | *
|
---|
90 | * @returns VBox status code.
|
---|
91 | *
|
---|
92 | * @param pMemDisk The memory disk handle.
|
---|
93 | * @param cbSize The new size to set.
|
---|
94 | */
|
---|
95 | int VDMemDiskSetSize(PVDMEMDISK pMemDisk, uint64_t cbSize);
|
---|
96 |
|
---|
97 | /**
|
---|
98 | * Gets the current size of the memory disk.
|
---|
99 | *
|
---|
100 | * @returns VBox status code.
|
---|
101 | *
|
---|
102 | * @param pMemDisk The memory disk handle.
|
---|
103 | * @param pcbSize Where to store the size of the memory
|
---|
104 | * disk.
|
---|
105 | */
|
---|
106 | int VDMemDiskGetSize(PVDMEMDISK pMemDisk, uint64_t *pcbSize);
|
---|
107 |
|
---|
108 | /**
|
---|
109 | * Dumps the memory disk to a file.
|
---|
110 | *
|
---|
111 | * @returns VBox status code.
|
---|
112 | *
|
---|
113 | * @param pMemDisk The memory disk handle.
|
---|
114 | * @param pcszFilename Where to dump the content.
|
---|
115 | */
|
---|
116 | int VDMemDiskWriteToFile(PVDMEMDISK pMemDisk, const char *pcszFilename);
|
---|
117 |
|
---|
118 | /**
|
---|
119 | * Reads the content of a file into the given memory disk.
|
---|
120 | * All data stored in the memory disk will be overwritten.
|
---|
121 | *
|
---|
122 | * @returns VBox status code.
|
---|
123 | *
|
---|
124 | * @param pMemDisk The memory disk handle.
|
---|
125 | * @param pcszFilename The file to load from.
|
---|
126 | */
|
---|
127 | int VDMemDiskReadFromFile(PVDMEMDISK pMemDisk, const char *pcszFilename);
|
---|
128 |
|
---|
129 | /**
|
---|
130 | * Compares the given range of the memory disk with a provided S/G buffer.
|
---|
131 | *
|
---|
132 | * @returns whatever memcmp returns.
|
---|
133 | *
|
---|
134 | * @param pMemDisk The memory disk handle.
|
---|
135 | * @param off Where to start comparing.
|
---|
136 | * @param cbCmp How many bytes to compare.
|
---|
137 | * @param pSgBuf The S/G buffer to compare with.
|
---|
138 | */
|
---|
139 | int VDMemDiskCmp(PVDMEMDISK pMemDisk, uint64_t off, size_t cbCmp, PRTSGBUF pSgBuf);
|
---|
140 |
|
---|
141 | #endif /* !VBOX_INCLUDED_SRC_testcase_VDMemDisk_h */
|
---|