Skip to content

Commit

Permalink
FAT driver bugfix: Check disk change on GetFileAttr(). Fix disk chang…
Browse files Browse the repository at this point in the history
…e handling bug that read the BPB but failed to use it
  • Loading branch information
joncampbell123 committed Jul 18, 2024
1 parent e837f5a commit 13276da
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/dos/dos_programs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6349,7 +6349,7 @@ class IMGMOUNT : public Program {
if (image->class_id == imageDisk::ID_INT13) {
imageDiskINT13Drive *x = (imageDiskINT13Drive*)image;
x->enable_int13 = true;
LOG_MSG("INT 13 image enabling calling");
LOG(LOG_MISC,LOG_DEBUG)("INT 13 image enabling calling");
}
}
return true;
Expand Down
12 changes: 10 additions & 2 deletions src/dos/drive_fat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2293,6 +2293,10 @@ void fatDrive::fatDriveInit(const char *sysFilename, uint32_t bytesector, uint32
CountOfClusters = DataSectors / BPB.v.BPB_SecPerClus;
firstDataSector = ((Bitu)BPB.v.BPB_RsvdSecCnt + ((Bitu)BPB.v.BPB_NumFATs * (Bitu)BPB.v.BPB_FATSz16) + (Bitu)RootDirSectors) + (Bitu)partSectOff;
firstRootDirSect = (Bitu)BPB.v.BPB_RsvdSecCnt + ((Bitu)BPB.v.BPB_NumFATs * (Bitu)BPB.v.BPB_FATSz16) + (Bitu)partSectOff;

LOG(LOG_MISC,LOG_DEBUG)("INIT FAT: data=%llu root=%llu rootdirsect=%lu datasect=%lu",
(unsigned long long)firstDataSector,(unsigned long long)firstRootDirSect,
(unsigned long)RootDirSectors,(unsigned long)DataSectors);
}

if(CountOfClusters < 4085) {
Expand Down Expand Up @@ -3087,6 +3091,8 @@ bool fatDrive::SetFileAttr(const char *name, uint16_t attr) {
bool fatDrive::GetFileAttr(const char *name, uint16_t *attr) {
if (unformatted) return false;

checkDiskChange();

direntry fileEntry = {};
uint32_t dirClust, subEntry;

Expand Down Expand Up @@ -3673,7 +3679,7 @@ void fatDrive::checkDiskChange(void) {
* to read it. Furthermore, at some parts of the demo, the INT 13h hook changes the root
* directory and FAT table to make the next "disk" appear, even if the volume label does not. */
if (loadedDisk->detectDiskChange() && !BPB.is_fat32()) {
LOG_MSG("FAT: disk change\n");
LOG(LOG_MISC,LOG_DEBUG)("FAT: disk change");

FAT_BootSector bootbuffer = {};
loadedDisk->Read_AbsoluteSector(0+partSectOff,&bootbuffer);
Expand All @@ -3699,6 +3705,8 @@ void fatDrive::checkDiskChange(void) {
var = &bootbuffer.bpb.v.BPB_VolID;
bootbuffer.bpb.v.BPB_VolID = var_read((uint32_t*)var);

BPB = bootbuffer.bpb;

if (BPB.v.BPB_FATSz16 == 0) {
LOG_MSG("BPB_FATSz16 == 0 and not FAT32 BPB, not valid");
return;
Expand All @@ -3723,7 +3731,7 @@ void fatDrive::checkDiskChange(void) {
memset(fatSectBuffer,0,1024);
curFatSect = 0xffffffff;

LOG_MSG("NEW FAT: data=%llu root=%llu rootdirsect=%lu datasect=%lu",
LOG(LOG_MISC,LOG_DEBUG)("NEW FAT: data=%llu root=%llu rootdirsect=%lu datasect=%lu",
(unsigned long long)firstDataSector,(unsigned long long)firstRootDirSect,
(unsigned long)RootDirSectors,(unsigned long)DataSectors);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ints/bios_disk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3918,7 +3918,7 @@ bool imageDiskINT13Drive::detectDiskChange(void) {

if (reg_flags & FLAG_CF) {
if (reg_ah == 0x06) {
LOG_MSG("INT13 image disk change flag\n");
LOG(LOG_MISC,LOG_DEBUG)("INT13 image disk change flag");
diskChangeFlag = true;
}
}
Expand Down

0 comments on commit 13276da

Please sign in to comment.