1
0
Fork 0

Unify unmounting code. Fix unmounting of complex drives where parts were left and file pointers were kept open. (thanks jmarsh)

Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@4205
This commit is contained in:
Peter Veenstra 2019-04-11 15:48:04 +00:00
parent 8688dc9702
commit ee2d3e73ce

View file

@ -59,6 +59,37 @@ Bitu DEBUG_EnableDebugger(void);
void MSCDEX_SetCDInterface(int intNr, int forceCD);
static Bitu ZDRIVE_NUM = 25;
static const char* UnmountHelper(char umount) {
int i_drive;
if (umount < '0' || umount > 3+'0')
i_drive = toupper(umount) - 'A';
else
i_drive = umount - '0';
if (i_drive >= DOS_DRIVES || i_drive < 0 || (Drives[i_drive] == NULL && imageDiskList[i_drive] == NULL))
return MSG_Get("PROGRAM_MOUNT_UMOUNT_NOT_MOUNTED");
if (Drives[i_drive]) {
switch (DriveManager::UnmountDrive(i_drive)) {
case 1: return MSG_Get("PROGRAM_MOUNT_UMOUNT_NO_VIRTUAL");
case 2: return MSG_Get("MSCDEX_ERROR_MULTIPLE_CDROMS");
}
Drives[i_drive] = 0;
mem_writeb(Real2Phys(dos.tables.mediaid)+i_drive*9,0);
if (i_drive == DOS_GetDefaultDrive()) {
DOS_SetDrive(ZDRIVE_NUM);
}
}
if (imageDiskList[i_drive]) {
delete imageDiskList[i_drive];
imageDiskList[i_drive] = NULL;
}
return MSG_Get("PROGRAM_MOUNT_UMOUNT_SUCCESS");
}
class MOUNT : public Program {
public:
void ListMounts(void) {
@ -120,27 +151,7 @@ public:
/* Check for unmounting */
if (cmd->FindString("-u",umount,false)) {
umount[0] = toupper(umount[0]);
int i_drive = umount[0]-'A';
if (i_drive < DOS_DRIVES && i_drive >= 0 && Drives[i_drive]) {
switch (DriveManager::UnmountDrive(i_drive)) {
case 0:
Drives[i_drive] = 0;
mem_writeb(Real2Phys(dos.tables.mediaid)+i_drive*9,0);
if(i_drive == DOS_GetDefaultDrive())
DOS_SetDrive(ZDRIVE_NUM);
WriteOut(MSG_Get("PROGRAM_MOUNT_UMOUNT_SUCCESS"),umount[0]);
break;
case 1:
WriteOut(MSG_Get("PROGRAM_MOUNT_UMOUNT_NO_VIRTUAL"));
break;
case 2:
WriteOut(MSG_Get("MSCDEX_ERROR_MULTIPLE_CDROMS"));
break;
}
} else {
WriteOut(MSG_Get("PROGRAM_MOUNT_UMOUNT_NOT_MOUNTED"),umount[0]);
}
WriteOut(UnmountHelper(umount[0]), toupper(umount[0]));
return;
}
@ -1150,26 +1161,7 @@ public:
std::string umount;
/* Check for unmounting */
if (cmd->FindString("-u",umount,false)) {
umount[0] = toupper(umount[0]);
int i_drive = umount[0]-'A';
if (i_drive < DOS_DRIVES && i_drive >= 0 && Drives[i_drive]) {
switch (DriveManager::UnmountDrive(i_drive)) {
case 0:
Drives[i_drive] = 0;
if (i_drive == DOS_GetDefaultDrive())
DOS_SetDrive(toupper('Z') - 'A');
WriteOut(MSG_Get("PROGRAM_MOUNT_UMOUNT_SUCCESS"),umount[0]);
break;
case 1:
WriteOut(MSG_Get("PROGRAM_MOUNT_UMOUNT_NO_VIRTUAL"));
break;
case 2:
WriteOut(MSG_Get("MSCDEX_ERROR_MULTIPLE_CDROMS"));
break;
}
} else {
WriteOut(MSG_Get("PROGRAM_MOUNT_UMOUNT_NOT_MOUNTED"),umount[0]);
}
WriteOut(UnmountHelper(umount[0]), toupper(umount[0]));
return;
}