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