1 | /** @file
|
---|
2 | *
|
---|
3 | * VBox HDD container test utility, memory disk/file.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2011-2022 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 | * @returns nothing.
|
---|
58 | *
|
---|
59 | * @param pMemDisk The memory disk to destroy.
|
---|
60 | */
|
---|
61 | void VDMemDiskDestroy(PVDMEMDISK pMemDisk);
|
---|
62 |
|
---|
63 | /**
|
---|
64 | * Writes the specified amount of data from the S/G buffer at
|
---|
65 | * the given offset.
|
---|
66 | *
|
---|
67 | * @returns VBox status code.
|
---|
68 | *
|
---|
69 | * @param pMemDisk The memory disk handle.
|
---|
70 | * @param off Where to start writing to.
|
---|
71 | * @param cbWrite How many bytes to write.
|
---|
72 | * @param pSgBuf The S/G buffer to write from.
|
---|
73 | */
|
---|
74 | int VDMemDiskWrite(PVDMEMDISK pMemDisk, uint64_t off, size_t cbWrite, PRTSGBUF pSgBuf);
|
---|
75 |
|
---|
76 | /**
|
---|
77 | * Reads the specified amount of data into the S/G buffer
|
---|
78 | * starting from the given offset.
|
---|
79 | *
|
---|
80 | * @returns VBox status code.
|
---|
81 | *
|
---|
82 | * @param pMemDisk The memory disk handle.
|
---|
83 | * @param off Where to start reading from.
|
---|
84 | * @param cbRead The amount of bytes to read.
|
---|
85 | * @param pSgBuf The S/G buffer to read into.
|
---|
86 | */
|
---|
87 | int VDMemDiskRead(PVDMEMDISK pMemDisk, uint64_t off, size_t cbRead, PRTSGBUF pSgBuf);
|
---|
88 |
|
---|
89 | /**
|
---|
90 | * Sets the size of the memory disk.
|
---|
91 | *
|
---|
92 | * @returns VBox status code.
|
---|
93 | *
|
---|
94 | * @param pMemDisk The memory disk handle.
|
---|
95 | * @param cbSize The new size to set.
|
---|
96 | */
|
---|
97 | int VDMemDiskSetSize(PVDMEMDISK pMemDisk, uint64_t cbSize);
|
---|
98 |
|
---|
99 | /**
|
---|
100 | * Gets the current size of the memory disk.
|
---|
101 | *
|
---|
102 | * @returns VBox status code.
|
---|
103 | *
|
---|
104 | * @param pMemDisk The memory disk handle.
|
---|
105 | * @param pcbSize Where to store the size of the memory
|
---|
106 | * disk.
|
---|
107 | */
|
---|
108 | int VDMemDiskGetSize(PVDMEMDISK pMemDisk, uint64_t *pcbSize);
|
---|
109 |
|
---|
110 | /**
|
---|
111 | * Dumps the memory disk to a file.
|
---|
112 | *
|
---|
113 | * @returns VBox status code.
|
---|
114 | *
|
---|
115 | * @param pMemDisk The memory disk handle.
|
---|
116 | * @param pcszFilename Where to dump the content.
|
---|
117 | */
|
---|
118 | int VDMemDiskWriteToFile(PVDMEMDISK pMemDisk, const char *pcszFilename);
|
---|
119 |
|
---|
120 | /**
|
---|
121 | * Reads the content of a file into the given memory disk.
|
---|
122 | * All data stored in the memory disk will be overwritten.
|
---|
123 | *
|
---|
124 | * @returns VBox status code.
|
---|
125 | *
|
---|
126 | * @param pMemDisk The memory disk handle.
|
---|
127 | * @param pcszFilename The file to load from.
|
---|
128 | */
|
---|
129 | int VDMemDiskReadFromFile(PVDMEMDISK pMemDisk, const char *pcszFilename);
|
---|
130 |
|
---|
131 | /**
|
---|
132 | * Compares the given range of the memory disk with a provided S/G buffer.
|
---|
133 | *
|
---|
134 | * @returns whatever memcmp returns.
|
---|
135 | *
|
---|
136 | * @param pMemDisk The memory disk handle.
|
---|
137 | * @param off Where to start comparing.
|
---|
138 | * @param cbCmp How many bytes to compare.
|
---|
139 | * @param pSgBuf The S/G buffer to compare with.
|
---|
140 | */
|
---|
141 | int VDMemDiskCmp(PVDMEMDISK pMemDisk, uint64_t off, size_t cbCmp, PRTSGBUF pSgBuf);
|
---|
142 |
|
---|
143 | #endif /* !VBOX_INCLUDED_SRC_testcase_VDMemDisk_h */
|
---|