Skip to content

Commit

Permalink
Fix localDrive not listing '.' and '..' entries when using certain Li…
Browse files Browse the repository at this point in the history
…nux file systems (#519)

This fixes a crash during boot of an installed operating system on Android which expects these entries to exist.
  • Loading branch information
schellingb committed Oct 15, 2024
1 parent 0e9c62e commit f6294f3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
15 changes: 15 additions & 0 deletions src/dos/drive_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,21 @@ bool DOS_Drive_Cache::ReadDir(Bit16u id, char* &result) {
sprintf(buffer,"DIR: Caching in %s (%d Files)",dirPath,dirSearch[srchNr]->fileList.size());
LOG_DEBUG(buffer);
};*/

//DBP: Make sure "." and ".." exist in directories (some Linux filesystems don't report them)
//DBP: Make sure "." and ".." doesn't exist in the drive root
const bool isroot = (strlen(dirPath) == strlen(basePath));
std::vector<CFileInfo*>& filelist = dirSearch[id]->fileList;
for (std::vector<CFileInfo*>::iterator it = filelist.begin(), itend = filelist.end(); it != itend; ++it)
if ((*it)->shortname[0] == '.' && (*it)->shortname[1] != '\0')
{ if (isroot) filelist.erase(it); goto founddot; } // remove superfluous entry
if (!isroot) CreateEntry(dirSearch[id], ".", true); // add missing entry
founddot:
for (std::vector<CFileInfo*>::iterator it = filelist.begin(), itend = filelist.end(); it != itend; ++it)
if ((*it)->shortname[0] == '.' && (*it)->shortname[1] == '.' && (*it)->shortname[2] == '\0')
{ if (isroot) filelist.erase(it); goto founddotdot; } // remove superfluous entry
if (!isroot) CreateEntry(dirSearch[id], "..", true); // add missing entry
founddotdot:;
};
if (SetResult(dirSearch[id], result, dirSearch[id]->nextEntry)) return true;
if (dirSearch[id]) {
Expand Down
4 changes: 2 additions & 2 deletions src/ints/bios_disk.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2002-2021 The DOSBox Team
* Copyright (C) 2022-2023 Bernhard Schelling
* Copyright (C) 2022-2024 Bernhard Schelling
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -345,7 +345,7 @@ struct fatFromDOSDrive
dta.GetResult(dta_name, dta_size, dta_date, dta_time, dta_attr);
const char *fend = dta_name + strlen(dta_name);
const bool dot = (dta_name[0] == '.' && dta_name[1] == '\0'), dotdot = (dta_name[0] == '.' && dta_name[1] == '.' && dta_name[2] == '\0');
if (!dirlen && (dot || dotdot)) continue; // root shouldn't have dot entries (yet localDrive does...)
if (!dirlen && (dot || dotdot)) continue; // root shouldn't have dot entries (yet unpatched localDrive can)

ffddFile f;
memcpy(f.path, dir, dirlen);
Expand Down

0 comments on commit f6294f3

Please sign in to comment.