VirtualBox

source: vbox/trunk/src/VBox/Devices/Storage/DrvHostBase.h@ 82781

Last change on this file since 82781 was 76565, checked in by vboxsync, 5 years ago

Devices: Use VBOX_INCLUDED_SRC_ as header guard prefix with scm.

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

© 2023 Oracle
ContactPrivacy policyTerms of Use