1 | /* $Id: DrvHostBase.h 106061 2024-09-16 14:03:52Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * DrvHostBase - Host base drive access driver.
|
---|
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 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 | #ifndef VBOX_INCLUDED_SRC_Storage_DrvHostBase_h
|
---|
29 | #define VBOX_INCLUDED_SRC_Storage_DrvHostBase_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | #include <iprt/assert.h>
|
---|
35 | #include <iprt/err.h>
|
---|
36 | #include <iprt/critsect.h>
|
---|
37 | #include <iprt/log.h>
|
---|
38 | #include <iprt/semaphore.h>
|
---|
39 | #include <VBox/cdefs.h>
|
---|
40 | #include <VBox/vmm/pdmdrv.h>
|
---|
41 | #include <VBox/vmm/pdmstorageifs.h>
|
---|
42 |
|
---|
43 | RT_C_DECLS_BEGIN
|
---|
44 |
|
---|
45 |
|
---|
46 | /** Pointer to host base drive access driver instance data. */
|
---|
47 | typedef struct DRVHOSTBASE *PDRVHOSTBASE;
|
---|
48 | /**
|
---|
49 | * Host base drive access driver instance data.
|
---|
50 | *
|
---|
51 | * @implements PDMIMOUNT
|
---|
52 | * @implements PDMIMEDIA
|
---|
53 | */
|
---|
54 | typedef struct DRVHOSTBASE
|
---|
55 | {
|
---|
56 | /** Critical section used to serialize access to the handle and other
|
---|
57 | * members of this struct. */
|
---|
58 | RTCRITSECT CritSect;
|
---|
59 | /** Pointer driver instance. */
|
---|
60 | PPDMDRVINS pDrvIns;
|
---|
61 | /** Drive type. */
|
---|
62 | PDMMEDIATYPE enmType;
|
---|
63 | /** Visible to the BIOS. */
|
---|
64 | bool fBiosVisible;
|
---|
65 | /** The configuration readonly value. */
|
---|
66 | bool fReadOnlyConfig;
|
---|
67 | /** The current readonly status. */
|
---|
68 | bool fReadOnly;
|
---|
69 | /** Flag whether failure to attach is an error or not. */
|
---|
70 | bool fAttachFailError;
|
---|
71 | /** Flag whether to keep instance working (as unmounted though). */
|
---|
72 | bool fKeepInstance;
|
---|
73 | /** Device name (MMHeap). */
|
---|
74 | char *pszDevice;
|
---|
75 | /** Device name to open (RTStrFree). */
|
---|
76 | char *pszDeviceOpen;
|
---|
77 | /** Uuid of the drive. */
|
---|
78 | RTUUID Uuid;
|
---|
79 |
|
---|
80 | /** Pointer to the media port interface above us. */
|
---|
81 | PPDMIMEDIAPORT pDrvMediaPort;
|
---|
82 | /** Pointer to the extended media port interface above us. */
|
---|
83 | PPDMIMEDIAEXPORT pDrvMediaExPort;
|
---|
84 | /** Pointer to the mount notify interface above us. */
|
---|
85 | PPDMIMOUNTNOTIFY pDrvMountNotify;
|
---|
86 | /** Our media interface. */
|
---|
87 | PDMIMEDIA IMedia;
|
---|
88 | /** Our extended media interface. */
|
---|
89 | PDMIMEDIAEX IMediaEx;
|
---|
90 | /** Our mountable interface. */
|
---|
91 | PDMIMOUNT IMount;
|
---|
92 |
|
---|
93 | /** Media present indicator. */
|
---|
94 | bool volatile fMediaPresent;
|
---|
95 | /** Locked indicator. */
|
---|
96 | bool fLocked;
|
---|
97 | /** The size of the media currently in the drive.
|
---|
98 | * This is invalid if no drive is in the drive. */
|
---|
99 | uint64_t volatile cbSize;
|
---|
100 |
|
---|
101 | /** Handle of the poller thread. */
|
---|
102 | RTTHREAD ThreadPoller;
|
---|
103 | /** Event semaphore the thread will wait on. */
|
---|
104 | RTSEMEVENT EventPoller;
|
---|
105 | /** The poller interval. */
|
---|
106 | RTMSINTERVAL cMilliesPoller;
|
---|
107 | /** The shutdown indicator. */
|
---|
108 | bool volatile fShutdownPoller;
|
---|
109 |
|
---|
110 | /** BIOS PCHS geometry. */
|
---|
111 | PDMMEDIAGEOMETRY PCHSGeometry;
|
---|
112 | /** BIOS LCHS geometry. */
|
---|
113 | PDMMEDIAGEOMETRY LCHSGeometry;
|
---|
114 |
|
---|
115 | /** Pointer to the current buffer holding data. */
|
---|
116 | void *pvBuf;
|
---|
117 | /** Size of the buffer. */
|
---|
118 | size_t cbBuf;
|
---|
119 | /** Size of the I/O request to allocate. */
|
---|
120 | size_t cbIoReqAlloc;
|
---|
121 |
|
---|
122 | /** Release statistics: number of bytes written. */
|
---|
123 | STAMCOUNTER StatBytesWritten;
|
---|
124 | /** Release statistics: number of bytes read. */
|
---|
125 | STAMCOUNTER StatBytesRead;
|
---|
126 | /** Release statistics: Number of requests submitted. */
|
---|
127 | STAMCOUNTER StatReqsSubmitted;
|
---|
128 | /** Release statistics: Number of requests failed. */
|
---|
129 | STAMCOUNTER StatReqsFailed;
|
---|
130 | /** Release statistics: Number of requests succeeded. */
|
---|
131 | STAMCOUNTER StatReqsSucceeded;
|
---|
132 | /** Release statistics: Number of flush requests. */
|
---|
133 | STAMCOUNTER StatReqsFlush;
|
---|
134 | /** Release statistics: Number of write requests. */
|
---|
135 | STAMCOUNTER StatReqsWrite;
|
---|
136 | /** Release statistics: Number of read requests. */
|
---|
137 | STAMCOUNTER StatReqsRead;
|
---|
138 |
|
---|
139 | /**
|
---|
140 | * Performs the locking / unlocking of the device.
|
---|
141 | *
|
---|
142 | * This callback pointer should be set to NULL if the device doesn't support this action.
|
---|
143 | *
|
---|
144 | * @returns VBox status code.
|
---|
145 | * @param pThis Pointer to the instance data.
|
---|
146 | * @param fLock Set if locking, clear if unlocking.
|
---|
147 | */
|
---|
148 | DECLCALLBACKMEMBER(int, pfnDoLock,(PDRVHOSTBASE pThis, bool fLock));
|
---|
149 |
|
---|
150 | union
|
---|
151 | {
|
---|
152 | #ifdef DRVHOSTBASE_OS_INT_DECLARED
|
---|
153 | DRVHOSTBASEOS Os;
|
---|
154 | #endif
|
---|
155 | uint8_t abPadding[64];
|
---|
156 | };
|
---|
157 | } DRVHOSTBASE;
|
---|
158 |
|
---|
159 |
|
---|
160 | /**
|
---|
161 | * Request structure fo a request.
|
---|
162 | */
|
---|
163 | typedef struct DRVHOSTBASEREQ
|
---|
164 | {
|
---|
165 | /** Transfer size. */
|
---|
166 | size_t cbReq;
|
---|
167 | /** Amount of residual data. */
|
---|
168 | size_t cbResidual;
|
---|
169 | /** Start of the request data for the device above us. */
|
---|
170 | uint8_t abAlloc[1];
|
---|
171 | } DRVHOSTBASEREQ;
|
---|
172 | /** Pointer to a request structure. */
|
---|
173 | typedef DRVHOSTBASEREQ *PDRVHOSTBASEREQ;
|
---|
174 |
|
---|
175 | DECLHIDDEN(int) DRVHostBaseInit(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, const char *pszCfgValid, PDMMEDIATYPE enmType);
|
---|
176 | DECLHIDDEN(int) DRVHostBaseMediaPresent(PDRVHOSTBASE pThis);
|
---|
177 | DECLHIDDEN(void) DRVHostBaseMediaNotPresent(PDRVHOSTBASE pThis);
|
---|
178 | DECLCALLBACK(void) DRVHostBaseDestruct(PPDMDRVINS pDrvIns);
|
---|
179 |
|
---|
180 | DECLHIDDEN(int) drvHostBaseScsiCmdOs(PDRVHOSTBASE pThis, const uint8_t *pbCmd, size_t cbCmd, PDMMEDIATXDIR enmTxDir,
|
---|
181 | void *pvBuf, uint32_t *pcbBuf, uint8_t *pbSense, size_t cbSense, uint32_t cTimeoutMillies);
|
---|
182 | DECLHIDDEN(size_t) drvHostBaseScsiCmdGetBufLimitOs(PDRVHOSTBASE pThis);
|
---|
183 | DECLHIDDEN(int) drvHostBaseGetMediaSizeOs(PDRVHOSTBASE pThis, uint64_t *pcb);
|
---|
184 | DECLHIDDEN(int) drvHostBaseReadOs(PDRVHOSTBASE pThis, uint64_t off, void *pvBuf, size_t cbRead);
|
---|
185 | DECLHIDDEN(int) drvHostBaseWriteOs(PDRVHOSTBASE pThis, uint64_t off, const void *pvBuf, size_t cbWrite);
|
---|
186 | DECLHIDDEN(int) drvHostBaseFlushOs(PDRVHOSTBASE pThis);
|
---|
187 | DECLHIDDEN(int) drvHostBaseDoLockOs(PDRVHOSTBASE pThis, bool fLock);
|
---|
188 | DECLHIDDEN(int) drvHostBaseEjectOs(PDRVHOSTBASE pThis);
|
---|
189 |
|
---|
190 | DECLHIDDEN(void) drvHostBaseInitOs(PDRVHOSTBASE pThis);
|
---|
191 | DECLHIDDEN(int) drvHostBaseOpenOs(PDRVHOSTBASE pThis, bool fReadOnly);
|
---|
192 | DECLHIDDEN(int) drvHostBaseMediaRefreshOs(PDRVHOSTBASE pThis);
|
---|
193 | DECLHIDDEN(int) drvHostBaseQueryMediaStatusOs(PDRVHOSTBASE pThis, bool *pfMediaChanged, bool *pfMediaPresent);
|
---|
194 | DECLHIDDEN(bool) drvHostBaseIsMediaPollingRequiredOs(PDRVHOSTBASE pThis);
|
---|
195 | DECLHIDDEN(void) drvHostBaseDestructOs(PDRVHOSTBASE pThis);
|
---|
196 |
|
---|
197 | DECLHIDDEN(int) drvHostBaseBufferRetain(PDRVHOSTBASE pThis, PDRVHOSTBASEREQ pReq, size_t cbBuf, bool fWrite, void **ppvBuf);
|
---|
198 | DECLHIDDEN(int) drvHostBaseBufferRelease(PDRVHOSTBASE pThis, PDRVHOSTBASEREQ pReq, size_t cbBuf, bool fWrite, void *pvBuf);
|
---|
199 |
|
---|
200 | RT_C_DECLS_END
|
---|
201 |
|
---|
202 | #endif /* !VBOX_INCLUDED_SRC_Storage_DrvHostBase_h */
|
---|