From 5f965cc48bd287e3226a49ae07be8cb742bf2ac7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Strohh=C3=A4cker?= Date: Sun, 17 Jun 2007 12:26:35 +0000 Subject: [PATCH] allow read-only disk images to be booted (fixes some booter games) Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@2891 --- src/dos/dos_programs.cpp | 41 ++++++++++++++++++++++++++++------------ src/ints/bios_disk.cpp | 6 +++--- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/src/dos/dos_programs.cpp b/src/dos/dos_programs.cpp index 61504b47..dc9a4e33 100644 --- a/src/dos/dos_programs.cpp +++ b/src/dos/dos_programs.cpp @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: dos_programs.cpp,v 1.74 2007-06-12 20:22:08 c2woody Exp $ */ +/* $Id: dos_programs.cpp,v 1.75 2007-06-17 12:26:35 c2woody Exp $ */ #include "dosbox.h" #include @@ -403,21 +403,30 @@ private: ldp=dynamic_cast(Drives[drive]); if(!ldp) return NULL; - tmpfile = ldp->GetSystemFilePtr(fullname, "r"); + tmpfile = ldp->GetSystemFilePtr(fullname, "rb"); if(tmpfile == NULL) { if (!tryload) *error=1; return NULL; } - fclose(tmpfile); - tmpfile = ldp->GetSystemFilePtr(fullname, "rb+"); - if(tmpfile == NULL) { - if (!tryload) *error=2; - return NULL; - } + // get file size fseek(tmpfile,0L, SEEK_END); *ksize = (ftell(tmpfile) / 1024); *bsize = ftell(tmpfile); + fclose(tmpfile); + + tmpfile = ldp->GetSystemFilePtr(fullname, "rb+"); + if(tmpfile == NULL) { +// if (!tryload) *error=2; +// return NULL; + WriteOut(MSG_Get("PROGRAM_BOOT_WRITE_PROTECTED")); + tmpfile = ldp->GetSystemFilePtr(fullname, "rb"); + if(tmpfile == NULL) { + if (!tryload) *error=1; + return NULL; + } + } + return tmpfile; } catch(...) { @@ -430,12 +439,19 @@ private: FILE* tmpfile = getFSFile_mounted(filename,ksize,bsize,&error); if(tmpfile) return tmpfile; //File not found on mounted filesystem. Try regular filesystem - tmpfile = fopen(filename,"rb+"); + std::string filename_s(filename); + ResolveHomedir(filename_s); + tmpfile = fopen(filename_s.c_str(),"rb+"); if(!tmpfile) { - if( (tmpfile = fopen(filename,"r")) ) { + if( (tmpfile = fopen(filename_s.c_str(),"rb")) ) { //File exists; So can't be opened in correct mode => error 2 - fclose(tmpfile); - if(tryload) error = 2; +// fclose(tmpfile); +// if(tryload) error = 2; + WriteOut(MSG_Get("PROGRAM_BOOT_WRITE_PROTECTED")); + fseek(tmpfile,0L, SEEK_END); + *ksize = (ftell(tmpfile) / 1024); + *bsize = ftell(tmpfile); + return tmpfile; } // Give the delayed errormessages from the mounted variant (or from above) if(error == 1) WriteOut(MSG_Get("PROGRAM_BOOT_NOT_EXIST")); @@ -1363,6 +1379,7 @@ void DOS_SetupPrograms(void) { ); MSG_Add("PROGRAM_BOOT_NOT_EXIST","Bootdisk file does not exist. Failing.\n"); MSG_Add("PROGRAM_BOOT_NOT_OPEN","Cannot open bootdisk file. Failing.\n"); + MSG_Add("PROGRAM_BOOT_WRITE_PROTECTED","Image file is read-only! Might create problems.\n"); MSG_Add("PROGRAM_BOOT_PRINT_ERROR","This command boots DOSBox from either a floppy or hard disk image.\n\n" "For this command, one can specify a succession of floppy disks swappable\n" "by pressing Ctrl-F4, and -l specifies the mounted drive to boot from. If\n" diff --git a/src/ints/bios_disk.cpp b/src/ints/bios_disk.cpp index b97a5b1f..5b56feba 100644 --- a/src/ints/bios_disk.cpp +++ b/src/ints/bios_disk.cpp @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: bios_disk.cpp,v 1.35 2007-06-12 20:22:08 c2woody Exp $ */ +/* $Id: bios_disk.cpp,v 1.36 2007-06-17 12:26:35 c2woody Exp $ */ #include "dosbox.h" #include "callback.h" @@ -173,9 +173,9 @@ Bit8u imageDisk::Write_AbsoluteSector(Bit32u sectnum, void *data) { //LOG_MSG("Writing sectors to %ld at bytenum %d", sectnum, bytenum); fseek(diskimg,bytenum,SEEK_SET); - fwrite(data, sector_size, 1, diskimg); + size_t ret=fwrite(data, sector_size, 1, diskimg); - return 0x00; + return ((ret>0)?0x00:0x05); }