浏览代码

Make Toolbox doCountFiles count the same way as onListFiles

Niels Martin Hansen 1 年之前
父节点
当前提交
0fcb1b987d
共有 1 个文件被更改,包括 9 次插入2 次删除
  1. 9 2
      src/Toolbox.cpp

+ 9 - 2
src/Toolbox.cpp

@@ -30,6 +30,9 @@ extern "C" {
 }
 }
 
 
 
 
+const uint8_t MAX_FILE_LISTING_FILES = 100;
+
+
 extern "C" int8_t scsiToolboxEnabled()
 extern "C" int8_t scsiToolboxEnabled()
 {
 {
     static int8_t enabled = -1;
     static int8_t enabled = -1;
@@ -72,15 +75,19 @@ static void doCountFiles(const char * dir_name, bool isCD = false)
             break;
             break;
         }
         }
         bool isDir = file.isDirectory();
         bool isDir = file.isDirectory();
-        file.getName(name, MAX_FILE_PATH);
+        size_t len = file.getName(name, MAX_FILE_PATH);
         file.close();
         file.close();
         if (isCD && isDir)
         if (isCD && isDir)
             continue;
             continue;
+        // truncate filename the same way listing does, before validating name
+        if (len > MAX_MAC_PATH)
+            name[MAX_MAC_PATH] = 0x0;
+        dbgmsg("TOOLBOX COUNT FILES: truncated filename is '", name, "'");
         // only count valid files.
         // only count valid files.
         if(toolboxFilenameValid(name, isCD))
         if(toolboxFilenameValid(name, isCD))
         {
         {
             file_count = file_count + 1;
             file_count = file_count + 1;
-            if(file_count > 100) {
+            if(file_count > MAX_FILE_LISTING_FILES) {
                 scsiDev.status = CHECK_CONDITION;
                 scsiDev.status = CHECK_CONDITION;
                 scsiDev.target->sense.code = ILLEGAL_REQUEST;
                 scsiDev.target->sense.code = ILLEGAL_REQUEST;
                 scsiDev.target->sense.asc = OPEN_RETRO_SCSI_TOO_MANY_FILES;
                 scsiDev.target->sense.asc = OPEN_RETRO_SCSI_TOO_MANY_FILES;