VirtualBox

Changeset 59248 in vbox for trunk


Ignore:
Timestamp:
Jan 4, 2016 2:13:22 PM (9 years ago)
Author:
vboxsync
Message:

Storage: Get rid of the block driver and merge the the little extra functionality it had into the VD driver. Enables us to get rid of PDMIBLOCK which is basically a subset of PDMIMEDIA and makes changes to the latter interface tedious because it had to be replicated in the former. (bugref:4114)

Location:
trunk
Files:
3 deleted
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/vmm/pdmifs.h

    r58154 r59248  
    10181018
    10191019
    1020 /** Pointer to a block port interface. */
    1021 typedef struct PDMIBLOCKPORT *PPDMIBLOCKPORT;
    1022 /**
    1023  * Block notify interface (down).
    1024  * Pair with PDMIBLOCK.
    1025  */
    1026 typedef struct PDMIBLOCKPORT
    1027 {
    1028     /**
    1029      * Returns the storage controller name, instance and LUN of the attached medium.
    1030      *
    1031      * @returns VBox status.
     1020/** Pointer to a mount interface. */
     1021typedef struct PDMIMOUNTNOTIFY *PPDMIMOUNTNOTIFY;
     1022/**
     1023 * Block interface (up).
     1024 * Pair with PDMIMOUNT.
     1025 */
     1026typedef struct PDMIMOUNTNOTIFY
     1027{
     1028    /**
     1029     * Called when a media is mounted.
     1030     *
     1031     * @param   pInterface      Pointer to the interface structure containing the called function pointer.
     1032     * @thread  The emulation thread.
     1033     */
     1034    DECLR3CALLBACKMEMBER(void, pfnMountNotify,(PPDMIMOUNTNOTIFY pInterface));
     1035
     1036    /**
     1037     * Called when a media is unmounted
     1038     * @param   pInterface      Pointer to the interface structure containing the called function pointer.
     1039     * @thread  The emulation thread.
     1040     */
     1041    DECLR3CALLBACKMEMBER(void, pfnUnmountNotify,(PPDMIMOUNTNOTIFY pInterface));
     1042} PDMIMOUNTNOTIFY;
     1043/** PDMIMOUNTNOTIFY interface ID. */
     1044#define PDMIMOUNTNOTIFY_IID                     "fa143ac9-9fc6-498e-997f-945380a558f9"
     1045
     1046
     1047/** Pointer to mount interface. */
     1048typedef struct PDMIMOUNT *PPDMIMOUNT;
     1049/**
     1050 * Mount interface (down).
     1051 * Pair with PDMIMOUNTNOTIFY.
     1052 */
     1053typedef struct PDMIMOUNT
     1054{
     1055    /**
     1056     * Unmount the media.
     1057     *
     1058     * The driver will validate and pass it on. On the rebounce it will decide whether or not to detach it self.
     1059     *
     1060     * @returns VBox status code.
     1061     * @param   pInterface      Pointer to the interface structure containing the called function pointer.
     1062     * @thread  The emulation thread.
     1063     * @param   fForce          Force the unmount, even for locked media.
     1064     * @param   fEject          Eject the medium. Only relevant for host drives.
     1065     * @thread  The emulation thread.
     1066     */
     1067    DECLR3CALLBACKMEMBER(int, pfnUnmount,(PPDMIMOUNT pInterface, bool fForce, bool fEject));
     1068
     1069    /**
     1070     * Checks if a media is mounted.
     1071     *
     1072     * @returns true if mounted.
     1073     * @returns false if not mounted.
     1074     * @param   pInterface      Pointer to the interface structure containing the called function pointer.
     1075     * @thread  Any thread.
     1076     */
     1077    DECLR3CALLBACKMEMBER(bool, pfnIsMounted,(PPDMIMOUNT pInterface));
     1078
     1079    /**
     1080     * Locks the media, preventing any unmounting of it.
     1081     *
     1082     * @returns VBox status code.
     1083     * @param   pInterface      Pointer to the interface structure containing the called function pointer.
     1084     * @thread  The emulation thread.
     1085     */
     1086    DECLR3CALLBACKMEMBER(int, pfnLock,(PPDMIMOUNT pInterface));
     1087
     1088    /**
     1089     * Unlocks the media, canceling previous calls to pfnLock().
     1090     *
     1091     * @returns VBox status code.
     1092     * @param   pInterface      Pointer to the interface structure containing the called function pointer.
     1093     * @thread  The emulation thread.
     1094     */
     1095    DECLR3CALLBACKMEMBER(int, pfnUnlock,(PPDMIMOUNT pInterface));
     1096
     1097    /**
     1098     * Checks if a media is locked.
     1099     *
     1100     * @returns true if locked.
     1101     * @returns false if not locked.
     1102     * @param   pInterface      Pointer to the interface structure containing the called function pointer.
     1103     * @thread  Any thread.
     1104     */
     1105    DECLR3CALLBACKMEMBER(bool, pfnIsLocked,(PPDMIMOUNT pInterface));
     1106} PDMIMOUNT;
     1107/** PDMIMOUNT interface ID. */
     1108#define PDMIMOUNT_IID                           "34fc7a4c-623a-4806-a6bf-5be1be33c99f"
     1109
     1110/** Pointer to a secret key interface. */
     1111typedef struct PDMISECKEY *PPDMISECKEY;
     1112
     1113/**
     1114 * Secret key interface to retrieve secret keys.
     1115 */
     1116typedef struct PDMISECKEY
     1117{
     1118    /**
     1119     * Retains a key identified by the ID. The caller will only hold a reference
     1120     * to the key and must not modify the key buffer in any way.
     1121     *
     1122     * @returns VBox status code.
    10321123     * @param   pInterface      Pointer to this interface.
    1033      * @param   ppcszController Where to store the name of the storage controller.
    1034      * @param   piInstance      Where to store the instance number of the controller.
    1035      * @param   piLUN           Where to store the LUN of the attached device.
    1036      */
    1037     DECLR3CALLBACKMEMBER(int, pfnQueryDeviceLocation, (PPDMIBLOCKPORT pInterface, const char **ppcszController,
    1038                                                        uint32_t *piInstance, uint32_t *piLUN));
    1039 
    1040 } PDMIBLOCKPORT;
    1041 /** PDMIBLOCKPORT interface ID. */
    1042 #define PDMIBLOCKPORT_IID                 "bbbed4cf-0862-4ffd-b60c-f7a65ef8e8ff"
     1124     * @param   pszId           The alias/id for the key to retrieve.
     1125     * @param   ppbKey          Where to store the pointer to the key buffer on success.
     1126     * @param   pcbKey          Where to store the size of the key in bytes on success.
     1127     */
     1128    DECLR3CALLBACKMEMBER(int, pfnKeyRetain, (PPDMISECKEY pInterface, const char *pszId,
     1129                                             const uint8_t **pbKey, size_t *pcbKey));
     1130
     1131    /**
     1132     * Releases one reference of the key identified by the given identifier.
     1133     * The caller must not access the key buffer after calling this operation.
     1134     *
     1135     * @returns VBox status code.
     1136     * @param   pInterface      Pointer to this interface.
     1137     * @param   pszId          The alias/id for the key to release.
     1138     *
     1139     * @note: It is advised to release the key whenever it is not used anymore so the entity
     1140     *        storing the key can do anything to make retrieving the key from memory more
     1141     *        difficult like scrambling the memory buffer for instance.
     1142     */
     1143    DECLR3CALLBACKMEMBER(int, pfnKeyRelease, (PPDMISECKEY pInterface, const char *pszId));
     1144
     1145    /**
     1146     * Retains a password identified by the ID. The caller will only hold a reference
     1147     * to the password and must not modify the buffer in any way.
     1148     *
     1149     * @returns VBox status code.
     1150     * @param   pInterface      Pointer to this interface.
     1151     * @param   pszId           The alias/id for the password to retrieve.
     1152     * @param   ppszPassword    Where to store the pointer to the password on success.
     1153     */
     1154    DECLR3CALLBACKMEMBER(int, pfnPasswordRetain, (PPDMISECKEY pInterface, const char *pszId,
     1155                                                  const char **ppszPassword));
     1156
     1157    /**
     1158     * Releases one reference of the password identified by the given identifier.
     1159     * The caller must not access the password after calling this operation.
     1160     *
     1161     * @returns VBox status code.
     1162     * @param   pInterface      Pointer to this interface.
     1163     * @param   pszId           The alias/id for the password to release.
     1164     *
     1165     * @note: It is advised to release the password whenever it is not used anymore so the entity
     1166     *        storing the password can do anything to make retrieving the password from memory more
     1167     *        difficult like scrambling the memory buffer for instance.
     1168     */
     1169    DECLR3CALLBACKMEMBER(int, pfnPasswordRelease, (PPDMISECKEY pInterface, const char *pszId));
     1170} PDMISECKEY;
     1171/** PDMISECKEY interface ID. */
     1172#define PDMISECKEY_IID                           "3d698355-d995-453d-960f-31566a891df2"
     1173
     1174/** Pointer to a secret key helper interface. */
     1175typedef struct PDMISECKEYHLP *PPDMISECKEYHLP;
     1176
     1177/**
     1178 * Secret key helper interface for non critical functionality.
     1179 */
     1180typedef struct PDMISECKEYHLP
     1181{
     1182    /**
     1183     * Notifies the interface provider that a key couldn't be retrieved from the key store.
     1184     *
     1185     * @returns VBox status code.
     1186     * @param   pInterface      Pointer to this interface.
     1187     */
     1188    DECLR3CALLBACKMEMBER(int, pfnKeyMissingNotify, (PPDMISECKEYHLP pInterface));
     1189
     1190} PDMISECKEYHLP;
     1191/** PDMISECKEY interface ID. */
     1192#define PDMISECKEYHLP_IID                        "7be96168-4156-40ac-86d2-3073bf8b318e"
    10431193
    10441194
     
    10561206
    10571207/**
    1058  * Block drive type.
    1059  */
    1060 typedef enum PDMBLOCKTYPE
     1208 * Media type.
     1209 */
     1210typedef enum PDMMEDIATYPE
    10611211{
    10621212    /** Error (for the query function). */
    1063     PDMBLOCKTYPE_ERROR = 1,
     1213    PDMMEDIATYPE_ERROR = 1,
    10641214    /** 360KB 5 1/4" floppy drive. */
    1065     PDMBLOCKTYPE_FLOPPY_360,
     1215    PDMMEDIATYPE_FLOPPY_360,
    10661216    /** 720KB 3 1/2" floppy drive. */
    1067     PDMBLOCKTYPE_FLOPPY_720,
     1217    PDMMEDIATYPE_FLOPPY_720,
    10681218    /** 1.2MB 5 1/4" floppy drive. */
    1069     PDMBLOCKTYPE_FLOPPY_1_20,
     1219    PDMMEDIATYPE_FLOPPY_1_20,
    10701220    /** 1.44MB 3 1/2" floppy drive. */
    1071     PDMBLOCKTYPE_FLOPPY_1_44,
     1221    PDMMEDIATYPE_FLOPPY_1_44,
    10721222    /** 2.88MB 3 1/2" floppy drive. */
    1073     PDMBLOCKTYPE_FLOPPY_2_88,
     1223    PDMMEDIATYPE_FLOPPY_2_88,
    10741224    /** Fake drive that can take up to 15.6 MB images.
    10751225     * C=255, H=2, S=63.  */
    1076     PDMBLOCKTYPE_FLOPPY_FAKE_15_6,
     1226    PDMMEDIATYPE_FLOPPY_FAKE_15_6,
    10771227    /** Fake drive that can take up to 63.5 MB images.
    10781228     * C=255, H=2, S=255.  */
    1079     PDMBLOCKTYPE_FLOPPY_FAKE_63_5,
     1229    PDMMEDIATYPE_FLOPPY_FAKE_63_5,
    10801230    /** CDROM drive. */
    1081     PDMBLOCKTYPE_CDROM,
     1231    PDMMEDIATYPE_CDROM,
    10821232    /** DVD drive. */
    1083     PDMBLOCKTYPE_DVD,
     1233    PDMMEDIATYPE_DVD,
    10841234    /** Hard disk drive. */
    1085     PDMBLOCKTYPE_HARD_DISK
    1086 } PDMBLOCKTYPE;
     1235    PDMMEDIATYPE_HARD_DISK
     1236} PDMMEDIATYPE;
    10871237
    10881238/** Check if the given block type is a floppy. */
    1089 #define PDMBLOCKTYPE_IS_FLOPPY(a_enmType) ( (a_enmType) >= PDMBLOCKTYPE_FLOPPY_360 && (a_enmType) <= PDMBLOCKTYPE_FLOPPY_2_88 )
    1090 
    1091 /**
    1092  * Block raw command data transfer direction.
    1093  */
    1094 typedef enum PDMBLOCKTXDIR
    1095 {
    1096     PDMBLOCKTXDIR_NONE = 0,
    1097     PDMBLOCKTXDIR_FROM_DEVICE,
    1098     PDMBLOCKTXDIR_TO_DEVICE
    1099 } PDMBLOCKTXDIR;
    1100 
    1101 
    1102 /** Pointer to a block interface. */
    1103 typedef struct PDMIBLOCK *PPDMIBLOCK;
    1104 /**
    1105  * Block interface (up).
    1106  * Pair with PDMIBLOCKPORT.
    1107  */
    1108 typedef struct PDMIBLOCK
    1109 {
    1110     /**
    1111      * Read bits.
    1112      *
    1113      * @returns VBox status code.
    1114      * @param   pInterface      Pointer to the interface structure containing the called function pointer.
    1115      * @param   off             Offset to start reading from. The offset must be aligned to a sector boundary.
    1116      * @param   pvBuf           Where to store the read bits.
    1117      * @param   cbRead          Number of bytes to read. Must be aligned to a sector boundary.
    1118      * @thread  Any thread.
    1119      */
    1120     DECLR3CALLBACKMEMBER(int, pfnRead,(PPDMIBLOCK pInterface, uint64_t off, void *pvBuf, size_t cbRead));
    1121 
    1122     /**
    1123      * Read bits - version for DevPcBios.
    1124      *
    1125      * @returns VBox status code.
    1126      * @param   pInterface      Pointer to the interface structure containing the called function pointer.
    1127      * @param   off             Offset to start reading from. The offset must be aligned to a sector boundary.
    1128      * @param   pvBuf           Where to store the read bits.
    1129      * @param   cbRead          Number of bytes to read. Must be aligned to a sector boundary.
    1130      * @thread  Any thread.
    1131      *
    1132      * @note: Special version of pfnRead which doesn't try to suspend the VM when the DEKs for encrypted disks
    1133      *        are missing but just returns an error.
    1134      */
    1135     DECLR3CALLBACKMEMBER(int, pfnReadPcBios,(PPDMIBLOCK pInterface, uint64_t off, void *pvBuf, size_t cbRead));
    1136 
    1137     /**
    1138      * Write bits.
    1139      *
    1140      * @returns VBox status code.
    1141      * @param   pInterface      Pointer to the interface structure containing the called function pointer.
    1142      * @param   off             Offset to start writing at. The offset must be aligned to a sector boundary.
    1143      * @param   pvBuf           Where to store the write bits.
    1144      * @param   cbWrite         Number of bytes to write. Must be aligned to a sector boundary.
    1145      * @thread  Any thread.
    1146      */
    1147     DECLR3CALLBACKMEMBER(int, pfnWrite,(PPDMIBLOCK pInterface, uint64_t off, const void *pvBuf, size_t cbWrite));
    1148 
    1149     /**
    1150      * Make sure that the bits written are actually on the storage medium.
    1151      *
    1152      * @returns VBox status code.
    1153      * @param   pInterface      Pointer to the interface structure containing the called function pointer.
    1154      * @thread  Any thread.
    1155      */
    1156     DECLR3CALLBACKMEMBER(int, pfnFlush,(PPDMIBLOCK pInterface));
    1157 
    1158     /**
    1159      * Send a raw command to the underlying device (CDROM).
    1160      * This method is optional (i.e. the function pointer may be NULL).
    1161      *
    1162      * @returns VBox status code.
    1163      * @param   pInterface      Pointer to the interface structure containing the called function pointer.
    1164      * @param   pbCmd           Offset to start reading from.
    1165      * @param   enmTxDir        Direction of transfer.
    1166      * @param   pvBuf           Pointer tp the transfer buffer.
    1167      * @param   cbBuf           Size of the transfer buffer.
    1168      * @param   pbSenseKey      Status of the command (when return value is VERR_DEV_IO_ERROR).
    1169      * @param   cTimeoutMillies Command timeout in milliseconds.
    1170      * @thread  Any thread.
    1171      */
    1172     DECLR3CALLBACKMEMBER(int, pfnSendCmd,(PPDMIBLOCK pInterface, const uint8_t *pbCmd, PDMBLOCKTXDIR enmTxDir, void *pvBuf, uint32_t *pcbBuf, uint8_t *pabSense, size_t cbSense, uint32_t cTimeoutMillies));
    1173 
    1174     /**
    1175      * Merge medium contents during a live snapshot deletion.
    1176      *
    1177      * @returns VBox status code.
    1178      * @param   pInterface      Pointer to the interface structure containing the called function pointer.
    1179      * @param   pfnProgress     Function pointer for progress notification.
    1180      * @param   pvUser          Opaque user data for progress notification.
    1181      * @thread  Any thread.
    1182      */
    1183     DECLR3CALLBACKMEMBER(int, pfnMerge,(PPDMIBLOCK pInterface, PFNSIMPLEPROGRESS pfnProgress, void *pvUser));
    1184 
    1185     /**
    1186      * Check if the media is readonly or not.
    1187      *
    1188      * @returns true if readonly.
    1189      * @returns false if read/write.
    1190      * @param   pInterface      Pointer to the interface structure containing the called function pointer.
    1191      * @thread  Any thread.
    1192      */
    1193     DECLR3CALLBACKMEMBER(bool, pfnIsReadOnly,(PPDMIBLOCK pInterface));
    1194 
    1195     /**
    1196      * Gets the media size in bytes.
    1197      *
    1198      * @returns Media size in bytes.
    1199      * @param   pInterface      Pointer to the interface structure containing the called function pointer.
    1200      * @thread  Any thread.
    1201      */
    1202     DECLR3CALLBACKMEMBER(uint64_t, pfnGetSize,(PPDMIBLOCK pInterface));
    1203 
    1204     /**
    1205      * Gets the media sector size in bytes.
    1206      *
    1207      * @returns Media sector size in bytes.
    1208      * @param   pInterface      Pointer to the interface structure containing the called function pointer.
    1209      * @thread  Any thread.
    1210      */
    1211     DECLR3CALLBACKMEMBER(uint32_t, pfnGetSectorSize,(PPDMIBLOCK pInterface));
    1212 
    1213     /**
    1214      * Gets the block drive type.
    1215      *
    1216      * @returns block drive type.
    1217      * @param   pInterface      Pointer to the interface structure containing the called function pointer.
    1218      * @thread  Any thread.
    1219      */
    1220     DECLR3CALLBACKMEMBER(PDMBLOCKTYPE, pfnGetType,(PPDMIBLOCK pInterface));
    1221 
    1222     /**
    1223      * Gets the UUID of the block drive.
    1224      * Don't return the media UUID if it's removable.
    1225      *
    1226      * @returns VBox status code.
    1227      * @param   pInterface      Pointer to the interface structure containing the called function pointer.
    1228      * @param   pUuid           Where to store the UUID on success.
    1229      * @thread  Any thread.
    1230      */
    1231     DECLR3CALLBACKMEMBER(int, pfnGetUuid,(PPDMIBLOCK pInterface, PRTUUID pUuid));
    1232 
    1233     /**
    1234      * Discards the given range.
    1235      *
    1236      * @returns VBox status code.
    1237      * @param   pInterface      Pointer to the interface structure containing the called function pointer.
    1238      * @param   paRanges        Array of ranges to discard.
    1239      * @param   cRanges         Number of entries in the array.
    1240      * @thread  Any thread.
    1241      */
    1242     DECLR3CALLBACKMEMBER(int, pfnDiscard,(PPDMIBLOCK pInterface, PCRTRANGE paRanges, unsigned cRanges));
    1243 
    1244     /**
    1245      * Allocate buffer memory which is suitable for I/O and might have special proerties for secure
    1246      * environments (non-pageable memory for sensitive data which should not end up on the disk).
    1247      *
    1248      * @returns VBox status code.
    1249      * @param   pInterface      Pointer to the interface structure containing the called function pointer.
    1250      * @param   cb              Amount of memory to allocate.
    1251      * @param   ppvNew          Where to store the pointer to the buffer on success.
    1252      */
    1253     DECLR3CALLBACKMEMBER(int, pfnIoBufAlloc, (PPDMIBLOCK pInterface, size_t cb, void **ppvNew));
    1254 
    1255     /**
    1256      * Free memory allocated with PDMIBLOCK::pfnIoBufAlloc().
    1257      *
    1258      * @returns VBox status code.
    1259      * @param   pInterface      Pointer to the interface structure containing the called function pointer.
    1260      * @param   pv              Pointer to the memory to free.
    1261      * @param   cb              Amount of bytes given in PDMIBLOCK::pfnIoBufAlloc().
    1262      */
    1263     DECLR3CALLBACKMEMBER(int, pfnIoBufFree, (PPDMIBLOCK pInterface, void *pv, size_t cb));
    1264 
    1265 } PDMIBLOCK;
    1266 /** PDMIBLOCK interface ID. */
    1267 #define PDMIBLOCK_IID                           "4e804e8e-3c01-4f20-98d9-a30ece8ec9f5"
    1268 
    1269 
    1270 /** Pointer to a mount interface. */
    1271 typedef struct PDMIMOUNTNOTIFY *PPDMIMOUNTNOTIFY;
    1272 /**
    1273  * Block interface (up).
    1274  * Pair with PDMIMOUNT.
    1275  */
    1276 typedef struct PDMIMOUNTNOTIFY
    1277 {
    1278     /**
    1279      * Called when a media is mounted.
    1280      *
    1281      * @param   pInterface      Pointer to the interface structure containing the called function pointer.
    1282      * @thread  The emulation thread.
    1283      */
    1284     DECLR3CALLBACKMEMBER(void, pfnMountNotify,(PPDMIMOUNTNOTIFY pInterface));
    1285 
    1286     /**
    1287      * Called when a media is unmounted
    1288      * @param   pInterface      Pointer to the interface structure containing the called function pointer.
    1289      * @thread  The emulation thread.
    1290      */
    1291     DECLR3CALLBACKMEMBER(void, pfnUnmountNotify,(PPDMIMOUNTNOTIFY pInterface));
    1292 } PDMIMOUNTNOTIFY;
    1293 /** PDMIMOUNTNOTIFY interface ID. */
    1294 #define PDMIMOUNTNOTIFY_IID                     "fa143ac9-9fc6-498e-997f-945380a558f9"
    1295 
    1296 
    1297 /** Pointer to mount interface. */
    1298 typedef struct PDMIMOUNT *PPDMIMOUNT;
    1299 /**
    1300  * Mount interface (down).
    1301  * Pair with PDMIMOUNTNOTIFY.
    1302  */
    1303 typedef struct PDMIMOUNT
    1304 {
    1305     /**
    1306      * Mount a media.
    1307      *
    1308      * This will not unmount any currently mounted media!
    1309      *
    1310      * @returns VBox status code.
    1311      * @param   pInterface      Pointer to the interface structure containing the called function pointer.
    1312      * @param   pszFilename     Pointer to filename. If this is NULL it assumed that the caller have
    1313      *                          constructed a configuration which can be attached to the bottom driver.
    1314      * @param   pszCoreDriver   Core driver name. NULL will cause autodetection. Ignored if pszFilanem is NULL.
    1315      * @thread  The emulation thread.
    1316      */
    1317     DECLR3CALLBACKMEMBER(int, pfnMount,(PPDMIMOUNT pInterface, const char *pszFilename, const char *pszCoreDriver));
    1318 
    1319     /**
    1320      * Unmount the media.
    1321      *
    1322      * The driver will validate and pass it on. On the rebounce it will decide whether or not to detach it self.
    1323      *
    1324      * @returns VBox status code.
    1325      * @param   pInterface      Pointer to the interface structure containing the called function pointer.
    1326      * @thread  The emulation thread.
    1327      * @param   fForce          Force the unmount, even for locked media.
    1328      * @param   fEject          Eject the medium. Only relevant for host drives.
    1329      * @thread  The emulation thread.
    1330      */
    1331     DECLR3CALLBACKMEMBER(int, pfnUnmount,(PPDMIMOUNT pInterface, bool fForce, bool fEject));
    1332 
    1333     /**
    1334      * Checks if a media is mounted.
    1335      *
    1336      * @returns true if mounted.
    1337      * @returns false if not mounted.
    1338      * @param   pInterface      Pointer to the interface structure containing the called function pointer.
    1339      * @thread  Any thread.
    1340      */
    1341     DECLR3CALLBACKMEMBER(bool, pfnIsMounted,(PPDMIMOUNT pInterface));
    1342 
    1343     /**
    1344      * Locks the media, preventing any unmounting of it.
    1345      *
    1346      * @returns VBox status code.
    1347      * @param   pInterface      Pointer to the interface structure containing the called function pointer.
    1348      * @thread  The emulation thread.
    1349      */
    1350     DECLR3CALLBACKMEMBER(int, pfnLock,(PPDMIMOUNT pInterface));
    1351 
    1352     /**
    1353      * Unlocks the media, canceling previous calls to pfnLock().
    1354      *
    1355      * @returns VBox status code.
    1356      * @param   pInterface      Pointer to the interface structure containing the called function pointer.
    1357      * @thread  The emulation thread.
    1358      */
    1359     DECLR3CALLBACKMEMBER(int, pfnUnlock,(PPDMIMOUNT pInterface));
    1360 
    1361     /**
    1362      * Checks if a media is locked.
    1363      *
    1364      * @returns true if locked.
    1365      * @returns false if not locked.
    1366      * @param   pInterface      Pointer to the interface structure containing the called function pointer.
    1367      * @thread  Any thread.
    1368      */
    1369     DECLR3CALLBACKMEMBER(bool, pfnIsLocked,(PPDMIMOUNT pInterface));
    1370 } PDMIMOUNT;
    1371 /** PDMIMOUNT interface ID. */
    1372 #define PDMIMOUNT_IID                           "34fc7a4c-623a-4806-a6bf-5be1be33c99f"
    1373 
    1374 /** Pointer to a secret key interface. */
    1375 typedef struct PDMISECKEY *PPDMISECKEY;
    1376 
    1377 /**
    1378  * Secret key interface to retrieve secret keys.
    1379  */
    1380 typedef struct PDMISECKEY
    1381 {
    1382     /**
    1383      * Retains a key identified by the ID. The caller will only hold a reference
    1384      * to the key and must not modify the key buffer in any way.
    1385      *
    1386      * @returns VBox status code.
    1387      * @param   pInterface      Pointer to this interface.
    1388      * @param   pszId           The alias/id for the key to retrieve.
    1389      * @param   ppbKey          Where to store the pointer to the key buffer on success.
    1390      * @param   pcbKey          Where to store the size of the key in bytes on success.
    1391      */
    1392     DECLR3CALLBACKMEMBER(int, pfnKeyRetain, (PPDMISECKEY pInterface, const char *pszId,
    1393                                              const uint8_t **pbKey, size_t *pcbKey));
    1394 
    1395     /**
    1396      * Releases one reference of the key identified by the given identifier.
    1397      * The caller must not access the key buffer after calling this operation.
    1398      *
    1399      * @returns VBox status code.
    1400      * @param   pInterface      Pointer to this interface.
    1401      * @param   pszId          The alias/id for the key to release.
    1402      *
    1403      * @note: It is advised to release the key whenever it is not used anymore so the entity
    1404      *        storing the key can do anything to make retrieving the key from memory more
    1405      *        difficult like scrambling the memory buffer for instance.
    1406      */
    1407     DECLR3CALLBACKMEMBER(int, pfnKeyRelease, (PPDMISECKEY pInterface, const char *pszId));
    1408 
    1409     /**
    1410      * Retains a password identified by the ID. The caller will only hold a reference
    1411      * to the password and must not modify the buffer in any way.
    1412      *
    1413      * @returns VBox status code.
    1414      * @param   pInterface      Pointer to this interface.
    1415      * @param   pszId           The alias/id for the password to retrieve.
    1416      * @param   ppszPassword    Where to store the pointer to the password on success.
    1417      */
    1418     DECLR3CALLBACKMEMBER(int, pfnPasswordRetain, (PPDMISECKEY pInterface, const char *pszId,
    1419                                                   const char **ppszPassword));
    1420 
    1421     /**
    1422      * Releases one reference of the password identified by the given identifier.
    1423      * The caller must not access the password after calling this operation.
    1424      *
    1425      * @returns VBox status code.
    1426      * @param   pInterface      Pointer to this interface.
    1427      * @param   pszId           The alias/id for the password to release.
    1428      *
    1429      * @note: It is advised to release the password whenever it is not used anymore so the entity
    1430      *        storing the password can do anything to make retrieving the password from memory more
    1431      *        difficult like scrambling the memory buffer for instance.
    1432      */
    1433     DECLR3CALLBACKMEMBER(int, pfnPasswordRelease, (PPDMISECKEY pInterface, const char *pszId));
    1434 } PDMISECKEY;
    1435 /** PDMISECKEY interface ID. */
    1436 #define PDMISECKEY_IID                           "3d698355-d995-453d-960f-31566a891df2"
    1437 
    1438 /** Pointer to a secret key helper interface. */
    1439 typedef struct PDMISECKEYHLP *PPDMISECKEYHLP;
    1440 
    1441 /**
    1442  * Secret key helper interface for non critical functionality.
    1443  */
    1444 typedef struct PDMISECKEYHLP
    1445 {
    1446     /**
    1447      * Notifies the interface provider that a key couldn't be retrieved from the key store.
    1448      *
    1449      * @returns VBox status code.
    1450      * @param   pInterface      Pointer to this interface.
    1451      */
    1452     DECLR3CALLBACKMEMBER(int, pfnKeyMissingNotify, (PPDMISECKEYHLP pInterface));
    1453 
    1454 } PDMISECKEYHLP;
    1455 /** PDMISECKEY interface ID. */
    1456 #define PDMISECKEYHLP_IID                        "7be96168-4156-40ac-86d2-3073bf8b318e"
     1239#define PDMMEDIATYPE_IS_FLOPPY(a_enmType) ( (a_enmType) >= PDMMEDIATYPE_FLOPPY_360 && (a_enmType) <= PDMMEDIATYPE_FLOPPY_2_88 )
     1240
     1241/**
     1242 * Raw command data transfer direction.
     1243 */
     1244typedef enum PDMMEDIATXDIR
     1245{
     1246    PDMMEDIATXDIR_NONE = 0,
     1247    PDMMEDIATXDIR_FROM_DEVICE,
     1248    PDMMEDIATXDIR_TO_DEVICE
     1249} PDMMEDIATXDIR;
    14571250
    14581251/**
     
    15011294/**
    15021295 * Media interface (up).
    1503  * Makes up the foundation for PDMIBLOCK and PDMIBLOCKBIOS.
    15041296 * Pairs with PDMIMEDIAPORT.
    15051297 */
     
    15531345     */
    15541346    DECLR3CALLBACKMEMBER(int, pfnFlush,(PPDMIMEDIA pInterface));
     1347
     1348    /**
     1349     * Send a raw command to the underlying device (CDROM).
     1350     * This method is optional (i.e. the function pointer may be NULL).
     1351     *
     1352     * @returns VBox status code.
     1353     * @param   pInterface      Pointer to the interface structure containing the called function pointer.
     1354     * @param   pbCmd           Offset to start reading from.
     1355     * @param   enmTxDir        Direction of transfer.
     1356     * @param   pvBuf           Pointer tp the transfer buffer.
     1357     * @param   cbBuf           Size of the transfer buffer.
     1358     * @param   pbSenseKey      Status of the command (when return value is VERR_DEV_IO_ERROR).
     1359     * @param   cTimeoutMillies Command timeout in milliseconds.
     1360     * @thread  Any thread.
     1361     */
     1362    DECLR3CALLBACKMEMBER(int, pfnSendCmd,(PPDMIMEDIA pInterface, const uint8_t *pbCmd, PDMMEDIATXDIR enmTxDir, void *pvBuf, uint32_t *pcbBuf, uint8_t *pabSense, size_t cbSense, uint32_t cTimeoutMillies));
    15551363
    15561364    /**
     
    16641472
    16651473    /**
     1474     * Checks if the device should be visible to the BIOS or not.
     1475     *
     1476     * @returns true if the device is visible to the BIOS.
     1477     * @returns false if the device is not visible to the BIOS.
     1478     * @param   pInterface      Pointer to the interface structure containing the called function pointer.
     1479     * @thread  Any thread.
     1480     */
     1481    DECLR3CALLBACKMEMBER(bool, pfnBiosIsVisible,(PPDMIMEDIA pInterface));
     1482
     1483    /**
     1484     * Gets the media type.
     1485     *
     1486     * @returns media type.
     1487     * @param   pInterface      Pointer to the interface structure containing the called function pointer.
     1488     * @thread  Any thread.
     1489     */
     1490    DECLR3CALLBACKMEMBER(PDMMEDIATYPE, pfnGetType,(PPDMIMEDIA pInterface));
     1491
     1492    /**
    16661493     * Gets the UUID of the media drive.
    16671494     *
     
    17071534} PDMIMEDIA;
    17081535/** PDMIMEDIA interface ID. */
    1709 #define PDMIMEDIA_IID                           "d8997ad8-4dda-4352-aa99-99bf87d54102"
    1710 
    1711 
    1712 /** Pointer to a block BIOS interface. */
    1713 typedef struct PDMIBLOCKBIOS *PPDMIBLOCKBIOS;
    1714 /**
    1715  * Media BIOS interface (Up / External).
    1716  * The interface the getting and setting properties which the BIOS/CMOS care about.
    1717  */
    1718 typedef struct PDMIBLOCKBIOS
    1719 {
    1720     /**
    1721      * Get stored media geometry (physical CHS, PCHS) - BIOS property.
    1722      * This is an optional feature of a media.
    1723      *
    1724      * @returns VBox status code.
    1725      * @returns VERR_NOT_IMPLEMENTED if the media doesn't support storing the geometry.
    1726      * @returns VERR_PDM_GEOMETRY_NOT_SET if the geometry hasn't been set using pfnSetPCHSGeometry() yet.
    1727      * @param   pInterface      Pointer to the interface structure containing the called function pointer.
    1728      * @param   pPCHSGeometry   Pointer to PCHS geometry (cylinders/heads/sectors).
    1729      * @remark  This has no influence on the read/write operations.
    1730      * @thread  Any thread.
    1731      */
    1732     DECLR3CALLBACKMEMBER(int, pfnGetPCHSGeometry,(PPDMIBLOCKBIOS pInterface, PPDMMEDIAGEOMETRY pPCHSGeometry));
    1733 
    1734     /**
    1735      * Store the media geometry (physical CHS, PCHS) - BIOS property.
    1736      * This is an optional feature of a media.
    1737      *
    1738      * @returns VBox status code.
    1739      * @returns VERR_NOT_IMPLEMENTED if the media doesn't support storing the geometry.
    1740      * @param   pInterface      Pointer to the interface structure containing the called function pointer.
    1741      * @param   pPCHSGeometry   Pointer to PCHS geometry (cylinders/heads/sectors).
    1742      * @remark  This has no influence on the read/write operations.
    1743      * @thread  The emulation thread.
    1744      */
    1745     DECLR3CALLBACKMEMBER(int, pfnSetPCHSGeometry,(PPDMIBLOCKBIOS pInterface, PCPDMMEDIAGEOMETRY pPCHSGeometry));
    1746 
    1747     /**
    1748      * Get stored media geometry (logical CHS, LCHS) - BIOS property.
    1749      * This is an optional feature of a media.
    1750      *
    1751      * @returns VBox status code.
    1752      * @returns VERR_NOT_IMPLEMENTED if the media doesn't support storing the geometry.
    1753      * @returns VERR_PDM_GEOMETRY_NOT_SET if the geometry hasn't been set using pfnSetLCHSGeometry() yet.
    1754      * @param   pInterface      Pointer to the interface structure containing the called function pointer.
    1755      * @param   pLCHSGeometry   Pointer to LCHS geometry (cylinders/heads/sectors).
    1756      * @remark  This has no influence on the read/write operations.
    1757      * @thread  Any thread.
    1758      */
    1759     DECLR3CALLBACKMEMBER(int, pfnGetLCHSGeometry,(PPDMIBLOCKBIOS pInterface, PPDMMEDIAGEOMETRY pLCHSGeometry));
    1760 
    1761     /**
    1762      * Store the media geometry (logical CHS, LCHS) - BIOS property.
    1763      * This is an optional feature of a media.
    1764      *
    1765      * @returns VBox status code.
    1766      * @returns VERR_NOT_IMPLEMENTED if the media doesn't support storing the geometry.
    1767      * @param   pInterface      Pointer to the interface structure containing the called function pointer.
    1768      * @param   pLCHSGeometry   Pointer to LCHS geometry (cylinders/heads/sectors).
    1769      * @remark  This has no influence on the read/write operations.
    1770      * @thread  The emulation thread.
    1771      */
    1772     DECLR3CALLBACKMEMBER(int, pfnSetLCHSGeometry,(PPDMIBLOCKBIOS pInterface, PCPDMMEDIAGEOMETRY pLCHSGeometry));
    1773 
    1774     /**
    1775      * Checks if the device should be visible to the BIOS or not.
    1776      *
    1777      * @returns true if the device is visible to the BIOS.
    1778      * @returns false if the device is not visible to the BIOS.
    1779      * @param   pInterface      Pointer to the interface structure containing the called function pointer.
    1780      * @thread  Any thread.
    1781      */
    1782     DECLR3CALLBACKMEMBER(bool, pfnIsVisible,(PPDMIBLOCKBIOS pInterface));
    1783 
    1784     /**
    1785      * Gets the block drive type.
    1786      *
    1787      * @returns block drive type.
    1788      * @param   pInterface      Pointer to the interface structure containing the called function pointer.
    1789      * @thread  Any thread.
    1790      */
    1791     DECLR3CALLBACKMEMBER(PDMBLOCKTYPE, pfnGetType,(PPDMIBLOCKBIOS pInterface));
    1792 
    1793 } PDMIBLOCKBIOS;
    1794 /** PDMIBLOCKBIOS interface ID. */
    1795 #define PDMIBLOCKBIOS_IID                       "477c3eee-a48d-48a9-82fd-2a54de16b2e9"
    1796 
    1797 
    1798 /** Pointer to a static block core driver interface. */
    1799 typedef struct PDMIMEDIASTATIC *PPDMIMEDIASTATIC;
    1800 /**
    1801  * Static block core driver interface.
    1802  */
    1803 typedef struct PDMIMEDIASTATIC
    1804 {
    1805     /**
    1806      * Check if the specified file is a format which the core driver can handle.
    1807      *
    1808      * @returns true / false accordingly.
    1809      * @param   pInterface      Pointer to the interface structure containing the called function pointer.
    1810      * @param   pszFilename     Name of the file to probe.
    1811      */
    1812     DECLR3CALLBACKMEMBER(bool, pfnCanHandle,(PPDMIMEDIASTATIC pInterface, const char *pszFilename));
    1813 } PDMIMEDIASTATIC;
    1814 
    1815 
    1816 
    1817 
    1818 
    1819 /** Pointer to an asynchronous block notify interface. */
    1820 typedef struct PDMIBLOCKASYNCPORT *PPDMIBLOCKASYNCPORT;
    1821 /**
    1822  * Asynchronous block notify interface (up).
    1823  * Pair with PDMIBLOCKASYNC.
    1824  */
    1825 typedef struct PDMIBLOCKASYNCPORT
    1826 {
    1827     /**
    1828      * Notify completion of an asynchronous transfer.
    1829      *
    1830      * @returns VBox status code.
    1831      * @param   pInterface      Pointer to the interface structure containing the called function pointer.
    1832      * @param   pvUser          The user argument given in pfnStartWrite/Read.
    1833      * @param   rcReq           IPRT Status code of the completed request.
    1834      * @thread  Any thread.
    1835      */
    1836     DECLR3CALLBACKMEMBER(int, pfnTransferCompleteNotify, (PPDMIBLOCKASYNCPORT pInterface, void *pvUser, int rcReq));
    1837 } PDMIBLOCKASYNCPORT;
    1838 /** PDMIBLOCKASYNCPORT interface ID. */
    1839 #define PDMIBLOCKASYNCPORT_IID                  "e3bdc0cb-9d99-41dd-8eec-0dc8cf5b2a92"
    1840 
    1841 
    1842 
    1843 /** Pointer to an asynchronous block interface. */
    1844 typedef struct PDMIBLOCKASYNC *PPDMIBLOCKASYNC;
    1845 /**
    1846  * Asynchronous block interface (down).
    1847  * Pair with PDMIBLOCKASYNCPORT.
    1848  */
    1849 typedef struct PDMIBLOCKASYNC
    1850 {
    1851     /**
    1852      * Start reading task.
    1853      *
    1854      * @returns VBox status code.
    1855      * @param   pInterface      Pointer to the interface structure containing the called function pointer.
    1856      * @param   off             Offset to start reading from.c
    1857      * @param   paSegs          Pointer to the S/G segment array.
    1858      * @param   cSegs           Number of entries in the array.
    1859      * @param   cbRead          Number of bytes to read. Must be aligned to a sector boundary.
    1860      * @param   pvUser          User argument which is returned in completion callback.
    1861      * @thread  Any thread.
    1862      */
    1863     DECLR3CALLBACKMEMBER(int, pfnStartRead,(PPDMIBLOCKASYNC pInterface, uint64_t off, PCRTSGSEG paSegs, unsigned cSegs, size_t cbRead, void *pvUser));
    1864 
    1865     /**
    1866      * Write bits.
    1867      *
    1868      * @returns VBox status code.
    1869      * @param   pInterface      Pointer to the interface structure containing the called function pointer.
    1870      * @param   off             Offset to start writing at. The offset must be aligned to a sector boundary.
    1871      * @param   paSegs          Pointer to the S/G segment array.
    1872      * @param   cSegs           Number of entries in the array.
    1873      * @param   cbWrite         Number of bytes to write. Must be aligned to a sector boundary.
    1874      * @param   pvUser          User argument which is returned in completion callback.
    1875      * @thread  Any thread.
    1876      */
    1877     DECLR3CALLBACKMEMBER(int, pfnStartWrite,(PPDMIBLOCKASYNC pInterface, uint64_t off, PCRTSGSEG paSegs, unsigned cSegs, size_t cbWrite, void *pvUser));
    1878 
    1879     /**
    1880      * Flush everything to disk.
    1881      *
    1882      * @returns VBox status code.
    1883      * @param   pInterface      Pointer to the interface structure containing the called function pointer.
    1884      * @param   pvUser          User argument which is returned in completion callback.
    1885      * @thread  Any thread.
    1886      */
    1887     DECLR3CALLBACKMEMBER(int, pfnStartFlush,(PPDMIBLOCKASYNC pInterface, void *pvUser));
    1888 
    1889     /**
    1890      * Discards the given range.
    1891      *
    1892      * @returns VBox status code.
    1893      * @param   pInterface      Pointer to the interface structure containing the called function pointer.
    1894      * @param   paRanges        Array of ranges to discard.
    1895      * @param   cRanges         Number of entries in the array.
    1896      * @param   pvUser          User argument which is returned in completion callback.
    1897      * @thread  Any thread.
    1898      */
    1899     DECLR3CALLBACKMEMBER(int, pfnStartDiscard,(PPDMIBLOCKASYNC pInterface, PCRTRANGE paRanges, unsigned cRanges, void *pvUser));
    1900 
    1901 } PDMIBLOCKASYNC;
    1902 /** PDMIBLOCKASYNC interface ID. */
    1903 #define PDMIBLOCKASYNC_IID                      "a921dd96-1748-4ecd-941e-d5f3cd4c8fe4"
     1536#define PDMIMEDIA_IID                           "352f2fa2-52c0-4e51-ba3c-9f59b7043218"
    19041537
    19051538
  • trunk/src/VBox/Devices/Makefile.kmk

    r59063 r59248  
    173173        Serial/DrvTCP.cpp \
    174174        Serial/DrvRawFile.cpp \
    175         Storage/DrvBlock.cpp \
    176         Storage/DrvMediaISO.cpp \
    177         Storage/DrvRawImage.cpp \
    178175        Storage/Debug.cpp \
    179176        Storage/DrvVD.cpp \
  • trunk/src/VBox/Devices/PC/DevPcBios.cpp

    r59227 r59248  
    291291 * @param   pLCHSGeometry   Where to return the disk geometry on success
    292292 */
    293 static int biosGuessDiskLCHS(PPDMIBLOCK pBlock, PPDMMEDIAGEOMETRY pLCHSGeometry)
     293static int biosGuessDiskLCHS(PPDMIMEDIA pMedia, PPDMMEDIAGEOMETRY pLCHSGeometry)
    294294{
    295295    uint8_t aMBR[512], *p;
     
    297297    uint32_t iEndHead, iEndSector, cLCHSCylinders, cLCHSHeads, cLCHSSectors;
    298298
    299     if (!pBlock)
     299    if (!pMedia)
    300300        return VERR_INVALID_PARAMETER;
    301     rc = pBlock->pfnReadPcBios(pBlock, 0, aMBR, sizeof(aMBR));
     301    rc = pMedia->pfnReadPcBios(pMedia, 0, aMBR, sizeof(aMBR));
    302302    if (RT_FAILURE(rc))
    303303        return rc;
     
    316316            cLCHSHeads = iEndHead + 1;
    317317            cLCHSSectors = iEndSector;
    318             cLCHSCylinders = RT_MIN(1024, pBlock->pfnGetSize(pBlock) / (512 * cLCHSHeads * cLCHSSectors));
     318            cLCHSCylinders = RT_MIN(1024, pMedia->pfnGetSize(pMedia) / (512 * cLCHSHeads * cLCHSSectors));
    319319            if (cLCHSCylinders >= 1)
    320320            {
     
    397397 * @param   pLCHSGeometry Where to store the geometry settings.
    398398 */
    399 static int setLogicalDiskGeometry(PPDMIBASE pBase, PPDMIBLOCKBIOS pHardDisk, PPDMMEDIAGEOMETRY pLCHSGeometry)
     399static int setLogicalDiskGeometry(PPDMIBASE pBase, PPDMIMEDIA pHardDisk, PPDMMEDIAGEOMETRY pLCHSGeometry)
    400400{
    401401    PDMMEDIAGEOMETRY LCHSGeometry;
    402402    int rc = VINF_SUCCESS;
    403403
    404     rc = pHardDisk->pfnGetLCHSGeometry(pHardDisk, &LCHSGeometry);
     404    rc = pHardDisk->pfnBiosGetLCHSGeometry(pHardDisk, &LCHSGeometry);
    405405    if (   rc == VERR_PDM_GEOMETRY_NOT_SET
    406406        || LCHSGeometry.cCylinders == 0
     
    410410        || LCHSGeometry.cSectors > 63)
    411411    {
    412         PPDMIBLOCK pBlock;
    413         pBlock = PDMIBASE_QUERY_INTERFACE(pBase, PDMIBLOCK);
    414412        /* No LCHS geometry, autodetect and set. */
    415         rc = biosGuessDiskLCHS(pBlock, &LCHSGeometry);
     413        rc = biosGuessDiskLCHS(pHardDisk, &LCHSGeometry);
    416414        if (RT_FAILURE(rc))
    417415        {
    418416            /* Try if PCHS geometry works, otherwise fall back. */
    419             rc = pHardDisk->pfnGetPCHSGeometry(pHardDisk, &LCHSGeometry);
     417            rc = pHardDisk->pfnBiosGetPCHSGeometry(pHardDisk, &LCHSGeometry);
    420418        }
    421419        if (   RT_FAILURE(rc)
     
    427425            || LCHSGeometry.cSectors > 63)
    428426        {
    429             uint64_t cSectors = pBlock->pfnGetSize(pBlock) / 512;
     427            uint64_t cSectors = pHardDisk->pfnGetSize(pHardDisk) / 512;
    430428            if (cSectors / 16 / 63 <= 1024)
    431429            {
     
    456454
    457455        }
    458         rc = pHardDisk->pfnSetLCHSGeometry(pHardDisk, &LCHSGeometry);
     456        rc = pHardDisk->pfnBiosSetLCHSGeometry(pHardDisk, &LCHSGeometry);
    459457        if (rc == VERR_VD_IMAGE_READ_ONLY)
    460458        {
     
    483481 * @param   pLCHSGeometry Where to store the geometry settings.
    484482 */
    485 static int getLogicalDiskGeometry(PPDMIBLOCKBIOS pHardDisk, PPDMMEDIAGEOMETRY pLCHSGeometry)
     483static int getLogicalDiskGeometry(PPDMIMEDIA pHardDisk, PPDMMEDIAGEOMETRY pLCHSGeometry)
    486484{
    487485    PDMMEDIAGEOMETRY LCHSGeometry;
    488486    int rc = VINF_SUCCESS;
    489487
    490     rc = pHardDisk->pfnGetLCHSGeometry(pHardDisk, &LCHSGeometry);
     488    rc = pHardDisk->pfnBiosGetLCHSGeometry(pHardDisk, &LCHSGeometry);
    491489    if (   rc == VERR_PDM_GEOMETRY_NOT_SET
    492490        || LCHSGeometry.cCylinders == 0
     
    549547    unsigned        i;
    550548    PUVM            pUVM = PDMDevHlpGetUVM(pDevIns); AssertRelease(pUVM);
    551     PPDMIBLOCKBIOS  apHDs[4] = {0};
     549    PPDMIMEDIA      apHDs[4] = {0};
    552550    LogFlow(("pcbiosInitComplete:\n"));
    553551
     
    642640        if (RT_SUCCESS(rc))
    643641        {
    644             PPDMIBLOCKBIOS pFD = PDMIBASE_QUERY_INTERFACE(pBase, PDMIBLOCKBIOS);
     642            PPDMIMEDIA pFD = PDMIBASE_QUERY_INTERFACE(pBase, PDMIMEDIA);
    645643            if (pFD)
    646644            {
     
    649647                switch (pFD->pfnGetType(pFD))
    650648                {
    651                     case PDMBLOCKTYPE_FLOPPY_360:       u32 |= 1  << cShift; break;
    652                     case PDMBLOCKTYPE_FLOPPY_1_20:      u32 |= 2  << cShift; break;
    653                     case PDMBLOCKTYPE_FLOPPY_720:       u32 |= 3  << cShift; break;
    654                     case PDMBLOCKTYPE_FLOPPY_1_44:      u32 |= 4  << cShift; break;
    655                     case PDMBLOCKTYPE_FLOPPY_2_88:      u32 |= 5  << cShift; break;
    656                     case PDMBLOCKTYPE_FLOPPY_FAKE_15_6: u32 |= 14 << cShift; break;
    657                     case PDMBLOCKTYPE_FLOPPY_FAKE_63_5: u32 |= 15 << cShift; break;
     649                    case PDMMEDIATYPE_FLOPPY_360:       u32 |= 1  << cShift; break;
     650                    case PDMMEDIATYPE_FLOPPY_1_20:      u32 |= 2  << cShift; break;
     651                    case PDMMEDIATYPE_FLOPPY_720:       u32 |= 3  << cShift; break;
     652                    case PDMMEDIATYPE_FLOPPY_1_44:      u32 |= 4  << cShift; break;
     653                    case PDMMEDIATYPE_FLOPPY_2_88:      u32 |= 5  << cShift; break;
     654                    case PDMMEDIATYPE_FLOPPY_FAKE_15_6: u32 |= 14 << cShift; break;
     655                    case PDMMEDIATYPE_FLOPPY_FAKE_63_5: u32 |= 15 << cShift; break;
    658656                    default:                        AssertFailed(); break;
    659657                }
     
    683681        int rc = PDMR3QueryLun(pUVM, pThis->pszHDDevice, 0, i, &pBase);
    684682        if (RT_SUCCESS(rc))
    685             apHDs[i] = PDMIBASE_QUERY_INTERFACE(pBase, PDMIBLOCKBIOS);
     683            apHDs[i] = PDMIBASE_QUERY_INTERFACE(pBase, PDMIMEDIA);
    686684        if (   apHDs[i]
    687             && (   apHDs[i]->pfnGetType(apHDs[i]) != PDMBLOCKTYPE_HARD_DISK
    688                 || !apHDs[i]->pfnIsVisible(apHDs[i])))
     685            && (   apHDs[i]->pfnGetType(apHDs[i]) != PDMMEDIATYPE_HARD_DISK
     686                || !apHDs[i]->pfnBiosIsVisible(apHDs[i])))
    689687            apHDs[i] = NULL;
    690688        if (apHDs[i])
     
    744742            int rc = PDMR3QueryLun(pUVM, pThis->pszSataDevice, 0, pThis->iSataHDLUN[i], &pBase);
    745743            if (RT_SUCCESS(rc))
    746                 apHDs[i] = PDMIBASE_QUERY_INTERFACE(pBase, PDMIBLOCKBIOS);
     744                apHDs[i] = PDMIBASE_QUERY_INTERFACE(pBase, PDMIMEDIA);
    747745            if (   apHDs[i]
    748                 && (   apHDs[i]->pfnGetType(apHDs[i]) != PDMBLOCKTYPE_HARD_DISK
    749                     || !apHDs[i]->pfnIsVisible(apHDs[i])))
     746                && (   apHDs[i]->pfnGetType(apHDs[i]) != PDMMEDIATYPE_HARD_DISK
     747                    || !apHDs[i]->pfnBiosIsVisible(apHDs[i])))
    750748                apHDs[i] = NULL;
    751749            if (apHDs[i])
     
    798796            int rc = PDMR3QueryLun(pUVM, pThis->pszScsiDevice, 0, pThis->iScsiHDLUN[i], &pBase);
    799797            if (RT_SUCCESS(rc))
    800                 apHDs[i] = PDMIBASE_QUERY_INTERFACE(pBase, PDMIBLOCKBIOS);
     798                apHDs[i] = PDMIBASE_QUERY_INTERFACE(pBase, PDMIMEDIA);
    801799            if (   apHDs[i]
    802                 && (   apHDs[i]->pfnGetType(apHDs[i]) != PDMBLOCKTYPE_HARD_DISK
    803                     || !apHDs[i]->pfnIsVisible(apHDs[i])))
     800                && (   apHDs[i]->pfnGetType(apHDs[i]) != PDMMEDIATYPE_HARD_DISK
     801                    || !apHDs[i]->pfnBiosIsVisible(apHDs[i])))
    804802                apHDs[i] = NULL;
    805803            if (apHDs[i])
  • trunk/src/VBox/Devices/Storage/DevAHCI.cpp

    r58170 r59248  
    375375/**
    376376 * @implements PDMIBASE
    377  * @implements PDMIBLOCKPORT
    378  * @implements PDMIBLOCKASYNCPORT
     377 * @implements PDMIMEDIAPORT
     378 * @implements PDMIMEDIAASYNCPORT
    379379 * @implements PDMIMOUNTNOTIFY
    380380 */
     
    505505    R3PTRTYPE(PPDMIBASE)            pDrvBase;
    506506    /** Pointer to the attached driver's block interface. */
    507     R3PTRTYPE(PPDMIBLOCK)           pDrvBlock;
     507    R3PTRTYPE(PPDMIMEDIA)           pDrvMedia;
    508508    /** Pointer to the attached driver's async block interface. */
    509     R3PTRTYPE(PPDMIBLOCKASYNC)      pDrvBlockAsync;
    510     /** Pointer to the attached driver's block bios interface. */
    511     R3PTRTYPE(PPDMIBLOCKBIOS)       pDrvBlockBios;
     509    R3PTRTYPE(PPDMIMEDIAASYNC)      pDrvMediaAsync;
    512510    /** Pointer to the attached driver's mount interface. */
    513511    R3PTRTYPE(PPDMIMOUNT)           pDrvMount;
     
    515513    PDMIBASE                        IBase;
    516514    /** The block port interface. */
    517     PDMIBLOCKPORT                   IPort;
     515    PDMIMEDIAPORT                   IPort;
    518516    /** The optional block async port interface. */
    519     PDMIBLOCKASYNCPORT              IPortAsync;
     517    PDMIMEDIAASYNCPORT              IPortAsync;
    520518    /** The mount notify interface. */
    521519    PDMIMOUNTNOTIFY                 IMountNotify;
     
    971969#define PDMIMOUNTNOTIFY_2_PAHCIPORT(pInterface)  ( (PAHCIPort)((uintptr_t)(pInterface) - RT_OFFSETOF(AHCIPort, IMountNotify)) )
    972970#define PDMIBASE_2_PAHCIPORT(pInterface)         ( (PAHCIPort)((uintptr_t)(pInterface) - RT_OFFSETOF(AHCIPort, IBase)) )
    973 #define PDMIBLOCKPORT_2_PAHCIPORT(pInterface)    ( (PAHCIPort)((uintptr_t)(pInterface) - RT_OFFSETOF(AHCIPort, IPort)) )
     971#define PDMIMEDIAPORT_2_PAHCIPORT(pInterface)    ( (PAHCIPort)((uintptr_t)(pInterface) - RT_OFFSETOF(AHCIPort, IPort)) )
    974972#define PDMIBASE_2_PAHCI(pInterface)             ( (PAHCI)((uintptr_t)(pInterface) - RT_OFFSETOF(AHCI, IBase)) )
    975973#define PDMILEDPORTS_2_PAHCI(pInterface)         ( (PAHCI)((uintptr_t)(pInterface) - RT_OFFSETOF(AHCI, ILeds)) )
     
    26702668    PAHCIPort pAhciPort = PDMIBASE_2_PAHCIPORT(pInterface);
    26712669    PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pAhciPort->IBase);
    2672     PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBLOCKPORT, &pAhciPort->IPort);
    2673     PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBLOCKASYNCPORT, &pAhciPort->IPortAsync);
     2670    PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMEDIAPORT, &pAhciPort->IPort);
     2671    PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMEDIAASYNCPORT, &pAhciPort->IPortAsync);
    26742672    PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMOUNTNOTIFY, &pAhciPort->IMountNotify);
    26752673    return NULL;
     
    26772675
    26782676/**
    2679  * @interface_method_impl{PDMIBLOCKPORT,pfnQueryDeviceLocation}
    2680  */
    2681 static DECLCALLBACK(int) ahciR3PortQueryDeviceLocation(PPDMIBLOCKPORT pInterface, const char **ppcszController,
     2677 * @interface_method_impl{PDMIMEDIAPORT,pfnQueryDeviceLocation}
     2678 */
     2679static DECLCALLBACK(int) ahciR3PortQueryDeviceLocation(PPDMIMEDIAPORT pInterface, const char **ppcszController,
    26822680                                                       uint32_t *piInstance, uint32_t *piLUN)
    26832681{
    2684     PAHCIPort pAhciPort = PDMIBLOCKPORT_2_PAHCIPORT(pInterface);
     2682    PAHCIPort pAhciPort = PDMIMEDIAPORT_2_PAHCIPORT(pInterface);
    26852683    PPDMDEVINS pDevIns = pAhciPort->CTX_SUFF(pDevIns);
    26862684
     
    30993097    p[67] = RT_H2LE_U16(120); /* minimum PIO cycle time without flow control */
    31003098    p[68] = RT_H2LE_U16(120); /* minimum PIO cycle time with IORDY flow control */
    3101     if (   pAhciPort->pDrvBlock->pfnDiscard
     3099    if (   pAhciPort->pDrvMedia->pfnDiscard
    31023100        || ( pAhciPort->fAsyncInterface
    3103             && pAhciPort->pDrvBlockAsync->pfnStartDiscard)
     3101            && pAhciPort->pDrvMediaAsync->pfnStartDiscard)
    31043102        || pAhciPort->cbSector != 512
    31053103        || pAhciPort->fNonRotational)
     
    31423140        p[217] = RT_H2LE_U16(1); /* Non-rotational medium */
    31433141
    3144     if (   pAhciPort->pDrvBlock->pfnDiscard
     3142    if (   pAhciPort->pDrvMedia->pfnDiscard
    31453143        || (   pAhciPort->fAsyncInterface
    3146             && pAhciPort->pDrvBlockAsync->pfnStartDiscard)) /** @todo: Set bit 14 in word 69 too? (Deterministic read after TRIM). */
     3144            && pAhciPort->pDrvMediaAsync->pfnStartDiscard)) /** @todo: Set bit 14 in word 69 too? (Deterministic read after TRIM). */
    31473145        p[169] = RT_H2LE_U16(1); /* DATA SET MANAGEMENT command supported. */
    31483146
     
    40414039                    break;
    40424040            }
    4043             rc = pAhciPort->pDrvBlock->pfnSendCmd(pAhciPort->pDrvBlock,
     4041            rc = pAhciPort->pDrvMedia->pfnSendCmd(pAhciPort->pDrvMedia,
    40444042                                                  aATAPICmd,
    40454043                                                  pAhciReq->enmTxDir == AHCITXDIR_READ
    4046                                                   ? PDMBLOCKTXDIR_FROM_DEVICE
    4047                                                   : PDMBLOCKTXDIR_TO_DEVICE,
     4044                                                  ? PDMMEDIATXDIR_FROM_DEVICE
     4045                                                  : PDMMEDIATXDIR_TO_DEVICE,
    40484046                                                  pbBuf,
    40494047                                                  &cbCurrTX,
     
    40594057    else
    40604058    {
    4061         PDMBLOCKTXDIR enmBlockTxDir = PDMBLOCKTXDIR_NONE;
     4059        PDMMEDIATXDIR enmBlockTxDir = PDMMEDIATXDIR_NONE;
    40624060
    40634061        if (pAhciReq->enmTxDir == AHCITXDIR_READ)
    4064             enmBlockTxDir = PDMBLOCKTXDIR_FROM_DEVICE;
     4062            enmBlockTxDir = PDMMEDIATXDIR_FROM_DEVICE;
    40654063        else if (pAhciReq->enmTxDir == AHCITXDIR_WRITE)
    4066             enmBlockTxDir = PDMBLOCKTXDIR_TO_DEVICE;
     4064            enmBlockTxDir = PDMMEDIATXDIR_TO_DEVICE;
    40674065        else if (pAhciReq->enmTxDir == AHCITXDIR_NONE)
    4068             enmBlockTxDir = PDMBLOCKTXDIR_NONE;
     4066            enmBlockTxDir = PDMMEDIATXDIR_NONE;
    40694067        else
    40704068            AssertMsgFailed(("Invalid transfer direction %d\n", pAhciReq->enmTxDir));
    40714069
    4072         rc = pAhciPort->pDrvBlock->pfnSendCmd(pAhciPort->pDrvBlock,
     4070        rc = pAhciPort->pDrvMedia->pfnSendCmd(pAhciPort->pDrvMedia,
    40734071                                              pAhciReq->aATAPICmd,
    40744072                                              enmBlockTxDir,
     
    54765474    {
    54775475        if (pAhciReq->cbAlloc)
    5478             pAhciPort->pDrvBlock->pfnIoBufFree(pAhciPort->pDrvBlock, pAhciReq->pvAlloc, pAhciReq->cbAlloc);
     5476            pAhciPort->pDrvMedia->pfnIoBufFree(pAhciPort->pDrvMedia, pAhciReq->pvAlloc, pAhciReq->cbAlloc);
    54795477
    54805478        pAhciReq->pvAlloc = NULL;
    54815479        pAhciReq->cbAlloc = RT_ALIGN_Z(cb, _4K);
    5482         int rc = pAhciPort->pDrvBlock->pfnIoBufAlloc(pAhciPort->pDrvBlock, pAhciReq->cbAlloc, &pAhciReq->pvAlloc);
     5480        int rc = pAhciPort->pDrvMedia->pfnIoBufAlloc(pAhciPort->pDrvMedia, pAhciReq->cbAlloc, &pAhciReq->pvAlloc);
    54835481        if (RT_FAILURE(rc))
    54845482            pAhciReq->pvAlloc = NULL;
     
    55075505        if (pAhciReq->cbAlloc)
    55085506        {
    5509             pAhciPort->pDrvBlock->pfnIoBufFree(pAhciPort->pDrvBlock, pAhciReq->pvAlloc, pAhciReq->cbAlloc);
     5507            pAhciPort->pDrvMedia->pfnIoBufFree(pAhciPort->pDrvMedia, pAhciReq->pvAlloc, pAhciReq->cbAlloc);
    55105508            pAhciReq->cbAlloc = 0;
    55115509            pAhciReq->cAllocTooMuch = 0;
     
    57605758}
    57615759
    5762 /* -=-=-=-=- IBlockAsyncPort -=-=-=-=- */
    5763 
    5764 /** Makes a PAHCIPort out of a PPDMIBLOCKASYNCPORT. */
    5765 #define PDMIBLOCKASYNCPORT_2_PAHCIPORT(pInterface)    ( (PAHCIPort)((uintptr_t)pInterface - RT_OFFSETOF(AHCIPort, IPortAsync)) )
     5760/* -=-=-=-=- IMediaAsyncPort -=-=-=-=- */
     5761
     5762/** Makes a PAHCIPort out of a PPDMIMEDIAASYNCPORT. */
     5763#define PDMIMEDIAASYNCPORT_2_PAHCIPORT(pInterface)    ( (PAHCIPort)((uintptr_t)pInterface - RT_OFFSETOF(AHCIPort, IPortAsync)) )
    57665764
    57675765static void ahciWarningDiskFull(PPDMDEVINS pDevIns)
     
    62426240 * @param   rcReq        IPRT Status code of the completed request.
    62436241 */
    6244 static DECLCALLBACK(int) ahciR3TransferCompleteNotify(PPDMIBLOCKASYNCPORT pInterface, void *pvUser, int rcReq)
    6245 {
    6246     PAHCIPort pAhciPort = PDMIBLOCKASYNCPORT_2_PAHCIPORT(pInterface);
     6242static DECLCALLBACK(int) ahciR3TransferCompleteNotify(PPDMIMEDIAASYNCPORT pInterface, void *pvUser, int rcReq)
     6243{
     6244    PAHCIPort pAhciPort = PDMIMEDIAASYNCPORT_2_PAHCIPORT(pInterface);
    62476245    PAHCIREQ pAhciReq = (PAHCIREQ)pvUser;
    62486246
     
    62756273        case ATA_IDENTIFY_DEVICE:
    62766274        {
    6277             if (pAhciPort->pDrvBlock && !pAhciPort->fATAPI)
     6275            if (pAhciPort->pDrvMedia && !pAhciPort->fATAPI)
    62786276            {
    62796277                uint16_t u16Temp[256];
     
    65266524        {
    65276525            if (   (   !pAhciPort->fAsyncInterface
    6528                     && pAhciPort->pDrvBlock->pfnDiscard)
     6526                    && pAhciPort->pDrvMedia->pfnDiscard)
    65296527                || (   pAhciPort->fAsyncInterface
    6530                     && pAhciPort->pDrvBlockAsync->pfnStartDiscard))
     6528                    && pAhciPort->pDrvMediaAsync->pfnStartDiscard))
    65316529            {
    65326530                /* Check that the trim bit is set and all other bits are 0. */
     
    66726670        if (enmTxDir == AHCITXDIR_FLUSH)
    66736671        {
    6674             rc = pAhciPort->pDrvBlockAsync->pfnStartFlush(pAhciPort->pDrvBlockAsync,
     6672            rc = pAhciPort->pDrvMediaAsync->pfnStartFlush(pAhciPort->pDrvMediaAsync,
    66756673                                                          pAhciReq);
    66766674        }
     
    66816679            {
    66826680                pAhciPort->Led.Asserted.s.fWriting = pAhciPort->Led.Actual.s.fWriting = 1;
    6683                 rc = pAhciPort->pDrvBlockAsync->pfnStartDiscard(pAhciPort->pDrvBlockAsync, pAhciReq->u.Trim.paRanges,
     6681                rc = pAhciPort->pDrvMediaAsync->pfnStartDiscard(pAhciPort->pDrvMediaAsync, pAhciReq->u.Trim.paRanges,
    66846682                                                                pAhciReq->u.Trim.cRanges, pAhciReq);
    66856683            }
     
    66886686        {
    66896687            pAhciPort->Led.Asserted.s.fReading = pAhciPort->Led.Actual.s.fReading = 1;
    6690             rc = pAhciPort->pDrvBlockAsync->pfnStartRead(pAhciPort->pDrvBlockAsync, pAhciReq->uOffset,
     6688            rc = pAhciPort->pDrvMediaAsync->pfnStartRead(pAhciPort->pDrvMediaAsync, pAhciReq->uOffset,
    66916689                                                         &pAhciReq->u.Io.DataSeg, 1,
    66926690                                                         pAhciReq->cbTransfer,
     
    66966694        {
    66976695            pAhciPort->Led.Asserted.s.fWriting = pAhciPort->Led.Actual.s.fWriting = 1;
    6698             rc = pAhciPort->pDrvBlockAsync->pfnStartWrite(pAhciPort->pDrvBlockAsync, pAhciReq->uOffset,
     6696            rc = pAhciPort->pDrvMediaAsync->pfnStartWrite(pAhciPort->pDrvMediaAsync, pAhciReq->uOffset,
    66996697                                                          &pAhciReq->u.Io.DataSeg, 1,
    67006698                                                          pAhciReq->cbTransfer,
     
    67096707    {
    67106708        if (enmTxDir == AHCITXDIR_FLUSH)
    6711             rc = pAhciPort->pDrvBlock->pfnFlush(pAhciPort->pDrvBlock);
     6709            rc = pAhciPort->pDrvMedia->pfnFlush(pAhciPort->pDrvMedia);
    67126710        else if (enmTxDir == AHCITXDIR_TRIM)
    67136711        {
     
    67166714            {
    67176715                pAhciPort->Led.Asserted.s.fWriting = pAhciPort->Led.Actual.s.fWriting = 1;
    6718                 rc = pAhciPort->pDrvBlock->pfnDiscard(pAhciPort->pDrvBlock, pAhciReq->u.Trim.paRanges,
     6716                rc = pAhciPort->pDrvMedia->pfnDiscard(pAhciPort->pDrvMedia, pAhciReq->u.Trim.paRanges,
    67196717                                                      pAhciReq->u.Trim.cRanges);
    67206718                pAhciPort->Led.Asserted.s.fWriting = pAhciPort->Led.Actual.s.fWriting = 0;
     
    67246722        {
    67256723            pAhciPort->Led.Asserted.s.fReading = pAhciPort->Led.Actual.s.fReading = 1;
    6726             rc = pAhciPort->pDrvBlock->pfnRead(pAhciPort->pDrvBlock, pAhciReq->uOffset,
     6724            rc = pAhciPort->pDrvMedia->pfnRead(pAhciPort->pDrvMedia, pAhciReq->uOffset,
    67276725                                               pAhciReq->u.Io.DataSeg.pvSeg,
    67286726                                               pAhciReq->cbTransfer);
     
    67326730        {
    67336731            pAhciPort->Led.Asserted.s.fWriting = pAhciPort->Led.Actual.s.fWriting = 1;
    6734             rc = pAhciPort->pDrvBlock->pfnWrite(pAhciPort->pDrvBlock, pAhciReq->uOffset,
     6732            rc = pAhciPort->pDrvMedia->pfnWrite(pAhciPort->pDrvMedia, pAhciReq->uOffset,
    67356733                                                pAhciReq->u.Io.DataSeg.pvSeg,
    67366734                                                pAhciReq->cbTransfer);
     
    76017599
    76027600    /* Ignore the call if we're called while being attached. */
    7603     if (!pAhciPort->pDrvBlock)
     7601    if (!pAhciPort->pDrvMedia)
    76047602        return;
    76057603
    76067604    if (pAhciPort->fATAPI)
    76077605    {
    7608         pAhciPort->cTotalSectors = pAhciPort->pDrvBlock->pfnGetSize(pAhciPort->pDrvBlock) / 2048;
     7606        pAhciPort->cTotalSectors = pAhciPort->pDrvMedia->pfnGetSize(pAhciPort->pDrvMedia) / 2048;
    76097607
    76107608        LogRel(("AHCI: LUN#%d: CD/DVD, total number of sectors %Ld, passthrough unchanged\n", pAhciPort->iLUN, pAhciPort->cTotalSectors));
     
    76627660{
    76637661    int          rc = VINF_SUCCESS;
    7664     PDMBLOCKTYPE enmType;
     7662    PDMMEDIATYPE enmType;
    76657663
    76667664    /*
    76677665     * Query the block and blockbios interfaces.
    76687666     */
    7669     pAhciPort->pDrvBlock = PDMIBASE_QUERY_INTERFACE(pAhciPort->pDrvBase, PDMIBLOCK);
    7670     if (!pAhciPort->pDrvBlock)
     7667    pAhciPort->pDrvMedia = PDMIBASE_QUERY_INTERFACE(pAhciPort->pDrvBase, PDMIMEDIA);
     7668    if (!pAhciPort->pDrvMedia)
    76717669    {
    76727670        AssertMsgFailed(("Configuration error: LUN#%d hasn't a block interface!\n", pAhciPort->iLUN));
    76737671        return VERR_PDM_MISSING_INTERFACE;
    76747672    }
    7675     pAhciPort->pDrvBlockBios = PDMIBASE_QUERY_INTERFACE(pAhciPort->pDrvBase, PDMIBLOCKBIOS);
    7676     if (!pAhciPort->pDrvBlockBios)
    7677     {
    7678         AssertMsgFailed(("Configuration error: LUN#%d hasn't a block BIOS interface!\n", pAhciPort->iLUN));
    7679         return VERR_PDM_MISSING_INTERFACE;
    7680     }
    76817673
    76827674    pAhciPort->pDrvMount = PDMIBASE_QUERY_INTERFACE(pAhciPort->pDrvBase, PDMIMOUNT);
    76837675
    76847676    /* Try to get the optional async block interface. */
    7685     pAhciPort->pDrvBlockAsync = PDMIBASE_QUERY_INTERFACE(pAhciPort->pDrvBase, PDMIBLOCKASYNC);
     7677    pAhciPort->pDrvMediaAsync = PDMIBASE_QUERY_INTERFACE(pAhciPort->pDrvBase, PDMIMEDIAASYNC);
    76867678
    76877679    /*
    76887680     * Validate type.
    76897681     */
    7690     enmType = pAhciPort->pDrvBlock->pfnGetType(pAhciPort->pDrvBlock);
    7691 
    7692     if (   enmType != PDMBLOCKTYPE_HARD_DISK
    7693         && enmType != PDMBLOCKTYPE_CDROM
    7694         && enmType != PDMBLOCKTYPE_DVD)
     7682    enmType = pAhciPort->pDrvMedia->pfnGetType(pAhciPort->pDrvMedia);
     7683
     7684    if (   enmType != PDMMEDIATYPE_HARD_DISK
     7685        && enmType != PDMMEDIATYPE_CDROM
     7686        && enmType != PDMMEDIATYPE_DVD)
    76957687    {
    76967688        AssertMsgFailed(("Configuration error: LUN#%d isn't a disk or cd/dvd. enmType=%d\n", pAhciPort->iLUN, enmType));
     
    76987690    }
    76997691
    7700     if (   (enmType == PDMBLOCKTYPE_CDROM || enmType == PDMBLOCKTYPE_DVD)
     7692    if (   (enmType == PDMMEDIATYPE_CDROM || enmType == PDMMEDIATYPE_DVD)
    77017693        && !pAhciPort->pDrvMount)
    77027694    {
     
    77047696        return VERR_INTERNAL_ERROR;
    77057697    }
    7706     pAhciPort->fATAPI = (enmType == PDMBLOCKTYPE_CDROM || enmType == PDMBLOCKTYPE_DVD);
    7707     pAhciPort->fATAPIPassthrough = pAhciPort->fATAPI ? (pAhciPort->pDrvBlock->pfnSendCmd != NULL) : false;
     7698    pAhciPort->fATAPI = (enmType == PDMMEDIATYPE_CDROM || enmType == PDMMEDIATYPE_DVD);
     7699    pAhciPort->fATAPIPassthrough = pAhciPort->fATAPI ? (pAhciPort->pDrvMedia->pfnSendCmd != NULL) : false;
    77087700
    77097701    rc = RTCritSectInit(&pAhciPort->CritSectReqsFree);
     
    77217713    if (pAhciPort->fATAPI)
    77227714    {
    7723         pAhciPort->cTotalSectors = pAhciPort->pDrvBlock->pfnGetSize(pAhciPort->pDrvBlock) / 2048;
     7715        pAhciPort->cTotalSectors = pAhciPort->pDrvMedia->pfnGetSize(pAhciPort->pDrvMedia) / 2048;
    77247716        pAhciPort->PCHSGeometry.cCylinders = 0;
    77257717        pAhciPort->PCHSGeometry.cHeads     = 0;
     
    77307722    else
    77317723    {
    7732         pAhciPort->cbSector = pAhciPort->pDrvBlock->pfnGetSectorSize(pAhciPort->pDrvBlock);
    7733         pAhciPort->cTotalSectors = pAhciPort->pDrvBlock->pfnGetSize(pAhciPort->pDrvBlock) / pAhciPort->cbSector;
    7734         rc = pAhciPort->pDrvBlockBios->pfnGetPCHSGeometry(pAhciPort->pDrvBlockBios,
    7735                                                           &pAhciPort->PCHSGeometry);
     7724        pAhciPort->cbSector = pAhciPort->pDrvMedia->pfnGetSectorSize(pAhciPort->pDrvMedia);
     7725        pAhciPort->cTotalSectors = pAhciPort->pDrvMedia->pfnGetSize(pAhciPort->pDrvMedia) / pAhciPort->cbSector;
     7726        rc = pAhciPort->pDrvMedia->pfnBiosGetPCHSGeometry(pAhciPort->pDrvMedia, &pAhciPort->PCHSGeometry);
    77367727        if (rc == VERR_PDM_MEDIA_NOT_MOUNTED)
    77377728        {
     
    77567747            pAhciPort->PCHSGeometry.cSectors = 63;
    77577748            /* Set the disk geometry information. Ignore errors. */
    7758             pAhciPort->pDrvBlockBios->pfnSetPCHSGeometry(pAhciPort->pDrvBlockBios,
    7759                                                          &pAhciPort->PCHSGeometry);
     7749            pAhciPort->pDrvMedia->pfnBiosSetPCHSGeometry(pAhciPort->pDrvMedia, &pAhciPort->PCHSGeometry);
    77607750            rc = VINF_SUCCESS;
    77617751        }
     
    77647754                 pAhciPort->PCHSGeometry.cHeads, pAhciPort->PCHSGeometry.cSectors,
    77657755                 pAhciPort->cTotalSectors));
    7766         if (pAhciPort->pDrvBlock->pfnDiscard)
     7756        if (pAhciPort->pDrvMedia->pfnDiscard)
    77677757            LogRel(("AHCI: LUN#%d: Enabled TRIM support\n", pAhciPort->iLUN));
    77687758    }
     
    78797869    RTUUID Uuid;
    78807870
    7881     if (pAhciPort->pDrvBlock)
    7882         rc = pAhciPort->pDrvBlock->pfnGetUuid(pAhciPort->pDrvBlock, &Uuid);
     7871    if (pAhciPort->pDrvMedia)
     7872        rc = pAhciPort->pDrvMedia->pfnGetUuid(pAhciPort->pDrvMedia, &Uuid);
    78837873    else
    78847874        RTUuidClear(&Uuid);
     
    80568046     */
    80578047    pAhciPort->pDrvBase = NULL;
    8058     pAhciPort->pDrvBlock = NULL;
    8059     pAhciPort->pDrvBlockAsync = NULL;
    8060     pAhciPort->pDrvBlockBios = NULL;
     8048    pAhciPort->pDrvMedia = NULL;
     8049    pAhciPort->pDrvMediaAsync = NULL;
    80618050}
    80628051
     
    80838072    AssertMsg(iLUN < pThis->cPortsImpl, ("iLUN=%u", iLUN));
    80848073    AssertRelease(!pAhciPort->pDrvBase);
    8085     AssertRelease(!pAhciPort->pDrvBlock);
    8086     AssertRelease(!pAhciPort->pDrvBlockAsync);
     8074    AssertRelease(!pAhciPort->pDrvMedia);
     8075    AssertRelease(!pAhciPort->pDrvMediaAsync);
    80878076    Assert(pAhciPort->iLUN == iLUN);
    80888077
     
    81138102    {
    81148103        pAhciPort->pDrvBase = NULL;
    8115         pAhciPort->pDrvBlock = NULL;
     8104        pAhciPort->pDrvMedia = NULL;
    81168105    }
    81178106    else
     
    81208109        RTStrPrintf(szName, sizeof(szName), "Port%d", iLUN);
    81218110
    8122         if (   pAhciPort->pDrvBlockAsync
     8111        if (   pAhciPort->pDrvMediaAsync
    81238112            && !pAhciPort->fATAPI)
    81248113            pAhciPort->fAsyncInterface = true;
     
    86188607             * Otherwise we use a event semaphore and a async I/O thread which processes them.
    86198608             */
    8620             if (pAhciPort->pDrvBlockAsync && pThis->fUseAsyncInterfaceIfAvailable)
     8609            if (pAhciPort->pDrvMediaAsync && pThis->fUseAsyncInterfaceIfAvailable)
    86218610            {
    86228611                LogRel(("AHCI: LUN#%d: using async I/O\n", pAhciPort->iLUN));
  • trunk/src/VBox/Devices/Storage/DevATA.cpp

    r58170 r59248  
    277277    R3PTRTYPE(PPDMIBASE)            pDrvBase;
    278278    /** Pointer to the attached driver's block interface. */
    279     R3PTRTYPE(PPDMIBLOCK)           pDrvBlock;
    280     /** Pointer to the attached driver's block bios interface. */
    281     R3PTRTYPE(PPDMIBLOCKBIOS)       pDrvBlockBios;
     279    R3PTRTYPE(PPDMIMEDIA)           pDrvMedia;
    282280    /** Pointer to the attached driver's mount interface.
    283281     * This is NULL if the driver isn't a removable unit. */
     
    286284    PDMIBASE                        IBase;
    287285    /** The block port interface. */
    288     PDMIBLOCKPORT                   IPort;
     286    PDMIMEDIAPORT                   IPort;
    289287    /** The mount notify interface. */
    290288    PDMIMOUNTNOTIFY                 IMountNotify;
     
    510508#define PDMIBASE_2_PCIATASTATE(pInterface)      ( (PCIATAState *)((uintptr_t)(pInterface) - RT_OFFSETOF(PCIATAState, IBase)) )
    511509#define PDMILEDPORTS_2_PCIATASTATE(pInterface)  ( (PCIATAState *)((uintptr_t)(pInterface) - RT_OFFSETOF(PCIATAState, ILeds)) )
    512 #define PDMIBLOCKPORT_2_ATASTATE(pInterface)    ( (ATADevState *)((uintptr_t)(pInterface) - RT_OFFSETOF(ATADevState, IPort)) )
     510#define PDMIMEDIAPORT_2_ATASTATE(pInterface)    ( (ATADevState *)((uintptr_t)(pInterface) - RT_OFFSETOF(ATADevState, IPort)) )
    513511#define PDMIMOUNT_2_ATASTATE(pInterface)        ( (ATADevState *)((uintptr_t)(pInterface) - RT_OFFSETOF(ATADevState, IMount)) )
    514512#define PDMIMOUNTNOTIFY_2_ATASTATE(pInterface)  ( (ATADevState *)((uintptr_t)(pInterface) - RT_OFFSETOF(ATADevState, IMountNotify)) )
     
    521519#define CONTROLLER_2_DEVINS(pController)       ( (pController)->CTX_SUFF(pDevIns) )
    522520#define PDMIBASE_2_ATASTATE(pInterface)        ( (ATADevState *)((uintptr_t)(pInterface) - RT_OFFSETOF(ATADevState, IBase)) )
    523 #define PDMIBLOCKPORT_2_ATASTATE(pInterface)   ( (ATADevState *)((uintptr_t)(pInterface) - RT_OFFSETOF(ATADevState, IPort)) )
     521#define PDMIMEDIAPORT_2_ATASTATE(pInterface)   ( (ATADevState *)((uintptr_t)(pInterface) - RT_OFFSETOF(ATADevState, IPort)) )
    524522
    525523#ifndef VBOX_DEVICE_STRUCT_TESTCASE
     
    12101208    s->iIOBufferCur = 0;
    12111209    s->iIOBufferEnd = 0;
    1212     s->uTxDir = PDMBLOCKTXDIR_NONE;
     1210    s->uTxDir = PDMMEDIATXDIR_NONE;
    12131211    s->iBeginTransfer = ATAFN_BT_NULL;
    12141212    s->iSourceSink = ATAFN_SS_NULL;
     
    12321230    uint16_t *p;
    12331231
    1234     Assert(s->uTxDir == PDMBLOCKTXDIR_FROM_DEVICE);
     1232    Assert(s->uTxDir == PDMMEDIATXDIR_FROM_DEVICE);
    12351233    Assert(s->cbElementaryTransfer == 512);
    12361234
     
    12861284    p[67] = RT_H2LE_U16(120); /* minimum PIO cycle time without flow control */
    12871285    p[68] = RT_H2LE_U16(120); /* minimum PIO cycle time with IORDY flow control */
    1288     if (   s->pDrvBlock->pfnDiscard
     1286    if (   s->pDrvMedia->pfnDiscard
    12891287        || s->cbSector != 512
    12901288        || s->fNonRotational)
     
    13291327    }
    13301328
    1331     if (s->pDrvBlock->pfnDiscard) /** @todo: Set bit 14 in word 69 too? (Deterministic read after TRIM). */
     1329    if (s->pDrvMedia->pfnDiscard) /** @todo: Set bit 14 in word 69 too? (Deterministic read after TRIM). */
    13321330        p[169] = RT_H2LE_U16(1); /* DATA SET MANAGEMENT command supported. */
    13331331    if (s->fNonRotational)
     
    13461344    int rc;
    13471345
    1348     Assert(s->uTxDir == PDMBLOCKTXDIR_NONE);
     1346    Assert(s->uTxDir == PDMMEDIATXDIR_NONE);
    13491347    Assert(!s->cbElementaryTransfer);
    13501348
     
    13521350
    13531351    STAM_PROFILE_START(&s->StatFlushes, f);
    1354     rc = s->pDrvBlock->pfnFlush(s->pDrvBlock);
     1352    rc = s->pDrvMedia->pfnFlush(s->pDrvMedia);
    13551353    AssertRC(rc);
    13561354    STAM_PROFILE_STOP(&s->StatFlushes, f);
     
    13671365    uint16_t *p;
    13681366
    1369     Assert(s->uTxDir == PDMBLOCKTXDIR_FROM_DEVICE);
     1367    Assert(s->uTxDir == PDMMEDIATXDIR_FROM_DEVICE);
    13701368    Assert(s->cbElementaryTransfer == 512);
    13711369
     
    14361434        s->uATARegHCyl = 0xeb;
    14371435    }
    1438     else if (s->pDrvBlock)
     1436    else if (s->pDrvMedia)
    14391437    {
    14401438        s->uATARegLCyl = 0;
     
    15921590    STAM_PROFILE_ADV_START(&s->StatReads, r);
    15931591    s->Led.Asserted.s.fReading = s->Led.Actual.s.fReading = 1;
    1594     rc = s->pDrvBlock->pfnRead(s->pDrvBlock, u64Sector * s->cbSector, pvBuf, cSectors * s->cbSector);
     1592    rc = s->pDrvMedia->pfnRead(s->pDrvMedia, u64Sector * s->cbSector, pvBuf, cSectors * s->cbSector);
    15951593    s->Led.Actual.s.fReading = 0;
    15961594    STAM_PROFILE_ADV_STOP(&s->StatReads, r);
     
    16261624        STAM_PROFILE_ADV_START(&s->StatInstrVDWrites, vw);
    16271625# endif
    1628     rc = s->pDrvBlock->pfnWrite(s->pDrvBlock, u64Sector * s->cbSector, pvBuf, cSectors * s->cbSector);
     1626    rc = s->pDrvMedia->pfnWrite(s->pDrvMedia, u64Sector * s->cbSector, pvBuf, cSectors * s->cbSector);
    16291627# ifdef VBOX_INSTRUMENT_DMA_WRITES
    16301628    if (s->fDMA)
     
    16591657    else
    16601658        s->cbElementaryTransfer = cSectors * s->cbSector;
    1661     if (s->uTxDir == PDMBLOCKTXDIR_TO_DEVICE)
     1659    if (s->uTxDir == PDMMEDIATXDIR_TO_DEVICE)
    16621660        ataR3CmdOK(s, 0);
    16631661}
     
    17451743    ataSetStatusValue(s, ATA_STAT_READY);
    17461744    s->uATARegNSector = (s->uATARegNSector & ~7)
    1747         | ((s->uTxDir != PDMBLOCKTXDIR_TO_DEVICE) ? ATAPI_INT_REASON_IO : 0)
     1745        | ((s->uTxDir != PDMMEDIATXDIR_TO_DEVICE) ? ATAPI_INT_REASON_IO : 0)
    17481746        | (!s->cbTotalTransfer ? ATAPI_INT_REASON_CD : 0);
    17491747    Log2(("%s: interrupt reason %#04x\n", __FUNCTION__, s->uATARegNSector));
     
    17701768    s->iIOBufferCur = 0;
    17711769    s->iIOBufferEnd = 0;
    1772     s->uTxDir = PDMBLOCKTXDIR_NONE;
     1770    s->uTxDir = PDMMEDIATXDIR_NONE;
    17731771    s->iBeginTransfer = ATAFN_BT_NULL;
    17741772    s->iSourceSink = ATAFN_SS_NULL;
     
    17961794    s->cbAtapiPassthroughTransfer = s->cbTotalTransfer;
    17971795    s->cbPIOTransferLimit = s->uATARegLCyl | (s->uATARegHCyl << 8);
    1798     if (s->uTxDir == PDMBLOCKTXDIR_TO_DEVICE)
     1796    if (s->uTxDir == PDMMEDIATXDIR_TO_DEVICE)
    17991797        atapiR3CmdOK(s);
    18001798}
     
    18081806     * and replies. */
    18091807# if 0
    1810     if (s->uTxDir == PDMBLOCKTXDIR_TO_DEVICE)
     1808    if (s->uTxDir == PDMMEDIATXDIR_TO_DEVICE)
    18111809    {
    18121810        uint8_t cmd = s->aATAPICmd[0];
     
    18301828            aModeSenseCmd[8] = cbTransfer & 0xff;
    18311829            aModeSenseCmd[9] = 0; /* control */
    1832             rc = s->pDrvBlock->pfnSendCmd(s->pDrvBlock, aModeSenseCmd, PDMBLOCKTXDIR_FROM_DEVICE, aModeSenseResult, &cbTransfer, &uDummySense, 500);
     1830            rc = s->pDrvMedia->pfnSendCmd(s->pDrvMedia, aModeSenseCmd, PDMMEDIATXDIR_FROM_DEVICE, aModeSenseResult, &cbTransfer, &uDummySense, 500);
    18331831            if (RT_FAILURE(rc))
    18341832            {
     
    18711869            s->cbTotalTransfer *= s->cbATAPISector;
    18721870            if (s->cbTotalTransfer == 0)
    1873                 s->uTxDir = PDMBLOCKTXDIR_NONE;
     1871                s->uTxDir = PDMMEDIATXDIR_NONE;
    18741872        }
    18751873    }
     
    18841882    uint32_t cbTransfer, cSectors;
    18851883
    1886     Assert(s->uTxDir == PDMBLOCKTXDIR_FROM_DEVICE);
     1884    Assert(s->uTxDir == PDMMEDIATXDIR_FROM_DEVICE);
    18871885    cbTransfer = RT_MIN(s->cbTotalTransfer, s->cbIOBuffer);
    18881886    cSectors = cbTransfer / s->cbATAPISector;
     
    18971895    {
    18981896        case 2048:
    1899             rc = s->pDrvBlock->pfnRead(s->pDrvBlock, (uint64_t)s->iATAPILBA * s->cbATAPISector, s->CTX_SUFF(pbIOBuffer), s->cbATAPISector * cSectors);
     1897            rc = s->pDrvMedia->pfnRead(s->pDrvMedia, (uint64_t)s->iATAPILBA * s->cbATAPISector, s->CTX_SUFF(pbIOBuffer), s->cbATAPISector * cSectors);
    19001898            break;
    19011899        case 2352:
     
    19151913                *pbBuf++ = 0x01; /* mode 1 data */
    19161914                /* data */
    1917                 rc = s->pDrvBlock->pfnRead(s->pDrvBlock, (uint64_t)i * 2048, pbBuf, 2048);
     1915                rc = s->pDrvMedia->pfnRead(s->pDrvMedia, (uint64_t)i * 2048, pbBuf, 2048);
    19181916                if (RT_FAILURE(rc))
    19191917                    break;
     
    19861984    cbTransfer = RT_MIN(s->cbAtapiPassthroughTransfer, s->cbIOBuffer);
    19871985
    1988     if (s->uTxDir == PDMBLOCKTXDIR_TO_DEVICE)
     1986    if (s->uTxDir == PDMMEDIATXDIR_TO_DEVICE)
    19891987        Log3(("ATAPI PT data write (%d): %.*Rhxs\n", cbTransfer, cbTransfer, s->CTX_SUFF(pbIOBuffer)));
    19901988
     
    19931991    if (cbTransfer >= 2048)
    19941992    {
    1995         if (s->uTxDir != PDMBLOCKTXDIR_TO_DEVICE)
     1993        if (s->uTxDir != PDMMEDIATXDIR_TO_DEVICE)
    19961994        {
    19971995            s->Led.Asserted.s.fReading = s->Led.Actual.s.fReading = 1;
     
    21172115                    break;
    21182116            }
    2119             rc = s->pDrvBlock->pfnSendCmd(s->pDrvBlock, aATAPICmd, (PDMBLOCKTXDIR)s->uTxDir, pbBuf, &cbCurrTX, abATAPISense, sizeof(abATAPISense), 30000 /**< @todo timeout */);
     2117            rc = s->pDrvMedia->pfnSendCmd(s->pDrvMedia, aATAPICmd, (PDMMEDIATXDIR)s->uTxDir, pbBuf, &cbCurrTX, abATAPISense, sizeof(abATAPISense), 30000 /**< @todo timeout */);
    21202118            if (rc != VINF_SUCCESS)
    21212119                break;
     
    21582156    }
    21592157    else
    2160         rc = s->pDrvBlock->pfnSendCmd(s->pDrvBlock, s->aATAPICmd, (PDMBLOCKTXDIR)s->uTxDir, s->CTX_SUFF(pbIOBuffer), &cbTransfer, abATAPISense, sizeof(abATAPISense), 30000 /**< @todo timeout */);
     2158        rc = s->pDrvMedia->pfnSendCmd(s->pDrvMedia, s->aATAPICmd, (PDMMEDIATXDIR)s->uTxDir, s->CTX_SUFF(pbIOBuffer), &cbTransfer, abATAPISense, sizeof(abATAPISense), 30000 /**< @todo timeout */);
    21612159    if (pProf) { STAM_PROFILE_ADV_STOP(pProf, b); }
    21622160
     
    21682166    if (cbTransfer >= 2048)
    21692167    {
    2170         if (s->uTxDir != PDMBLOCKTXDIR_TO_DEVICE)
     2168        if (s->uTxDir != PDMMEDIATXDIR_TO_DEVICE)
    21712169        {
    21722170            s->Led.Actual.s.fReading = 0;
     
    22082206        }
    22092207
    2210         if (s->uTxDir == PDMBLOCKTXDIR_FROM_DEVICE)
     2208        if (s->uTxDir == PDMMEDIATXDIR_FROM_DEVICE)
    22112209        {
    22122210            Assert(cbTransfer <= s->cbAtapiPassthroughTransfer);
     
    24332431    s->iATAPILBA = iATAPILBA;
    24342432    s->cbATAPISector = cbSector;
    2435     ataR3StartTransfer(s, cSectors * cbSector, PDMBLOCKTXDIR_FROM_DEVICE, ATAFN_BT_ATAPI_CMD, ATAFN_SS_ATAPI_READ, true);
     2433    ataR3StartTransfer(s, cSectors * cbSector, PDMMEDIATXDIR_FROM_DEVICE, ATAFN_BT_ATAPI_CMD, ATAFN_SS_ATAPI_READ, true);
    24362434    return false;
    24372435}
     
    24422440    uint8_t *pbBuf = s->CTX_SUFF(pbIOBuffer);
    24432441
    2444     Assert(s->uTxDir == PDMBLOCKTXDIR_FROM_DEVICE);
     2442    Assert(s->uTxDir == PDMMEDIATXDIR_FROM_DEVICE);
    24452443    Assert(s->cbElementaryTransfer <= 8);
    24462444    ataH2BE_U32(pbBuf, s->cTotalSectors - 1);
     
    24562454    uint8_t *pbBuf = s->CTX_SUFF(pbIOBuffer);
    24572455
    2458     Assert(s->uTxDir == PDMBLOCKTXDIR_FROM_DEVICE);
     2456    Assert(s->uTxDir == PDMMEDIATXDIR_FROM_DEVICE);
    24592457    Assert(s->cbElementaryTransfer <= 34);
    24602458    memset(pbBuf, '\0', 34);
     
    24822480    uint8_t *pbBuf = s->CTX_SUFF(pbIOBuffer);
    24832481
    2484     Assert(s->uTxDir == PDMBLOCKTXDIR_FROM_DEVICE);
     2482    Assert(s->uTxDir == PDMMEDIATXDIR_FROM_DEVICE);
    24852483    Assert(s->cbElementaryTransfer <= 36);
    24862484    /* Accept address/number type of 1 only, and only track 1 exists. */
     
    26302628    uint16_t u16Sfn = ataBE2H_U16(&s->aATAPICmd[2]);
    26312629
    2632     Assert(s->uTxDir == PDMBLOCKTXDIR_FROM_DEVICE);
     2630    Assert(s->uTxDir == PDMMEDIATXDIR_FROM_DEVICE);
    26332631    Assert(s->cbElementaryTransfer <= 80);
    26342632    /* Accept valid request types only, and only starting feature 0. */
     
    26942692    uint8_t *pbBuf = s->CTX_SUFF(pbIOBuffer);
    26952693
    2696     Assert(s->uTxDir == PDMBLOCKTXDIR_FROM_DEVICE);
     2694    Assert(s->uTxDir == PDMMEDIATXDIR_FROM_DEVICE);
    26972695    Assert(s->cbElementaryTransfer <= 8);
    26982696
     
    27692767    uint8_t *pbBuf = s->CTX_SUFF(pbIOBuffer);
    27702768
    2771     Assert(s->uTxDir == PDMBLOCKTXDIR_FROM_DEVICE);
     2769    Assert(s->uTxDir == PDMMEDIATXDIR_FROM_DEVICE);
    27722770    Assert(s->cbElementaryTransfer <= 36);
    27732771    pbBuf[0] = 0x05; /* CD-ROM */
     
    27972795    uint8_t *pbBuf = s->CTX_SUFF(pbIOBuffer);
    27982796
    2799     Assert(s->uTxDir == PDMBLOCKTXDIR_FROM_DEVICE);
     2797    Assert(s->uTxDir == PDMMEDIATXDIR_FROM_DEVICE);
    28002798    Assert(s->cbElementaryTransfer <= 16);
    28012799    ataH2BE_U16(&pbBuf[0], 16 + 6);
     
    28252823    uint8_t *pbBuf = s->CTX_SUFF(pbIOBuffer);
    28262824
    2827     Assert(s->uTxDir == PDMBLOCKTXDIR_FROM_DEVICE);
     2825    Assert(s->uTxDir == PDMMEDIATXDIR_FROM_DEVICE);
    28282826    Assert(s->cbElementaryTransfer <= 40);
    28292827    ataH2BE_U16(&pbBuf[0], 38);
     
    28732871    uint8_t *pbBuf = s->CTX_SUFF(pbIOBuffer);
    28742872
    2875     Assert(s->uTxDir == PDMBLOCKTXDIR_FROM_DEVICE);
     2873    Assert(s->uTxDir == PDMMEDIATXDIR_FROM_DEVICE);
    28762874    memset(pbBuf, '\0', s->cbElementaryTransfer);
    28772875    memcpy(pbBuf, s->abATAPISense, RT_MIN(s->cbElementaryTransfer, sizeof(s->abATAPISense)));
     
    28862884    uint8_t *pbBuf = s->CTX_SUFF(pbIOBuffer);
    28872885
    2888     Assert(s->uTxDir == PDMBLOCKTXDIR_FROM_DEVICE);
     2886    Assert(s->uTxDir == PDMMEDIATXDIR_FROM_DEVICE);
    28892887    Assert(s->cbElementaryTransfer <= 8);
    28902888    ataH2BE_U16(pbBuf, 0);
     
    29072905    uint32_t cbSize;
    29082906
    2909     Assert(s->uTxDir == PDMBLOCKTXDIR_FROM_DEVICE);
     2907    Assert(s->uTxDir == PDMMEDIATXDIR_FROM_DEVICE);
    29102908    fMSF = (s->aATAPICmd[1] >> 1) & 1;
    29112909    iStartTrack = s->aATAPICmd[6];
     
    29682966    bool fMSF;
    29692967
    2970     Assert(s->uTxDir == PDMBLOCKTXDIR_FROM_DEVICE);
     2968    Assert(s->uTxDir == PDMMEDIATXDIR_FROM_DEVICE);
    29712969    Assert(s->cbElementaryTransfer <= 12);
    29722970    fMSF = (s->aATAPICmd[1] >> 1) & 1;
     
    30012999    uint32_t cbSize;
    30023000
    3003     Assert(s->uTxDir == PDMBLOCKTXDIR_FROM_DEVICE);
     3001    Assert(s->uTxDir == PDMMEDIATXDIR_FROM_DEVICE);
    30043002    fMSF = (s->aATAPICmd[1] >> 1) & 1;
    30053003    iStartTrack = s->aATAPICmd[6];
     
    31073105        case SCSI_GET_EVENT_STATUS_NOTIFICATION:
    31083106            cbMax = ataBE2H_U16(pbPacket + 7);
    3109             ataR3StartTransfer(s, RT_MIN(cbMax, 8), PDMBLOCKTXDIR_FROM_DEVICE, ATAFN_BT_ATAPI_CMD, ATAFN_SS_ATAPI_GET_EVENT_STATUS_NOTIFICATION, true);
     3107            ataR3StartTransfer(s, RT_MIN(cbMax, 8), PDMMEDIATXDIR_FROM_DEVICE, ATAFN_BT_ATAPI_CMD, ATAFN_SS_ATAPI_GET_EVENT_STATUS_NOTIFICATION, true);
    31103108            break;
    31113109        case SCSI_MODE_SENSE_10:
     
    31213119                    {
    31223120                        case SCSI_MODEPAGE_ERROR_RECOVERY:
    3123                             ataR3StartTransfer(s, RT_MIN(cbMax, 16), PDMBLOCKTXDIR_FROM_DEVICE, ATAFN_BT_ATAPI_CMD, ATAFN_SS_ATAPI_MODE_SENSE_ERROR_RECOVERY, true);
     3121                            ataR3StartTransfer(s, RT_MIN(cbMax, 16), PDMMEDIATXDIR_FROM_DEVICE, ATAFN_BT_ATAPI_CMD, ATAFN_SS_ATAPI_MODE_SENSE_ERROR_RECOVERY, true);
    31243122                            break;
    31253123                        case SCSI_MODEPAGE_CD_STATUS:
    3126                             ataR3StartTransfer(s, RT_MIN(cbMax, 40), PDMBLOCKTXDIR_FROM_DEVICE, ATAFN_BT_ATAPI_CMD, ATAFN_SS_ATAPI_MODE_SENSE_CD_STATUS, true);
     3124                            ataR3StartTransfer(s, RT_MIN(cbMax, 40), PDMMEDIATXDIR_FROM_DEVICE, ATAFN_BT_ATAPI_CMD, ATAFN_SS_ATAPI_MODE_SENSE_CD_STATUS, true);
    31273125                            break;
    31283126                        default:
     
    31433141        case SCSI_REQUEST_SENSE:
    31443142            cbMax = pbPacket[4];
    3145             ataR3StartTransfer(s, RT_MIN(cbMax, 18), PDMBLOCKTXDIR_FROM_DEVICE, ATAFN_BT_ATAPI_CMD, ATAFN_SS_ATAPI_REQUEST_SENSE, true);
     3143            ataR3StartTransfer(s, RT_MIN(cbMax, 18), PDMMEDIATXDIR_FROM_DEVICE, ATAFN_BT_ATAPI_CMD, ATAFN_SS_ATAPI_REQUEST_SENSE, true);
    31463144            break;
    31473145        case SCSI_PREVENT_ALLOW_MEDIUM_REMOVAL:
     
    33403338        {
    33413339            cbMax = ataBE2H_U16(pbPacket + 8);
    3342             ataR3StartTransfer(s, RT_MIN(cbMax, 8), PDMBLOCKTXDIR_FROM_DEVICE, ATAFN_BT_ATAPI_CMD, ATAFN_SS_ATAPI_MECHANISM_STATUS, true);
     3340            ataR3StartTransfer(s, RT_MIN(cbMax, 8), PDMMEDIATXDIR_FROM_DEVICE, ATAFN_BT_ATAPI_CMD, ATAFN_SS_ATAPI_MECHANISM_STATUS, true);
    33433341            break;
    33443342        }
     
    33663364            {
    33673365                case 0:
    3368                     ataR3StartTransfer(s, cbMax, PDMBLOCKTXDIR_FROM_DEVICE, ATAFN_BT_ATAPI_CMD, ATAFN_SS_ATAPI_READ_TOC_NORMAL, true);
     3366                    ataR3StartTransfer(s, cbMax, PDMMEDIATXDIR_FROM_DEVICE, ATAFN_BT_ATAPI_CMD, ATAFN_SS_ATAPI_READ_TOC_NORMAL, true);
    33693367                    break;
    33703368                case 1:
    3371                     ataR3StartTransfer(s, RT_MIN(cbMax, 12), PDMBLOCKTXDIR_FROM_DEVICE, ATAFN_BT_ATAPI_CMD, ATAFN_SS_ATAPI_READ_TOC_MULTI, true);
     3369                    ataR3StartTransfer(s, RT_MIN(cbMax, 12), PDMMEDIATXDIR_FROM_DEVICE, ATAFN_BT_ATAPI_CMD, ATAFN_SS_ATAPI_READ_TOC_MULTI, true);
    33723370                    break;
    33733371                case 2:
    3374                     ataR3StartTransfer(s, cbMax, PDMBLOCKTXDIR_FROM_DEVICE, ATAFN_BT_ATAPI_CMD, ATAFN_SS_ATAPI_READ_TOC_RAW, true);
     3372                    ataR3StartTransfer(s, cbMax, PDMMEDIATXDIR_FROM_DEVICE, ATAFN_BT_ATAPI_CMD, ATAFN_SS_ATAPI_READ_TOC_RAW, true);
    33753373                    break;
    33763374                default:
     
    33933391                break;
    33943392            }
    3395             ataR3StartTransfer(s, 8, PDMBLOCKTXDIR_FROM_DEVICE, ATAFN_BT_ATAPI_CMD, ATAFN_SS_ATAPI_READ_CAPACITY, true);
     3393            ataR3StartTransfer(s, 8, PDMMEDIATXDIR_FROM_DEVICE, ATAFN_BT_ATAPI_CMD, ATAFN_SS_ATAPI_READ_CAPACITY, true);
    33963394            break;
    33973395        case SCSI_READ_DISC_INFORMATION:
     
    34083406            }
    34093407            cbMax = ataBE2H_U16(pbPacket + 7);
    3410             ataR3StartTransfer(s, RT_MIN(cbMax, 34), PDMBLOCKTXDIR_FROM_DEVICE, ATAFN_BT_ATAPI_CMD, ATAFN_SS_ATAPI_READ_DISC_INFORMATION, true);
     3408            ataR3StartTransfer(s, RT_MIN(cbMax, 34), PDMMEDIATXDIR_FROM_DEVICE, ATAFN_BT_ATAPI_CMD, ATAFN_SS_ATAPI_READ_DISC_INFORMATION, true);
    34113409            break;
    34123410        case SCSI_READ_TRACK_INFORMATION:
     
    34233421            }
    34243422            cbMax = ataBE2H_U16(pbPacket + 7);
    3425             ataR3StartTransfer(s, RT_MIN(cbMax, 36), PDMBLOCKTXDIR_FROM_DEVICE, ATAFN_BT_ATAPI_CMD, ATAFN_SS_ATAPI_READ_TRACK_INFORMATION, true);
     3423            ataR3StartTransfer(s, RT_MIN(cbMax, 36), PDMMEDIATXDIR_FROM_DEVICE, ATAFN_BT_ATAPI_CMD, ATAFN_SS_ATAPI_READ_TRACK_INFORMATION, true);
    34263424            break;
    34273425        case SCSI_GET_CONFIGURATION:
    34283426            /* No media change stuff here, it can confuse Linux guests. */
    34293427            cbMax = ataBE2H_U16(pbPacket + 7);
    3430             ataR3StartTransfer(s, RT_MIN(cbMax, 80), PDMBLOCKTXDIR_FROM_DEVICE, ATAFN_BT_ATAPI_CMD, ATAFN_SS_ATAPI_GET_CONFIGURATION, true);
     3428            ataR3StartTransfer(s, RT_MIN(cbMax, 80), PDMMEDIATXDIR_FROM_DEVICE, ATAFN_BT_ATAPI_CMD, ATAFN_SS_ATAPI_GET_CONFIGURATION, true);
    34313429            break;
    34323430        case SCSI_INQUIRY:
    34333431            cbMax = ataBE2H_U16(pbPacket + 3);
    3434             ataR3StartTransfer(s, RT_MIN(cbMax, 36), PDMBLOCKTXDIR_FROM_DEVICE, ATAFN_BT_ATAPI_CMD, ATAFN_SS_ATAPI_INQUIRY, true);
     3432            ataR3StartTransfer(s, RT_MIN(cbMax, 36), PDMMEDIATXDIR_FROM_DEVICE, ATAFN_BT_ATAPI_CMD, ATAFN_SS_ATAPI_INQUIRY, true);
    34353433            break;
    34363434        case SCSI_READ_DVD_STRUCTURE:
    34373435        {
    34383436            cbMax = ataBE2H_U16(pbPacket + 8);
    3439             ataR3StartTransfer(s, RT_MIN(cbMax, 4), PDMBLOCKTXDIR_FROM_DEVICE, ATAFN_BT_ATAPI_CMD, ATAFN_SS_ATAPI_READ_DVD_STRUCTURE, true);
     3437            ataR3StartTransfer(s, RT_MIN(cbMax, 4), PDMMEDIATXDIR_FROM_DEVICE, ATAFN_BT_ATAPI_CMD, ATAFN_SS_ATAPI_READ_DVD_STRUCTURE, true);
    34403438            break;
    34413439        }
     
    34563454    uint32_t cSectors, iATAPILBA;
    34573455    uint32_t cbTransfer = 0;
    3458     PDMBLOCKTXDIR uTxDir = PDMBLOCKTXDIR_NONE;
     3456    PDMMEDIATXDIR uTxDir = PDMMEDIATXDIR_NONE;
    34593457
    34603458    pbPacket = s->aATAPICmd;
     
    34703468            cbTransfer = ataBE2H_U16(pbPacket + 7);
    34713469            Log2(("ATAPI PT: lba %d\n", iATAPILBA));
    3472             uTxDir = PDMBLOCKTXDIR_TO_DEVICE;
     3470            uTxDir = PDMMEDIATXDIR_TO_DEVICE;
    34733471            goto sendcmd;
    34743472        case SCSI_FORMAT_UNIT:
    34753473            cbTransfer = s->uATARegLCyl | (s->uATARegHCyl << 8); /* use ATAPI transfer length */
    3476             uTxDir = PDMBLOCKTXDIR_TO_DEVICE;
     3474            uTxDir = PDMMEDIATXDIR_TO_DEVICE;
    34773475            goto sendcmd;
    34783476        case SCSI_GET_CONFIGURATION:
    34793477            cbTransfer = ataBE2H_U16(pbPacket + 7);
    3480             uTxDir = PDMBLOCKTXDIR_FROM_DEVICE;
     3478            uTxDir = PDMMEDIATXDIR_FROM_DEVICE;
    34813479            goto sendcmd;
    34823480        case SCSI_GET_EVENT_STATUS_NOTIFICATION:
     
    34843482            if (ASMAtomicReadU32(&s->MediaEventStatus) != ATA_EVENT_STATUS_UNCHANGED)
    34853483            {
    3486                 ataR3StartTransfer(s, RT_MIN(cbTransfer, 8), PDMBLOCKTXDIR_FROM_DEVICE, ATAFN_BT_ATAPI_CMD, ATAFN_SS_ATAPI_GET_EVENT_STATUS_NOTIFICATION, true);
     3484                ataR3StartTransfer(s, RT_MIN(cbTransfer, 8), PDMMEDIATXDIR_FROM_DEVICE, ATAFN_BT_ATAPI_CMD, ATAFN_SS_ATAPI_GET_EVENT_STATUS_NOTIFICATION, true);
    34873485                break;
    34883486            }
    3489             uTxDir = PDMBLOCKTXDIR_FROM_DEVICE;
     3487            uTxDir = PDMMEDIATXDIR_FROM_DEVICE;
    34903488            goto sendcmd;
    34913489        case SCSI_GET_PERFORMANCE:
    34923490            cbTransfer = s->uATARegLCyl | (s->uATARegHCyl << 8); /* use ATAPI transfer length */
    3493             uTxDir = PDMBLOCKTXDIR_FROM_DEVICE;
     3491            uTxDir = PDMMEDIATXDIR_FROM_DEVICE;
    34943492            goto sendcmd;
    34953493        case SCSI_INQUIRY:
    34963494            cbTransfer = ataBE2H_U16(pbPacket + 3);
    3497             uTxDir = PDMBLOCKTXDIR_FROM_DEVICE;
     3495            uTxDir = PDMMEDIATXDIR_FROM_DEVICE;
    34983496            goto sendcmd;
    34993497        case SCSI_LOAD_UNLOAD_MEDIUM:
     
    35013499        case SCSI_MECHANISM_STATUS:
    35023500            cbTransfer = ataBE2H_U16(pbPacket + 8);
    3503             uTxDir = PDMBLOCKTXDIR_FROM_DEVICE;
     3501            uTxDir = PDMMEDIATXDIR_FROM_DEVICE;
    35043502            goto sendcmd;
    35053503        case SCSI_MODE_SELECT_10:
    35063504            cbTransfer = ataBE2H_U16(pbPacket + 7);
    3507             uTxDir = PDMBLOCKTXDIR_TO_DEVICE;
     3505            uTxDir = PDMMEDIATXDIR_TO_DEVICE;
    35083506            goto sendcmd;
    35093507        case SCSI_MODE_SENSE_10:
    35103508            cbTransfer = ataBE2H_U16(pbPacket + 7);
    3511             uTxDir = PDMBLOCKTXDIR_FROM_DEVICE;
     3509            uTxDir = PDMMEDIATXDIR_FROM_DEVICE;
    35123510            goto sendcmd;
    35133511        case SCSI_PAUSE_RESUME:
     
    35283526            s->cbATAPISector = 2048;
    35293527            cbTransfer = cSectors * s->cbATAPISector;
    3530             uTxDir = PDMBLOCKTXDIR_FROM_DEVICE;
     3528            uTxDir = PDMMEDIATXDIR_FROM_DEVICE;
    35313529            goto sendcmd;
    35323530        case SCSI_READ_12:
     
    35363534            s->cbATAPISector = 2048;
    35373535            cbTransfer = cSectors * s->cbATAPISector;
    3538             uTxDir = PDMBLOCKTXDIR_FROM_DEVICE;
     3536            uTxDir = PDMMEDIATXDIR_FROM_DEVICE;
    35393537            goto sendcmd;
    35403538        case SCSI_READ_BUFFER:
    35413539            cbTransfer = ataBE2H_U24(pbPacket + 6);
    3542             uTxDir = PDMBLOCKTXDIR_FROM_DEVICE;
     3540            uTxDir = PDMMEDIATXDIR_FROM_DEVICE;
    35433541            goto sendcmd;
    35443542        case SCSI_READ_BUFFER_CAPACITY:
    35453543            cbTransfer = ataBE2H_U16(pbPacket + 7);
    3546             uTxDir = PDMBLOCKTXDIR_FROM_DEVICE;
     3544            uTxDir = PDMMEDIATXDIR_FROM_DEVICE;
    35473545            goto sendcmd;
    35483546        case SCSI_READ_CAPACITY:
    35493547            cbTransfer = 8;
    3550             uTxDir = PDMBLOCKTXDIR_FROM_DEVICE;
     3548            uTxDir = PDMMEDIATXDIR_FROM_DEVICE;
    35513549            goto sendcmd;
    35523550        case SCSI_READ_CD:
     
    36003598                cbTransfer = cSectors * s->cbATAPISector;
    36013599            }
    3602             uTxDir = PDMBLOCKTXDIR_FROM_DEVICE;
     3600            uTxDir = PDMMEDIATXDIR_FROM_DEVICE;
    36033601            goto sendcmd;
    36043602        }
    36053603        case SCSI_READ_DISC_INFORMATION:
    36063604            cbTransfer = ataBE2H_U16(pbPacket + 7);
    3607             uTxDir = PDMBLOCKTXDIR_FROM_DEVICE;
     3605            uTxDir = PDMMEDIATXDIR_FROM_DEVICE;
    36083606            goto sendcmd;
    36093607        case SCSI_READ_DVD_STRUCTURE:
    36103608            cbTransfer = ataBE2H_U16(pbPacket + 8);
    3611             uTxDir = PDMBLOCKTXDIR_FROM_DEVICE;
     3609            uTxDir = PDMMEDIATXDIR_FROM_DEVICE;
    36123610            goto sendcmd;
    36133611        case SCSI_READ_FORMAT_CAPACITIES:
    36143612            cbTransfer = ataBE2H_U16(pbPacket + 7);
    3615             uTxDir = PDMBLOCKTXDIR_FROM_DEVICE;
     3613            uTxDir = PDMMEDIATXDIR_FROM_DEVICE;
    36163614            goto sendcmd;
    36173615        case SCSI_READ_SUBCHANNEL:
    36183616            cbTransfer = ataBE2H_U16(pbPacket + 7);
    3619             uTxDir = PDMBLOCKTXDIR_FROM_DEVICE;
     3617            uTxDir = PDMMEDIATXDIR_FROM_DEVICE;
    36203618            goto sendcmd;
    36213619        case SCSI_READ_TOC_PMA_ATIP:
    36223620            cbTransfer = ataBE2H_U16(pbPacket + 7);
    3623             uTxDir = PDMBLOCKTXDIR_FROM_DEVICE;
     3621            uTxDir = PDMMEDIATXDIR_FROM_DEVICE;
    36243622            goto sendcmd;
    36253623        case SCSI_READ_TRACK_INFORMATION:
    36263624            cbTransfer = ataBE2H_U16(pbPacket + 7);
    3627             uTxDir = PDMBLOCKTXDIR_FROM_DEVICE;
     3625            uTxDir = PDMMEDIATXDIR_FROM_DEVICE;
    36283626            goto sendcmd;
    36293627        case SCSI_REPAIR_TRACK:
     
    36313629        case SCSI_REPORT_KEY:
    36323630            cbTransfer = ataBE2H_U16(pbPacket + 8);
    3633             uTxDir = PDMBLOCKTXDIR_FROM_DEVICE;
     3631            uTxDir = PDMMEDIATXDIR_FROM_DEVICE;
    36343632            goto sendcmd;
    36353633        case SCSI_REQUEST_SENSE:
     
    36373635            if ((s->abATAPISense[2] & 0x0f) != SCSI_SENSE_NONE)
    36383636            {
    3639                 ataR3StartTransfer(s, RT_MIN(cbTransfer, 18), PDMBLOCKTXDIR_FROM_DEVICE, ATAFN_BT_ATAPI_CMD, ATAFN_SS_ATAPI_REQUEST_SENSE, true);
     3637                ataR3StartTransfer(s, RT_MIN(cbTransfer, 18), PDMMEDIATXDIR_FROM_DEVICE, ATAFN_BT_ATAPI_CMD, ATAFN_SS_ATAPI_REQUEST_SENSE, true);
    36403638                break;
    36413639            }
    3642             uTxDir = PDMBLOCKTXDIR_FROM_DEVICE;
     3640            uTxDir = PDMMEDIATXDIR_FROM_DEVICE;
    36433641            goto sendcmd;
    36443642        case SCSI_RESERVE_TRACK:
     
    36503648        case SCSI_SEND_CUE_SHEET:
    36513649            cbTransfer = ataBE2H_U24(pbPacket + 6);
    3652             uTxDir = PDMBLOCKTXDIR_TO_DEVICE;
     3650            uTxDir = PDMMEDIATXDIR_TO_DEVICE;
    36533651            goto sendcmd;
    36543652        case SCSI_SEND_DVD_STRUCTURE:
    36553653            cbTransfer = ataBE2H_U16(pbPacket + 8);
    3656             uTxDir = PDMBLOCKTXDIR_TO_DEVICE;
     3654            uTxDir = PDMMEDIATXDIR_TO_DEVICE;
    36573655            goto sendcmd;
    36583656        case SCSI_SEND_EVENT:
    36593657            cbTransfer = ataBE2H_U16(pbPacket + 8);
    3660             uTxDir = PDMBLOCKTXDIR_TO_DEVICE;
     3658            uTxDir = PDMMEDIATXDIR_TO_DEVICE;
    36613659            goto sendcmd;
    36623660        case SCSI_SEND_KEY:
    36633661            cbTransfer = ataBE2H_U16(pbPacket + 8);
    3664             uTxDir = PDMBLOCKTXDIR_TO_DEVICE;
     3662            uTxDir = PDMMEDIATXDIR_TO_DEVICE;
    36653663            goto sendcmd;
    36663664        case SCSI_SEND_OPC_INFORMATION:
    36673665            cbTransfer = ataBE2H_U16(pbPacket + 7);
    3668             uTxDir = PDMBLOCKTXDIR_TO_DEVICE;
     3666            uTxDir = PDMMEDIATXDIR_TO_DEVICE;
    36693667            goto sendcmd;
    36703668        case SCSI_SET_CD_SPEED:
     
    36743672        case SCSI_SET_STREAMING:
    36753673            cbTransfer = ataBE2H_U16(pbPacket + 9);
    3676             uTxDir = PDMBLOCKTXDIR_TO_DEVICE;
     3674            uTxDir = PDMMEDIATXDIR_TO_DEVICE;
    36773675            goto sendcmd;
    36783676        case SCSI_START_STOP_UNIT:
     
    36963694            Log2(("ATAPI PT: lba %d sectors %d sector size %d\n", iATAPILBA, cSectors, s->cbATAPISector));
    36973695            cbTransfer = cSectors * s->cbATAPISector;
    3698             uTxDir = PDMBLOCKTXDIR_TO_DEVICE;
     3696            uTxDir = PDMMEDIATXDIR_TO_DEVICE;
    36993697            goto sendcmd;
    37003698        case SCSI_WRITE_12:
     
    37073705            Log2(("ATAPI PT: lba %d sectors %d sector size %d\n", iATAPILBA, cSectors, s->cbATAPISector));
    37083706            cbTransfer = cSectors * s->cbATAPISector;
    3709             uTxDir = PDMBLOCKTXDIR_TO_DEVICE;
     3707            uTxDir = PDMMEDIATXDIR_TO_DEVICE;
    37103708            goto sendcmd;
    37113709        case SCSI_WRITE_BUFFER:
     
    37233721                default:
    37243722                    cbTransfer = ataBE2H_U16(pbPacket + 6);
    3725                     uTxDir = PDMBLOCKTXDIR_TO_DEVICE;
     3723                    uTxDir = PDMMEDIATXDIR_TO_DEVICE;
    37263724                    goto sendcmd;
    37273725            }
     
    37293727        case SCSI_REPORT_LUNS: /* Not part of MMC-3, but used by Windows. */
    37303728            cbTransfer = ataBE2H_U32(pbPacket + 6);
    3731             uTxDir = PDMBLOCKTXDIR_FROM_DEVICE;
     3729            uTxDir = PDMMEDIATXDIR_FROM_DEVICE;
    37323730            goto sendcmd;
    37333731        case SCSI_REZERO_UNIT:
     
    37513749            Log2(("ATAPI PT: max size %d\n", cbTransfer));
    37523750            if (cbTransfer == 0)
    3753                 uTxDir = PDMBLOCKTXDIR_NONE;
     3751                uTxDir = PDMMEDIATXDIR_NONE;
    37543752            ataR3StartTransfer(s, cbTransfer, uTxDir, ATAFN_BT_ATAPI_PASSTHROUGH_CMD, ATAFN_SS_ATAPI_PASSTHROUGH, true);
    37553753    }
     
    37803778    s->fDMA = !!(s->uATARegFeature & 1);
    37813779    memcpy(s->aATAPICmd, s->CTX_SUFF(pbIOBuffer), ATAPI_PACKET_SIZE);
    3782     s->uTxDir = PDMBLOCKTXDIR_NONE;
     3780    s->uTxDir = PDMMEDIATXDIR_NONE;
    37833781    s->cbTotalTransfer = 0;
    37843782    s->cbElementaryTransfer = 0;
     
    38343832
    38353833    /* Ignore the call if we're called while being attached. */
    3836     if (!pIf->pDrvBlock)
     3834    if (!pIf->pDrvMedia)
    38373835        return;
    38383836
    38393837    if (pIf->fATAPI)
    3840         pIf->cTotalSectors = pIf->pDrvBlock->pfnGetSize(pIf->pDrvBlock) / 2048;
     3838        pIf->cTotalSectors = pIf->pDrvMedia->pfnGetSize(pIf->pDrvMedia) / 2048;
    38413839    else
    3842         pIf->cTotalSectors = pIf->pDrvBlock->pfnGetSize(pIf->pDrvBlock) / pIf->cbSector;
     3840        pIf->cTotalSectors = pIf->pDrvMedia->pfnGetSize(pIf->pDrvMedia) / pIf->cbSector;
    38433841
    38443842    LogRel(("PIIX3 ATA: LUN#%d: CD/DVD, total number of sectors %Ld, passthrough unchanged\n", pIf->iLUN, pIf->cTotalSectors));
     
    39323930
    39333931    s->Led.Asserted.s.fWriting = s->Led.Actual.s.fWriting = 1;
    3934     rc = s->pDrvBlock->pfnDiscard(s->pDrvBlock, &TrimRange, 1);
     3932    rc = s->pDrvMedia->pfnDiscard(s->pDrvMedia, &TrimRange, 1);
    39353933    s->Led.Actual.s.fWriting = 0;
    39363934
     
    40194017    {
    40204018        case ATA_IDENTIFY_DEVICE:
    4021             if (s->pDrvBlock && !s->fATAPI)
    4022                 ataR3StartTransfer(s, 512, PDMBLOCKTXDIR_FROM_DEVICE, ATAFN_BT_NULL, ATAFN_SS_IDENTIFY, false);
     4019            if (s->pDrvMedia && !s->fATAPI)
     4020                ataR3StartTransfer(s, 512, PDMMEDIATXDIR_FROM_DEVICE, ATAFN_BT_NULL, ATAFN_SS_IDENTIFY, false);
    40234021            else
    40244022            {
     
    40654063        case ATA_READ_SECTORS:
    40664064        case ATA_READ_SECTORS_WITHOUT_RETRIES:
    4067             if (!s->pDrvBlock || s->fATAPI)
     4065            if (!s->pDrvMedia || s->fATAPI)
    40684066                goto abort_cmd;
    40694067            s->cSectorsPerIRQ = 1;
    4070             ataR3StartTransfer(s, ataR3GetNSectors(s) * s->cbSector, PDMBLOCKTXDIR_FROM_DEVICE, ATAFN_BT_READ_WRITE_SECTORS, ATAFN_SS_READ_SECTORS, false);
     4068            ataR3StartTransfer(s, ataR3GetNSectors(s) * s->cbSector, PDMMEDIATXDIR_FROM_DEVICE, ATAFN_BT_READ_WRITE_SECTORS, ATAFN_SS_READ_SECTORS, false);
    40714069            break;
    40724070        case ATA_WRITE_SECTORS_EXT:
     
    40744072        case ATA_WRITE_SECTORS:
    40754073        case ATA_WRITE_SECTORS_WITHOUT_RETRIES:
    4076             if (!s->pDrvBlock || s->fATAPI)
     4074            if (!s->pDrvMedia || s->fATAPI)
    40774075                goto abort_cmd;
    40784076            s->cSectorsPerIRQ = 1;
    4079             ataR3StartTransfer(s, ataR3GetNSectors(s) * s->cbSector, PDMBLOCKTXDIR_TO_DEVICE, ATAFN_BT_READ_WRITE_SECTORS, ATAFN_SS_WRITE_SECTORS, false);
     4077            ataR3StartTransfer(s, ataR3GetNSectors(s) * s->cbSector, PDMMEDIATXDIR_TO_DEVICE, ATAFN_BT_READ_WRITE_SECTORS, ATAFN_SS_WRITE_SECTORS, false);
    40804078            break;
    40814079        case ATA_READ_MULTIPLE_EXT:
    40824080            s->fLBA48 = true;
    40834081        case ATA_READ_MULTIPLE:
    4084             if (!s->pDrvBlock || !s->cMultSectors || s->fATAPI)
     4082            if (!s->pDrvMedia || !s->cMultSectors || s->fATAPI)
    40854083                goto abort_cmd;
    40864084            s->cSectorsPerIRQ = s->cMultSectors;
    4087             ataR3StartTransfer(s, ataR3GetNSectors(s) * s->cbSector, PDMBLOCKTXDIR_FROM_DEVICE, ATAFN_BT_READ_WRITE_SECTORS, ATAFN_SS_READ_SECTORS, false);
     4085            ataR3StartTransfer(s, ataR3GetNSectors(s) * s->cbSector, PDMMEDIATXDIR_FROM_DEVICE, ATAFN_BT_READ_WRITE_SECTORS, ATAFN_SS_READ_SECTORS, false);
    40884086            break;
    40894087        case ATA_WRITE_MULTIPLE_EXT:
    40904088            s->fLBA48 = true;
    40914089        case ATA_WRITE_MULTIPLE:
    4092             if (!s->pDrvBlock || !s->cMultSectors || s->fATAPI)
     4090            if (!s->pDrvMedia || !s->cMultSectors || s->fATAPI)
    40934091                goto abort_cmd;
    40944092            s->cSectorsPerIRQ = s->cMultSectors;
    4095             ataR3StartTransfer(s, ataR3GetNSectors(s) * s->cbSector, PDMBLOCKTXDIR_TO_DEVICE, ATAFN_BT_READ_WRITE_SECTORS, ATAFN_SS_WRITE_SECTORS, false);
     4093            ataR3StartTransfer(s, ataR3GetNSectors(s) * s->cbSector, PDMMEDIATXDIR_TO_DEVICE, ATAFN_BT_READ_WRITE_SECTORS, ATAFN_SS_WRITE_SECTORS, false);
    40964094            break;
    40974095        case ATA_READ_DMA_EXT:
     
    40994097        case ATA_READ_DMA:
    41004098        case ATA_READ_DMA_WITHOUT_RETRIES:
    4101             if (!s->pDrvBlock || s->fATAPI)
     4099            if (!s->pDrvMedia || s->fATAPI)
    41024100                goto abort_cmd;
    41034101            s->cSectorsPerIRQ = ATA_MAX_MULT_SECTORS;
    41044102            s->fDMA = true;
    4105             ataR3StartTransfer(s, ataR3GetNSectors(s) * s->cbSector, PDMBLOCKTXDIR_FROM_DEVICE, ATAFN_BT_READ_WRITE_SECTORS, ATAFN_SS_READ_SECTORS, false);
     4103            ataR3StartTransfer(s, ataR3GetNSectors(s) * s->cbSector, PDMMEDIATXDIR_FROM_DEVICE, ATAFN_BT_READ_WRITE_SECTORS, ATAFN_SS_READ_SECTORS, false);
    41064104            break;
    41074105        case ATA_WRITE_DMA_EXT:
     
    41094107        case ATA_WRITE_DMA:
    41104108        case ATA_WRITE_DMA_WITHOUT_RETRIES:
    4111             if (!s->pDrvBlock || s->fATAPI)
     4109            if (!s->pDrvMedia || s->fATAPI)
    41124110                goto abort_cmd;
    41134111            s->cSectorsPerIRQ = ATA_MAX_MULT_SECTORS;
    41144112            s->fDMA = true;
    4115             ataR3StartTransfer(s, ataR3GetNSectors(s) * s->cbSector, PDMBLOCKTXDIR_TO_DEVICE, ATAFN_BT_READ_WRITE_SECTORS, ATAFN_SS_WRITE_SECTORS, false);
     4113            ataR3StartTransfer(s, ataR3GetNSectors(s) * s->cbSector, PDMMEDIATXDIR_TO_DEVICE, ATAFN_BT_READ_WRITE_SECTORS, ATAFN_SS_WRITE_SECTORS, false);
    41164114            break;
    41174115        case ATA_READ_NATIVE_MAX_ADDRESS_EXT:
     
    41374135        case ATA_SET_FEATURES:
    41384136            Log2(("%s: feature=%#x\n", __FUNCTION__, s->uATARegFeature));
    4139             if (!s->pDrvBlock)
     4137            if (!s->pDrvMedia)
    41404138                goto abort_cmd;
    41414139            switch (s->uATARegFeature)
     
    41704168                    /* As per the ATA/ATAPI-6 specs, a write cache disable
    41714169                     * command MUST flush the write buffers to disc. */
    4172                     ataR3StartTransfer(s, 0, PDMBLOCKTXDIR_NONE, ATAFN_BT_NULL, ATAFN_SS_FLUSH, false);
     4170                    ataR3StartTransfer(s, 0, PDMMEDIATXDIR_NONE, ATAFN_BT_NULL, ATAFN_SS_FLUSH, false);
    41734171                    break;
    41744172                case 0x03: { /* set transfer mode */
     
    42054203        case ATA_FLUSH_CACHE_EXT:
    42064204        case ATA_FLUSH_CACHE:
    4207             if (!s->pDrvBlock || s->fATAPI)
     4205            if (!s->pDrvMedia || s->fATAPI)
    42084206                goto abort_cmd;
    4209             ataR3StartTransfer(s, 0, PDMBLOCKTXDIR_NONE, ATAFN_BT_NULL, ATAFN_SS_FLUSH, false);
     4207            ataR3StartTransfer(s, 0, PDMMEDIATXDIR_NONE, ATAFN_BT_NULL, ATAFN_SS_FLUSH, false);
    42104208            break;
    42114209        case ATA_STANDBY_IMMEDIATE:
     
    42244222        case ATA_IDENTIFY_PACKET_DEVICE:
    42254223            if (s->fATAPI)
    4226                 ataR3StartTransfer(s, 512, PDMBLOCKTXDIR_FROM_DEVICE, ATAFN_BT_NULL, ATAFN_SS_ATAPI_IDENTIFY, false);
     4224                ataR3StartTransfer(s, 512, PDMMEDIATXDIR_FROM_DEVICE, ATAFN_BT_NULL, ATAFN_SS_ATAPI_IDENTIFY, false);
    42274225            else
    42284226            {
     
    42324230            break;
    42334231        case ATA_EXECUTE_DEVICE_DIAGNOSTIC:
    4234             ataR3StartTransfer(s, 0, PDMBLOCKTXDIR_NONE, ATAFN_BT_NULL, ATAFN_SS_EXECUTE_DEVICE_DIAGNOSTIC, false);
     4232            ataR3StartTransfer(s, 0, PDMMEDIATXDIR_NONE, ATAFN_BT_NULL, ATAFN_SS_EXECUTE_DEVICE_DIAGNOSTIC, false);
    42354233            break;
    42364234        case ATA_DEVICE_RESET:
     
    42464244            if (s->uATARegFeature & 0x02)
    42474245                goto abort_cmd;
    4248             ataR3StartTransfer(s, ATAPI_PACKET_SIZE, PDMBLOCKTXDIR_TO_DEVICE, ATAFN_BT_PACKET, ATAFN_SS_PACKET, false);
     4246            ataR3StartTransfer(s, ATAPI_PACKET_SIZE, PDMMEDIATXDIR_TO_DEVICE, ATAFN_BT_PACKET, ATAFN_SS_PACKET, false);
    42494247            break;
    42504248        case ATA_DATA_SET_MANAGEMENT:
    4251             if (!s->pDrvBlock || !s->pDrvBlock->pfnDiscard)
     4249            if (!s->pDrvMedia || !s->pDrvMedia->pfnDiscard)
    42524250                goto abort_cmd;
    42534251            if (   !(s->uATARegFeature & UINT8_C(0x01))
     
    42554253                goto abort_cmd;
    42564254            s->fDMA = true;
    4257             ataR3StartTransfer(s, (s->uATARegNSectorHOB << 8 | s->uATARegNSector) * s->cbSector, PDMBLOCKTXDIR_TO_DEVICE, ATAFN_BT_NULL, ATAFN_SS_TRIM, false);
     4255            ataR3StartTransfer(s, (s->uATARegNSectorHOB << 8 | s->uATARegNSector) * s->cbSector, PDMMEDIATXDIR_TO_DEVICE, ATAFN_BT_NULL, ATAFN_SS_TRIM, false);
    42584256            break;
    42594257        default:
     
    43854383        case 7: /* command */
    43864384            /* ignore commands to non-existent device */
    4387             if (pCtl->iSelectedIf && !pCtl->aIfs[pCtl->iSelectedIf].pDrvBlock)
     4385            if (pCtl->iSelectedIf && !pCtl->aIfs[pCtl->iSelectedIf].pDrvMedia)
    43884386                break;
    43894387#ifndef IN_RING3
     
    44054403
    44064404    /* Check if the guest is reading from a non-existent device. */
    4407     if (!s->pDrvBlock)
     4405    if (!s->pDrvMedia)
    44084406    {
    44094407        if (pCtl->iSelectedIf)  /* Device 1 selected, Device 0 responding for it. */
    44104408        {
    4411             if (!pCtl->aIfs[0].pDrvBlock)   /** @todo this case should never get here! */
     4409            if (!pCtl->aIfs[0].pDrvMedia)   /** @todo this case should never get here! */
    44124410            {
    44134411                Log2(("%s: addr=%#x: no device on channel\n", __FUNCTION__, addr));
     
    44404438             * the feature register (write-only), so it seems that it's not
    44414439             * necessary to support the usual HOB readback here. */
    4442             if (!s->pDrvBlock)
     4440            if (!s->pDrvMedia)
    44434441                val = 0;
    44444442            else
     
    44734471             * one drive attached to the controller. It is common between
    44744472             * both drives anyway (completely identical content). */
    4475             if (!pCtl->aIfs[0].pDrvBlock && !pCtl->aIfs[1].pDrvBlock)
     4473            if (!pCtl->aIfs[0].pDrvMedia && !pCtl->aIfs[1].pDrvMedia)
    44764474                val = 0;
    44774475            else
     
    44844482            static unsigned cBusy = 0;
    44854483
    4486             if (!s->pDrvBlock)
     4484            if (!s->pDrvMedia)
    44874485                val = 0;
    44884486            else
     
    45694567    //@todo: The handler should not be even registered if there
    45704568    // is no device on an IDE channel.
    4571     if (!pCtl->aIfs[0].pDrvBlock && !pCtl->aIfs[1].pDrvBlock)
     4569    if (!pCtl->aIfs[0].pDrvMedia && !pCtl->aIfs[1].pDrvMedia)
    45724570        val = 0xff;
    4573     else if (pCtl->iSelectedIf == 1 && !s->pDrvBlock)
     4571    else if (pCtl->iSelectedIf == 1 && !s->pDrvMedia)
    45744572        val = 0;    /* Device 1 selected, Device 0 responding for it. */
    45754573    else
     
    47014699    {
    47024700# ifdef IN_RING3
    4703         LogRel(("PIIX3 ATA: LUN#%d: %s data in the middle of a PIO transfer - VERY SLOW\n", s->iLUN, s->uTxDir == PDMBLOCKTXDIR_FROM_DEVICE ? "loading" : "storing"));
     4701        LogRel(("PIIX3 ATA: LUN#%d: %s data in the middle of a PIO transfer - VERY SLOW\n", s->iLUN, s->uTxDir == PDMMEDIATXDIR_FROM_DEVICE ? "loading" : "storing"));
    47044702        /* Any guest OS that triggers this case has a pathetic ATA driver.
    47054703         * In a real system it would block the CPU via IORDY, here we do it
     
    47294727            ataHCPIOTransferLimitATAPI(s);
    47304728
    4731         if (s->uTxDir == PDMBLOCKTXDIR_TO_DEVICE && s->cbElementaryTransfer > s->cbTotalTransfer)
     4729        if (s->uTxDir == PDMMEDIATXDIR_TO_DEVICE && s->cbElementaryTransfer > s->cbTotalTransfer)
    47324730            s->cbElementaryTransfer = s->cbTotalTransfer;
    47334731
    47344732        Log2(("%s: %s tx_size=%d elem_tx_size=%d index=%d end=%d\n",
    4735              __FUNCTION__, s->uTxDir == PDMBLOCKTXDIR_FROM_DEVICE ? "T2I" : "I2T",
     4733             __FUNCTION__, s->uTxDir == PDMMEDIATXDIR_FROM_DEVICE ? "T2I" : "I2T",
    47364734             s->cbTotalTransfer, s->cbElementaryTransfer,
    47374735             s->iIOBufferCur, s->iIOBufferEnd));
     
    47404738        s->iIOBufferCur += s->cbElementaryTransfer;
    47414739
    4742         if (s->uTxDir == PDMBLOCKTXDIR_FROM_DEVICE && s->cbElementaryTransfer > s->cbTotalTransfer)
     4740        if (s->uTxDir == PDMMEDIATXDIR_FROM_DEVICE && s->cbElementaryTransfer > s->cbTotalTransfer)
    47434741            s->cbElementaryTransfer = s->cbTotalTransfer;
    47444742    }
     
    47584756    }
    47594757
    4760     if (   s->uTxDir == PDMBLOCKTXDIR_TO_DEVICE
     4758    if (   s->uTxDir == PDMMEDIATXDIR_TO_DEVICE
    47614759        || (   s->iSourceSink != ATAFN_SS_NULL
    47624760            && s->iIOBufferCur >= s->iIOBufferEnd))
     
    48984896        if (s->iIOBufferPIODataStart < s->iIOBufferPIODataEnd)
    48994897        {
    4900             Assert(s->uTxDir == PDMBLOCKTXDIR_TO_DEVICE);
     4898            Assert(s->uTxDir == PDMMEDIATXDIR_TO_DEVICE);
    49014899            uint8_t       *pbDst = s->CTX_SUFF(pbIOBuffer) + s->iIOBufferPIODataStart;
    49024900            uint8_t const *pbSrc = (uint8_t const *)&u32;
     
    49154913            if (s->iIOBufferPIODataStart + cb < s->iIOBufferPIODataEnd)
    49164914                ataCopyPioData124(s, pbDst, pbSrc, cb);
    4917             else if (s->uTxDir == PDMBLOCKTXDIR_TO_DEVICE) /* paranoia */
     4915            else if (s->uTxDir == PDMMEDIATXDIR_TO_DEVICE) /* paranoia */
    49184916            {
    49194917                ataCopyPioData124(s, pbDst, pbSrc, cb);
     
    49704968        if (s->iIOBufferPIODataStart < s->iIOBufferPIODataEnd)
    49714969        {
    4972             Assert(s->uTxDir == PDMBLOCKTXDIR_FROM_DEVICE);
     4970            Assert(s->uTxDir == PDMMEDIATXDIR_FROM_DEVICE);
    49734971            uint8_t const *pbSrc = s->CTX_SUFF(pbIOBuffer) + s->iIOBufferPIODataStart;
    49744972            uint8_t       *pbDst = (uint8_t *)pu32;
     
    52275225    uint32_t iIOBufferCur, iIOBufferEnd;
    52285226    uint32_t dmalen;
    5229     PDMBLOCKTXDIR uTxDir;
     5227    PDMMEDIATXDIR uTxDir;
    52305228    bool fLastDesc = false;
    52315229
     
    52355233    if (RT_LIKELY(!fRedo))
    52365234        Assert(s->cbTotalTransfer);
    5237     uTxDir = (PDMBLOCKTXDIR)s->uTxDir;
     5235    uTxDir = (PDMMEDIATXDIR)s->uTxDir;
    52385236    cbTotalTransfer = s->cbTotalTransfer;
    52395237    cbElementaryTransfer = s->cbElementaryTransfer;
     
    52475245
    52485246    Log2(("%s: %s tx_size=%d elem_tx_size=%d index=%d end=%d\n",
    5249          __FUNCTION__, uTxDir == PDMBLOCKTXDIR_FROM_DEVICE ? "T2I" : "I2T",
     5247         __FUNCTION__, uTxDir == PDMMEDIATXDIR_FROM_DEVICE ? "T2I" : "I2T",
    52505248         cbTotalTransfer, cbElementaryTransfer,
    52515249         iIOBufferCur, iIOBufferEnd));
     
    52855283                PCIATAState *pATAState = PDMINS_2_DATA(pDevIns, PCIATAState *);
    52865284                AssertPtr(pATAState);
    5287                 if (uTxDir == PDMBLOCKTXDIR_FROM_DEVICE)
     5285                if (uTxDir == PDMMEDIATXDIR_FROM_DEVICE)
    52885286                    PDMDevHlpPCIPhysWrite(pDevIns, pBuffer, s->CTX_SUFF(pbIOBuffer) + iIOBufferCur, dmalen);
    52895287                else
     
    52965294            }
    52975295            if (    iIOBufferCur == iIOBufferEnd
    5298                 &&  (uTxDir == PDMBLOCKTXDIR_TO_DEVICE || cbTotalTransfer))
     5296                &&  (uTxDir == PDMMEDIATXDIR_TO_DEVICE || cbTotalTransfer))
    52995297            {
    5300                 if (uTxDir == PDMBLOCKTXDIR_FROM_DEVICE && cbElementaryTransfer > cbTotalTransfer)
     5298                if (uTxDir == PDMMEDIATXDIR_FROM_DEVICE && cbElementaryTransfer > cbTotalTransfer)
    53015299                    cbElementaryTransfer = cbTotalTransfer;
    53025300
     
    53315329                        cbElementaryTransfer = s->cbElementaryTransfer;
    53325330
    5333                         if (uTxDir == PDMBLOCKTXDIR_TO_DEVICE && cbElementaryTransfer > cbTotalTransfer)
     5331                        if (uTxDir == PDMMEDIATXDIR_TO_DEVICE && cbElementaryTransfer > cbTotalTransfer)
    53345332                            cbElementaryTransfer = cbTotalTransfer;
    53355333                        iIOBufferCur = 0;
     
    55505548                    g_apfnBeginTransFuncs[s->iBeginTransfer](s);
    55515549                    s->iBeginTransfer = ATAFN_BT_NULL;
    5552                     if (s->uTxDir != PDMBLOCKTXDIR_FROM_DEVICE)
     5550                    if (s->uTxDir != PDMMEDIATXDIR_FROM_DEVICE)
    55535551                        s->iIOBufferEnd = s->cbElementaryTransfer;
    55545552                }
     
    55605558                s->iIOBufferCur = 0;
    55615559
    5562                 if (s->uTxDir != PDMBLOCKTXDIR_TO_DEVICE)
     5560                if (s->uTxDir != PDMMEDIATXDIR_TO_DEVICE)
    55635561                {
    55645562                    if (s->iSourceSink != ATAFN_SS_NULL)
     
    56075605                    else
    56085606                    {
    5609                         Assert(s->uTxDir == PDMBLOCKTXDIR_NONE); /* Any transfer which has an initial transfer size of 0 must be marked as such. */
     5607                        Assert(s->uTxDir == PDMMEDIATXDIR_NONE); /* Any transfer which has an initial transfer size of 0 must be marked as such. */
    56105608                        /* Finish DMA transfer. */
    56115609                        ataR3DMATransferStop(s);
     
    56205618                        ataHCPIOTransfer(pCtl);
    56215619                        Assert(!pCtl->fRedo);
    5622                         if (s->fATAPITransfer || s->uTxDir != PDMBLOCKTXDIR_TO_DEVICE)
     5620                        if (s->fATAPITransfer || s->uTxDir != PDMMEDIATXDIR_TO_DEVICE)
    56235621                            ataHCSetIRQ(s);
    56245622
    5625                         if (s->uTxDir == PDMBLOCKTXDIR_TO_DEVICE || s->iSourceSink != ATAFN_SS_NULL)
     5623                        if (s->uTxDir == PDMMEDIATXDIR_TO_DEVICE || s->iSourceSink != ATAFN_SS_NULL)
    56265624                        {
    56275625                            /* Write operations and not yet finished transfers
     
    56445642                    else
    56455643                    {
    5646                         Assert(s->uTxDir == PDMBLOCKTXDIR_NONE); /* Any transfer which has an initial transfer size of 0 must be marked as such. */
     5644                        Assert(s->uTxDir == PDMMEDIATXDIR_NONE); /* Any transfer which has an initial transfer size of 0 must be marked as such. */
    56475645                        /* Finish PIO transfer. */
    56485646                        ataHCPIOTransfer(pCtl);
     
    56615659                ATAFNSS iOriginalSourceSink = (ATAFNSS)s->iSourceSink; /* Used by the hack below, but gets reset by then. */
    56625660
    5663                 if (s->uTxDir == PDMBLOCKTXDIR_FROM_DEVICE)
     5661                if (s->uTxDir == PDMMEDIATXDIR_FROM_DEVICE)
    56645662                    AssertRelease(bm->u8Cmd & BM_CMD_WRITE);
    56655663                else
     
    57495747                    ataHCSetIRQ(s);
    57505748
    5751                     if (s->uTxDir == PDMBLOCKTXDIR_TO_DEVICE || s->iSourceSink != ATAFN_SS_NULL)
     5749                    if (s->uTxDir == PDMMEDIATXDIR_TO_DEVICE || s->iSourceSink != ATAFN_SS_NULL)
    57525750                    {
    57535751                        /* Write operations and not yet finished transfers
     
    57745772                    if (    !pCtl->fChainedTransfer
    57755773                        &&  !s->fATAPITransfer
    5776                         &&  s->uTxDir != PDMBLOCKTXDIR_FROM_DEVICE)
     5774                        &&  s->uTxDir != PDMMEDIATXDIR_FROM_DEVICE)
    57775775                    {
    57785776                            ataHCSetIRQ(s);
     
    61866184    ATADevState *pIf = PDMIBASE_2_ATASTATE(pInterface);
    61876185    PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pIf->IBase);
    6188     PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBLOCKPORT, &pIf->IPort);
     6186    PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMEDIAPORT, &pIf->IPort);
    61896187    PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMOUNTNOTIFY, &pIf->IMountNotify);
    61906188    return NULL;
     
    61956193
    61966194/**
    6197  * @interface_method_impl{PDMIBLOCKPORT,pfnQueryDeviceLocation}
     6195 * @interface_method_impl{PDMIMEDIAPORT,pfnQueryDeviceLocation}
    61986196 */
    6199 static DECLCALLBACK(int) ataR3QueryDeviceLocation(PPDMIBLOCKPORT pInterface, const char **ppcszController,
     6197static DECLCALLBACK(int) ataR3QueryDeviceLocation(PPDMIMEDIAPORT pInterface, const char **ppcszController,
    62006198                                                  uint32_t *piInstance, uint32_t *piLUN)
    62016199{
    6202     ATADevState *pIf = PDMIBLOCKPORT_2_ATASTATE(pInterface);
     6200    ATADevState *pIf = PDMIMEDIAPORT_2_ATASTATE(pInterface);
    62036201    PPDMDEVINS pDevIns = pIf->CTX_SUFF(pDevIns);
    62046202
     
    63876385     */
    63886386    pIf->pDrvBase = NULL;
    6389     pIf->pDrvBlock = NULL;
    6390     pIf->pDrvBlockBios = NULL;
     6387    pIf->pDrvMedia = NULL;
    63916388    pIf->pDrvMount = NULL;
    63926389
     
    64086405{
    64096406    int             rc = VINF_SUCCESS;
    6410     PDMBLOCKTYPE    enmType;
     6407    PDMMEDIATYPE    enmType;
    64116408
    64126409    /*
    64136410     * Query Block, Bios and Mount interfaces.
    64146411     */
    6415     pIf->pDrvBlock = PDMIBASE_QUERY_INTERFACE(pIf->pDrvBase, PDMIBLOCK);
    6416     if (!pIf->pDrvBlock)
     6412    pIf->pDrvMedia = PDMIBASE_QUERY_INTERFACE(pIf->pDrvBase, PDMIMEDIA);
     6413    if (!pIf->pDrvMedia)
    64176414    {
    64186415        AssertMsgFailed(("Configuration error: LUN#%d hasn't a block interface!\n", pIf->iLUN));
     
    64206417    }
    64216418
    6422     /** @todo implement the BIOS invisible code path. */
    6423     pIf->pDrvBlockBios = PDMIBASE_QUERY_INTERFACE(pIf->pDrvBase, PDMIBLOCKBIOS);
    6424     if (!pIf->pDrvBlockBios)
    6425     {
    6426         AssertMsgFailed(("Configuration error: LUN#%d hasn't a block BIOS interface!\n", pIf->iLUN));
    6427         return VERR_PDM_MISSING_INTERFACE;
    6428     }
    64296419    pIf->pDrvMount = PDMIBASE_QUERY_INTERFACE(pIf->pDrvBase, PDMIMOUNT);
    64306420
     
    64326422     * Validate type.
    64336423     */
    6434     enmType = pIf->pDrvBlock->pfnGetType(pIf->pDrvBlock);
    6435     if (    enmType != PDMBLOCKTYPE_CDROM
    6436         &&  enmType != PDMBLOCKTYPE_DVD
    6437         &&  enmType != PDMBLOCKTYPE_HARD_DISK)
     6424    enmType = pIf->pDrvMedia->pfnGetType(pIf->pDrvMedia);
     6425    if (    enmType != PDMMEDIATYPE_CDROM
     6426        &&  enmType != PDMMEDIATYPE_DVD
     6427        &&  enmType != PDMMEDIATYPE_HARD_DISK)
    64386428    {
    64396429        AssertMsgFailed(("Configuration error: LUN#%d isn't a disk or cd/dvd-rom. enmType=%d\n", pIf->iLUN, enmType));
    64406430        return VERR_PDM_UNSUPPORTED_BLOCK_TYPE;
    64416431    }
    6442     if (    (   enmType == PDMBLOCKTYPE_DVD
    6443              || enmType == PDMBLOCKTYPE_CDROM)
     6432    if (    (   enmType == PDMMEDIATYPE_DVD
     6433             || enmType == PDMMEDIATYPE_CDROM)
    64446434        &&  !pIf->pDrvMount)
    64456435    {
     
    64476437        return VERR_INTERNAL_ERROR;
    64486438    }
    6449     pIf->fATAPI = enmType == PDMBLOCKTYPE_DVD || enmType == PDMBLOCKTYPE_CDROM;
    6450     pIf->fATAPIPassthrough = pIf->fATAPI ? (pIf->pDrvBlock->pfnSendCmd != NULL) : false;
     6439    pIf->fATAPI = enmType == PDMMEDIATYPE_DVD || enmType == PDMMEDIATYPE_CDROM;
     6440    pIf->fATAPIPassthrough = pIf->fATAPI ? (pIf->pDrvMedia->pfnSendCmd != NULL) : false;
    64516441
    64526442    /*
     
    64566446        pIf->cbSector = 2048;
    64576447    else
    6458         pIf->cbSector = pIf->pDrvBlock->pfnGetSectorSize(pIf->pDrvBlock);
     6448        pIf->cbSector = pIf->pDrvMedia->pfnGetSectorSize(pIf->pDrvMedia);
    64596449
    64606450    PVM pVM = PDMDevHlpGetVM(pDevIns);
     
    64906480    if (pIf->fATAPI)
    64916481    {
    6492         pIf->cTotalSectors = pIf->pDrvBlock->pfnGetSize(pIf->pDrvBlock) / pIf->cbSector;
     6482        pIf->cTotalSectors = pIf->pDrvMedia->pfnGetSize(pIf->pDrvMedia) / pIf->cbSector;
    64936483        pIf->PCHSGeometry.cCylinders = 0; /* dummy */
    64946484        pIf->PCHSGeometry.cHeads     = 0; /* dummy */
     
    64986488    else
    64996489    {
    6500         pIf->cTotalSectors = pIf->pDrvBlock->pfnGetSize(pIf->pDrvBlock) / pIf->cbSector;
    6501         rc = pIf->pDrvBlockBios->pfnGetPCHSGeometry(pIf->pDrvBlockBios,
    6502                                                     &pIf->PCHSGeometry);
     6490        pIf->cTotalSectors = pIf->pDrvMedia->pfnGetSize(pIf->pDrvMedia) / pIf->cbSector;
     6491        rc = pIf->pDrvMedia->pfnBiosGetPCHSGeometry(pIf->pDrvMedia, &pIf->PCHSGeometry);
    65036492        if (rc == VERR_PDM_MEDIA_NOT_MOUNTED)
    65046493        {
     
    65246513            pIf->PCHSGeometry.cSectors = 63;
    65256514            /* Set the disk geometry information. Ignore errors. */
    6526             pIf->pDrvBlockBios->pfnSetPCHSGeometry(pIf->pDrvBlockBios,
    6527                                                    &pIf->PCHSGeometry);
     6515            pIf->pDrvMedia->pfnBiosSetPCHSGeometry(pIf->pDrvMedia, &pIf->PCHSGeometry);
    65286516            rc = VINF_SUCCESS;
    65296517        }
    65306518        LogRel(("PIIX3 ATA: LUN#%d: disk, PCHS=%u/%u/%u, total number of sectors %Ld\n", pIf->iLUN, pIf->PCHSGeometry.cCylinders, pIf->PCHSGeometry.cHeads, pIf->PCHSGeometry.cSectors, pIf->cTotalSectors));
    65316519
    6532         if (pIf->pDrvBlock->pfnDiscard)
     6520        if (pIf->pDrvMedia->pfnDiscard)
    65336521            LogRel(("PIIX3 ATA: LUN#%d: TRIM enabled\n", pIf->iLUN));
    65346522    }
     
    65726560    /* the usual paranoia */
    65736561    AssertRelease(!pIf->pDrvBase);
    6574     AssertRelease(!pIf->pDrvBlock);
     6562    AssertRelease(!pIf->pDrvMedia);
    65756563    Assert(ATADEVSTATE_2_CONTROLLER(pIf) == pCtl);
    65766564    Assert(pIf->iLUN == iLUN);
     
    65966584    {
    65976585        pIf->pDrvBase = NULL;
    6598         pIf->pDrvBlock = NULL;
     6586        pIf->pDrvMedia = NULL;
    65996587    }
    66006588    return rc;
     
    76927680                    char szSerial[ATA_SERIAL_NUMBER_LENGTH+1];
    76937681                    RTUUID Uuid;
    7694                     if (pIf->pDrvBlock)
    7695                         rc = pIf->pDrvBlock->pfnGetUuid(pIf->pDrvBlock, &Uuid);
     7682                    if (pIf->pDrvMedia)
     7683                        rc = pIf->pDrvMedia->pfnGetUuid(pIf->pDrvMedia, &Uuid);
    76967684                    else
    76977685                        RTUuidClear(&Uuid);
     
    77947782            {
    77957783                pIf->pDrvBase = NULL;
    7796                 pIf->pDrvBlock = NULL;
     7784                pIf->pDrvMedia = NULL;
    77977785                pIf->cbIOBuffer = 0;
    77987786                pIf->pbIOBufferR3 = NULL;
  • trunk/src/VBox/Devices/Storage/DevFdc.cpp

    r57358 r59248  
    141141 *
    142142 * @implements  PDMIBASE
    143  * @implements  PDMIBLOCKPORT
     143 * @implements  PDMIMEDIAPORT
    144144 * @implements  PDMIMOUNTNOTIFY
    145145 */
     
    151151    R3PTRTYPE(PPDMIBASE)            pDrvBase;
    152152    /** Pointer to the attached driver's block interface. */
    153     R3PTRTYPE(PPDMIBLOCK)           pDrvBlock;
    154     /** Pointer to the attached driver's block bios interface. */
    155     R3PTRTYPE(PPDMIBLOCKBIOS)       pDrvBlockBios;
     153    R3PTRTYPE(PPDMIMEDIA)           pDrvMedia;
    156154    /** Pointer to the attached driver's mount interface.
    157155     * This is NULL if the driver isn't a removable unit. */
     
    160158    PDMIBASE                        IBase;
    161159    /** The block port interface. */
    162     PDMIBLOCKPORT                   IPort;
     160    PDMIMEDIAPORT                   IPort;
    163161    /** The mount notify interface. */
    164162    PDMIMOUNTNOTIFY                 IMountNotify;
     
    196194    if (fInit) {
    197195        /* Fixate the drive type at init time if possible. */
    198         if (drv->pDrvBlock) {
    199             PDMBLOCKTYPE enmType = drv->pDrvBlock->pfnGetType(drv->pDrvBlock);
     196        if (drv->pDrvMedia) {
     197            PDMMEDIATYPE enmType = drv->pDrvMedia->pfnGetType(drv->pDrvMedia);
    200198            switch (enmType) {
    201                 case PDMBLOCKTYPE_FLOPPY_360:
    202                 case PDMBLOCKTYPE_FLOPPY_1_20:
     199                case PDMMEDIATYPE_FLOPPY_360:
     200                case PDMMEDIATYPE_FLOPPY_1_20:
    203201                    drv->drive = FDRIVE_DRV_120;
    204202                    break;
    205                 case PDMBLOCKTYPE_FLOPPY_720:
    206                 case PDMBLOCKTYPE_FLOPPY_1_44:
     203                case PDMMEDIATYPE_FLOPPY_720:
     204                case PDMMEDIATYPE_FLOPPY_1_44:
    207205                    drv->drive = FDRIVE_DRV_144;
    208206                    break;
    209207                default:
    210208                    AssertFailed();
    211                 case PDMBLOCKTYPE_FLOPPY_2_88:
     209                case PDMMEDIATYPE_FLOPPY_2_88:
    212210                    drv->drive = FDRIVE_DRV_288;
    213211                    break;
    214                 case PDMBLOCKTYPE_FLOPPY_FAKE_15_6:
     212                case PDMMEDIATYPE_FLOPPY_FAKE_15_6:
    215213                    drv->drive = FDRIVE_DRV_FAKE_15_6;
    216214                    break;
    217                 case PDMBLOCKTYPE_FLOPPY_FAKE_63_5:
     215                case PDMMEDIATYPE_FLOPPY_FAKE_63_5:
    218216                    drv->drive = FDRIVE_DRV_FAKE_63_5;
    219217                    break;
     
    439437        bdrv_get_geometry_hint(drv->bs, &nb_heads, &max_track, &last_sect);
    440438#else /* VBOX */
    441     if (   drv->pDrvBlock
     439    if (   drv->pDrvMedia
    442440        && drv->pDrvMount
    443441        && drv->pDrvMount->pfnIsMounted (drv->pDrvMount)) {
    444         ro = drv->pDrvBlock->pfnIsReadOnly (drv->pDrvBlock);
     442        ro = drv->pDrvMedia->pfnIsReadOnly (drv->pDrvMedia);
    445443        nb_heads = max_track = last_sect = 0;
    446444#endif /* VBOX */
     
    453451#else /* VBOX */
    454452            {
    455                 uint64_t size2 = drv->pDrvBlock->pfnGetSize (drv->pDrvBlock);
     453                uint64_t size2 = drv->pDrvMedia->pfnGetSize (drv->pDrvMedia);
    456454                nb_sectors = size2 / FD_SECTOR_LEN;
    457455            }
     
    884882    fdctrl->srb = 0xc0;
    885883#ifdef VBOX
    886     if (!fdctrl->drives[1].pDrvBlock)
     884    if (!fdctrl->drives[1].pDrvMedia)
    887885#else
    888886    if (!fdctrl->drives[1].bs)
     
    15011499    drv->Led.Asserted.s.fWriting = drv->Led.Actual.s.fWriting = 1;
    15021500
    1503     rc = drv->pDrvBlock->pfnWrite(drv->pDrvBlock, sector_num * FD_SECTOR_LEN,
     1501    rc = drv->pDrvMedia->pfnWrite(drv->pDrvMedia, sector_num * FD_SECTOR_LEN,
    15041502                                  buf, nb_sectors * FD_SECTOR_LEN);
    15051503
     
    15171515    drv->Led.Asserted.s.fReading = drv->Led.Actual.s.fReading = 1;
    15181516
    1519     rc = drv->pDrvBlock->pfnRead(drv->pDrvBlock, sector_num * FD_SECTOR_LEN,
     1517    rc = drv->pDrvMedia->pfnRead(drv->pDrvMedia, sector_num * FD_SECTOR_LEN,
    15201518                                 buf, nb_sectors * FD_SECTOR_LEN);
    15211519
     
    15671565    if (cur_drv->bs == NULL)
    15681566#else  /* !VBOX */
    1569     if (cur_drv->pDrvBlock == NULL)
     1567    if (cur_drv->pDrvMedia == NULL)
    15701568#endif
    15711569    {
     
    18611859    memset(fdctrl->fifo, 0, FD_SECTOR_LEN);
    18621860#ifdef VBOX
    1863     if (cur_drv->pDrvBlock) {
     1861    if (cur_drv->pDrvMedia) {
    18641862        rc = blk_write(cur_drv, fd_sector(cur_drv), fdctrl->fifo, 1);
    18651863        if (RT_FAILURE (rc)) {
     
    26442642
    26452643    PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrv->IBase);
    2646     PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBLOCKPORT, &pDrv->IPort);
     2644    PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMEDIAPORT, &pDrv->IPort);
    26472645    PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMOUNTNOTIFY, &pDrv->IMountNotify);
    26482646    return NULL;
     
    27062704    rc = PDMDevHlpDriverAttach (pDevIns, drv->iLUN, &drv->IBase, &drv->pDrvBase, s_apszDesc[drv->iLUN]);
    27072705    if (RT_SUCCESS (rc)) {
    2708         drv->pDrvBlock = PDMIBASE_QUERY_INTERFACE(drv->pDrvBase, PDMIBLOCK);
    2709         if (drv->pDrvBlock) {
    2710             drv->pDrvBlockBios = PDMIBASE_QUERY_INTERFACE(drv->pDrvBase, PDMIBLOCKBIOS);
    2711             if (drv->pDrvBlockBios) {
    2712                 drv->pDrvMount = PDMIBASE_QUERY_INTERFACE(drv->pDrvBase, PDMIMOUNT);
    2713                 if (drv->pDrvMount) {
    2714                     fd_init(drv, fInit);
    2715                 } else {
    2716                     AssertMsgFailed (("Configuration error: LUN#%d without mountable interface!\n", drv->iLUN));
    2717                     rc = VERR_PDM_MISSING_INTERFACE;
    2718                 }
    2719 
     2706        drv->pDrvMedia = PDMIBASE_QUERY_INTERFACE(drv->pDrvBase, PDMIMEDIA);
     2707        if (drv->pDrvMedia) {
     2708            drv->pDrvMount = PDMIBASE_QUERY_INTERFACE(drv->pDrvBase, PDMIMOUNT);
     2709            if (drv->pDrvMount) {
     2710                fd_init(drv, fInit);
    27202711            } else {
    2721                 AssertMsgFailed (("Configuration error: LUN#%d hasn't a block BIOS interface!\n", drv->iLUN));
     2712                AssertMsgFailed (("Configuration error: LUN#%d without mountable interface!\n", drv->iLUN));
    27222713                rc = VERR_PDM_MISSING_INTERFACE;
    27232714            }
     
    27462737    if (RT_FAILURE (rc)) {
    27472738        drv->pDrvBase = NULL;
    2748         drv->pDrvBlock = NULL;
    2749         drv->pDrvBlockBios = NULL;
     2739        drv->pDrvMedia = NULL;
    27502740        drv->pDrvMount = NULL;
    27512741    }
     
    27872777    /* the usual paranoia */
    27882778    AssertRelease (!drv->pDrvBase);
    2789     AssertRelease (!drv->pDrvBlock);
    2790     AssertRelease (!drv->pDrvBlockBios);
     2779    AssertRelease (!drv->pDrvMedia);
    27912780    AssertRelease (!drv->pDrvMount);
    27922781
     
    28202809            fdrive_t *drv = &pThis->drives[iLUN];
    28212810            drv->pDrvBase = NULL;
    2822             drv->pDrvBlock = NULL;
    2823             drv->pDrvBlockBios = NULL;
     2811            drv->pDrvMedia = NULL;
    28242812            drv->pDrvMount = NULL;
    28252813            break;
  • trunk/src/VBox/Devices/Storage/DrvHostBase.cpp

    r57393 r59248  
    133133
    134134/** @copydoc PDMIBLOCK::pfnRead */
    135 static DECLCALLBACK(int) drvHostBaseRead(PPDMIBLOCK pInterface, uint64_t off, void *pvBuf, size_t cbRead)
    136 {
    137     PDRVHOSTBASE pThis = PDMIBLOCK_2_DRVHOSTBASE(pInterface);
     135static DECLCALLBACK(int) drvHostBaseRead(PPDMIMEDIA pInterface, uint64_t off, void *pvBuf, size_t cbRead)
     136{
     137    PDRVHOSTBASE pThis = PDMIMEDIA_2_DRVHOSTBASE(pInterface);
    138138    LogFlow(("%s-%d: drvHostBaseRead: off=%#llx pvBuf=%p cbRead=%#x (%s)\n",
    139139             pThis->pDrvIns->pReg->szName, pThis->pDrvIns->iInstance, off, pvBuf, cbRead, pThis->pszDevice));
     
    209209
    210210/** @copydoc PDMIBLOCK::pfnWrite */
    211 static DECLCALLBACK(int) drvHostBaseWrite(PPDMIBLOCK pInterface, uint64_t off, const void *pvBuf, size_t cbWrite)
    212 {
    213     PDRVHOSTBASE pThis = PDMIBLOCK_2_DRVHOSTBASE(pInterface);
     211static DECLCALLBACK(int) drvHostBaseWrite(PPDMIMEDIA pInterface, uint64_t off, const void *pvBuf, size_t cbWrite)
     212{
     213    PDRVHOSTBASE pThis = PDMIMEDIA_2_DRVHOSTBASE(pInterface);
    214214    LogFlow(("%s-%d: drvHostBaseWrite: off=%#llx pvBuf=%p cbWrite=%#x (%s)\n",
    215215             pThis->pDrvIns->pReg->szName, pThis->pDrvIns->iInstance, off, pvBuf, cbWrite, pThis->pszDevice));
     
    255255
    256256/** @copydoc PDMIBLOCK::pfnFlush */
    257 static DECLCALLBACK(int) drvHostBaseFlush(PPDMIBLOCK pInterface)
     257static DECLCALLBACK(int) drvHostBaseFlush(PPDMIMEDIA pInterface)
    258258{
    259259    int rc;
    260     PDRVHOSTBASE pThis = PDMIBLOCK_2_DRVHOSTBASE(pInterface);
     260    PDRVHOSTBASE pThis = PDMIMEDIA_2_DRVHOSTBASE(pInterface);
    261261    LogFlow(("%s-%d: drvHostBaseFlush: (%s)\n",
    262262             pThis->pDrvIns->pReg->szName, pThis->pDrvIns->iInstance, pThis->pszDevice));
     
    282282
    283283/** @copydoc PDMIBLOCK::pfnIsReadOnly */
    284 static DECLCALLBACK(bool) drvHostBaseIsReadOnly(PPDMIBLOCK pInterface)
    285 {
    286     PDRVHOSTBASE pThis = PDMIBLOCK_2_DRVHOSTBASE(pInterface);
     284static DECLCALLBACK(bool) drvHostBaseIsReadOnly(PPDMIMEDIA pInterface)
     285{
     286    PDRVHOSTBASE pThis = PDMIMEDIA_2_DRVHOSTBASE(pInterface);
    287287    return pThis->fReadOnly;
    288288}
     
    290290
    291291/** @copydoc PDMIBLOCK::pfnGetSize */
    292 static DECLCALLBACK(uint64_t) drvHostBaseGetSize(PPDMIBLOCK pInterface)
    293 {
    294     PDRVHOSTBASE pThis = PDMIBLOCK_2_DRVHOSTBASE(pInterface);
     292static DECLCALLBACK(uint64_t) drvHostBaseGetSize(PPDMIMEDIA pInterface)
     293{
     294    PDRVHOSTBASE pThis = PDMIMEDIA_2_DRVHOSTBASE(pInterface);
    295295    RTCritSectEnter(&pThis->CritSect);
    296296
     
    306306
    307307/** @copydoc PDMIBLOCK::pfnGetType */
    308 static DECLCALLBACK(PDMBLOCKTYPE) drvHostBaseGetType(PPDMIBLOCK pInterface)
    309 {
    310     PDRVHOSTBASE pThis = PDMIBLOCK_2_DRVHOSTBASE(pInterface);
     308static DECLCALLBACK(PDMMEDIATYPE) drvHostBaseGetType(PPDMIMEDIA pInterface)
     309{
     310    PDRVHOSTBASE pThis = PDMIMEDIA_2_DRVHOSTBASE(pInterface);
    311311    LogFlow(("%s-%d: drvHostBaseGetType: returns %d\n", pThis->pDrvIns->pReg->szName, pThis->pDrvIns->iInstance, pThis->enmType));
    312312    return pThis->enmType;
     
    315315
    316316/** @copydoc PDMIBLOCK::pfnGetUuid */
    317 static DECLCALLBACK(int) drvHostBaseGetUuid(PPDMIBLOCK pInterface, PRTUUID pUuid)
    318 {
    319     PDRVHOSTBASE pThis = PDMIBLOCK_2_DRVHOSTBASE(pInterface);
     317static DECLCALLBACK(int) drvHostBaseGetUuid(PPDMIMEDIA pInterface, PRTUUID pUuid)
     318{
     319    PDRVHOSTBASE pThis = PDMIMEDIA_2_DRVHOSTBASE(pInterface);
    320320
    321321    *pUuid = pThis->Uuid;
     
    327327
    328328/** @copydoc PDMIBLOCK::pfnIoBufAlloc */
    329 static DECLCALLBACK(int) drvHostBaseIoBufAlloc(PPDMIBLOCK pInterface, size_t cb, void **ppvNew)
     329static DECLCALLBACK(int) drvHostBaseIoBufAlloc(PPDMIMEDIA pInterface, size_t cb, void **ppvNew)
    330330{
    331331    LogFlowFunc(("\n"));
    332332    int rc;
    333     PDRVHOSTBASE pThis = PDMIBLOCK_2_DRVHOSTBASE(pInterface);
     333    PDRVHOSTBASE pThis = PDMIMEDIA_2_DRVHOSTBASE(pInterface);
    334334
    335335    void *pvNew = RTMemAlloc(cb);
     
    347347
    348348/** @copydoc PDMIBLOCK::pfnIoBufFree */
    349 static DECLCALLBACK(int) drvHostBaseIoBufFree(PPDMIBLOCK pInterface, void *pv, size_t cb)
     349static DECLCALLBACK(int) drvHostBaseIoBufFree(PPDMIMEDIA pInterface, void *pv, size_t cb)
    350350{
    351351    LogFlowFunc(("\n"));
    352352    int rc = VINF_SUCCESS;
    353     PDRVHOSTBASE pThis = PDMIBLOCK_2_DRVHOSTBASE(pInterface);
     353    PDRVHOSTBASE pThis = PDMIMEDIA_2_DRVHOSTBASE(pInterface);
    354354
    355355    NOREF(cb);
     
    361361
    362362
    363 
    364 /* -=-=-=-=- IBlockBios -=-=-=-=- */
    365 
    366 /** Makes a PDRVHOSTBASE out of a PPDMIBLOCKBIOS. */
    367 #define PDMIBLOCKBIOS_2_DRVHOSTBASE(pInterface)    ( (PDRVHOSTBASE((uintptr_t)pInterface - RT_OFFSETOF(DRVHOSTBASE, IBlockBios))) )
    368 
    369 
    370 /** @copydoc PDMIBLOCKBIOS::pfnGetPCHSGeometry */
    371 static DECLCALLBACK(int) drvHostBaseGetPCHSGeometry(PPDMIBLOCKBIOS pInterface, PPDMMEDIAGEOMETRY pPCHSGeometry)
    372 {
    373     PDRVHOSTBASE pThis =  PDMIBLOCKBIOS_2_DRVHOSTBASE(pInterface);
     363/** @copydoc PDMIBLOCKBIOS::pfnBiosGetPCHSGeometry */
     364static DECLCALLBACK(int) drvHostBaseGetPCHSGeometry(PPDMIMEDIA pInterface, PPDMMEDIAGEOMETRY pPCHSGeometry)
     365{
     366    PDRVHOSTBASE pThis =  PDMIMEDIA_2_DRVHOSTBASE(pInterface);
    374367    RTCritSectEnter(&pThis->CritSect);
    375368
     
    396389
    397390
    398 /** @copydoc PDMIBLOCKBIOS::pfnSetPCHSGeometry */
    399 static DECLCALLBACK(int) drvHostBaseSetPCHSGeometry(PPDMIBLOCKBIOS pInterface, PCPDMMEDIAGEOMETRY pPCHSGeometry)
    400 {
    401     PDRVHOSTBASE pThis = PDMIBLOCKBIOS_2_DRVHOSTBASE(pInterface);
     391/** @copydoc PDMIBLOCKBIOS::pfnBiosSetPCHSGeometry */
     392static DECLCALLBACK(int) drvHostBaseSetPCHSGeometry(PPDMIMEDIA pInterface, PCPDMMEDIAGEOMETRY pPCHSGeometry)
     393{
     394    PDRVHOSTBASE pThis =  PDMIMEDIA_2_DRVHOSTBASE(pInterface);
    402395    LogFlow(("%s-%d: %s: cCylinders=%d cHeads=%d cSectors=%d\n",
    403396             pThis->pDrvIns->pReg->szName, pThis->pDrvIns->iInstance, __FUNCTION__, pPCHSGeometry->cCylinders, pPCHSGeometry->cHeads, pPCHSGeometry->cSectors));
     
    421414
    422415/** @copydoc PDMIBLOCKBIOS::pfnGetLCHSGeometry */
    423 static DECLCALLBACK(int) drvHostBaseGetLCHSGeometry(PPDMIBLOCKBIOS pInterface, PPDMMEDIAGEOMETRY pLCHSGeometry)
    424 {
    425     PDRVHOSTBASE pThis =  PDMIBLOCKBIOS_2_DRVHOSTBASE(pInterface);
     416static DECLCALLBACK(int) drvHostBaseGetLCHSGeometry(PPDMIMEDIA pInterface, PPDMMEDIAGEOMETRY pLCHSGeometry)
     417{
     418    PDRVHOSTBASE pThis =  PDMIMEDIA_2_DRVHOSTBASE(pInterface);
    426419    RTCritSectEnter(&pThis->CritSect);
    427420
     
    449442
    450443/** @copydoc PDMIBLOCKBIOS::pfnSetLCHSGeometry */
    451 static DECLCALLBACK(int) drvHostBaseSetLCHSGeometry(PPDMIBLOCKBIOS pInterface, PCPDMMEDIAGEOMETRY pLCHSGeometry)
    452 {
    453     PDRVHOSTBASE pThis = PDMIBLOCKBIOS_2_DRVHOSTBASE(pInterface);
     444static DECLCALLBACK(int) drvHostBaseSetLCHSGeometry(PPDMIMEDIA pInterface, PCPDMMEDIAGEOMETRY pLCHSGeometry)
     445{
     446    PDRVHOSTBASE pThis =  PDMIMEDIA_2_DRVHOSTBASE(pInterface);
    454447    LogFlow(("%s-%d: %s: cCylinders=%d cHeads=%d cSectors=%d\n",
    455448             pThis->pDrvIns->pReg->szName, pThis->pDrvIns->iInstance, __FUNCTION__, pLCHSGeometry->cCylinders, pLCHSGeometry->cHeads, pLCHSGeometry->cSectors));
     
    473466
    474467/** @copydoc PDMIBLOCKBIOS::pfnIsVisible */
    475 static DECLCALLBACK(bool) drvHostBaseIsVisible(PPDMIBLOCKBIOS pInterface)
    476 {
    477     PDRVHOSTBASE pThis = PDMIBLOCKBIOS_2_DRVHOSTBASE(pInterface);
     468static DECLCALLBACK(bool) drvHostBaseIsVisible(PPDMIMEDIA pInterface)
     469{
     470    PDRVHOSTBASE pThis =  PDMIMEDIA_2_DRVHOSTBASE(pInterface);
    478471    return pThis->fBiosVisible;
    479472}
    480473
    481474
    482 /** @copydoc PDMIBLOCKBIOS::pfnGetType */
    483 static DECLCALLBACK(PDMBLOCKTYPE) drvHostBaseBiosGetType(PPDMIBLOCKBIOS pInterface)
    484 {
    485     PDRVHOSTBASE pThis = PDMIBLOCKBIOS_2_DRVHOSTBASE(pInterface);
    486     return pThis->enmType;
    487 }
    488 
    489 
    490475
    491476/* -=-=-=-=- IMount -=-=-=-=- */
    492 
    493 /** @copydoc PDMIMOUNT::pfnMount */
    494 static DECLCALLBACK(int) drvHostBaseMount(PPDMIMOUNT pInterface, const char *pszFilename, const char *pszCoreDriver)
    495 {
    496     /* We're not mountable. */
    497     AssertMsgFailed(("drvHostBaseMount: This shouldn't be called!\n"));
    498     return VERR_PDM_MEDIA_MOUNTED;
    499 }
    500 
    501477
    502478/** @copydoc PDMIMOUNT::pfnUnmount */
     
    622598
    623599    PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
    624     PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBLOCK, &pThis->IBlock);
    625     PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBLOCKBIOS, pThis->fBiosVisible ? &pThis->IBlockBios : NULL);
     600    PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMEDIA, &pThis->IMedia);
    626601    PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMOUNT, &pThis->IMount);
    627602    return NULL;
     
    18871862 * @param   enmType         Device type.
    18881863 */
    1889 int DRVHostBaseInitData(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, PDMBLOCKTYPE enmType)
     1864int DRVHostBaseInitData(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, PDMMEDIATYPE enmType)
    18901865{
    18911866    PDRVHOSTBASE pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTBASE);
     
    19201895    pDrvIns->IBase.pfnQueryInterface        = drvHostBaseQueryInterface;
    19211896
    1922     /* IBlock. */
    1923     pThis->IBlock.pfnRead                   = drvHostBaseRead;
    1924     pThis->IBlock.pfnWrite                  = drvHostBaseWrite;
    1925     pThis->IBlock.pfnFlush                  = drvHostBaseFlush;
    1926     pThis->IBlock.pfnIsReadOnly             = drvHostBaseIsReadOnly;
    1927     pThis->IBlock.pfnGetSize                = drvHostBaseGetSize;
    1928     pThis->IBlock.pfnGetType                = drvHostBaseGetType;
    1929     pThis->IBlock.pfnGetUuid                = drvHostBaseGetUuid;
    1930     pThis->IBlock.pfnIoBufAlloc             = drvHostBaseIoBufAlloc;
    1931     pThis->IBlock.pfnIoBufFree              = drvHostBaseIoBufFree;
    1932 
    1933     /* IBlockBios. */
    1934     pThis->IBlockBios.pfnGetPCHSGeometry    = drvHostBaseGetPCHSGeometry;
    1935     pThis->IBlockBios.pfnSetPCHSGeometry    = drvHostBaseSetPCHSGeometry;
    1936     pThis->IBlockBios.pfnGetLCHSGeometry    = drvHostBaseGetLCHSGeometry;
    1937     pThis->IBlockBios.pfnSetLCHSGeometry    = drvHostBaseSetLCHSGeometry;
    1938     pThis->IBlockBios.pfnIsVisible          = drvHostBaseIsVisible;
    1939     pThis->IBlockBios.pfnGetType            = drvHostBaseBiosGetType;
     1897    /* IMedia. */
     1898    pThis->IMedia.pfnRead                   = drvHostBaseRead;
     1899    pThis->IMedia.pfnWrite                  = drvHostBaseWrite;
     1900    pThis->IMedia.pfnFlush                  = drvHostBaseFlush;
     1901    pThis->IMedia.pfnIsReadOnly             = drvHostBaseIsReadOnly;
     1902    pThis->IMedia.pfnGetSize                = drvHostBaseGetSize;
     1903    pThis->IMedia.pfnGetType                = drvHostBaseGetType;
     1904    pThis->IMedia.pfnGetUuid                = drvHostBaseGetUuid;
     1905    pThis->IMedia.pfnIoBufAlloc             = drvHostBaseIoBufAlloc;
     1906    pThis->IMedia.pfnIoBufFree              = drvHostBaseIoBufFree;
     1907    pThis->IMedia.pfnBiosGetPCHSGeometry    = drvHostBaseGetPCHSGeometry;
     1908    pThis->IMedia.pfnBiosSetPCHSGeometry    = drvHostBaseSetPCHSGeometry;
     1909    pThis->IMedia.pfnBiosGetLCHSGeometry    = drvHostBaseGetLCHSGeometry;
     1910    pThis->IMedia.pfnBiosSetLCHSGeometry    = drvHostBaseSetLCHSGeometry;
     1911    pThis->IMedia.pfnBiosIsVisible          = drvHostBaseIsVisible;
    19401912
    19411913    /* IMount. */
    1942     pThis->IMount.pfnMount                  = drvHostBaseMount;
    19431914    pThis->IMount.pfnUnmount                = drvHostBaseUnmount;
    19441915    pThis->IMount.pfnIsMounted              = drvHostBaseIsMounted;
     
    19501921     * Get the IBlockPort & IMountNotify interfaces of the above driver/device.
    19511922     */
    1952     pThis->pDrvBlockPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIBLOCKPORT);
    1953     if (!pThis->pDrvBlockPort)
    1954     {
    1955         AssertMsgFailed(("Configuration error: No block port interface above!\n"));
     1923    pThis->pDrvMediaPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIMEDIAPORT);
     1924    if (!pThis->pDrvMediaPort)
     1925    {
     1926        AssertMsgFailed(("Configuration error: No media port interface above!\n"));
    19561927        return VERR_PDM_MISSING_INTERFACE_ABOVE;
    19571928    }
     
    19851956    rc = CFGMR3QueryBool(pCfg, "ReadOnly", &pThis->fReadOnlyConfig);
    19861957    if (rc == VERR_CFGM_VALUE_NOT_FOUND)
    1987         pThis->fReadOnlyConfig = enmType == PDMBLOCKTYPE_DVD || enmType == PDMBLOCKTYPE_CDROM ? true : false;
     1958        pThis->fReadOnlyConfig = enmType == PDMMEDIATYPE_DVD || enmType == PDMMEDIATYPE_CDROM ? true : false;
    19881959    else if (RT_FAILURE(rc))
    19891960    {
     
    21122083    switch (pThis->enmType)
    21132084    {
    2114         case PDMBLOCKTYPE_FLOPPY_360:
    2115         case PDMBLOCKTYPE_FLOPPY_720:
    2116         case PDMBLOCKTYPE_FLOPPY_1_20:
    2117         case PDMBLOCKTYPE_FLOPPY_1_44:
    2118         case PDMBLOCKTYPE_FLOPPY_2_88:
    2119         case PDMBLOCKTYPE_FLOPPY_FAKE_15_6:
    2120         case PDMBLOCKTYPE_FLOPPY_FAKE_63_5:
     2085        case PDMMEDIATYPE_FLOPPY_360:
     2086        case PDMMEDIATYPE_FLOPPY_720:
     2087        case PDMMEDIATYPE_FLOPPY_1_20:
     2088        case PDMMEDIATYPE_FLOPPY_1_44:
     2089        case PDMMEDIATYPE_FLOPPY_2_88:
     2090        case PDMMEDIATYPE_FLOPPY_FAKE_15_6:
     2091        case PDMMEDIATYPE_FLOPPY_FAKE_63_5:
    21212092            if (uDriveType != DRIVE_REMOVABLE)
    21222093            {
     
    21262097            }
    21272098            break;
    2128         case PDMBLOCKTYPE_CDROM:
    2129         case PDMBLOCKTYPE_DVD:
     2099        case PDMMEDIATYPE_CDROM:
     2100        case PDMMEDIATYPE_DVD:
    21302101            if (uDriveType != DRIVE_CDROM)
    21312102            {
     
    21352106            }
    21362107            break;
    2137         case PDMBLOCKTYPE_HARD_DISK:
     2108        case PDMMEDIATYPE_HARD_DISK:
    21382109        default:
    21392110            AssertMsgFailed(("enmType=%d\n", pThis->enmType));
     
    21712142         * "media" - actually a complete drive in this case.
    21722143         */
    2173         pThis->IBlock.pfnSendCmd = NULL;
     2144        pThis->IMedia.pfnSendCmd = NULL;
    21742145        AssertMsgFailed(("Could not open host device %s, rc=%Rrc\n", pszDevice, rc));
    21752146        switch (rc)
  • trunk/src/VBox/Devices/Storage/DrvHostBase.h

    r56292 r59248  
    4141    PPDMDRVINS              pDrvIns;
    4242    /** Drive type. */
    43     PDMBLOCKTYPE            enmType;
     43    PDMMEDIATYPE            enmType;
    4444    /** Visible to the BIOS. */
    4545    bool                    fBiosVisible;
     
    6464
    6565    /** Pointer to the block port interface above us. */
    66     PPDMIBLOCKPORT          pDrvBlockPort;
     66    PPDMIMEDIAPORT          pDrvMediaPort;
    6767    /** Pointer to the mount notify interface above us. */
    6868    PPDMIMOUNTNOTIFY        pDrvMountNotify;
    69     /** Our block interface. */
    70     PDMIBLOCK               IBlock;
    71     /** Our block interface. */
    72     PDMIBLOCKBIOS           IBlockBios;
     69    /** Our media interface. */
     70    PDMIMEDIA               IMedia;
    7371    /** Our mountable interface. */
    7472    PDMIMOUNT               IMount;
     
    181179
    182180
    183 int DRVHostBaseInitData(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, PDMBLOCKTYPE enmType);
     181int DRVHostBaseInitData(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, PDMMEDIATYPE enmType);
    184182int DRVHostBaseInitFinish(PDRVHOSTBASE pThis);
    185183int DRVHostBaseMediaPresent(PDRVHOSTBASE pThis);
     
    195193#define PDMIMOUNT_2_DRVHOSTBASE(pInterface)        ( (PDRVHOSTBASE)((uintptr_t)pInterface - RT_OFFSETOF(DRVHOSTBASE, IMount)) )
    196194
    197 /** Makes a PDRVHOSTBASE out of a PPDMIBLOCK. */
    198 #define PDMIBLOCK_2_DRVHOSTBASE(pInterface)        ( (PDRVHOSTBASE)((uintptr_t)pInterface - RT_OFFSETOF(DRVHOSTBASE, IBlock)) )
     195/** Makes a PDRVHOSTBASE out of a PPDMIMEDIA. */
     196#define PDMIMEDIA_2_DRVHOSTBASE(pInterface)        ( (PDRVHOSTBASE)((uintptr_t)pInterface - RT_OFFSETOF(DRVHOSTBASE, IMedia)) )
    199197
    200198RT_C_DECLS_END
  • trunk/src/VBox/Devices/Storage/DrvHostDVD.cpp

    r57442 r59248  
    151151                0,0,0,0,0,0,0,0,0,0
    152152            };
    153             rc = DRVHostBaseScsiCmd(pThis, abCmd, 6, PDMBLOCKTXDIR_NONE, NULL, NULL, NULL, 0, 0);
     153            rc = DRVHostBaseScsiCmd(pThis, abCmd, 6, PDMMEDIATXDIR_NONE, NULL, NULL, NULL, 0, 0);
    154154
    155155#elif defined(RT_OS_LINUX)
     
    241241        0,0,0,0,0,0,0,0,0,0
    242242    };
    243     int rc = DRVHostBaseScsiCmd(pThis, abCmd, 6, PDMBLOCKTXDIR_NONE, NULL, NULL, NULL, 0, 0);
     243    int rc = DRVHostBaseScsiCmd(pThis, abCmd, 6, PDMMEDIATXDIR_NONE, NULL, NULL, NULL, 0, 0);
    244244
    245245#elif defined(RT_OS_LINUX)
     
    335335    uint8_t abCmd[16] = { SCSI_TEST_UNIT_READY, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
    336336    uint8_t abSense[32];
    337     int rc2 = DRVHostBaseScsiCmd(pThis, abCmd, 6, PDMBLOCKTXDIR_NONE, NULL, NULL, abSense, sizeof(abSense), 0);
     337    int rc2 = DRVHostBaseScsiCmd(pThis, abCmd, 6, PDMMEDIATXDIR_NONE, NULL, NULL, abSense, sizeof(abSense), 0);
    338338    if (RT_SUCCESS(rc2))
    339339        fMediaPresent = true;
     
    414414
    415415
    416 /** @copydoc PDMIBLOCK::pfnSendCmd */
    417 static DECLCALLBACK(int) drvHostDvdSendCmd(PPDMIBLOCK pInterface, const uint8_t *pbCmd,
    418                                            PDMBLOCKTXDIR enmTxDir, void *pvBuf, uint32_t *pcbBuf,
     416/** @copydoc PDMIMEDIA::pfnSendCmd */
     417static DECLCALLBACK(int) drvHostDvdSendCmd(PPDMIMEDIA pInterface, const uint8_t *pbCmd,
     418                                           PDMMEDIATXDIR enmTxDir, void *pvBuf, uint32_t *pcbBuf,
    419419                                           uint8_t *pabSense, size_t cbSense, uint32_t cTimeoutMillies)
    420420{
    421     PDRVHOSTBASE pThis = PDMIBLOCK_2_DRVHOSTBASE(pInterface);
     421    PDRVHOSTBASE pThis = PDMIMEDIA_2_DRVHOSTBASE(pInterface);
    422422    int rc;
    423423    LogFlow(("%s: cmd[0]=%#04x txdir=%d pcbBuf=%d timeout=%d\n", __FUNCTION__, pbCmd[0], enmTxDir, *pcbBuf, cTimeoutMillies));
     
    428428     * The command seems to be 12 bytes long, the docs a bit copy&pasty on the command length point...
    429429     */
    430     if (enmTxDir == PDMBLOCKTXDIR_FROM_DEVICE)
     430    if (enmTxDir == PDMMEDIATXDIR_FROM_DEVICE)
    431431        memset(pvBuf, '\0', *pcbBuf); /* we got read size, but zero it anyway. */
    432     rc = DRVHostBaseScsiCmd(pThis, pbCmd, 12, PDMBLOCKTXDIR_FROM_DEVICE, pvBuf, pcbBuf, pabSense, cbSense, cTimeoutMillies);
     432    rc = DRVHostBaseScsiCmd(pThis, pbCmd, 12, PDMMEDIATXDIR_FROM_DEVICE, pvBuf, pcbBuf, pabSense, cbSense, cTimeoutMillies);
    433433    if (rc == VERR_UNRESOLVED_ERROR)
    434434        /* sense information set */
     
    441441    switch (enmTxDir)
    442442    {
    443         case PDMBLOCKTXDIR_NONE:
     443        case PDMMEDIATXDIR_NONE:
    444444            Assert(*pcbBuf == 0);
    445445            direction = CGC_DATA_NONE;
    446446            break;
    447         case PDMBLOCKTXDIR_FROM_DEVICE:
     447        case PDMMEDIATXDIR_FROM_DEVICE:
    448448            Assert(*pcbBuf != 0);
    449449            Assert(*pcbBuf <= SCSI_MAX_BUFFER_SIZE);
     
    458458            direction = CGC_DATA_READ;
    459459            break;
    460         case PDMBLOCKTXDIR_TO_DEVICE:
     460        case PDMMEDIATXDIR_TO_DEVICE:
    461461            Assert(*pcbBuf != 0);
    462462            Assert(*pcbBuf <= SCSI_MAX_BUFFER_SIZE);
     
    495495    switch (enmTxDir)
    496496    {
    497         case PDMBLOCKTXDIR_FROM_DEVICE:
     497        case PDMMEDIATXDIR_FROM_DEVICE:
    498498            memcpy(pvBuf, pThis->pbDoubleBuffer, *pcbBuf);
    499499            break;
     
    514514    switch (enmTxDir)
    515515    {
    516         case PDMBLOCKTXDIR_NONE:
     516        case PDMMEDIATXDIR_NONE:
    517517            Assert(*pcbBuf == 0);
    518518            usc.uscsi_flags = USCSI_READ;
     
    520520            break;
    521521
    522         case PDMBLOCKTXDIR_FROM_DEVICE:
     522        case PDMMEDIATXDIR_FROM_DEVICE:
    523523            Assert(*pcbBuf != 0);
    524524            /* Make sure that the buffer is clear for commands reading
     
    532532            usc.uscsi_flags = USCSI_READ;
    533533            break;
    534         case PDMBLOCKTXDIR_TO_DEVICE:
     534        case PDMMEDIATXDIR_TO_DEVICE:
    535535            Assert(*pcbBuf != 0);
    536536            usc.uscsi_flags = USCSI_WRITE;
     
    581581    switch (enmTxDir)
    582582    {
    583         case PDMBLOCKTXDIR_NONE:
     583        case PDMMEDIATXDIR_NONE:
    584584            direction = SCSI_IOCTL_DATA_UNSPECIFIED;
    585585            break;
    586         case PDMBLOCKTXDIR_FROM_DEVICE:
     586        case PDMMEDIATXDIR_FROM_DEVICE:
    587587            Assert(*pcbBuf != 0);
    588588            /* Make sure that the buffer is clear for commands reading
     
    596596            direction = SCSI_IOCTL_DATA_IN;
    597597            break;
    598         case PDMBLOCKTXDIR_TO_DEVICE:
     598        case PDMMEDIATXDIR_TO_DEVICE:
    599599            direction = SCSI_IOCTL_DATA_OUT;
    600600            break;
     
    754754     * Init instance data.
    755755     */
    756     int rc = DRVHostBaseInitData(pDrvIns, pCfg, PDMBLOCKTYPE_DVD);
     756    int rc = DRVHostBaseInitData(pDrvIns, pCfg, PDMMEDIATYPE_DVD);
    757757    if (RT_SUCCESS(rc))
    758758    {
     
    775775            if (RT_SUCCESS(rc) && fPassthrough)
    776776            {
    777                 pThis->IBlock.pfnSendCmd = drvHostDvdSendCmd;
     777                pThis->IMedia.pfnSendCmd = drvHostDvdSendCmd;
    778778                /* Passthrough requires opening the device in R/W mode. */
    779779                pThis->fReadOnlyConfig = false;
  • trunk/src/VBox/Devices/Storage/DrvHostFloppy.cpp

    r57358 r59248  
    188188     * Init instance data.
    189189     */
    190     int rc = DRVHostBaseInitData(pDrvIns, pCfg, PDMBLOCKTYPE_FLOPPY_1_44);
     190    int rc = DRVHostBaseInitData(pDrvIns, pCfg, PDMMEDIATYPE_FLOPPY_1_44);
    191191    if (RT_SUCCESS(rc))
    192192    {
  • trunk/src/VBox/Devices/Storage/DrvSCSI.cpp

    r59152 r59248  
    4444 *
    4545 * @implements  PDMISCSICONNECTOR
    46  * @implements  PDMIBLOCKASYNCPORT
     46 * @implements  PDMIMEDIAASYNCPORT
    4747 * @implements  PDMIMOUNTNOTIFY
    4848 */
     
    5555    PPDMIBASE               pDrvBase;
    5656    /** Pointer to the attached driver's block interface. */
    57     PPDMIBLOCK              pDrvBlock;
     57    PPDMIMEDIA              pDrvMedia;
    5858    /** Pointer to the attached driver's async block interface. */
    59     PPDMIBLOCKASYNC         pDrvBlockAsync;
    60     /** Pointer to the attached driver's block bios interface. */
    61     PPDMIBLOCKBIOS          pDrvBlockBios;
     59    PPDMIMEDIAASYNC         pDrvMediaAsync;
    6260    /** Pointer to the attached driver's mount interface. */
    6361    PPDMIMOUNT              pDrvMount;
     
    6866    /** The scsi connector interface .*/
    6967    PDMISCSICONNECTOR       ISCSIConnector;
    70     /** The block port interface. */
    71     PDMIBLOCKPORT           IPort;
    72     /** The optional block async port interface. */
    73     PDMIBLOCKASYNCPORT      IPortAsync;
     68    /** The media port interface. */
     69    PDMIMEDIAPORT           IPort;
     70    /** The optional media async port interface. */
     71    PDMIMEDIAASYNCPORT      IPortAsync;
    7472    /** The mount notify interface. */
    7573    PDMIMOUNTNOTIFY         IMountNotify;
     
    113111#define PDMISCSICONNECTOR_2_DRVSCSI(pInterface)  ( (PDRVSCSI)((uintptr_t)pInterface - RT_OFFSETOF(DRVSCSI, ISCSIConnector)) )
    114112/** Converts a pointer to DRVSCSI::IPortAsync to a PDRVSCSI. */
    115 #define PDMIBLOCKASYNCPORT_2_DRVSCSI(pInterface) ( (PDRVSCSI)((uintptr_t)pInterface - RT_OFFSETOF(DRVSCSI, IPortAsync)) )
     113#define PDMIMEDIAASYNCPORT_2_DRVSCSI(pInterface) ( (PDRVSCSI)((uintptr_t)pInterface - RT_OFFSETOF(DRVSCSI, IPortAsync)) )
    116114/** Converts a pointer to DRVSCSI::IMountNotify to PDRVSCSI. */
    117115#define PDMIMOUNTNOTIFY_2_DRVSCSI(pInterface)    ( (PDRVSCSI)((uintptr_t)pInterface - RT_OFFSETOF(DRVSCSI, IMountNotify)) )
    118116/** Converts a pointer to DRVSCSI::IPort to a PDRVSCSI. */
    119 #define PDMIBLOCKPORT_2_DRVSCSI(pInterface)      ( (PDRVSCSI)((uintptr_t)pInterface - RT_OFFSETOF(DRVSCSI, IPort)) )
     117#define PDMIMEDIAPORT_2_DRVSCSI(pInterface)      ( (PDRVSCSI)((uintptr_t)pInterface - RT_OFFSETOF(DRVSCSI, IPort)) )
    120118
    121119static bool drvscsiIsRedoPossible(int rc)
     
    142140        case VSCSIIOREQTXDIR_FLUSH:
    143141        {
    144             rc = pThis->pDrvBlock->pfnFlush(pThis->pDrvBlock);
     142            rc = pThis->pDrvMedia->pfnFlush(pThis->pDrvMedia);
    145143            if (   RT_FAILURE(rc)
    146144                && pThis->cErrors++ < MAX_LOG_REL_ERRORS)
     
    171169                {
    172170                    pThis->pLed->Asserted.s.fReading = pThis->pLed->Actual.s.fReading = 1;
    173                     rc = pThis->pDrvBlock->pfnRead(pThis->pDrvBlock, uOffset,
     171                    rc = pThis->pDrvMedia->pfnRead(pThis->pDrvMedia, uOffset,
    174172                                                    paSeg->pvSeg, cbProcess);
    175173                    pThis->pLed->Actual.s.fReading = 0;
     
    181179                {
    182180                    pThis->pLed->Asserted.s.fWriting = pThis->pLed->Actual.s.fWriting = 1;
    183                     rc = pThis->pDrvBlock->pfnWrite(pThis->pDrvBlock, uOffset,
     181                    rc = pThis->pDrvMedia->pfnWrite(pThis->pDrvMedia, uOffset,
    184182                                                    paSeg->pvSeg, cbProcess);
    185183                    pThis->pLed->Actual.s.fWriting = 0;
     
    217215
    218216            pThis->pLed->Asserted.s.fWriting = pThis->pLed->Actual.s.fWriting = 1;
    219             rc = pThis->pDrvBlock->pfnDiscard(pThis->pDrvBlock, paRanges, cRanges);
     217            rc = pThis->pDrvMedia->pfnDiscard(pThis->pDrvMedia, paRanges, cRanges);
    220218            pThis->pLed->Actual.s.fWriting = 0;
    221219
     
    243241    PDRVSCSI pThis = (PDRVSCSI)pvScsiLunUser;
    244242
    245     *pcbSize = pThis->pDrvBlock->pfnGetSize(pThis->pDrvBlock);
     243    *pcbSize = pThis->pDrvMedia->pfnGetSize(pThis->pDrvMedia);
    246244
    247245    return VINF_SUCCESS;
     
    253251    PDRVSCSI pThis = (PDRVSCSI)pvScsiLunUser;
    254252
    255     *pcbSectorSize = pThis->pDrvBlock->pfnGetSectorSize(pThis->pDrvBlock);
     253    *pcbSectorSize = pThis->pDrvMedia->pfnGetSectorSize(pThis->pDrvMedia);
    256254
    257255    return VINF_SUCCESS;
     
    269267}
    270268
    271 static DECLCALLBACK(int) drvscsiTransferCompleteNotify(PPDMIBLOCKASYNCPORT pInterface, void *pvUser, int rc)
    272 {
    273     PDRVSCSI pThis = PDMIBLOCKASYNCPORT_2_DRVSCSI(pInterface);
     269static DECLCALLBACK(int) drvscsiTransferCompleteNotify(PPDMIMEDIAASYNCPORT pInterface, void *pvUser, int rc)
     270{
     271    PDRVSCSI pThis = PDMIMEDIAASYNCPORT_2_DRVSCSI(pInterface);
    274272    VSCSIIOREQ hVScsiIoReq = (VSCSIIOREQ)pvUser;
    275273    VSCSIIOREQTXDIR enmTxDir = VSCSIIoReqTxDirGet(hVScsiIoReq);
     
    332330    PDRVSCSI pThis = (PDRVSCSI)pvScsiLunUser;
    333331
    334     if (pThis->pDrvBlockAsync)
     332    if (pThis->pDrvMediaAsync)
    335333    {
    336334        /* async I/O path. */
     
    345343            case VSCSIIOREQTXDIR_FLUSH:
    346344            {
    347                 rc = pThis->pDrvBlockAsync->pfnStartFlush(pThis->pDrvBlockAsync, hVScsiIoReq);
     345                rc = pThis->pDrvMediaAsync->pfnStartFlush(pThis->pDrvMediaAsync, hVScsiIoReq);
    348346                if (   RT_FAILURE(rc)
    349347                    && rc != VERR_VD_ASYNC_IO_IN_PROGRESS
     
    362360
    363361                pThis->pLed->Asserted.s.fWriting = pThis->pLed->Actual.s.fWriting = 1;
    364                 rc = pThis->pDrvBlockAsync->pfnStartDiscard(pThis->pDrvBlockAsync, paRanges, cRanges, hVScsiIoReq);
     362                rc = pThis->pDrvMediaAsync->pfnStartDiscard(pThis->pDrvMediaAsync, paRanges, cRanges, hVScsiIoReq);
    365363                if (   RT_FAILURE(rc)
    366364                    && rc != VERR_VD_ASYNC_IO_IN_PROGRESS
     
    386384                {
    387385                    pThis->pLed->Asserted.s.fReading = pThis->pLed->Actual.s.fReading = 1;
    388                     rc = pThis->pDrvBlockAsync->pfnStartRead(pThis->pDrvBlockAsync, uOffset,
     386                    rc = pThis->pDrvMediaAsync->pfnStartRead(pThis->pDrvMediaAsync, uOffset,
    389387                                                             paSeg, cSeg, cbTransfer,
    390388                                                             hVScsiIoReq);
     
    394392                {
    395393                    pThis->pLed->Asserted.s.fWriting = pThis->pLed->Actual.s.fWriting = 1;
    396                     rc = pThis->pDrvBlockAsync->pfnStartWrite(pThis->pDrvBlockAsync, uOffset,
     394                    rc = pThis->pDrvMediaAsync->pfnStartWrite(pThis->pDrvMediaAsync, uOffset,
    397395                                                              paSeg, cSeg, cbTransfer,
    398396                                                              hVScsiIoReq);
     
    464462    *pfFeatures = 0;
    465463
    466     if (   pThis->pDrvBlock->pfnDiscard
    467         || (   pThis->pDrvBlockAsync
    468             && pThis->pDrvBlockAsync->pfnStartDiscard))
     464    if (   pThis->pDrvMedia->pfnDiscard
     465        || (   pThis->pDrvMediaAsync
     466            && pThis->pDrvMediaAsync->pfnStartDiscard))
    469467        *pfFeatures |= VSCSI_LUN_FEATURE_UNMAP;
    470468
     
    682680
    683681    PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMOUNT, pThis->pDrvMount);
    684     PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBLOCKBIOS, pThis->pDrvBlockBios);
    685682    PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
    686683    PDMIBASE_RETURN_INTERFACE(pszIID, PDMISCSICONNECTOR, &pThis->ISCSIConnector);
    687     PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBLOCKPORT, &pThis->IPort);
     684    PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMEDIAPORT, &pThis->IPort);
    688685    PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMOUNTNOTIFY, &pThis->IMountNotify);
    689     PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBLOCKASYNCPORT, &pThis->IPortAsync);
     686    PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMEDIAASYNCPORT, &pThis->IPortAsync);
    690687    return NULL;
    691688}
    692689
    693 static DECLCALLBACK(int) drvscsiQueryDeviceLocation(PPDMIBLOCKPORT pInterface, const char **ppcszController,
     690static DECLCALLBACK(int) drvscsiQueryDeviceLocation(PPDMIMEDIAPORT pInterface, const char **ppcszController,
    694691                                                    uint32_t *piInstance, uint32_t *piLUN)
    695692{
    696     PDRVSCSI pThis = PDMIBLOCKPORT_2_DRVSCSI(pInterface);
     693    PDRVSCSI pThis = PDMIMEDIAPORT_2_DRVSCSI(pInterface);
    697694
    698695    return pThis->pDevScsiPort->pfnQueryDeviceLocation(pThis->pDevScsiPort, ppcszController,
     
    711708
    712709    /* Ignore the call if we're called while being attached. */
    713     if (!pThis->pDrvBlock)
     710    if (!pThis->pDrvMedia)
    714711        return;
    715712
     
    742739    PDRVSCSI pThis = PDMINS_2_DATA(pDrvIns, PDRVSCSI);
    743740
    744     if (!pThis->pDrvBlockAsync)
     741    if (!pThis->pDrvMediaAsync)
    745742    {
    746743        if (pThis->hQueueRequests != NIL_RTREQQUEUE)
     
    790787    PDRVSCSI pThis = PDMINS_2_DATA(pDrvIns, PDRVSCSI);
    791788
    792     if (pThis->pDrvBlockAsync)
     789    if (pThis->pDrvMediaAsync)
    793790    {
    794791        if (pThis->StatIoDepth > 0)
     
    833830    PDRVSCSI pThis = PDMINS_2_DATA(pDrvIns, PDRVSCSI);
    834831
    835     if (pThis->pDrvBlockAsync)
     832    if (pThis->pDrvMediaAsync)
    836833    {
    837834        if (pThis->StatIoDepth > 0)
     
    967964     * Query the block and blockbios interfaces.
    968965     */
    969     pThis->pDrvBlock = PDMIBASE_QUERY_INTERFACE(pThis->pDrvBase, PDMIBLOCK);
    970     if (!pThis->pDrvBlock)
     966    pThis->pDrvMedia = PDMIBASE_QUERY_INTERFACE(pThis->pDrvBase, PDMIMEDIA);
     967    if (!pThis->pDrvMedia)
    971968    {
    972969        AssertMsgFailed(("Configuration error: No block interface!\n"));
    973970        return VERR_PDM_MISSING_INTERFACE;
    974971    }
    975     pThis->pDrvBlockBios = PDMIBASE_QUERY_INTERFACE(pThis->pDrvBase, PDMIBLOCKBIOS);
    976     if (!pThis->pDrvBlockBios)
    977     {
    978         AssertMsgFailed(("Configuration error: No block BIOS interface!\n"));
    979         return VERR_PDM_MISSING_INTERFACE;
    980     }
    981972
    982973    pThis->pDrvMount = PDMIBASE_QUERY_INTERFACE(pThis->pDrvBase, PDMIMOUNT);
    983974
    984975    /* Try to get the optional async block interface. */
    985     pThis->pDrvBlockAsync = PDMIBASE_QUERY_INTERFACE(pThis->pDrvBase, PDMIBLOCKASYNC);
    986 
    987     PDMBLOCKTYPE enmType = pThis->pDrvBlock->pfnGetType(pThis->pDrvBlock);
     976    pThis->pDrvMediaAsync = PDMIBASE_QUERY_INTERFACE(pThis->pDrvBase, PDMIMEDIAASYNC);
     977
     978    PDMMEDIATYPE enmType = pThis->pDrvMedia->pfnGetType(pThis->pDrvMedia);
    988979    VSCSILUNTYPE enmLunType;
    989980    switch (enmType)
    990981    {
    991     case PDMBLOCKTYPE_HARD_DISK:
     982    case PDMMEDIATYPE_HARD_DISK:
    992983        enmLunType = VSCSILUNTYPE_SBC;
    993984        break;
    994     case PDMBLOCKTYPE_CDROM:
    995     case PDMBLOCKTYPE_DVD:
     985    case PDMMEDIATYPE_CDROM:
     986    case PDMMEDIATYPE_DVD:
    996987        enmLunType = VSCSILUNTYPE_MMC;
    997988        break;
     
    1001992                                   enmType);
    1002993    }
    1003     if (    (   enmType == PDMBLOCKTYPE_DVD
    1004              || enmType == PDMBLOCKTYPE_CDROM)
     994    if (    (   enmType == PDMMEDIATYPE_DVD
     995             || enmType == PDMMEDIATYPE_CDROM)
    1005996        &&  !pThis->pDrvMount)
    1006997    {
     
    10281019    if (pThis->pDrvMount)
    10291020    {
    1030         if (pThis->pDrvBlock->pfnGetSize(pThis->pDrvBlock))
     1021        if (pThis->pDrvMedia->pfnGetSize(pThis->pDrvMedia))
    10311022        {
    10321023            rc = VINF_SUCCESS; VSCSILunMountNotify(pThis->hVScsiLun);
     
    10611052    pThis->StatIoDepth = 0;
    10621053
    1063     if (!pThis->pDrvBlockAsync)
     1054    if (!pThis->pDrvMediaAsync)
    10641055    {
    10651056        /* Create request queue. */
     
    10761067        LogRel(("SCSI#%d: using async I/O\n", pDrvIns->iInstance));
    10771068
    1078     if (   pThis->pDrvBlock->pfnDiscard
    1079         || (   pThis->pDrvBlockAsync
    1080             && pThis->pDrvBlockAsync->pfnStartDiscard))
     1069    if (   pThis->pDrvMedia->pfnDiscard
     1070        || (   pThis->pDrvMediaAsync
     1071            && pThis->pDrvMediaAsync->pfnStartDiscard))
    10811072        LogRel(("SCSI#%d: Enabled UNMAP support\n", pDrvIns->iInstance));
    10821073
  • trunk/src/VBox/Devices/Storage/DrvVD.cpp

    r58132 r59248  
    6262
    6363
     64/** @def VBOX_PERIODIC_FLUSH
     65 * Enable support for periodically flushing the VDI to disk. This may prove
     66 * useful for those nasty problems with the ultra-slow host filesystems.
     67 * If this is enabled, it can be configured via the CFGM key
     68 * "VBoxInternal/Devices/piix3ide/0/LUN#<x>/Config/FlushInterval". <x>
     69 * must be replaced with the correct LUN number of the disk that should
     70 * do the periodic flushes. The value of the key is the number of bytes
     71 * written between flushes. A value of 0 (the default) denotes no flushes. */
     72#define VBOX_PERIODIC_FLUSH
     73
     74/** @def VBOX_IGNORE_FLUSH
     75 * Enable support for ignoring VDI flush requests. This can be useful for
     76 * filesystems that show bad guest IDE write performance (especially with
     77 * Windows guests). NOTE that this does not disable the flushes caused by
     78 * the periodic flush cache feature above.
     79 * If this feature is enabled, it can be configured via the CFGM key
     80 * "VBoxInternal/Devices/piix3ide/0/LUN#<x>/Config/IgnoreFlush". <x>
     81 * must be replaced with the correct LUN number of the disk that should
     82 * ignore flush requests. The value of the key is a boolean. The default
     83 * is to ignore flushes, i.e. true. */
     84#define VBOX_IGNORE_FLUSH
     85
    6486/*********************************************************************************************************************************
    6587*   Defined types, constants and macros                                                                                          *
     
    116138 * @implements  PDMIMEDIA
    117139 * @implements  PDMIMEDIAASYNC
     140 * @implements  PDMIMOUNT
    118141 * @implements  VDINTERFACEERROR
    119142 * @implements  VDINTERFACETCPNET
     
    192215    HBDMGR                   hHbdMgr;
    193216
     217    /** Drive type. */
     218    PDMMEDIATYPE            enmType;
     219    /** Locked indicator. */
     220    bool                    fLocked;
     221    /** Mountable indicator. */
     222    bool                    fMountable;
     223    /** Visible to the BIOS. */
     224    bool                    fBiosVisible;
     225#ifdef VBOX_PERIODIC_FLUSH
     226    /** HACK: Configuration value for number of bytes written after which to flush. */
     227    uint32_t                cbFlushInterval;
     228    /** HACK: Current count for the number of bytes written since the last flush. */
     229    uint32_t                cbDataWritten;
     230#endif /* VBOX_PERIODIC_FLUSH */
     231#ifdef VBOX_IGNORE_FLUSH
     232    /** HACK: Disable flushes for this drive. */
     233    bool                    fIgnoreFlush;
     234    /** Disable async flushes for this drive. */
     235    bool                    fIgnoreFlushAsync;
     236#endif /* VBOX_IGNORE_FLUSH */
     237    /** Our mountable interface. */
     238    PDMIMOUNT               IMount;
     239    /** Pointer to the mount notify interface above us. */
     240    PPDMIMOUNTNOTIFY        pDrvMountNotify;
     241    /** Uuid of the drive. */
     242    RTUUID                  Uuid;
     243    /** BIOS PCHS Geometry. */
     244    PDMMEDIAGEOMETRY        PCHSGeometry;
     245    /** BIOS LCHS Geometry. */
     246    PDMMEDIAGEOMETRY        LCHSGeometry;
     247
    194248    /** Cryptographic support
    195249     * @{ */
     
    256310{
    257311    int rc = VINF_SUCCESS;
    258     if (!VDIsReadOnly(pThis->pDisk))
     312    if (   pThis->pDisk
     313        && !VDIsReadOnly(pThis->pDisk))
    259314    {
    260315        unsigned uOpenFlags;
     
    16431698    PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
    16441699
     1700    /*
     1701     * Check the state.
     1702     */
     1703    if (!pThis->pDisk)
     1704    {
     1705        AssertMsgFailed(("Invalid state! Not mounted!\n"));
     1706        return VERR_PDM_MEDIA_NOT_MOUNTED;
     1707    }
     1708
    16451709    rc = drvvdKeyCheckPrereqs(pThis);
    16461710    if (RT_FAILURE(rc))
     
    16971761    PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
    16981762
     1763    /*
     1764     * Check the state.
     1765     */
     1766    if (!pThis->pDisk)
     1767    {
     1768        AssertMsgFailed(("Invalid state! Not mounted!\n"));
     1769        return VERR_PDM_MEDIA_NOT_MOUNTED;
     1770    }
     1771
    16991772    if (   pThis->pCfgCrypto
    17001773        && !pThis->pIfSecKey)
     
    17531826          off, pvBuf, cbWrite, cbWrite, pvBuf));
    17541827
     1828    /*
     1829     * Check the state.
     1830     */
     1831    if (!pThis->pDisk)
     1832    {
     1833        AssertMsgFailed(("Invalid state! Not mounted!\n"));
     1834        return VERR_PDM_MEDIA_NOT_MOUNTED;
     1835    }
     1836
     1837    /* Set an FTM checkpoint as this operation changes the state permanently. */
     1838    PDMDrvHlpFTSetCheckpoint(pThis->pDrvIns, FTMCHECKPOINTTYPE_STORAGE);
     1839
    17551840    int rc = drvvdKeyCheckPrereqs(pThis);
    17561841    if (RT_FAILURE(rc))
     
    17651850
    17661851    rc = VDWrite(pThis->pDisk, off, pvBuf, cbWrite);
     1852#ifdef VBOX_PERIODIC_FLUSH
     1853    if (pThis->cbFlushInterval)
     1854    {
     1855        pThis->cbDataWritten += (uint32_t)cbWrite;
     1856        if (pThis->cbDataWritten > pThis->cbFlushInterval)
     1857        {
     1858            pThis->cbDataWritten = 0;
     1859            VDFlush(pThis->pDisk);
     1860        }
     1861    }
     1862#endif /* VBOX_PERIODIC_FLUSH */
     1863
    17671864    LogFlowFunc(("returns %Rrc\n", rc));
    17681865    return rc;
     
    17741871    LogFlowFunc(("\n"));
    17751872    PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
     1873
     1874    /*
     1875     * Check the state.
     1876     */
     1877    if (!pThis->pDisk)
     1878    {
     1879        AssertMsgFailed(("Invalid state! Not mounted!\n"));
     1880        return VERR_PDM_MEDIA_NOT_MOUNTED;
     1881    }
     1882
     1883#ifdef VBOX_IGNORE_FLUSH
     1884    if (pThis->fIgnoreFlush)
     1885        return VINF_SUCCESS;
     1886#endif /* VBOX_IGNORE_FLUSH */
     1887
    17761888    int rc = VDFlush(pThis->pDisk);
    17771889    LogFlowFunc(("returns %Rrc\n", rc));
     
    17871899    PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
    17881900    int rc = VINF_SUCCESS;
     1901
     1902    /*
     1903     * Check the state.
     1904     */
     1905    if (!pThis->pDisk)
     1906    {
     1907        AssertMsgFailed(("Invalid state! Not mounted!\n"));
     1908        return VERR_PDM_MEDIA_NOT_MOUNTED;
     1909    }
    17891910
    17901911    /* Note: There is an unavoidable race between destruction and another
     
    18681989    LogFlowFunc(("\n"));
    18691990    PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
     1991
     1992    /*
     1993     * Check the state.
     1994     */
     1995    if (!pThis->pDisk)
     1996        return 0;
     1997
    18701998    uint64_t cb = VDGetSize(pThis->pDisk, VD_LAST_IMAGE);
    18711999    LogFlowFunc(("returns %#llx (%llu)\n", cb, cb));
     
    18782006    LogFlowFunc(("\n"));
    18792007    PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
     2008
     2009    /*
     2010     * Check the state.
     2011     */
     2012    if (!pThis->pDisk)
     2013        return 0;
     2014
    18802015    uint32_t cb = VDGetSectorSize(pThis->pDisk, VD_LAST_IMAGE);
    18812016    LogFlowFunc(("returns %u\n", cb));
     
    18882023    LogFlowFunc(("\n"));
    18892024    PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
     2025
     2026    /*
     2027     * Check the state.
     2028     */
     2029    if (!pThis->pDisk)
     2030        return false;
     2031
    18902032    bool f = VDIsReadOnly(pThis->pDisk);
    18912033    LogFlowFunc(("returns %d\n", f));
     
    19002042    PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
    19012043    VDGEOMETRY geo;
     2044
     2045    /*
     2046     * Check the state.
     2047     */
     2048    if (!pThis->pDisk)
     2049        return VERR_PDM_MEDIA_NOT_MOUNTED;
     2050
     2051    /*
     2052     * Use configured/cached values if present.
     2053     */
     2054    if (    pThis->PCHSGeometry.cCylinders > 0
     2055        &&  pThis->PCHSGeometry.cHeads > 0
     2056        &&  pThis->PCHSGeometry.cSectors > 0)
     2057    {
     2058        *pPCHSGeometry = pThis->PCHSGeometry;
     2059        LogFlow(("%s: returns VINF_SUCCESS {%d,%d,%d}\n", __FUNCTION__, pThis->PCHSGeometry.cCylinders, pThis->PCHSGeometry.cHeads, pThis->PCHSGeometry.cSectors));
     2060        return VINF_SUCCESS;
     2061    }
     2062
    19022063    int rc = VDGetPCHSGeometry(pThis->pDisk, VD_LAST_IMAGE, &geo);
    19032064    if (RT_SUCCESS(rc))
     
    19062067        pPCHSGeometry->cHeads = geo.cHeads;
    19072068        pPCHSGeometry->cSectors = geo.cSectors;
     2069        pThis->PCHSGeometry = *pPCHSGeometry;
    19082070    }
    19092071    else
     
    19252087    PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
    19262088    VDGEOMETRY geo;
     2089
     2090    /*
     2091     * Check the state.
     2092     */
     2093    if (!pThis->pDisk)
     2094    {
     2095        AssertMsgFailed(("Invalid state! Not mounted!\n"));
     2096        return VERR_PDM_MEDIA_NOT_MOUNTED;
     2097    }
     2098
    19272099    geo.cCylinders = pPCHSGeometry->cCylinders;
    19282100    geo.cHeads = pPCHSGeometry->cHeads;
     
    19312103    if (rc == VERR_VD_GEOMETRY_NOT_SET)
    19322104        rc = VERR_PDM_GEOMETRY_NOT_SET;
     2105    if (RT_SUCCESS(rc))
     2106        pThis->PCHSGeometry = *pPCHSGeometry;
    19332107    LogFlowFunc(("returns %Rrc\n", rc));
    19342108    return rc;
     
    19422116    PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
    19432117    VDGEOMETRY geo;
     2118
     2119    /*
     2120     * Check the state.
     2121     */
     2122    if (!pThis->pDisk)
     2123        return VERR_PDM_MEDIA_NOT_MOUNTED;
     2124
     2125    /*
     2126     * Use configured/cached values if present.
     2127     */
     2128    if (    pThis->LCHSGeometry.cCylinders > 0
     2129        &&  pThis->LCHSGeometry.cHeads > 0
     2130        &&  pThis->LCHSGeometry.cSectors > 0)
     2131    {
     2132        *pLCHSGeometry = pThis->LCHSGeometry;
     2133        LogFlow(("%s: returns VINF_SUCCESS {%d,%d,%d}\n", __FUNCTION__, pThis->LCHSGeometry.cCylinders, pThis->LCHSGeometry.cHeads, pThis->LCHSGeometry.cSectors));
     2134        return VINF_SUCCESS;
     2135    }
     2136
    19442137    int rc = VDGetLCHSGeometry(pThis->pDisk, VD_LAST_IMAGE, &geo);
    19452138    if (RT_SUCCESS(rc))
     
    19482141        pLCHSGeometry->cHeads = geo.cHeads;
    19492142        pLCHSGeometry->cSectors = geo.cSectors;
     2143        pThis->LCHSGeometry = *pLCHSGeometry;
    19502144    }
    19512145    else
     
    19672161    PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
    19682162    VDGEOMETRY geo;
     2163
     2164    /*
     2165     * Check the state.
     2166     */
     2167    if (!pThis->pDisk)
     2168    {
     2169        AssertMsgFailed(("Invalid state! Not mounted!\n"));
     2170        return VERR_PDM_MEDIA_NOT_MOUNTED;
     2171    }
     2172
    19692173    geo.cCylinders = pLCHSGeometry->cCylinders;
    19702174    geo.cHeads = pLCHSGeometry->cHeads;
     
    19732177    if (rc == VERR_VD_GEOMETRY_NOT_SET)
    19742178        rc = VERR_PDM_GEOMETRY_NOT_SET;
     2179    if (RT_SUCCESS(rc))
     2180        pThis->LCHSGeometry = *pLCHSGeometry;
    19752181    LogFlowFunc(("returns %Rrc\n", rc));
    19762182    return rc;
    19772183}
    19782184
     2185/** @interface_method_impl{PDMIMEDIA,pfnBiosIsVisible} */
     2186static DECLCALLBACK(bool) drvvdBiosIsVisible(PPDMIMEDIA pInterface)
     2187{
     2188    PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
     2189    LogFlow(("drvvdBiosIsVisible: returns %d\n", pThis->fBiosVisible));
     2190    return pThis->fBiosVisible;
     2191}
     2192
     2193/** @interface_method_impl{PDMIMEDIA,pfnGetType} */
     2194static DECLCALLBACK(PDMMEDIATYPE) drvvdGetType(PPDMIMEDIA pInterface)
     2195{
     2196    PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
     2197    LogFlow(("drvvdBiosIsVisible: returns %d\n", pThis->fBiosVisible));
     2198    return pThis->enmType;
     2199}
     2200
    19792201/** @interface_method_impl{PDMIMEDIA,pfnGetUuid} */
    19802202static DECLCALLBACK(int) drvvdGetUuid(PPDMIMEDIA pInterface, PRTUUID pUuid)
     
    19822204    LogFlowFunc(("\n"));
    19832205    PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
    1984     int rc = VDGetUuid(pThis->pDisk, 0, pUuid);
    1985     LogFlowFunc(("returns %Rrc ({%RTuuid})\n", rc, pUuid));
    1986     return rc;
     2206
     2207    /*
     2208     * Copy the uuid.
     2209     */
     2210    *pUuid = pThis->Uuid;
     2211    LogFlowFunc(("returns {%RTuuid}\n", pUuid));
     2212    return VINF_SUCCESS;
    19872213}
    19882214
     
    20442270
    20452271
     2272/* -=-=-=-=- IMount -=-=-=-=- */
     2273
     2274/** @copydoc PDMIMOUNT::pfnUnmount */
     2275static DECLCALLBACK(int) drvvdUnmount(PPDMIMOUNT pInterface, bool fForce, bool fEject)
     2276{
     2277    PVBOXDISK pThis = RT_FROM_MEMBER(pInterface, VBOXDISK, IMount);
     2278
     2279    /*
     2280     * Validate state.
     2281     */
     2282    if (!pThis->pDisk)
     2283    {
     2284        Log(("drvvdUnmount: Not mounted\n"));
     2285        return VERR_PDM_MEDIA_NOT_MOUNTED;
     2286    }
     2287    if (pThis->fLocked && !fForce)
     2288    {
     2289        Log(("drvvdUnmount: Locked\n"));
     2290        return VERR_PDM_MEDIA_LOCKED;
     2291    }
     2292
     2293    /* Media is no longer locked even if it was previously. */
     2294    pThis->fLocked = false;
     2295
     2296    /*
     2297     * Notify driver/device above us.
     2298     */
     2299    if (pThis->pDrvMountNotify)
     2300        pThis->pDrvMountNotify->pfnUnmountNotify(pThis->pDrvMountNotify);
     2301    Log(("drvblockUnmount: success\n"));
     2302    return VINF_SUCCESS;
     2303}
     2304
     2305
     2306/** @copydoc PDMIMOUNT::pfnIsMounted */
     2307static DECLCALLBACK(bool) drvvdIsMounted(PPDMIMOUNT pInterface)
     2308{
     2309    PVBOXDISK pThis = RT_FROM_MEMBER(pInterface, VBOXDISK, IMount);
     2310    return pThis->pDisk != NULL;
     2311}
     2312
     2313/** @copydoc PDMIMOUNT::pfnLock */
     2314static DECLCALLBACK(int) drvvdLock(PPDMIMOUNT pInterface)
     2315{
     2316    PVBOXDISK pThis = RT_FROM_MEMBER(pInterface, VBOXDISK, IMount);
     2317    Log(("drvblockLock: %d -> %d\n", pThis->fLocked, true));
     2318    pThis->fLocked = true;
     2319    return VINF_SUCCESS;
     2320}
     2321
     2322/** @copydoc PDMIMOUNT::pfnUnlock */
     2323static DECLCALLBACK(int) drvvdUnlock(PPDMIMOUNT pInterface)
     2324{
     2325    PVBOXDISK pThis = RT_FROM_MEMBER(pInterface, VBOXDISK, IMount);
     2326    Log(("drvblockUnlock: %d -> %d\n", pThis->fLocked, false));
     2327    pThis->fLocked = false;
     2328    return VINF_SUCCESS;
     2329}
     2330
     2331/** @copydoc PDMIMOUNT::pfnIsLocked */
     2332static DECLCALLBACK(bool) drvvdIsLocked(PPDMIMOUNT pInterface)
     2333{
     2334    PVBOXDISK pThis = RT_FROM_MEMBER(pInterface, VBOXDISK, IMount);
     2335    return pThis->fLocked;
     2336}
     2337
    20462338/*********************************************************************************************************************************
    20472339*   Async Media interface methods                                                                                                *
     
    20702362    int rc = VINF_SUCCESS;
    20712363    PVBOXDISK pThis = PDMIMEDIAASYNC_2_VBOXDISK(pInterface);
     2364
     2365    /*
     2366     * Check the state.
     2367     */
     2368    if (!pThis->pDisk)
     2369    {
     2370        AssertMsgFailed(("Invalid state! Not mounted!\n"));
     2371        return VERR_PDM_MEDIA_NOT_MOUNTED;
     2372    }
    20722373
    20732374    rc = drvvdKeyCheckPrereqs(pThis);
     
    21042405    PVBOXDISK pThis = PDMIMEDIAASYNC_2_VBOXDISK(pInterface);
    21052406
     2407    /*
     2408     * Check the state.
     2409     */
     2410    if (!pThis->pDisk)
     2411    {
     2412        AssertMsgFailed(("Invalid state! Not mounted!\n"));
     2413        return VERR_PDM_MEDIA_NOT_MOUNTED;
     2414    }
     2415
    21062416    rc = drvvdKeyCheckPrereqs(pThis);
    21072417    if (RT_FAILURE(rc))
     
    21352445    PVBOXDISK pThis = PDMIMEDIAASYNC_2_VBOXDISK(pInterface);
    21362446
     2447    /*
     2448     * Check the state.
     2449     */
     2450    if (!pThis->pDisk)
     2451    {
     2452        AssertMsgFailed(("Invalid state! Not mounted!\n"));
     2453        return VERR_PDM_MEDIA_NOT_MOUNTED;
     2454    }
     2455
     2456#ifdef VBOX_IGNORE_FLUSH
     2457    if (pThis->fIgnoreFlushAsync)
     2458        return VINF_VD_ASYNC_IO_FINISHED;
     2459#endif /* VBOX_IGNORE_FLUSH */
     2460
    21372461    if (!pThis->pBlkCache)
    21382462        rc = VDAsyncFlush(pThis->pDisk, drvvdAsyncReqComplete, pThis, pvUser);
     
    21572481    LogFlowFunc(("paRanges=%#p cRanges=%u pvUser=%#p\n",
    21582482                 paRanges, cRanges, pvUser));
     2483
     2484    /*
     2485     * Check the state.
     2486     */
     2487    if (!pThis->pDisk)
     2488    {
     2489        AssertMsgFailed(("Invalid state! Not mounted!\n"));
     2490        return VERR_PDM_MEDIA_NOT_MOUNTED;
     2491    }
    21592492
    21602493    if (!pThis->pBlkCache)
     
    23092642
    23102643
     2644/**
     2645 * Translates a PDMMEDIATYPE value into a string.
     2646 *
     2647 * @returns Read only string.
     2648 * @param   enmType             The type value.
     2649 */
     2650static const char *drvvdGetTypeName(PDMMEDIATYPE enmType)
     2651{
     2652    switch (enmType)
     2653    {
     2654        case PDMMEDIATYPE_ERROR:                return "ERROR";
     2655        case PDMMEDIATYPE_FLOPPY_360:           return "FLOPPY_360";
     2656        case PDMMEDIATYPE_FLOPPY_720:           return "FLOPPY_720";
     2657        case PDMMEDIATYPE_FLOPPY_1_20:          return "FLOPPY_1_20";
     2658        case PDMMEDIATYPE_FLOPPY_1_44:          return "FLOPPY_1_44";
     2659        case PDMMEDIATYPE_FLOPPY_2_88:          return "FLOPPY_2_88";
     2660        case PDMMEDIATYPE_FLOPPY_FAKE_15_6:     return "FLOPPY_FAKE_15_6";
     2661        case PDMMEDIATYPE_FLOPPY_FAKE_63_5:     return "FLOPPY_FAKE_63_5";
     2662        case PDMMEDIATYPE_CDROM:                return "CDROM";
     2663        case PDMMEDIATYPE_DVD:                  return "DVD";
     2664        case PDMMEDIATYPE_HARD_DISK:            return "HARD_DISK";
     2665        default:                                return "Unknown";
     2666    }
     2667}
     2668
     2669/**
     2670 * Returns the appropriate PDMMEDIATYPE for t he given string.
     2671 *
     2672 * @returns PDMMEDIATYPE
     2673 * @param   pszType    The string representation of the media type.
     2674 */
     2675static PDMMEDIATYPE drvvdGetMediaTypeFromString(const char *pszType)
     2676{
     2677    PDMMEDIATYPE enmType = PDMMEDIATYPE_ERROR;
     2678
     2679    if (!strcmp(pszType, "HardDisk"))
     2680        enmType = PDMMEDIATYPE_HARD_DISK;
     2681    else if (!strcmp(pszType, "DVD"))
     2682        enmType = PDMMEDIATYPE_DVD;
     2683    else if (!strcmp(pszType, "CDROM"))
     2684        enmType = PDMMEDIATYPE_CDROM;
     2685    else if (!strcmp(pszType, "Floppy 2.88"))
     2686        enmType = PDMMEDIATYPE_FLOPPY_2_88;
     2687    else if (!strcmp(pszType, "Floppy 1.44"))
     2688        enmType = PDMMEDIATYPE_FLOPPY_1_44;
     2689    else if (!strcmp(pszType, "Floppy 1.20"))
     2690        enmType = PDMMEDIATYPE_FLOPPY_1_20;
     2691    else if (!strcmp(pszType, "Floppy 720"))
     2692        enmType = PDMMEDIATYPE_FLOPPY_720;
     2693    else if (!strcmp(pszType, "Floppy 360"))
     2694        enmType = PDMMEDIATYPE_FLOPPY_360;
     2695    else if (!strcmp(pszType, "Floppy 15.6"))
     2696        enmType = PDMMEDIATYPE_FLOPPY_FAKE_15_6;
     2697    else if (!strcmp(pszType, "Floppy 63.5"))
     2698        enmType = PDMMEDIATYPE_FLOPPY_FAKE_63_5;
     2699
     2700    return enmType;
     2701}
     2702
     2703/**
     2704 * Converts PDMMEDIATYPE to the appropriate VDTYPE.
     2705 *
     2706 * @returns The VDTYPE.
     2707 * @param   enmType    The PDMMEDIATYPE to convert from.
     2708 */
     2709static VDTYPE drvvdGetVDFromMediaType(PDMMEDIATYPE enmType)
     2710{
     2711    if (PDMMEDIATYPE_IS_FLOPPY(enmType))
     2712        return VDTYPE_FLOPPY;
     2713    else if (enmType == PDMMEDIATYPE_DVD || enmType == PDMMEDIATYPE_CDROM)
     2714        return VDTYPE_DVD;
     2715    else if (enmType == PDMMEDIATYPE_HARD_DISK)
     2716        return VDTYPE_HDD;
     2717
     2718    AssertMsgFailed(("Invalid media type %d{%s} given!\n", enmType, drvvdGetTypeName(enmType)));
     2719    return VDTYPE_HDD;
     2720}
     2721
    23112722/*********************************************************************************************************************************
    23122723*   Base interface methods                                                                                                       *
     
    23232734    PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
    23242735    PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMEDIA, &pThis->IMedia);
     2736    PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMOUNT, pThis->fMountable ? &pThis->IMount : NULL);
    23252737    PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMEDIAASYNC, pThis->fAsyncIOSupported ? &pThis->IMediaAsync : NULL);
    23262738    return NULL;
     
    25933005    pThis->IMedia.pfnBiosGetLCHSGeometry = drvvdBiosGetLCHSGeometry;
    25943006    pThis->IMedia.pfnBiosSetLCHSGeometry = drvvdBiosSetLCHSGeometry;
     3007    pThis->IMedia.pfnBiosIsVisible       = drvvdBiosIsVisible;
     3008    pThis->IMedia.pfnGetType             = drvvdGetType;
    25953009    pThis->IMedia.pfnGetUuid             = drvvdGetUuid;
    25963010    pThis->IMedia.pfnDiscard             = drvvdDiscard;
    25973011    pThis->IMedia.pfnIoBufAlloc          = drvvdIoBufAlloc;
    25983012    pThis->IMedia.pfnIoBufFree           = drvvdIoBufFree;
     3013    pThis->IMedia.pfnSendCmd             = NULL;
     3014
     3015    /* IMount */
     3016    pThis->IMount.pfnUnmount                = drvvdUnmount;
     3017    pThis->IMount.pfnIsMounted              = drvvdIsMounted;
     3018    pThis->IMount.pfnLock                   = drvvdLock;
     3019    pThis->IMount.pfnUnlock                 = drvvdUnlock;
     3020    pThis->IMount.pfnIsLocked               = drvvdIsLocked;
    25993021
    26003022    /* IMediaAsync */
     
    26233045    /* Try to attach async media port interface above.*/
    26243046    pThis->pDrvMediaAsyncPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIMEDIAASYNCPORT);
     3047    pThis->pDrvMountNotify    = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIMOUNTNOTIFY);
    26253048
    26263049    /* Before we access any VD API load all given plugins. */
     
    26393062    bool        fInformAboutZeroBlocks = false;
    26403063    bool        fSkipConsistencyChecks = false;
     3064    bool        fEmptyDrive            = false;
    26413065    unsigned    iLevel = 0;
    26423066    PCFGMNODE   pCurNode = pCfg;
    2643     VDTYPE      enmType = VDTYPE_HDD;
    26443067
    26453068    for (;;)
     
    26573080                                          "SetupMerge\0MergeSource\0MergeTarget\0BwGroup\0Type\0BlockCache\0"
    26583081                                          "CachePath\0CacheFormat\0Discard\0InformAboutZeroBlocks\0"
    2659                                           "SkipConsistencyChecks\0");
     3082                                          "SkipConsistencyChecks\0"
     3083                                          "SubType\0Locked\0BIOSVisible\0Cylinders\0Heads\0Sectors\0Mountable\0"
     3084                                          "EmptyDrive\0"
     3085#if defined(VBOX_PERIODIC_FLUSH) || defined(VBOX_IGNORE_FLUSH)
     3086                                          "FlushInterval\0IgnoreFlush\0IgnoreFlushAsync\0"
     3087#endif /* !(VBOX_PERIODIC_FLUSH || VBOX_IGNORE_FLUSH) */
     3088                                           );
    26603089        }
    26613090        else
     
    28073236            }
    28083237
    2809             char *psz;
    2810             rc = CFGMR3QueryStringAlloc(pCfg, "Type", &psz);
     3238            char *psz = NULL;
     3239           rc = CFGMR3QueryStringAlloc(pCfg, "Type", &psz);
    28113240            if (RT_FAILURE(rc))
    2812             {
    2813                 rc = PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_BLOCK_NO_TYPE, N_("Failed to obtain the type"));
    2814                 break;
    2815             }
    2816             else if (!strcmp(psz, "HardDisk"))
    2817                 enmType = VDTYPE_HDD;
    2818             else if (!strcmp(psz, "DVD"))
    2819                 enmType = VDTYPE_DVD;
    2820             else if (!strcmp(psz, "Floppy"))
    2821                 enmType = VDTYPE_FLOPPY;
    2822             else
    2823             {
    2824                 rc = PDMDrvHlpVMSetError(pDrvIns, VERR_PDM_BLOCK_UNKNOWN_TYPE, RT_SRC_POS,
    2825                                          N_("Unknown type \"%s\""), psz);
     3241                return PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_BLOCK_NO_TYPE, N_("Failed to obtain the sub type"));
     3242            pThis->enmType = drvvdGetMediaTypeFromString(psz);
     3243            if (pThis->enmType == PDMMEDIATYPE_ERROR)
     3244            {
     3245                PDMDrvHlpVMSetError(pDrvIns, VERR_PDM_BLOCK_UNKNOWN_TYPE, RT_SRC_POS,
     3246                                    N_("Unknown type \"%s\""), psz);
    28263247                MMR3HeapFree(psz);
    2827                 break;
     3248                return VERR_PDM_BLOCK_UNKNOWN_TYPE;
    28283249            }
    28293250            MMR3HeapFree(psz); psz = NULL;
     
    28493270                }
    28503271            }
     3272
     3273            /* Mountable */
     3274            rc = CFGMR3QueryBoolDef(pCfg, "Mountable", &pThis->fMountable, false);
     3275            if (RT_FAILURE(rc))
     3276                return PDMDRV_SET_ERROR(pDrvIns, rc, N_("Failed to query \"Mountable\" from the config"));
     3277
     3278            /* Locked */
     3279            rc = CFGMR3QueryBoolDef(pCfg, "Locked", &pThis->fLocked, false);
     3280            if (RT_FAILURE(rc))
     3281                return PDMDRV_SET_ERROR(pDrvIns, rc, N_("Failed to query \"Locked\" from the config"));
     3282
     3283            /* BIOS visible */
     3284            rc = CFGMR3QueryBoolDef(pCfg, "BIOSVisible", &pThis->fBiosVisible, true);
     3285            if (RT_FAILURE(rc))
     3286                return PDMDRV_SET_ERROR(pDrvIns, rc, N_("Failed to query \"BIOSVisible\" from the config"));
     3287
     3288            /* Cylinders */
     3289            rc = CFGMR3QueryU32Def(pCfg, "Cylinders", &pThis->LCHSGeometry.cCylinders, 0);
     3290            if (RT_FAILURE(rc))
     3291                return PDMDRV_SET_ERROR(pDrvIns, rc, N_("Failed to query \"Cylinders\" from the config"));
     3292
     3293            /* Heads */
     3294            rc = CFGMR3QueryU32Def(pCfg, "Heads", &pThis->LCHSGeometry.cHeads, 0);
     3295            if (RT_FAILURE(rc))
     3296                return PDMDRV_SET_ERROR(pDrvIns, rc, N_("Failed to query \"Heads\" from the config"));
     3297
     3298            /* Sectors */
     3299            rc = CFGMR3QueryU32Def(pCfg, "Sectors", &pThis->LCHSGeometry.cSectors, 0);
     3300            if (RT_FAILURE(rc))
     3301                return PDMDRV_SET_ERROR(pDrvIns, rc, N_("Failed to query \"Sectors\" from the config"));
     3302
     3303            /* Uuid */
     3304            rc = CFGMR3QueryStringAlloc(pCfg, "Uuid", &psz);
     3305            if (rc == VERR_CFGM_VALUE_NOT_FOUND)
     3306                RTUuidClear(&pThis->Uuid);
     3307            else if (RT_SUCCESS(rc))
     3308            {
     3309                rc = RTUuidFromStr(&pThis->Uuid, psz);
     3310                if (RT_FAILURE(rc))
     3311                {
     3312                    PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS, N_("Uuid from string failed on \"%s\""), psz);
     3313                    MMR3HeapFree(psz);
     3314                    return rc;
     3315                }
     3316                MMR3HeapFree(psz); psz = NULL;
     3317            }
     3318            else
     3319                return PDMDRV_SET_ERROR(pDrvIns, rc, N_("Failed to query \"Uuid\" from the config"));
     3320
     3321#ifdef VBOX_PERIODIC_FLUSH
     3322            rc = CFGMR3QueryU32Def(pCfg, "FlushInterval", &pThis->cbFlushInterval, 0);
     3323            if (RT_FAILURE(rc))
     3324                return PDMDRV_SET_ERROR(pDrvIns, rc, N_("Failed to query \"FlushInterval\" from the config"));
     3325#endif /* VBOX_PERIODIC_FLUSH */
     3326
     3327#ifdef VBOX_IGNORE_FLUSH
     3328            rc = CFGMR3QueryBoolDef(pCfg, "IgnoreFlush", &pThis->fIgnoreFlush, true);
     3329            if (RT_FAILURE(rc))
     3330                return PDMDRV_SET_ERROR(pDrvIns, rc, N_("Failed to query \"IgnoreFlush\" from the config"));
     3331
     3332            if (pThis->fIgnoreFlush)
     3333                LogRel(("DrvVD: Flushes will be ignored\n"));
     3334            else
     3335                LogRel(("DrvVD: Flushes will be passed to the disk\n"));
     3336
     3337            rc = CFGMR3QueryBoolDef(pCfg, "IgnoreFlushAsync", &pThis->fIgnoreFlushAsync, false);
     3338            if (RT_FAILURE(rc))
     3339                return PDMDRV_SET_ERROR(pDrvIns, rc, N_("Failed to query \"IgnoreFlushAsync\" from the config"));
     3340
     3341            if (pThis->fIgnoreFlushAsync)
     3342                LogRel(("DrvVD: Async flushes will be ignored\n"));
     3343            else
     3344                LogRel(("DrvVD: Async flushes will be passed to the disk\n"));
     3345#endif /* VBOX_IGNORE_FLUSH */
     3346
     3347            rc = CFGMR3QueryBoolDef(pCurNode, "EmptyDrive", &fEmptyDrive, false);
     3348            if (RT_FAILURE(rc))
     3349            {
     3350                rc = PDMDRV_SET_ERROR(pDrvIns, rc,
     3351                                      N_("DrvVD: Configuration error: Querying \"EmptyDrive\" as boolean failed"));
     3352                break;
     3353            }
    28513354        }
    28523355
     
    28583361    }
    28593362
    2860     /*
    2861      * Create the image container and the necessary interfaces.
    2862      */
    2863     if (RT_SUCCESS(rc))
     3363    if (!fEmptyDrive)
    28643364    {
    28653365        /*
    2866          * The image has a bandwidth group but the host cache is enabled.
    2867          * Use the async I/O framework but tell it to enable the host cache.
     3366         * Create the image container and the necessary interfaces.
    28683367         */
    2869         if (!fUseNewIo && pThis->pszBwGroup)
    2870         {
    2871             pThis->fAsyncIoWithHostCache = true;
    2872             fUseNewIo = true;
    2873         }
    2874 
    2875         /** @todo quick hack to work around problems in the async I/O
    2876          * implementation (rw semaphore thread ownership problem)
    2877          * while a merge is running. Remove once this is fixed. */
    2878         if (pThis->fMergePending)
    2879             fUseNewIo = false;
    2880 
    2881         if (RT_SUCCESS(rc) && pThis->fMergePending)
    2882         {
    2883             rc = RTSemFastMutexCreate(&pThis->MergeCompleteMutex);
    2884             if (RT_SUCCESS(rc))
    2885                 rc = RTSemRWCreate(&pThis->MergeLock);
    2886             if (RT_SUCCESS(rc))
    2887             {
    2888                 pThis->VDIfThreadSync.pfnStartRead   = drvvdThreadStartRead;
    2889                 pThis->VDIfThreadSync.pfnFinishRead  = drvvdThreadFinishRead;
    2890                 pThis->VDIfThreadSync.pfnStartWrite  = drvvdThreadStartWrite;
    2891                 pThis->VDIfThreadSync.pfnFinishWrite = drvvdThreadFinishWrite;
    2892 
    2893                 rc = VDInterfaceAdd(&pThis->VDIfThreadSync.Core, "DrvVD_ThreadSync", VDINTERFACETYPE_THREADSYNC,
    2894                                     pThis, sizeof(VDINTERFACETHREADSYNC), &pThis->pVDIfsDisk);
    2895             }
    2896             else
    2897             {
    2898                 rc = PDMDRV_SET_ERROR(pDrvIns, rc,
    2899                                       N_("DrvVD: Failed to create semaphores for \"MergePending\""));
    2900             }
    2901         }
    2902 
    29033368        if (RT_SUCCESS(rc))
    29043369        {
    2905             rc = VDCreate(pThis->pVDIfsDisk, enmType, &pThis->pDisk);
    2906             /* Error message is already set correctly. */
    2907         }
    2908     }
    2909 
    2910     if (pThis->pDrvMediaAsyncPort && fUseNewIo)
    2911         pThis->fAsyncIOSupported = true;
    2912 
    2913     uint64_t tsStart = RTTimeNanoTS();
    2914 
    2915     unsigned iImageIdx = 0;
    2916     while (pCurNode && RT_SUCCESS(rc))
    2917     {
    2918         /* Allocate per-image data. */
    2919         PVBOXIMAGE pImage = drvvdNewImage(pThis);
    2920         if (!pImage)
    2921         {
    2922             rc = VERR_NO_MEMORY;
    2923             break;
    2924         }
    2925 
    2926         /*
    2927          * Read the image configuration.
    2928          */
    2929         rc = CFGMR3QueryStringAlloc(pCurNode, "Path", &pszName);
    2930         if (RT_FAILURE(rc))
    2931         {
    2932             rc = PDMDRV_SET_ERROR(pDrvIns, rc,
    2933                                   N_("DrvVD: Configuration error: Querying \"Path\" as string failed"));
    2934             break;
    2935         }
    2936 
    2937         rc = CFGMR3QueryStringAlloc(pCurNode, "Format", &pszFormat);
    2938         if (RT_FAILURE(rc))
    2939         {
    2940             rc = PDMDRV_SET_ERROR(pDrvIns, rc,
    2941                                   N_("DrvVD: Configuration error: Querying \"Format\" as string failed"));
    2942             break;
    2943         }
    2944 
    2945         bool fMergeSource;
    2946         rc = CFGMR3QueryBoolDef(pCurNode, "MergeSource", &fMergeSource, false);
    2947         if (RT_FAILURE(rc))
    2948         {
    2949             rc = PDMDRV_SET_ERROR(pDrvIns, rc,
    2950                                   N_("DrvVD: Configuration error: Querying \"MergeSource\" as boolean failed"));
    2951             break;
    2952         }
    2953         if (fMergeSource)
    2954         {
    2955             if (pThis->uMergeSource == VD_LAST_IMAGE)
    2956                 pThis->uMergeSource = iImageIdx;
    2957             else
    2958             {
    2959                 rc = PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_DRIVER_INVALID_PROPERTIES,
    2960                                       N_("DrvVD: Configuration error: Multiple \"MergeSource\" occurrences"));
    2961                 break;
    2962             }
    2963         }
    2964 
    2965         bool fMergeTarget;
    2966         rc = CFGMR3QueryBoolDef(pCurNode, "MergeTarget", &fMergeTarget, false);
    2967         if (RT_FAILURE(rc))
    2968         {
    2969             rc = PDMDRV_SET_ERROR(pDrvIns, rc,
    2970                                   N_("DrvVD: Configuration error: Querying \"MergeTarget\" as boolean failed"));
    2971             break;
    2972         }
    2973         if (fMergeTarget)
    2974         {
    2975             if (pThis->uMergeTarget == VD_LAST_IMAGE)
    2976                 pThis->uMergeTarget = iImageIdx;
    2977             else
    2978             {
    2979                 rc = PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_DRIVER_INVALID_PROPERTIES,
    2980                                       N_("DrvVD: Configuration error: Multiple \"MergeTarget\" occurrences"));
    2981                 break;
    2982             }
    2983         }
    2984 
    2985         PCFGMNODE pCfgVDConfig = CFGMR3GetChild(pCurNode, "VDConfig");
    2986         pImage->VDIfConfig.pfnAreKeysValid = drvvdCfgAreKeysValid;
    2987         pImage->VDIfConfig.pfnQuerySize    = drvvdCfgQuerySize;
    2988         pImage->VDIfConfig.pfnQuery        = drvvdCfgQuery;
    2989         pImage->VDIfConfig.pfnQueryBytes   = NULL;
    2990         rc = VDInterfaceAdd(&pImage->VDIfConfig.Core, "DrvVD_Config", VDINTERFACETYPE_CONFIG,
    2991                             pCfgVDConfig, sizeof(VDINTERFACECONFIG), &pImage->pVDIfsImage);
    2992         AssertRC(rc);
    2993 
    2994         /* Check VDConfig for encryption config. */
    2995         if (pCfgVDConfig)
    2996             pThis->pCfgCrypto = CFGMR3GetChild(pCfgVDConfig, "CRYPT");
    2997 
    2998         if (pThis->pCfgCrypto)
    2999         {
    3000             /* Setup VDConfig interface for disk encryption support. */
    3001             pThis->VDIfCfg.pfnAreKeysValid  = drvvdCfgAreKeysValid;
    3002             pThis->VDIfCfg.pfnQuerySize     = drvvdCfgQuerySize;
    3003             pThis->VDIfCfg.pfnQuery         = drvvdCfgQuery;
    3004             pThis->VDIfCfg.pfnQueryBytes    = NULL;
    3005 
    3006             pThis->VDIfCrypto.pfnKeyRetain               = drvvdCryptoKeyRetain;
    3007             pThis->VDIfCrypto.pfnKeyRelease              = drvvdCryptoKeyRelease;
    3008             pThis->VDIfCrypto.pfnKeyStorePasswordRetain  = drvvdCryptoKeyStorePasswordRetain;
    3009             pThis->VDIfCrypto.pfnKeyStorePasswordRelease = drvvdCryptoKeyStorePasswordRelease;
    3010         }
    3011 
    3012         /* Unconditionally insert the TCPNET interface, don't bother to check
    3013          * if an image really needs it. Will be ignored. Since the TCPNET
    3014          * interface is per image we could make this more flexible in the
    3015          * future if we want to. */
    3016         /* Construct TCPNET callback table depending on the config. This is
    3017          * done unconditionally, as uninterested backends will ignore it. */
    3018         if (fHostIP)
    3019         {
    3020             pImage->VDIfTcpNet.pfnSocketCreate = drvvdTcpSocketCreate;
    3021             pImage->VDIfTcpNet.pfnSocketDestroy = drvvdTcpSocketDestroy;
    3022             pImage->VDIfTcpNet.pfnClientConnect = drvvdTcpClientConnect;
    3023             pImage->VDIfTcpNet.pfnIsClientConnected = drvvdTcpIsClientConnected;
    3024             pImage->VDIfTcpNet.pfnClientClose = drvvdTcpClientClose;
    3025             pImage->VDIfTcpNet.pfnSelectOne = drvvdTcpSelectOne;
    3026             pImage->VDIfTcpNet.pfnRead = drvvdTcpRead;
    3027             pImage->VDIfTcpNet.pfnWrite = drvvdTcpWrite;
    3028             pImage->VDIfTcpNet.pfnSgWrite = drvvdTcpSgWrite;
    3029             pImage->VDIfTcpNet.pfnReadNB = drvvdTcpReadNB;
    3030             pImage->VDIfTcpNet.pfnWriteNB = drvvdTcpWriteNB;
    3031             pImage->VDIfTcpNet.pfnSgWriteNB = drvvdTcpSgWriteNB;
    3032             pImage->VDIfTcpNet.pfnFlush = drvvdTcpFlush;
    3033             pImage->VDIfTcpNet.pfnSetSendCoalescing = drvvdTcpSetSendCoalescing;
    3034             pImage->VDIfTcpNet.pfnGetLocalAddress = drvvdTcpGetLocalAddress;
    3035             pImage->VDIfTcpNet.pfnGetPeerAddress = drvvdTcpGetPeerAddress;
    3036 
    30373370            /*
    3038              * There is a 15ms delay between receiving the data and marking the socket
    3039              * as readable on Windows XP which hurts async I/O performance of
    3040              * TCP backends badly. Provide a different select method without
    3041              * using poll on XP.
    3042              * This is only used on XP because it is not as efficient as the one using poll
    3043              * and all other Windows versions are working fine.
     3371             * The image has a bandwidth group but the host cache is enabled.
     3372             * Use the async I/O framework but tell it to enable the host cache.
    30443373             */
    3045             char szOS[64];
    3046             memset(szOS, 0, sizeof(szOS));
    3047             rc = RTSystemQueryOSInfo(RTSYSOSINFO_PRODUCT, &szOS[0], sizeof(szOS));
    3048 
    3049             if (RT_SUCCESS(rc) && !strncmp(szOS, "Windows XP", 10))
    3050             {
    3051                 LogRel(("VD: Detected Windows XP, disabled poll based waiting for TCP\n"));
    3052                 pImage->VDIfTcpNet.pfnSelectOneEx = drvvdTcpSelectOneExNoPoll;
    3053             }
    3054             else
    3055                 pImage->VDIfTcpNet.pfnSelectOneEx = drvvdTcpSelectOneExPoll;
    3056 
    3057             pImage->VDIfTcpNet.pfnPoke = drvvdTcpPoke;
    3058         }
    3059         else
    3060         {
    3061 #ifndef VBOX_WITH_INIP
    3062             rc = PDMDrvHlpVMSetError(pDrvIns, VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES,
    3063                                      RT_SRC_POS, N_("DrvVD: Configuration error: TCP over Internal Networking not compiled in"));
    3064 #else /* VBOX_WITH_INIP */
    3065             pImage->VDIfTcpNet.pfnSocketCreate = drvvdINIPSocketCreate;
    3066             pImage->VDIfTcpNet.pfnSocketDestroy = drvvdINIPSocketDestroy;
    3067             pImage->VDIfTcpNet.pfnClientConnect = drvvdINIPClientConnect;
    3068             pImage->VDIfTcpNet.pfnClientClose = drvvdINIPClientClose;
    3069             pImage->VDIfTcpNet.pfnIsClientConnected = drvvdINIPIsClientConnected;
    3070             pImage->VDIfTcpNet.pfnSelectOne = drvvdINIPSelectOne;
    3071             pImage->VDIfTcpNet.pfnRead = drvvdINIPRead;
    3072             pImage->VDIfTcpNet.pfnWrite = drvvdINIPWrite;
    3073             pImage->VDIfTcpNet.pfnSgWrite = drvvdINIPSgWrite;
    3074             pImage->VDIfTcpNet.pfnFlush = drvvdINIPFlush;
    3075             pImage->VDIfTcpNet.pfnSetSendCoalescing = drvvdINIPSetSendCoalescing;
    3076             pImage->VDIfTcpNet.pfnGetLocalAddress = drvvdINIPGetLocalAddress;
    3077             pImage->VDIfTcpNet.pfnGetPeerAddress = drvvdINIPGetPeerAddress;
    3078             pImage->VDIfTcpNet.pfnSelectOneEx = drvvdINIPSelectOneEx;
    3079             pImage->VDIfTcpNet.pfnPoke = drvvdINIPPoke;
    3080 #endif /* VBOX_WITH_INIP */
    3081         }
    3082         rc = VDInterfaceAdd(&pImage->VDIfTcpNet.Core, "DrvVD_TCPNET",
    3083                             VDINTERFACETYPE_TCPNET, NULL,
    3084                             sizeof(VDINTERFACETCPNET), &pImage->pVDIfsImage);
    3085         AssertRC(rc);
    3086 
    3087         /* Insert the custom I/O interface only if we're told to use new IO.
    3088          * Since the I/O interface is per image we could make this more
    3089          * flexible in the future if we want to. */
    3090         if (fUseNewIo)
    3091         {
    3092 #ifdef VBOX_WITH_PDM_ASYNC_COMPLETION
    3093             pImage->VDIfIo.pfnOpen       = drvvdAsyncIOOpen;
    3094             pImage->VDIfIo.pfnClose      = drvvdAsyncIOClose;
    3095             pImage->VDIfIo.pfnGetSize    = drvvdAsyncIOGetSize;
    3096             pImage->VDIfIo.pfnSetSize    = drvvdAsyncIOSetSize;
    3097             pImage->VDIfIo.pfnReadSync   = drvvdAsyncIOReadSync;
    3098             pImage->VDIfIo.pfnWriteSync  = drvvdAsyncIOWriteSync;
    3099             pImage->VDIfIo.pfnFlushSync  = drvvdAsyncIOFlushSync;
    3100             pImage->VDIfIo.pfnReadAsync  = drvvdAsyncIOReadAsync;
    3101             pImage->VDIfIo.pfnWriteAsync = drvvdAsyncIOWriteAsync;
    3102             pImage->VDIfIo.pfnFlushAsync = drvvdAsyncIOFlushAsync;
    3103 #else /* !VBOX_WITH_PDM_ASYNC_COMPLETION */
    3104             rc = PDMDrvHlpVMSetError(pDrvIns, VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES,
    3105                                      RT_SRC_POS, N_("DrvVD: Configuration error: Async Completion Framework not compiled in"));
    3106 #endif /* !VBOX_WITH_PDM_ASYNC_COMPLETION */
    3107             if (RT_SUCCESS(rc))
    3108                 rc = VDInterfaceAdd(&pImage->VDIfIo.Core, "DrvVD_IO", VDINTERFACETYPE_IO,
    3109                                     pThis, sizeof(VDINTERFACEIO), &pImage->pVDIfsImage);
    3110             AssertRC(rc);
    3111         }
    3112 
    3113         /*
    3114          * Open the image.
    3115          */
    3116         unsigned uOpenFlags;
    3117         if (fReadOnly || pThis->fTempReadOnly || iLevel != 0)
    3118             uOpenFlags = VD_OPEN_FLAGS_READONLY;
    3119         else
    3120             uOpenFlags = VD_OPEN_FLAGS_NORMAL;
    3121         if (fHonorZeroWrites)
    3122             uOpenFlags |= VD_OPEN_FLAGS_HONOR_ZEROES;
    3123         if (pThis->fAsyncIOSupported)
    3124             uOpenFlags |= VD_OPEN_FLAGS_ASYNC_IO;
    3125         if (pThis->fShareable)
    3126             uOpenFlags |= VD_OPEN_FLAGS_SHAREABLE;
    3127         if (fDiscard && iLevel == 0)
    3128             uOpenFlags |= VD_OPEN_FLAGS_DISCARD;
    3129         if (fInformAboutZeroBlocks)
    3130             uOpenFlags |= VD_OPEN_FLAGS_INFORM_ABOUT_ZERO_BLOCKS;
    3131         if (   (uOpenFlags & VD_OPEN_FLAGS_READONLY)
    3132             && fSkipConsistencyChecks)
    3133             uOpenFlags |= VD_OPEN_FLAGS_SKIP_CONSISTENCY_CHECKS;
    3134 
    3135         /* Try to open backend in async I/O mode first. */
    3136         rc = VDOpen(pThis->pDisk, pszFormat, pszName, uOpenFlags, pImage->pVDIfsImage);
    3137         if (rc == VERR_NOT_SUPPORTED)
    3138         {
    3139             pThis->fAsyncIOSupported = false;
    3140             uOpenFlags &= ~VD_OPEN_FLAGS_ASYNC_IO;
    3141             rc = VDOpen(pThis->pDisk, pszFormat, pszName, uOpenFlags, pImage->pVDIfsImage);
    3142         }
    3143 
    3144         if (rc == VERR_VD_DISCARD_NOT_SUPPORTED)
    3145         {
    3146             fDiscard = false;
    3147             uOpenFlags &= ~VD_OPEN_FLAGS_DISCARD;
    3148             rc = VDOpen(pThis->pDisk, pszFormat, pszName, uOpenFlags, pImage->pVDIfsImage);
    3149         }
    3150 
    3151         if (!fDiscard)
    3152         {
    3153             pThis->IMedia.pfnDiscard = NULL;
    3154             pThis->IMediaAsync.pfnStartDiscard = NULL;
    3155         }
    3156 
    3157         if (RT_SUCCESS(rc))
    3158         {
    3159             LogFunc(("%d - Opened '%s' in %s mode\n",
    3160                      iLevel, pszName,
    3161                      VDIsReadOnly(pThis->pDisk) ? "read-only" : "read-write"));
    3162             if (  VDIsReadOnly(pThis->pDisk)
    3163                 && !fReadOnly
    3164                 && !fMaybeReadOnly
    3165                 && !pThis->fTempReadOnly
    3166                 && iLevel == 0)
    3167             {
    3168                 rc = PDMDrvHlpVMSetError(pDrvIns, VERR_VD_IMAGE_READ_ONLY, RT_SRC_POS,
    3169                                          N_("Failed to open image '%s' for writing due to wrong permissions"),
    3170                                          pszName);
    3171                 break;
    3172             }
    3173         }
    3174         else
    3175         {
    3176            rc = PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS,
    3177                                     N_("Failed to open image '%s' in %s mode"), pszName,
    3178                                     (uOpenFlags & VD_OPEN_FLAGS_READONLY) ? "read-only" : "read-write");
    3179            break;
    3180         }
    3181 
    3182 
    3183         MMR3HeapFree(pszName);
    3184         pszName = NULL;
    3185         MMR3HeapFree(pszFormat);
    3186         pszFormat = NULL;
    3187 
    3188         /* next */
    3189         iLevel--;
    3190         iImageIdx++;
    3191         pCurNode = CFGMR3GetParent(pCurNode);
    3192     }
    3193 
    3194     LogRel(("VD: Opening the disk took %lld ns\n", RTTimeNanoTS() - tsStart));
    3195 
    3196     /* Open the cache image if set. */
    3197     if (   RT_SUCCESS(rc)
    3198         && RT_VALID_PTR(pszCachePath))
    3199     {
    3200         /* Insert the custom I/O interface only if we're told to use new IO.
    3201          * Since the I/O interface is per image we could make this more
    3202          * flexible in the future if we want to. */
    3203         if (fUseNewIo)
    3204         {
    3205 #ifdef VBOX_WITH_PDM_ASYNC_COMPLETION
    3206             pThis->VDIfIoCache.pfnOpen       = drvvdAsyncIOOpen;
    3207             pThis->VDIfIoCache.pfnClose      = drvvdAsyncIOClose;
    3208             pThis->VDIfIoCache.pfnGetSize    = drvvdAsyncIOGetSize;
    3209             pThis->VDIfIoCache.pfnSetSize    = drvvdAsyncIOSetSize;
    3210             pThis->VDIfIoCache.pfnReadSync   = drvvdAsyncIOReadSync;
    3211             pThis->VDIfIoCache.pfnWriteSync  = drvvdAsyncIOWriteSync;
    3212             pThis->VDIfIoCache.pfnFlushSync  = drvvdAsyncIOFlushSync;
    3213             pThis->VDIfIoCache.pfnReadAsync  = drvvdAsyncIOReadAsync;
    3214             pThis->VDIfIoCache.pfnWriteAsync = drvvdAsyncIOWriteAsync;
    3215             pThis->VDIfIoCache.pfnFlushAsync = drvvdAsyncIOFlushAsync;
    3216 #else /* !VBOX_WITH_PDM_ASYNC_COMPLETION */
    3217             rc = PDMDrvHlpVMSetError(pDrvIns, VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES,
    3218                                      RT_SRC_POS, N_("DrvVD: Configuration error: Async Completion Framework not compiled in"));
    3219 #endif /* !VBOX_WITH_PDM_ASYNC_COMPLETION */
    3220             if (RT_SUCCESS(rc))
    3221                 rc = VDInterfaceAdd(&pThis->VDIfIoCache.Core, "DrvVD_IO", VDINTERFACETYPE_IO,
    3222                                     pThis, sizeof(VDINTERFACEIO), &pThis->pVDIfsCache);
    3223             AssertRC(rc);
    3224         }
    3225 
    3226         rc = VDCacheOpen(pThis->pDisk, pszCacheFormat, pszCachePath, VD_OPEN_FLAGS_NORMAL, pThis->pVDIfsCache);
    3227         if (RT_FAILURE(rc))
    3228             rc = PDMDRV_SET_ERROR(pDrvIns, rc, N_("DrvVD: Could not open cache image"));
    3229     }
    3230 
    3231     if (RT_VALID_PTR(pszCachePath))
    3232         MMR3HeapFree(pszCachePath);
    3233     if (RT_VALID_PTR(pszCacheFormat))
    3234         MMR3HeapFree(pszCacheFormat);
    3235 
    3236     if (   RT_SUCCESS(rc)
    3237         && pThis->fMergePending
    3238         && (   pThis->uMergeSource == VD_LAST_IMAGE
    3239             || pThis->uMergeTarget == VD_LAST_IMAGE))
    3240     {
    3241         rc = PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_DRIVER_INVALID_PROPERTIES,
    3242                               N_("DrvVD: Configuration error: Inconsistent image merge data"));
    3243     }
    3244 
    3245     /* Create the block cache if enabled. */
    3246     if (   fUseBlockCache
    3247         && !pThis->fShareable
    3248         && !fDiscard
    3249         && !pThis->pCfgCrypto /* Disk encryption disables the block cache for security reasons */
    3250         && RT_SUCCESS(rc))
    3251     {
    3252         /*
    3253          * We need a unique ID for the block cache (to identify the owner of data
    3254          * blocks in a saved state). UUIDs are not really suitable because
    3255          * there are image formats which don't support them. Furthermore it is
    3256          * possible that a new diff image was attached after a saved state
    3257          * which changes the UUID.
    3258          * However the device "name + device instance + LUN" triple the disk is
    3259          * attached to is always constant for saved states.
    3260          */
    3261         char *pszId = NULL;
    3262         uint32_t iInstance, iLUN;
    3263         const char *pcszController;
    3264 
    3265         rc = pThis->pDrvMediaPort->pfnQueryDeviceLocation(pThis->pDrvMediaPort, &pcszController,
    3266                                                           &iInstance, &iLUN);
    3267         if (RT_FAILURE(rc))
    3268             rc = PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_DRIVER_INVALID_PROPERTIES,
    3269                                   N_("DrvVD: Configuration error: Could not query device data"));
    3270         else
    3271         {
    3272             int cbStr = RTStrAPrintf(&pszId, "%s-%d-%d", pcszController, iInstance, iLUN);
    3273 
    3274             if (cbStr > 0)
    3275             {
    3276                 rc = PDMDrvHlpBlkCacheRetain(pDrvIns, &pThis->pBlkCache,
    3277                                              drvvdBlkCacheXferComplete,
    3278                                              drvvdBlkCacheXferEnqueue,
    3279                                              drvvdBlkCacheXferEnqueueDiscard,
    3280                                              pszId);
    3281                 if (rc == VERR_NOT_SUPPORTED)
     3374            if (!fUseNewIo && pThis->pszBwGroup)
     3375            {
     3376                pThis->fAsyncIoWithHostCache = true;
     3377                fUseNewIo = true;
     3378            }
     3379
     3380            /** @todo quick hack to work around problems in the async I/O
     3381             * implementation (rw semaphore thread ownership problem)
     3382             * while a merge is running. Remove once this is fixed. */
     3383            if (pThis->fMergePending)
     3384                fUseNewIo = false;
     3385
     3386            if (RT_SUCCESS(rc) && pThis->fMergePending)
     3387            {
     3388                rc = RTSemFastMutexCreate(&pThis->MergeCompleteMutex);
     3389                if (RT_SUCCESS(rc))
     3390                    rc = RTSemRWCreate(&pThis->MergeLock);
     3391                if (RT_SUCCESS(rc))
    32823392                {
    3283                     LogRel(("VD: Block cache is not supported\n"));
    3284                     rc = VINF_SUCCESS;
     3393                    pThis->VDIfThreadSync.pfnStartRead   = drvvdThreadStartRead;
     3394                    pThis->VDIfThreadSync.pfnFinishRead  = drvvdThreadFinishRead;
     3395                    pThis->VDIfThreadSync.pfnStartWrite  = drvvdThreadStartWrite;
     3396                    pThis->VDIfThreadSync.pfnFinishWrite = drvvdThreadFinishWrite;
     3397
     3398                    rc = VDInterfaceAdd(&pThis->VDIfThreadSync.Core, "DrvVD_ThreadSync", VDINTERFACETYPE_THREADSYNC,
     3399                                        pThis, sizeof(VDINTERFACETHREADSYNC), &pThis->pVDIfsDisk);
    32853400                }
    32863401                else
    3287                     AssertRC(rc);
    3288 
    3289                 RTStrFree(pszId);
     3402                {
     3403                    rc = PDMDRV_SET_ERROR(pDrvIns, rc,
     3404                                          N_("DrvVD: Failed to create semaphores for \"MergePending\""));
     3405                }
     3406            }
     3407
     3408            if (RT_SUCCESS(rc))
     3409            {
     3410                rc = VDCreate(pThis->pVDIfsDisk, drvvdGetVDFromMediaType(pThis->enmType), &pThis->pDisk);
     3411                /* Error message is already set correctly. */
     3412            }
     3413        }
     3414
     3415        if (pThis->pDrvMediaAsyncPort && fUseNewIo)
     3416            pThis->fAsyncIOSupported = true;
     3417
     3418        uint64_t tsStart = RTTimeNanoTS();
     3419
     3420        unsigned iImageIdx = 0;
     3421        while (pCurNode && RT_SUCCESS(rc))
     3422        {
     3423            /* Allocate per-image data. */
     3424            PVBOXIMAGE pImage = drvvdNewImage(pThis);
     3425            if (!pImage)
     3426            {
     3427                rc = VERR_NO_MEMORY;
     3428                break;
     3429            }
     3430
     3431            /*
     3432             * Read the image configuration.
     3433             */
     3434            rc = CFGMR3QueryStringAlloc(pCurNode, "Path", &pszName);
     3435            if (RT_FAILURE(rc))
     3436            {
     3437                rc = PDMDRV_SET_ERROR(pDrvIns, rc,
     3438                                      N_("DrvVD: Configuration error: Querying \"Path\" as string failed"));
     3439                break;
     3440            }
     3441
     3442            rc = CFGMR3QueryStringAlloc(pCurNode, "Format", &pszFormat);
     3443            if (RT_FAILURE(rc))
     3444            {
     3445                rc = PDMDRV_SET_ERROR(pDrvIns, rc,
     3446                                      N_("DrvVD: Configuration error: Querying \"Format\" as string failed"));
     3447                break;
     3448            }
     3449
     3450            bool fMergeSource;
     3451            rc = CFGMR3QueryBoolDef(pCurNode, "MergeSource", &fMergeSource, false);
     3452            if (RT_FAILURE(rc))
     3453            {
     3454                rc = PDMDRV_SET_ERROR(pDrvIns, rc,
     3455                                      N_("DrvVD: Configuration error: Querying \"MergeSource\" as boolean failed"));
     3456                break;
     3457            }
     3458            if (fMergeSource)
     3459            {
     3460                if (pThis->uMergeSource == VD_LAST_IMAGE)
     3461                    pThis->uMergeSource = iImageIdx;
     3462                else
     3463                {
     3464                    rc = PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_DRIVER_INVALID_PROPERTIES,
     3465                                          N_("DrvVD: Configuration error: Multiple \"MergeSource\" occurrences"));
     3466                    break;
     3467                }
     3468            }
     3469
     3470            bool fMergeTarget;
     3471            rc = CFGMR3QueryBoolDef(pCurNode, "MergeTarget", &fMergeTarget, false);
     3472            if (RT_FAILURE(rc))
     3473            {
     3474                rc = PDMDRV_SET_ERROR(pDrvIns, rc,
     3475                                      N_("DrvVD: Configuration error: Querying \"MergeTarget\" as boolean failed"));
     3476                break;
     3477            }
     3478            if (fMergeTarget)
     3479            {
     3480                if (pThis->uMergeTarget == VD_LAST_IMAGE)
     3481                    pThis->uMergeTarget = iImageIdx;
     3482                else
     3483                {
     3484                    rc = PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_DRIVER_INVALID_PROPERTIES,
     3485                                          N_("DrvVD: Configuration error: Multiple \"MergeTarget\" occurrences"));
     3486                    break;
     3487                }
     3488            }
     3489
     3490            PCFGMNODE pCfgVDConfig = CFGMR3GetChild(pCurNode, "VDConfig");
     3491            pImage->VDIfConfig.pfnAreKeysValid = drvvdCfgAreKeysValid;
     3492            pImage->VDIfConfig.pfnQuerySize    = drvvdCfgQuerySize;
     3493            pImage->VDIfConfig.pfnQuery        = drvvdCfgQuery;
     3494            pImage->VDIfConfig.pfnQueryBytes   = NULL;
     3495            rc = VDInterfaceAdd(&pImage->VDIfConfig.Core, "DrvVD_Config", VDINTERFACETYPE_CONFIG,
     3496                                pCfgVDConfig, sizeof(VDINTERFACECONFIG), &pImage->pVDIfsImage);
     3497            AssertRC(rc);
     3498
     3499            /* Check VDConfig for encryption config. */
     3500            if (pCfgVDConfig)
     3501                pThis->pCfgCrypto = CFGMR3GetChild(pCfgVDConfig, "CRYPT");
     3502
     3503            if (pThis->pCfgCrypto)
     3504            {
     3505                /* Setup VDConfig interface for disk encryption support. */
     3506                pThis->VDIfCfg.pfnAreKeysValid  = drvvdCfgAreKeysValid;
     3507                pThis->VDIfCfg.pfnQuerySize     = drvvdCfgQuerySize;
     3508                pThis->VDIfCfg.pfnQuery         = drvvdCfgQuery;
     3509                pThis->VDIfCfg.pfnQueryBytes    = NULL;
     3510
     3511                pThis->VDIfCrypto.pfnKeyRetain               = drvvdCryptoKeyRetain;
     3512                pThis->VDIfCrypto.pfnKeyRelease              = drvvdCryptoKeyRelease;
     3513                pThis->VDIfCrypto.pfnKeyStorePasswordRetain  = drvvdCryptoKeyStorePasswordRetain;
     3514                pThis->VDIfCrypto.pfnKeyStorePasswordRelease = drvvdCryptoKeyStorePasswordRelease;
     3515            }
     3516
     3517            /* Unconditionally insert the TCPNET interface, don't bother to check
     3518             * if an image really needs it. Will be ignored. Since the TCPNET
     3519             * interface is per image we could make this more flexible in the
     3520             * future if we want to. */
     3521            /* Construct TCPNET callback table depending on the config. This is
     3522             * done unconditionally, as uninterested backends will ignore it. */
     3523            if (fHostIP)
     3524            {
     3525                pImage->VDIfTcpNet.pfnSocketCreate = drvvdTcpSocketCreate;
     3526                pImage->VDIfTcpNet.pfnSocketDestroy = drvvdTcpSocketDestroy;
     3527                pImage->VDIfTcpNet.pfnClientConnect = drvvdTcpClientConnect;
     3528                pImage->VDIfTcpNet.pfnIsClientConnected = drvvdTcpIsClientConnected;
     3529                pImage->VDIfTcpNet.pfnClientClose = drvvdTcpClientClose;
     3530                pImage->VDIfTcpNet.pfnSelectOne = drvvdTcpSelectOne;
     3531                pImage->VDIfTcpNet.pfnRead = drvvdTcpRead;
     3532                pImage->VDIfTcpNet.pfnWrite = drvvdTcpWrite;
     3533                pImage->VDIfTcpNet.pfnSgWrite = drvvdTcpSgWrite;
     3534                pImage->VDIfTcpNet.pfnReadNB = drvvdTcpReadNB;
     3535                pImage->VDIfTcpNet.pfnWriteNB = drvvdTcpWriteNB;
     3536                pImage->VDIfTcpNet.pfnSgWriteNB = drvvdTcpSgWriteNB;
     3537                pImage->VDIfTcpNet.pfnFlush = drvvdTcpFlush;
     3538                pImage->VDIfTcpNet.pfnSetSendCoalescing = drvvdTcpSetSendCoalescing;
     3539                pImage->VDIfTcpNet.pfnGetLocalAddress = drvvdTcpGetLocalAddress;
     3540                pImage->VDIfTcpNet.pfnGetPeerAddress = drvvdTcpGetPeerAddress;
     3541
     3542                /*
     3543                 * There is a 15ms delay between receiving the data and marking the socket
     3544                 * as readable on Windows XP which hurts async I/O performance of
     3545                 * TCP backends badly. Provide a different select method without
     3546                 * using poll on XP.
     3547                 * This is only used on XP because it is not as efficient as the one using poll
     3548                 * and all other Windows versions are working fine.
     3549                 */
     3550                char szOS[64];
     3551                memset(szOS, 0, sizeof(szOS));
     3552                rc = RTSystemQueryOSInfo(RTSYSOSINFO_PRODUCT, &szOS[0], sizeof(szOS));
     3553
     3554                if (RT_SUCCESS(rc) && !strncmp(szOS, "Windows XP", 10))
     3555                {
     3556                    LogRel(("VD: Detected Windows XP, disabled poll based waiting for TCP\n"));
     3557                    pImage->VDIfTcpNet.pfnSelectOneEx = drvvdTcpSelectOneExNoPoll;
     3558                }
     3559                else
     3560                    pImage->VDIfTcpNet.pfnSelectOneEx = drvvdTcpSelectOneExPoll;
     3561
     3562                pImage->VDIfTcpNet.pfnPoke = drvvdTcpPoke;
    32903563            }
    32913564            else
     3565            {
     3566#ifndef VBOX_WITH_INIP
     3567                rc = PDMDrvHlpVMSetError(pDrvIns, VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES,
     3568                                         RT_SRC_POS, N_("DrvVD: Configuration error: TCP over Internal Networking not compiled in"));
     3569#else /* VBOX_WITH_INIP */
     3570                pImage->VDIfTcpNet.pfnSocketCreate = drvvdINIPSocketCreate;
     3571                pImage->VDIfTcpNet.pfnSocketDestroy = drvvdINIPSocketDestroy;
     3572                pImage->VDIfTcpNet.pfnClientConnect = drvvdINIPClientConnect;
     3573                pImage->VDIfTcpNet.pfnClientClose = drvvdINIPClientClose;
     3574                pImage->VDIfTcpNet.pfnIsClientConnected = drvvdINIPIsClientConnected;
     3575                pImage->VDIfTcpNet.pfnSelectOne = drvvdINIPSelectOne;
     3576                pImage->VDIfTcpNet.pfnRead = drvvdINIPRead;
     3577                pImage->VDIfTcpNet.pfnWrite = drvvdINIPWrite;
     3578                pImage->VDIfTcpNet.pfnSgWrite = drvvdINIPSgWrite;
     3579                pImage->VDIfTcpNet.pfnFlush = drvvdINIPFlush;
     3580                pImage->VDIfTcpNet.pfnSetSendCoalescing = drvvdINIPSetSendCoalescing;
     3581                pImage->VDIfTcpNet.pfnGetLocalAddress = drvvdINIPGetLocalAddress;
     3582                pImage->VDIfTcpNet.pfnGetPeerAddress = drvvdINIPGetPeerAddress;
     3583                pImage->VDIfTcpNet.pfnSelectOneEx = drvvdINIPSelectOneEx;
     3584                pImage->VDIfTcpNet.pfnPoke = drvvdINIPPoke;
     3585#endif /* VBOX_WITH_INIP */
     3586            }
     3587            rc = VDInterfaceAdd(&pImage->VDIfTcpNet.Core, "DrvVD_TCPNET",
     3588                                VDINTERFACETYPE_TCPNET, NULL,
     3589                                sizeof(VDINTERFACETCPNET), &pImage->pVDIfsImage);
     3590            AssertRC(rc);
     3591
     3592            /* Insert the custom I/O interface only if we're told to use new IO.
     3593             * Since the I/O interface is per image we could make this more
     3594             * flexible in the future if we want to. */
     3595            if (fUseNewIo)
     3596            {
     3597#ifdef VBOX_WITH_PDM_ASYNC_COMPLETION
     3598                pImage->VDIfIo.pfnOpen       = drvvdAsyncIOOpen;
     3599                pImage->VDIfIo.pfnClose      = drvvdAsyncIOClose;
     3600                pImage->VDIfIo.pfnGetSize    = drvvdAsyncIOGetSize;
     3601                pImage->VDIfIo.pfnSetSize    = drvvdAsyncIOSetSize;
     3602                pImage->VDIfIo.pfnReadSync   = drvvdAsyncIOReadSync;
     3603                pImage->VDIfIo.pfnWriteSync  = drvvdAsyncIOWriteSync;
     3604                pImage->VDIfIo.pfnFlushSync  = drvvdAsyncIOFlushSync;
     3605                pImage->VDIfIo.pfnReadAsync  = drvvdAsyncIOReadAsync;
     3606                pImage->VDIfIo.pfnWriteAsync = drvvdAsyncIOWriteAsync;
     3607                pImage->VDIfIo.pfnFlushAsync = drvvdAsyncIOFlushAsync;
     3608#else /* !VBOX_WITH_PDM_ASYNC_COMPLETION */
     3609                rc = PDMDrvHlpVMSetError(pDrvIns, VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES,
     3610                                         RT_SRC_POS, N_("DrvVD: Configuration error: Async Completion Framework not compiled in"));
     3611#endif /* !VBOX_WITH_PDM_ASYNC_COMPLETION */
     3612                if (RT_SUCCESS(rc))
     3613                    rc = VDInterfaceAdd(&pImage->VDIfIo.Core, "DrvVD_IO", VDINTERFACETYPE_IO,
     3614                                        pThis, sizeof(VDINTERFACEIO), &pImage->pVDIfsImage);
     3615                AssertRC(rc);
     3616            }
     3617
     3618            /*
     3619             * Open the image.
     3620             */
     3621            unsigned uOpenFlags;
     3622            if (fReadOnly || pThis->fTempReadOnly || iLevel != 0)
     3623                uOpenFlags = VD_OPEN_FLAGS_READONLY;
     3624            else
     3625                uOpenFlags = VD_OPEN_FLAGS_NORMAL;
     3626            if (fHonorZeroWrites)
     3627                uOpenFlags |= VD_OPEN_FLAGS_HONOR_ZEROES;
     3628            if (pThis->fAsyncIOSupported)
     3629                uOpenFlags |= VD_OPEN_FLAGS_ASYNC_IO;
     3630            if (pThis->fShareable)
     3631                uOpenFlags |= VD_OPEN_FLAGS_SHAREABLE;
     3632            if (fDiscard && iLevel == 0)
     3633                uOpenFlags |= VD_OPEN_FLAGS_DISCARD;
     3634            if (fInformAboutZeroBlocks)
     3635                uOpenFlags |= VD_OPEN_FLAGS_INFORM_ABOUT_ZERO_BLOCKS;
     3636            if (   (uOpenFlags & VD_OPEN_FLAGS_READONLY)
     3637                && fSkipConsistencyChecks)
     3638                uOpenFlags |= VD_OPEN_FLAGS_SKIP_CONSISTENCY_CHECKS;
     3639
     3640            /* Try to open backend in async I/O mode first. */
     3641            rc = VDOpen(pThis->pDisk, pszFormat, pszName, uOpenFlags, pImage->pVDIfsImage);
     3642            if (rc == VERR_NOT_SUPPORTED)
     3643            {
     3644                pThis->fAsyncIOSupported = false;
     3645                uOpenFlags &= ~VD_OPEN_FLAGS_ASYNC_IO;
     3646                rc = VDOpen(pThis->pDisk, pszFormat, pszName, uOpenFlags, pImage->pVDIfsImage);
     3647            }
     3648
     3649            if (rc == VERR_VD_DISCARD_NOT_SUPPORTED)
     3650            {
     3651                fDiscard = false;
     3652                uOpenFlags &= ~VD_OPEN_FLAGS_DISCARD;
     3653                rc = VDOpen(pThis->pDisk, pszFormat, pszName, uOpenFlags, pImage->pVDIfsImage);
     3654            }
     3655
     3656            if (!fDiscard)
     3657            {
     3658                pThis->IMedia.pfnDiscard = NULL;
     3659                pThis->IMediaAsync.pfnStartDiscard = NULL;
     3660            }
     3661
     3662            if (RT_SUCCESS(rc))
     3663            {
     3664                LogFunc(("%d - Opened '%s' in %s mode\n",
     3665                         iLevel, pszName,
     3666                         VDIsReadOnly(pThis->pDisk) ? "read-only" : "read-write"));
     3667                if (  VDIsReadOnly(pThis->pDisk)
     3668                    && !fReadOnly
     3669                    && !fMaybeReadOnly
     3670                    && !pThis->fTempReadOnly
     3671                    && iLevel == 0)
     3672                {
     3673                    rc = PDMDrvHlpVMSetError(pDrvIns, VERR_VD_IMAGE_READ_ONLY, RT_SRC_POS,
     3674                                             N_("Failed to open image '%s' for writing due to wrong permissions"),
     3675                                             pszName);
     3676                    break;
     3677                }
     3678            }
     3679            else
     3680            {
     3681               rc = PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS,
     3682                                        N_("Failed to open image '%s' in %s mode"), pszName,
     3683                                        (uOpenFlags & VD_OPEN_FLAGS_READONLY) ? "read-only" : "read-write");
     3684               break;
     3685            }
     3686
     3687            MMR3HeapFree(pszName);
     3688            pszName = NULL;
     3689            MMR3HeapFree(pszFormat);
     3690            pszFormat = NULL;
     3691
     3692            /* next */
     3693            iLevel--;
     3694            iImageIdx++;
     3695            pCurNode = CFGMR3GetParent(pCurNode);
     3696        }
     3697
     3698        LogRel(("VD: Opening the disk took %lld ns\n", RTTimeNanoTS() - tsStart));
     3699
     3700        /* Open the cache image if set. */
     3701        if (   RT_SUCCESS(rc)
     3702            && RT_VALID_PTR(pszCachePath))
     3703        {
     3704            /* Insert the custom I/O interface only if we're told to use new IO.
     3705             * Since the I/O interface is per image we could make this more
     3706             * flexible in the future if we want to. */
     3707            if (fUseNewIo)
     3708            {
     3709#ifdef VBOX_WITH_PDM_ASYNC_COMPLETION
     3710                pThis->VDIfIoCache.pfnOpen       = drvvdAsyncIOOpen;
     3711                pThis->VDIfIoCache.pfnClose      = drvvdAsyncIOClose;
     3712                pThis->VDIfIoCache.pfnGetSize    = drvvdAsyncIOGetSize;
     3713                pThis->VDIfIoCache.pfnSetSize    = drvvdAsyncIOSetSize;
     3714                pThis->VDIfIoCache.pfnReadSync   = drvvdAsyncIOReadSync;
     3715                pThis->VDIfIoCache.pfnWriteSync  = drvvdAsyncIOWriteSync;
     3716                pThis->VDIfIoCache.pfnFlushSync  = drvvdAsyncIOFlushSync;
     3717                pThis->VDIfIoCache.pfnReadAsync  = drvvdAsyncIOReadAsync;
     3718                pThis->VDIfIoCache.pfnWriteAsync = drvvdAsyncIOWriteAsync;
     3719                pThis->VDIfIoCache.pfnFlushAsync = drvvdAsyncIOFlushAsync;
     3720#else /* !VBOX_WITH_PDM_ASYNC_COMPLETION */
     3721                rc = PDMDrvHlpVMSetError(pDrvIns, VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES,
     3722                                         RT_SRC_POS, N_("DrvVD: Configuration error: Async Completion Framework not compiled in"));
     3723#endif /* !VBOX_WITH_PDM_ASYNC_COMPLETION */
     3724                if (RT_SUCCESS(rc))
     3725                    rc = VDInterfaceAdd(&pThis->VDIfIoCache.Core, "DrvVD_IO", VDINTERFACETYPE_IO,
     3726                                        pThis, sizeof(VDINTERFACEIO), &pThis->pVDIfsCache);
     3727                AssertRC(rc);
     3728            }
     3729
     3730            rc = VDCacheOpen(pThis->pDisk, pszCacheFormat, pszCachePath, VD_OPEN_FLAGS_NORMAL, pThis->pVDIfsCache);
     3731            if (RT_FAILURE(rc))
     3732                rc = PDMDRV_SET_ERROR(pDrvIns, rc, N_("DrvVD: Could not open cache image"));
     3733        }
     3734
     3735        if (RT_VALID_PTR(pszCachePath))
     3736            MMR3HeapFree(pszCachePath);
     3737        if (RT_VALID_PTR(pszCacheFormat))
     3738            MMR3HeapFree(pszCacheFormat);
     3739
     3740        if (   RT_SUCCESS(rc)
     3741            && pThis->fMergePending
     3742            && (   pThis->uMergeSource == VD_LAST_IMAGE
     3743                || pThis->uMergeTarget == VD_LAST_IMAGE))
     3744        {
     3745            rc = PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_DRIVER_INVALID_PROPERTIES,
     3746                                  N_("DrvVD: Configuration error: Inconsistent image merge data"));
     3747        }
     3748
     3749        /* Create the block cache if enabled. */
     3750        if (   fUseBlockCache
     3751            && !pThis->fShareable
     3752            && !fDiscard
     3753            && !pThis->pCfgCrypto /* Disk encryption disables the block cache for security reasons */
     3754            && RT_SUCCESS(rc))
     3755        {
     3756            /*
     3757             * We need a unique ID for the block cache (to identify the owner of data
     3758             * blocks in a saved state). UUIDs are not really suitable because
     3759             * there are image formats which don't support them. Furthermore it is
     3760             * possible that a new diff image was attached after a saved state
     3761             * which changes the UUID.
     3762             * However the device "name + device instance + LUN" triple the disk is
     3763             * attached to is always constant for saved states.
     3764             */
     3765            char *pszId = NULL;
     3766            uint32_t iInstance, iLUN;
     3767            const char *pcszController;
     3768
     3769            rc = pThis->pDrvMediaPort->pfnQueryDeviceLocation(pThis->pDrvMediaPort, &pcszController,
     3770                                                              &iInstance, &iLUN);
     3771            if (RT_FAILURE(rc))
    32923772                rc = PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_DRIVER_INVALID_PROPERTIES,
    3293                                       N_("DrvVD: Out of memory when creating block cache"));
     3773                                      N_("DrvVD: Configuration error: Could not query device data"));
     3774            else
     3775            {
     3776                int cbStr = RTStrAPrintf(&pszId, "%s-%d-%d", pcszController, iInstance, iLUN);
     3777
     3778                if (cbStr > 0)
     3779                {
     3780                    rc = PDMDrvHlpBlkCacheRetain(pDrvIns, &pThis->pBlkCache,
     3781                                                 drvvdBlkCacheXferComplete,
     3782                                                 drvvdBlkCacheXferEnqueue,
     3783                                                 drvvdBlkCacheXferEnqueueDiscard,
     3784                                                 pszId);
     3785                    if (rc == VERR_NOT_SUPPORTED)
     3786                    {
     3787                        LogRel(("VD: Block cache is not supported\n"));
     3788                        rc = VINF_SUCCESS;
     3789                    }
     3790                    else
     3791                        AssertRC(rc);
     3792
     3793                    RTStrFree(pszId);
     3794                }
     3795                else
     3796                    rc = PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_DRIVER_INVALID_PROPERTIES,
     3797                                          N_("DrvVD: Out of memory when creating block cache"));
     3798            }
    32943799        }
    3295     }
    3296 
    3297     if (RT_SUCCESS(rc))
    3298         rc = drvvdSetupFilters(pThis, pCfg);
    3299 
    3300     /*
    3301      * Register a load-done callback so we can undo TempReadOnly config before
    3302      * we get to drvvdResume.  Autoamtically deregistered upon destruction.
    3303      */
    3304     if (RT_SUCCESS(rc))
    3305         rc = PDMDrvHlpSSMRegisterEx(pDrvIns, 0 /* version */, 0 /* cbGuess */,
    3306                                     NULL /*pfnLivePrep*/, NULL /*pfnLiveExec*/, NULL /*pfnLiveVote*/,
    3307                                     NULL /*pfnSavePrep*/, NULL /*pfnSaveExec*/, NULL /*pfnSaveDone*/,
    3308                                     NULL /*pfnDonePrep*/, NULL /*pfnLoadExec*/, drvvdLoadDone);
    3309 
    3310     /* Setup the boot acceleration stuff if enabled. */
    3311     if (RT_SUCCESS(rc) && pThis->fBootAccelEnabled)
    3312     {
    3313         pThis->cbDisk = VDGetSize(pThis->pDisk, VD_LAST_IMAGE);
    3314         Assert(pThis->cbDisk > 0);
    3315         pThis->pbData = (uint8_t *)RTMemAllocZ(pThis->cbBootAccelBuffer);
    3316         if (pThis->pbData)
     3800
     3801        if (RT_SUCCESS(rc))
     3802            rc = drvvdSetupFilters(pThis, pCfg);
     3803
     3804        /*
     3805         * Register a load-done callback so we can undo TempReadOnly config before
     3806         * we get to drvvdResume.  Autoamtically deregistered upon destruction.
     3807         */
     3808        if (RT_SUCCESS(rc))
     3809            rc = PDMDrvHlpSSMRegisterEx(pDrvIns, 0 /* version */, 0 /* cbGuess */,
     3810                                        NULL /*pfnLivePrep*/, NULL /*pfnLiveExec*/, NULL /*pfnLiveVote*/,
     3811                                        NULL /*pfnSavePrep*/, NULL /*pfnSaveExec*/, NULL /*pfnSaveDone*/,
     3812                                        NULL /*pfnDonePrep*/, NULL /*pfnLoadExec*/, drvvdLoadDone);
     3813
     3814        /* Setup the boot acceleration stuff if enabled. */
     3815        if (RT_SUCCESS(rc) && pThis->fBootAccelEnabled)
    33173816        {
    3318             pThis->fBootAccelActive = true;
    3319             pThis->offDisk          = 0;
    3320             pThis->cbDataValid      = 0;
    3321             LogRel(("VD: Boot acceleration enabled\n"));
     3817            pThis->cbDisk = VDGetSize(pThis->pDisk, VD_LAST_IMAGE);
     3818            Assert(pThis->cbDisk > 0);
     3819            pThis->pbData = (uint8_t *)RTMemAllocZ(pThis->cbBootAccelBuffer);
     3820            if (pThis->pbData)
     3821            {
     3822                pThis->fBootAccelActive = true;
     3823                pThis->offDisk          = 0;
     3824                pThis->cbDataValid      = 0;
     3825                LogRel(("VD: Boot acceleration enabled\n"));
     3826            }
     3827            else
     3828                LogRel(("VD: Boot acceleration, out of memory, disabled\n"));
    33223829        }
    3323         else
    3324             LogRel(("VD: Boot acceleration, out of memory, disabled\n"));
    3325     }
     3830
     3831        if (   RTUuidIsNull(&pThis->Uuid)
     3832            && pThis->enmType == PDMMEDIATYPE_HARD_DISK)
     3833            rc = VDGetUuid(pThis->pDisk, 0, &pThis->Uuid);
     3834
     3835        /*
     3836         * Automatically upgrade the floppy drive if the specified one is too
     3837         * small to represent the whole boot time image. (We cannot do this later
     3838         * since the BIOS (and others) gets the info via CMOS.)
     3839         *
     3840         * This trick should make 2.88 images as well as the fake 15.6 and 63.5 MB
     3841         * images despite the hardcoded default 1.44 drive.
     3842         */
     3843        if (   PDMMEDIATYPE_IS_FLOPPY(pThis->enmType)
     3844            && pThis->pDisk)
     3845        {
     3846            uint64_t     const cbFloppyImg = VDGetSize(pThis->pDisk, VD_LAST_IMAGE);
     3847            PDMMEDIATYPE const enmCfgType  = pThis->enmType;
     3848            switch (enmCfgType)
     3849            {
     3850                default:
     3851                    AssertFailed();
     3852                case PDMMEDIATYPE_FLOPPY_360:
     3853                    if (cbFloppyImg > 40 * 2 * 9 * 512)
     3854                        pThis->enmType = PDMMEDIATYPE_FLOPPY_720;
     3855                    /* fall thru */
     3856                case PDMMEDIATYPE_FLOPPY_720:
     3857                    if (cbFloppyImg > 80 * 2 * 14 * 512)
     3858                        pThis->enmType = PDMMEDIATYPE_FLOPPY_1_20;
     3859                    /* fall thru */
     3860                case PDMMEDIATYPE_FLOPPY_1_20:
     3861                    if (cbFloppyImg > 80 * 2 * 20 * 512)
     3862                        pThis->enmType = PDMMEDIATYPE_FLOPPY_1_44;
     3863                    /* fall thru */
     3864                case PDMMEDIATYPE_FLOPPY_1_44:
     3865                    if (cbFloppyImg > 80 * 2 * 24 * 512)
     3866                        pThis->enmType = PDMMEDIATYPE_FLOPPY_2_88;
     3867                    /* fall thru */
     3868                case PDMMEDIATYPE_FLOPPY_2_88:
     3869                    if (cbFloppyImg > 80 * 2 * 48 * 512)
     3870                        pThis->enmType = PDMMEDIATYPE_FLOPPY_FAKE_15_6;
     3871                    /* fall thru */
     3872                case PDMMEDIATYPE_FLOPPY_FAKE_15_6:
     3873                    if (cbFloppyImg > 255 * 2 * 63 * 512)
     3874                        pThis->enmType = PDMMEDIATYPE_FLOPPY_FAKE_63_5;
     3875                case PDMMEDIATYPE_FLOPPY_FAKE_63_5:
     3876                    if (cbFloppyImg > 255 * 2 * 255 * 512)
     3877                        LogRel(("Warning: Floppy image is larger that 63.5 MB! (%llu bytes)\n", cbFloppyImg));
     3878                    break;
     3879            }
     3880            if (pThis->enmType != enmCfgType)
     3881                LogRel(("DrvVD: Automatically upgraded floppy drive from %s to %s to better support the %u byte image\n",
     3882                        drvvdGetTypeName(enmCfgType), drvvdGetTypeName(pThis->enmType), cbFloppyImg));
     3883        }
     3884    } /* !fEmptyDrive */
    33263885
    33273886    if (RT_FAILURE(rc))
  • trunk/src/VBox/Devices/build/VBoxDD.cpp

    r57989 r59248  
    222222    if (RT_FAILURE(rc))
    223223        return rc;
    224     rc = pCallbacks->pfnRegister(pCallbacks, &g_DrvBlock);
    225     if (RT_FAILURE(rc))
    226         return rc;
    227224    rc = pCallbacks->pfnRegister(pCallbacks, &g_DrvVD);
    228225    if (RT_FAILURE(rc))
     
    238235        return rc;
    239236#endif
    240     rc = pCallbacks->pfnRegister(pCallbacks, &g_DrvMediaISO);
    241     if (RT_FAILURE(rc))
    242         return rc;
    243     rc = pCallbacks->pfnRegister(pCallbacks, &g_DrvRawImage);
    244     if (RT_FAILURE(rc))
    245         return rc;
    246237    rc = pCallbacks->pfnRegister(pCallbacks, &g_DrvNAT);
    247238    if (RT_FAILURE(rc))
  • trunk/src/VBox/Devices/build/VBoxDD.h

    r57989 r59248  
    9292extern const PDMDRVREG g_DrvMouseQueue;
    9393extern const PDMDRVREG g_DrvKeyboardQueue;
    94 extern const PDMDRVREG g_DrvBlock;
    9594extern const PDMDRVREG g_DrvVBoxHDD;
    9695extern const PDMDRVREG g_DrvVD;
    9796extern const PDMDRVREG g_DrvHostDVD;
    9897extern const PDMDRVREG g_DrvHostFloppy;
    99 extern const PDMDRVREG g_DrvMediaISO;
    100 extern const PDMDRVREG g_DrvRawImage;
    10198extern const PDMDRVREG g_DrvISCSI;
    10299extern const PDMDRVREG g_DrvISCSITransportTcp;
  • trunk/src/VBox/Devices/testcase/tstDeviceStructSizeRC.cpp

    r59183 r59248  
    892892    GEN_CHECK_OFF(ATADevState, cErrors);
    893893    GEN_CHECK_OFF(ATADevState, pDrvBase);
    894     GEN_CHECK_OFF(ATADevState, pDrvBlock);
    895     GEN_CHECK_OFF(ATADevState, pDrvBlockBios);
     894    GEN_CHECK_OFF(ATADevState, pDrvMedia);
    896895    GEN_CHECK_OFF(ATADevState, pDrvMount);
    897896    GEN_CHECK_OFF(ATADevState, IBase);
     
    13491348    GEN_CHECK_OFF(AHCIPort, u32CurrentCommandSlot);
    13501349    GEN_CHECK_OFF(AHCIPort, pDrvBase);
    1351     GEN_CHECK_OFF(AHCIPort, pDrvBlock);
    1352     GEN_CHECK_OFF(AHCIPort, pDrvBlockAsync);
    1353     GEN_CHECK_OFF(AHCIPort, pDrvBlockBios);
     1350    GEN_CHECK_OFF(AHCIPort, pDrvMedia);
     1351    GEN_CHECK_OFF(AHCIPort, pDrvMediaAsync);
    13541352    GEN_CHECK_OFF(AHCIPort, pDrvMount);
    13551353    GEN_CHECK_OFF(AHCIPort, IBase);
  • trunk/src/VBox/Main/src-client/ConsoleImpl2.cpp

    r59229 r59248  
    42944294        else
    42954295        {
    4296             InsertConfigString(pLunL0, "Driver", "Block");
     4296#if 0 /* Enable for I/O debugging */
     4297            InsertConfigNode(pLunL0, "AttachedDriver", &pLunL0);
     4298            InsertConfigString(pLunL0, "Driver", "DiskIntegrity");
     4299            InsertConfigNode(pLunL0, "Config", &pCfg);
     4300            InsertConfigInteger(pCfg, "CheckConsistency", 0);
     4301            InsertConfigInteger(pCfg, "CheckDoubleCompletions", 1);
     4302#endif
     4303
     4304            InsertConfigString(pLunL0, "Driver", "VD");
    42974305            InsertConfigNode(pLunL0, "Config", &pCfg);
    42984306            switch (enmType)
     
    43504358                /* Index of last image */
    43514359                uImage--;
    4352 
    4353 #if 0 /* Enable for I/O debugging */
    4354                 InsertConfigNode(pLunL0, "AttachedDriver", &pLunL0);
    4355                 InsertConfigString(pLunL0, "Driver", "DiskIntegrity");
    4356                 InsertConfigNode(pLunL0, "Config", &pCfg);
    4357                 InsertConfigInteger(pCfg, "CheckConsistency", 0);
    4358                 InsertConfigInteger(pCfg, "CheckDoubleCompletions", 1);
    4359 #endif
    4360 
    4361                 InsertConfigNode(pLunL0, "AttachedDriver", &pLunL1);
    4362                 InsertConfigString(pLunL1, "Driver", "VD");
    4363                 InsertConfigNode(pLunL1, "Config", &pCfg);
    43644360
    43654361# ifdef VBOX_WITH_EXTPACK
     
    44364432                }
    44374433
    4438                 switch (enmType)
    4439                 {
    4440                     case DeviceType_DVD:
    4441                         InsertConfigString(pCfg, "Type", "DVD");
    4442                         break;
    4443                     case DeviceType_Floppy:
    4444                         InsertConfigString(pCfg, "Type", "Floppy");
    4445                         break;
    4446                     case DeviceType_HardDisk:
    4447                     default:
    4448                         InsertConfigString(pCfg, "Type", "HardDisk");
    4449                 }
    4450 
    44514434                if (pcszBwGroup)
    44524435                    InsertConfigString(pCfg, "BwGroup", pcszBwGroup);
     
    45004483                if (fEncrypted)
    45014484                    m_cDisksEncrypted++;
     4485            }
     4486            else
     4487            {
     4488                /* Set empty drive flag for DVD or floppy without media. */
     4489                if (   enmType == DeviceType_DVD
     4490                    || enmType == DeviceType_Floppy)
     4491                    InsertConfigInteger(pCfg, "EmptyDrive", 1);
    45024492            }
    45034493        }
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette