Skip to content

Commit

Permalink
toolbox: Make Toolbox doCountFiles count the same way as onListFiles
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsmh authored and erichelgeson committed May 10, 2024
1 parent 43fe446 commit 029787a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/BlueSCSI_Toolbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,20 @@ static void doCountFiles(const char * dir_name)
file.close();
break;
}
file.getName(name, MAX_FILE_PATH);
bool isDir = file.isDirectory();
size_t len = file.getName(name, MAX_FILE_PATH);
file.close();
if (isDir)
continue;
// truncate filename the same way listing does, before validating name
if (len > MAX_MAC_PATH)
name[MAX_MAC_PATH] = 0x0;
debuglog("TOOLBOX COUNT FILES: truncated filename is '", name, "'");
// only count valid files.
if(toolboxFilenameValid(name))
{
file_count = file_count + 1;
if(file_count > 100) {
if(file_count > MAX_FILE_LISTING_FILES) {
scsiDev.status = CHECK_CONDITION;
scsiDev.target->sense.code = ILLEGAL_REQUEST;
scsiDev.target->sense.asc = OPEN_RETRO_SCSI_TOO_MANY_FILES;
Expand Down
1 change: 1 addition & 0 deletions src/BlueSCSI_Toolbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#define MAX_MAC_PATH 32
#define ENTRY_SIZE 40
#define MAX_FILE_LISTING_FILES 100

#define CD_IMG_DIR "CD%d"

Expand Down

0 comments on commit 029787a

Please sign in to comment.