1 | /* $Id: DrvHostBase.h 26173 2010-02-02 21:11:09Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * DrvHostBase - Host base drive access driver.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
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 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
18 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
19 | * additional information or have any questions.
|
---|
20 | */
|
---|
21 |
|
---|
22 | #ifndef __HostDrvBase_h__
|
---|
23 | #define __HostDrvBase_h__
|
---|
24 |
|
---|
25 | #include <VBox/cdefs.h>
|
---|
26 |
|
---|
27 | RT_C_DECLS_BEGIN
|
---|
28 |
|
---|
29 |
|
---|
30 | /** Pointer to host base drive access driver instance data. */
|
---|
31 | typedef struct DRVHOSTBASE *PDRVHOSTBASE;
|
---|
32 | /**
|
---|
33 | * Host base drive access driver instance data.
|
---|
34 | *
|
---|
35 | * @implements PDMIMOUNT
|
---|
36 | * @implements PDMIBLOCKBIOS
|
---|
37 | * @implements PDMIBLOCK
|
---|
38 | */
|
---|
39 | typedef struct DRVHOSTBASE
|
---|
40 | {
|
---|
41 | /** Critical section used to serialize access to the handle and other
|
---|
42 | * members of this struct. */
|
---|
43 | RTCRITSECT CritSect;
|
---|
44 | /** Pointer driver instance. */
|
---|
45 | PPDMDRVINS pDrvIns;
|
---|
46 | /** Drive type. */
|
---|
47 | PDMBLOCKTYPE enmType;
|
---|
48 | /** Visible to the BIOS. */
|
---|
49 | bool fBiosVisible;
|
---|
50 | /** The configuration readonly value. */
|
---|
51 | bool fReadOnlyConfig;
|
---|
52 | /** The current readonly status. */
|
---|
53 | bool fReadOnly;
|
---|
54 | /** Flag whether failure to attach is an error or not. */
|
---|
55 | bool fAttachFailError;
|
---|
56 | /** Flag whether to keep instance working (as unmounted though). */
|
---|
57 | bool fKeepInstance;
|
---|
58 | /** Device name (MMHeap). */
|
---|
59 | char *pszDevice;
|
---|
60 | /** Device name to open (RTStrFree). */
|
---|
61 | char *pszDeviceOpen;
|
---|
62 | #ifdef RT_OS_SOLARIS
|
---|
63 | /** Device name of raw device (RTStrFree). */
|
---|
64 | char *pszRawDeviceOpen;
|
---|
65 | #endif
|
---|
66 | /** Uuid of the drive. */
|
---|
67 | RTUUID Uuid;
|
---|
68 |
|
---|
69 | /** Pointer to the block port interface above us. */
|
---|
70 | PPDMIBLOCKPORT pDrvBlockPort;
|
---|
71 | /** Pointer to the mount notify interface above us. */
|
---|
72 | PPDMIMOUNTNOTIFY pDrvMountNotify;
|
---|
73 | /** Our block interface. */
|
---|
74 | PDMIBLOCK IBlock;
|
---|
75 | /** Our block interface. */
|
---|
76 | PDMIBLOCKBIOS IBlockBios;
|
---|
77 | /** Our mountable interface. */
|
---|
78 | PDMIMOUNT IMount;
|
---|
79 |
|
---|
80 | /** Media present indicator. */
|
---|
81 | bool volatile fMediaPresent;
|
---|
82 | /** Locked indicator. */
|
---|
83 | bool fLocked;
|
---|
84 | /** The size of the media currently in the drive.
|
---|
85 | * This is invalid if no drive is in the drive. */
|
---|
86 | uint64_t volatile cbSize;
|
---|
87 | #if !defined(RT_OS_DARWIN)
|
---|
88 | /** The filehandle of the device. */
|
---|
89 | RTFILE FileDevice;
|
---|
90 | #endif
|
---|
91 | #ifdef RT_OS_SOLARIS
|
---|
92 | /** The raw filehandle of the device. */
|
---|
93 | RTFILE FileRawDevice;
|
---|
94 | #endif
|
---|
95 |
|
---|
96 | /** Handle of the poller thread. */
|
---|
97 | RTTHREAD ThreadPoller;
|
---|
98 | #ifndef RT_OS_WINDOWS
|
---|
99 | /** Event semaphore the thread will wait on. */
|
---|
100 | RTSEMEVENT EventPoller;
|
---|
101 | #endif
|
---|
102 | /** The poller interval. */
|
---|
103 | RTMSINTERVAL cMilliesPoller;
|
---|
104 | /** The shutdown indicator. */
|
---|
105 | bool volatile fShutdownPoller;
|
---|
106 |
|
---|
107 | /** BIOS PCHS geometry. */
|
---|
108 | PDMMEDIAGEOMETRY PCHSGeometry;
|
---|
109 | /** BIOS LCHS geometry. */
|
---|
110 | PDMMEDIAGEOMETRY LCHSGeometry;
|
---|
111 |
|
---|
112 | /** The number of errors that could go into the release log. (flood gate) */
|
---|
113 | uint32_t cLogRelErrors;
|
---|
114 |
|
---|
115 | #ifdef RT_OS_DARWIN
|
---|
116 | /** The master port. */
|
---|
117 | mach_port_t MasterPort;
|
---|
118 | /** The MMC-2 Device Interface. (This is only used to get the scsi task interface.) */
|
---|
119 | MMCDeviceInterface **ppMMCDI;
|
---|
120 | /** The SCSI Task Device Interface. */
|
---|
121 | SCSITaskDeviceInterface **ppScsiTaskDI;
|
---|
122 | /** The block size. Set when querying the media size. */
|
---|
123 | uint32_t cbBlock;
|
---|
124 | /** The disk arbitration session reference. NULL if we didn't have to claim & unmount the device. */
|
---|
125 | DASessionRef pDASession;
|
---|
126 | /** The disk arbritation disk reference. NULL if we didn't have to claim & unmount the device. */
|
---|
127 | DADiskRef pDADisk;
|
---|
128 | #endif
|
---|
129 |
|
---|
130 | #ifdef RT_OS_WINDOWS
|
---|
131 | /** Handle to the window we use to catch the device change broadcast messages. */
|
---|
132 | volatile HWND hwndDeviceChange;
|
---|
133 | /** The unit mask. */
|
---|
134 | DWORD fUnitMask;
|
---|
135 | #endif
|
---|
136 |
|
---|
137 | #ifdef RT_OS_LINUX
|
---|
138 | /** Double buffer required for ioctl with the Linux kernel as long as we use
|
---|
139 | * remap_pfn_range() instead of vm_insert_page(). */
|
---|
140 | uint8_t *pbDoubleBuffer;
|
---|
141 | #endif
|
---|
142 |
|
---|
143 | #ifdef RT_OS_FREEBSD
|
---|
144 | /** The block size. Set when querying the media size. */
|
---|
145 | uint32_t cbBlock;
|
---|
146 | /** SCSI bus number. */
|
---|
147 | path_id_t ScsiBus;
|
---|
148 | /** target ID of the passthrough device. */
|
---|
149 | target_id_t ScsiTargetID;
|
---|
150 | /** LUN of the passthrough device. */
|
---|
151 | lun_id_t ScsiLunID;
|
---|
152 | #endif
|
---|
153 |
|
---|
154 | /**
|
---|
155 | * Performs the locking / unlocking of the device.
|
---|
156 | *
|
---|
157 | * This callback pointer should be set to NULL if the device doesn't support this action.
|
---|
158 | *
|
---|
159 | * @returns VBox status code.
|
---|
160 | * @param pThis Pointer to the instance data.
|
---|
161 | * @param fLock Set if locking, clear if unlocking.
|
---|
162 | */
|
---|
163 | DECLCALLBACKMEMBER(int, pfnDoLock)(PDRVHOSTBASE pThis, bool fLock);
|
---|
164 |
|
---|
165 | /**
|
---|
166 | * Queries the media size.
|
---|
167 | * Can also be used to perform actions on media change.
|
---|
168 | *
|
---|
169 | * This callback pointer should be set to NULL if the default action is fine for this device.
|
---|
170 | *
|
---|
171 | * @returns VBox status code.
|
---|
172 | * @param pThis Pointer to the instance data.
|
---|
173 | * @param pcb Where to store the media size in bytes.
|
---|
174 | */
|
---|
175 | DECLCALLBACKMEMBER(int, pfnGetMediaSize)(PDRVHOSTBASE pThis, uint64_t *pcb);
|
---|
176 |
|
---|
177 | /***
|
---|
178 | * Performs the polling operation.
|
---|
179 | *
|
---|
180 | * @returns VBox status code. (Failure means retry.)
|
---|
181 | * @param pThis Pointer to the instance data.
|
---|
182 | */
|
---|
183 | DECLCALLBACKMEMBER(int, pfnPoll)(PDRVHOSTBASE pThis);
|
---|
184 | } DRVHOSTBASE;
|
---|
185 |
|
---|
186 |
|
---|
187 | int DRVHostBaseInitData(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, PDMBLOCKTYPE enmType);
|
---|
188 | int DRVHostBaseInitFinish(PDRVHOSTBASE pThis);
|
---|
189 | int DRVHostBaseMediaPresent(PDRVHOSTBASE pThis);
|
---|
190 | void DRVHostBaseMediaNotPresent(PDRVHOSTBASE pThis);
|
---|
191 | DECLCALLBACK(void) DRVHostBaseDestruct(PPDMDRVINS pDrvIns);
|
---|
192 | #if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD)
|
---|
193 | DECLCALLBACK(int) DRVHostBaseScsiCmd(PDRVHOSTBASE pThis, const uint8_t *pbCmd, size_t cbCmd, PDMBLOCKTXDIR enmTxDir,
|
---|
194 | void *pvBuf, uint32_t *pcbBuf, uint8_t *pbSense, size_t cbSense, uint32_t cTimeoutMillies);
|
---|
195 | #endif
|
---|
196 |
|
---|
197 |
|
---|
198 | /** Makes a PDRVHOSTBASE out of a PPDMIMOUNT. */
|
---|
199 | #define PDMIMOUNT_2_DRVHOSTBASE(pInterface) ( (PDRVHOSTBASE)((uintptr_t)pInterface - RT_OFFSETOF(DRVHOSTBASE, IMount)) )
|
---|
200 |
|
---|
201 | /** Makes a PDRVHOSTBASE out of a PPDMIBLOCK. */
|
---|
202 | #define PDMIBLOCK_2_DRVHOSTBASE(pInterface) ( (PDRVHOSTBASE)((uintptr_t)pInterface - RT_OFFSETOF(DRVHOSTBASE, IBlock)) )
|
---|
203 |
|
---|
204 | RT_C_DECLS_END
|
---|
205 |
|
---|
206 | #endif
|
---|