From 92c5771c4d38c8192401964d7ea471ddb7be51ce Mon Sep 17 00:00:00 2001 From: Peter Veenstra Date: Thu, 16 Apr 2009 12:16:52 +0000 Subject: [PATCH] Prepare system to mode current drive to sda. Check for problems with rename.(fixes linux rename). Small warning fixes + style changes. Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@3345 --- src/dos/dos.cpp | 5 ++-- src/dos/dos_classes.cpp | 62 +++++++++++++++++------------------------ src/dos/dos_files.cpp | 37 ++++++++++++++++++++---- src/dos/dos_ioctl.cpp | 4 +-- 4 files changed, 62 insertions(+), 46 deletions(-) diff --git a/src/dos/dos.cpp b/src/dos/dos.cpp index cd3ff0eb..fd5ebbe1 100644 --- a/src/dos/dos.cpp +++ b/src/dos/dos.cpp @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: dos.cpp,v 1.116 2009-03-14 16:10:00 c2woody Exp $ */ +/* $Id: dos.cpp,v 1.117 2009-04-16 12:16:52 qbix79 Exp $ */ #include #include @@ -397,7 +397,7 @@ static Bitu DOS_21Handler(void) { case 0x1f: /* Get drive parameter block for default drive */ case 0x32: /* Get drive parameter block for specific drive */ { /* Officially a dpb should be returned as well. The disk detection part is implemented */ - Bitu drive=reg_dl;if(!drive || reg_ah==0x1f) drive=dos.current_drive;else drive--; + Bitu drive=reg_dl;if(!drive || reg_ah==0x1f) drive = DOS_GetDefaultDrive();else drive--; if(Drives[drive]) { reg_al = 0x00; SegSet16(ds,dos.tables.dpb); @@ -1126,6 +1126,7 @@ public: DOS_SetupMemory(); /* Setup first MCB */ DOS_SetupPrograms(); DOS_SetupMisc(); /* Some additional dos interrupts */ + DOS_SDA(DOS_SDA_SEG,DOS_SDA_OFS).SetDrive(25); /* Else the next call gives a warning. */ DOS_SetDefaultDrive(25); dos.version.major=5; diff --git a/src/dos/dos_classes.cpp b/src/dos/dos_classes.cpp index 85e829e5..70b6c14b 100644 --- a/src/dos/dos_classes.cpp +++ b/src/dos/dos_classes.cpp @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: dos_classes.cpp,v 1.55 2008-09-07 10:55:14 c2woody Exp $ */ +/* $Id: dos_classes.cpp,v 1.56 2009-04-16 12:16:52 qbix79 Exp $ */ #include #include @@ -210,41 +210,36 @@ void DOS_PSP::MakeNew(Bit16u mem_size) { if (rootpsp==0) rootpsp = seg; } -Bit8u DOS_PSP::GetFileHandle(Bit16u index) -{ +Bit8u DOS_PSP::GetFileHandle(Bit16u index) { if (index>=sGet(sPSP,max_files)) return 0xff; PhysPt files=Real2Phys(sGet(sPSP,file_table)); return mem_readb(files+index); -}; +} -void DOS_PSP::SetFileHandle(Bit16u index, Bit8u handle) -{ +void DOS_PSP::SetFileHandle(Bit16u index, Bit8u handle) { if (indexGetFileHandle(i); @@ -266,53 +261,46 @@ void DOS_PSP::CopyFileTable(DOS_PSP* srcpsp,bool createchildpsp) SetFileHandle(i,handle); } } -}; +} -void DOS_PSP::CloseFiles(void) -{ +void DOS_PSP::CloseFiles(void) { for (Bit16u i=0;i20) { // Allocate needed paragraphs fileNum+=2; // Add a few more files for safety @@ -327,7 +315,7 @@ bool DOS_PSP::SetNumFiles(Bit16u fileNum) sSave(sPSP,max_files,fileNum); }; return true; -}; +} void DOS_DTA::SetupSearch(Bit8u _sdrive,Bit8u _sattr,char * pattern) { @@ -480,7 +468,7 @@ void DOS_FCB::FileClose(Bit8u & _fhandle) { Bit8u DOS_FCB::GetDrive(void) { Bit8u drive=sGet(sFCB,drive); - if (!drive) return dos.current_drive; + if (!drive) return DOS_GetDefaultDrive(); else return drive-1; } diff --git a/src/dos/dos_files.cpp b/src/dos/dos_files.cpp index 45903976..363bb1bf 100644 --- a/src/dos/dos_files.cpp +++ b/src/dos/dos_files.cpp @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: dos_files.cpp,v 1.107 2009-03-23 21:58:05 c2woody Exp $ */ +/* $Id: dos_files.cpp,v 1.108 2009-04-16 12:16:52 qbix79 Exp $ */ #include #include @@ -45,11 +45,15 @@ DOS_File * Files[DOS_FILES]; DOS_Drive * Drives[DOS_DRIVES]; Bit8u DOS_GetDefaultDrive(void) { +// return DOS_SDA(DOS_SDA_SEG,DOS_SDA_OFS).GetDrive(); + Bit8u d = DOS_SDA(DOS_SDA_SEG,DOS_SDA_OFS).GetDrive(); + if( d != dos.current_drive ) LOG(LOG_DOSMISC,LOG_ERROR)("SDA drive %d not the same as dos.current_drive %d",d,dos.current_drive); return dos.current_drive; } void DOS_SetDefaultDrive(Bit8u drive) { - if (drive<=DOS_DRIVES && ((drive<2) || Drives[drive])) dos.current_drive = drive; +// if (drive<=DOS_DRIVES && ((drive<2) || Drives[drive])) DOS_SDA(DOS_SDA_SEG,DOS_SDA_OFS).SetDrive(drive); + if (drive<=DOS_DRIVES && ((drive<2) || Drives[drive])) {dos.current_drive = drive; DOS_SDA(DOS_SDA_SEG,DOS_SDA_OFS).SetDrive(drive);} } bool DOS_MakeName(char const * const name,char * const fullname,Bit8u * drive) { @@ -63,7 +67,7 @@ bool DOS_MakeName(char const * const name,char * const fullname,Bit8u * drive) { char tempdir[DOS_PATHLENGTH]; char upname[DOS_PATHLENGTH]; Bitu r,w; - *drive=dos.current_drive; + *drive = DOS_GetDefaultDrive(); /* First get the drive */ if (name_int[1]==':') { *drive=(name_int[0] | 0x20)-'a'; @@ -256,8 +260,31 @@ bool DOS_Rename(char const * const oldname,char const * const newname) { Bit8u drivenew;char fullnew[DOS_PATHLENGTH]; if (!DOS_MakeName(oldname,fullold,&driveold)) return false; if (!DOS_MakeName(newname,fullnew,&drivenew)) return false; - //TODO Test for different drives maybe + /* No tricks with devices */ + if ( (DOS_FindDevice(oldname) != DOS_DEVICES) || + (DOS_FindDevice(newname) != DOS_DEVICES) ) { + DOS_SetError(DOSERR_FILE_NOT_FOUND); + return false; + } + /* Must be on the same drive */ + if(driveold != drivenew) { + DOS_SetError(DOSERR_NOT_SAME_DEVICE); + return false; + } + /*Test if target exists => no access */ + if(Drives[drivenew]->FileExists(fullnew)) { + DOS_SetError(DOSERR_ACCESS_DENIED); + return false; + } + /* Source must exist, check for path ? */ + if(!Drives[driveold]->FileExists(fullold)) { + DOS_SetError(DOSERR_FILE_NOT_FOUND); + return false; + } + if (Drives[drivenew]->Rename(fullold,fullnew)) return true; + /* If it still fails. which error should we give ? PATH NOT FOUND or EACCESS */ + LOG(LOG_FILES,LOG_NORMAL)("Rename fails on %c from %s to %s, no proper errorcode returned.",driveold+'A',oldname,newname); DOS_SetError(DOSERR_FILE_NOT_FOUND); return false; } @@ -1139,7 +1166,7 @@ bool DOS_FileExists(char const * const name) { } bool DOS_GetAllocationInfo(Bit8u drive,Bit16u * _bytes_sector,Bit8u * _sectors_cluster,Bit16u * _total_clusters) { - if (!drive) drive=dos.current_drive; + if (!drive) drive = DOS_GetDefaultDrive(); else drive--; if (drive >= DOS_DRIVES || !Drives[drive]) return false; Bit16u _free_clusters; diff --git a/src/dos/dos_ioctl.cpp b/src/dos/dos_ioctl.cpp index 342b113e..57c53777 100644 --- a/src/dos/dos_ioctl.cpp +++ b/src/dos/dos_ioctl.cpp @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: dos_ioctl.cpp,v 1.34 2009-03-24 17:07:30 c2woody Exp $ */ +/* $Id: dos_ioctl.cpp,v 1.35 2009-04-16 12:16:52 qbix79 Exp $ */ #include #include "dosbox.h" @@ -40,7 +40,7 @@ bool DOS_IOCTL(void) { } } else if (reg_al<0x12) { /* those use a diskdrive except 0x0b */ if (reg_al!=0x0b) { - drive=reg_bl;if (!drive) drive=dos.current_drive;else drive--; + drive=reg_bl;if (!drive) drive = DOS_GetDefaultDrive();else drive--; if( !(( drive < DOS_DRIVES ) && Drives[drive]) ) { DOS_SetError(DOSERR_INVALID_DRIVE); return false;