1
0
Fork 0

Fix some issues with mounting floppy images with invalid bootsector.

Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@2602
This commit is contained in:
Peter Veenstra 2006-04-17 10:45:32 +00:00
parent 0b6195208d
commit 329d32a8dd
4 changed files with 37 additions and 31 deletions

View file

@ -16,7 +16,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* $Id: dos_programs.cpp,v 1.57 2006-04-07 15:15:45 qbix79 Exp $ */
/* $Id: dos_programs.cpp,v 1.58 2006-04-17 10:45:32 qbix79 Exp $ */
#include <stdlib.h>
#include <string.h>
@ -54,22 +54,22 @@ public:
/* Check for unmounting */
if (cmd->FindString("-u",umount,false)) {
umount[0] = toupper(umount[0]);
int drive = umount[0]-'A';
if(drive < DOS_DRIVES && Drives[drive]) {
if(drive == DOS_GetDefaultDrive()) {
int i_drive = umount[0]-'A';
if(i_drive < DOS_DRIVES && Drives[i_drive]) {
if(i_drive == DOS_GetDefaultDrive()) {
WriteOut(MSG_Get("PROGRAM_MOUNT_UMOUNT_CURRENT"));
return;
}
try { /* Check if virtualdrive */
if( dynamic_cast<localDrive*>(Drives[drive]) == 0 ) throw 0;
if( dynamic_cast<localDrive*>(Drives[i_drive]) == 0 ) throw 0;
}
catch(...) {
WriteOut(MSG_Get("PROGRAM_MOUNT_UMOUNT_NO_VIRTUAL"));
return;
}
WriteOut(MSG_Get("PROGRAM_MOUNT_UMOUNT_SUCCES"),umount[0]);
delete Drives[drive];
Drives[drive] = 0;
delete Drives[i_drive];
Drives[i_drive] = 0;
} else {
WriteOut(MSG_Get("PROGRAM_MOUNT_UMOUNT_NOT_MOUNTED"),umount[0]);
}
@ -331,7 +331,8 @@ public:
}
/* Test for and show free EMS */
Bit16u handle;
if (DOS_OpenFile("EMMXXXX0",0,&handle)) {
char emm[9] = { 'E','M','M','X','X','X','X','0',0 };
if (DOS_OpenFile(emm,0,&handle)) {
DOS_CloseFile(handle);
reg_ah=0x42;
CALLBACK_RunRealInt(0x67);
@ -714,8 +715,8 @@ public:
WriteOut(MSG_Get("PROGRAM_IMGMOUNT_SPECIFY2"));
return;
}
drive=temp_line[0]-'0';
if(drive>3) {
drive=temp_line[0];
if((drive-'0')>3) {
WriteOut(MSG_Get("PROGRAM_IMGMOUNT_SPECIFY2"));
return;
}
@ -739,13 +740,13 @@ public:
char tmp[CROSS_LEN];
safe_strncpy(tmp, temp_line.c_str(), CROSS_LEN);
Bit8u drive;
if (!DOS_MakeName(tmp, fullname, &drive) || strncmp(Drives[drive]->GetInfo(),"local directory",15)) {
Bit8u dummy;
if (!DOS_MakeName(tmp, fullname, &dummy) || strncmp(Drives[dummy]->GetInfo(),"local directory",15)) {
WriteOut(MSG_Get("PROGRAM_IMGMOUNG_FILE_NOT_FOUND"));
return;
}
localDrive *ldp = (localDrive*)Drives[drive];
localDrive *ldp = (localDrive*)Drives[dummy];
ldp->GetSystemFilename(tmp, fullname);
temp_line = tmp;
@ -762,6 +763,10 @@ public:
if(fstype=="fat") {
newdrive=new fatDrive(temp_line.c_str(),sizes[0],sizes[1],sizes[2],sizes[3],0);
if(!(dynamic_cast<fatDrive*>(newdrive))->created_succesfully) {
delete newdrive;
newdrive = 0;
}
} else if (fstype=="iso") {
int error;
MSCDEX_SetCDInterface(CDROM_USE_SDL, -1);
@ -798,7 +803,7 @@ public:
if (newdrive) delete newdrive;
return;
}
if (!newdrive) WriteOut(MSG_Get("PROGRAM_IMGMOUNT_CANT_CREATE"));
if (!newdrive) {WriteOut(MSG_Get("PROGRAM_IMGMOUNT_CANT_CREATE"));return;}
Drives[drive-'A']=newdrive;
// Set the correct media byte in the table
mem_writeb(Real2Phys(dos.tables.mediaid)+(drive-'A')*2,mediaid);
@ -830,10 +835,10 @@ public:
mem_writeb(Real2Phys(dos.tables.mediaid)+(drive-'A')*2,mediaid);
WriteOut(MSG_Get("PROGRAM_MOUNT_STATUS_2"),drive,temp_line.c_str());
} else if (fstype=="none") {
if(imageDiskList[drive] != NULL) delete imageDiskList[drive];
imageDiskList[drive] = newImage;
if(imageDiskList[drive-'0'] != NULL) delete imageDiskList[drive-'0'];
imageDiskList[drive-'0'] = newImage;
updateDPT();
WriteOut(MSG_Get("PROGRAM_IMGMOUNT_MOUNT_NUMBER"),drive,temp_line.c_str());
WriteOut(MSG_Get("PROGRAM_IMGMOUNT_MOUNT_NUMBER"),drive-'0',temp_line.c_str());
}
// check if volume label is given

View file

@ -16,7 +16,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* $Id: drive_fat.cpp,v 1.12 2006-02-20 08:59:52 qbix79 Exp $ */
/* $Id: drive_fat.cpp,v 1.13 2006-04-17 10:45:32 qbix79 Exp $ */
#include <stdio.h>
#include <stdlib.h>
@ -582,6 +582,7 @@ bool fatDrive::allocateCluster(Bit32u useCluster, Bit32u prevCluster) {
}
fatDrive::fatDrive(const char *sysFilename, Bit32u bytesector, Bit32u cylsector, Bit32u headscyl, Bit32u cylinders, Bit32u startSector) {
created_succesfully = true;
FILE *diskfile;
Bit32u filesize;
struct partTable mbrData;
@ -593,14 +594,14 @@ fatDrive::fatDrive(const char *sysFilename, Bit32u bytesector, Bit32u cylsector,
}
diskfile = fopen(sysFilename, "rb+");
if(!diskfile) return;
if(!diskfile) {created_succesfully = false;return;}
fseek(diskfile, 0L, SEEK_END);
filesize = (Bit32u)ftell(diskfile) / 1024L;
/* Load disk image */
/* Load disk image */
loadedDisk = new imageDisk(diskfile, (Bit8u *)sysFilename, filesize, (filesize > 2880));
if(!loadedDisk) {
delete this;
created_succesfully = false;
return;
}
@ -629,13 +630,12 @@ fatDrive::fatDrive(const char *sysFilename, Bit32u bytesector, Bit32u cylsector,
loadedDisk->Read_AbsoluteSector(0+partSectOff,&bootbuffer);
if ((bootbuffer.magic1 != 0x55) || (bootbuffer.magic2 != 0xaa)) {
/* Not a FAT filesystem */
delete this;
return;
LOG_MSG("Loaded image has no valid magicnumbers at the end!");
}
if(!bootbuffer.sectorsperfat) {
/* FAT32 not implemented yet */
delete this;
created_succesfully = false;
return;
}
@ -673,7 +673,7 @@ fatDrive::fatDrive(const char *sysFilename, Bit32u bytesector, Bit32u cylsector,
cwdDirCluster = 0;
memset(fatSectBuffer,0,1024);
curFatSect = 0xffffffff;
curFatSect = 0xffffffff;
}
bool fatDrive::AllocationInfo(Bit16u *_bytes_sector, Bit8u *_sectors_cluster, Bit16u *_total_clusters, Bit16u *_free_clusters) {

View file

@ -16,7 +16,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* $Id: drive_local.cpp,v 1.65 2006-04-16 14:04:03 qbix79 Exp $ */
/* $Id: drive_local.cpp,v 1.66 2006-04-17 10:45:30 qbix79 Exp $ */
#include <stdio.h>
#include <stdlib.h>
@ -114,7 +114,7 @@ bool localDrive::FileOpen(DOS_File * * file,char * name,Bit32u flags) {
return true;
};
FILE * localDrive::GetSystemFilePtr(char * name, char * type) {
FILE * localDrive::GetSystemFilePtr(char const * const name, char const * const type) {
char newname[CROSS_LEN];
strcpy(newname,basedir);
@ -125,7 +125,7 @@ FILE * localDrive::GetSystemFilePtr(char * name, char * type) {
return fopen(newname,type);
}
bool localDrive::GetSystemFilename(char *sysName, char *dosName) {
bool localDrive::GetSystemFilename(char *sysName, char const * const dosName) {
strcpy(sysName, basedir);
strcat(sysName, dosName);

View file

@ -16,7 +16,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* $Id: drives.h,v 1.31 2006-02-12 13:32:30 qbix79 Exp $ */
/* $Id: drives.h,v 1.32 2006-04-17 10:45:32 qbix79 Exp $ */
#ifndef _DRIVES_H__
#define _DRIVES_H__
@ -33,8 +33,8 @@ class localDrive : public DOS_Drive {
public:
localDrive(const char * startdir,Bit16u _bytes_sector,Bit8u _sectors_cluster,Bit16u _total_clusters,Bit16u _free_clusters,Bit8u _mediaid);
virtual bool FileOpen(DOS_File * * file,char * name,Bit32u flags);
virtual FILE *GetSystemFilePtr(char * name, char * type);
virtual bool GetSystemFilename(char *sysName, char *dosName);
virtual FILE *GetSystemFilePtr(char const * const name, char const * const type);
virtual bool GetSystemFilename(char* sysName, char const * const dosName);
virtual bool FileCreate(DOS_File * * file,char * name,Bit16u attributes);
virtual bool FileUnlink(char * name);
virtual bool RemoveDir(char * dir);
@ -153,6 +153,7 @@ public:
bool directoryBrowse(Bit32u dirClustNumber, direntry *useEntry, Bit32s entNum);
bool directoryChange(Bit32u dirClustNumber, direntry *useEntry, Bit32s entNum);
imageDisk *loadedDisk;
bool created_succesfully;
private:
Bit32u getClusterValue(Bit32u clustNum);
void setClusterValue(Bit32u clustNum, Bit32u clustValue);