This is an automated email from the ASF dual-hosted git repository.

kasjer pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
     new 9ca5c949f tinyusb/msc_fat_view: Fix multi sector root write
9ca5c949f is described below

commit 9ca5c949fdd71363247e8fed83aa0948dd23118a
Author: Jerzy Kasenberg <[email protected]>
AuthorDate: Tue Sep 29 14:00:42 2026 +0200

    tinyusb/msc_fat_view: Fix multi sector root write
    
    When root directory was using more then 1 sector,
    to allow for more entries, entreis that span
    across sectors resulted in crash.
    
    Since long names are not really used for detecting
    new file writes, those are skipped if entry
    span two sectors. Short name is in one sector
    and can successfuly indicate new file.
    
    Additionally entreies starting with 0 stop scanning
    directory entries.
    
    Signed-off-by: Jerzy Kasenberg <[email protected]>
---
 hw/usb/tinyusb/msc_fat_view/src/msc_fat_view.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/hw/usb/tinyusb/msc_fat_view/src/msc_fat_view.c 
b/hw/usb/tinyusb/msc_fat_view/src/msc_fat_view.c
index a2aeb49f1..df4ba2f25 100644
--- a/hw/usb/tinyusb/msc_fat_view/src/msc_fat_view.c
+++ b/hw/usb/tinyusb/msc_fat_view/src/msc_fat_view.c
@@ -1051,9 +1051,11 @@ msc_fat_view_write_root_sector(uint32_t sector, const 
uint8_t *buffer)
 
     MSC_FAT_VIEW_LOG_INFO("Write root dir sector %d\n", sector);
 
-    for (i = 0; i < root_dir_entry_count; ++i) {
-        if (root_dir[i].deleted == 0) {
-            root_dir[i].deleted = 1;
+    if (sector == 0) {
+        for (i = 0; i < root_dir_entry_count; ++i) {
+            if (root_dir[i].deleted == 0) {
+                root_dir[i].deleted = 1;
+            }
         }
     }
 
@@ -1061,10 +1063,17 @@ msc_fat_view_write_root_sector(uint32_t sector, const 
uint8_t *buffer)
         if (entry->bytes[0] == 0xe5) {
             continue;
         }
+        if (entry->bytes[0] == 0x00) {
+            break;
+        }
         if (entry->attr == 0xF) {
             /* Long file name */
             if (entry->sequence & 0x40) {
                 n = (entry->sequence & 0xF);
+                if (entry + n > limit) {
+                    MSC_FAT_VIEW_LOG_DEBUG("Entry accross sectors\n");
+                    break;
+                }
                 checksum = entry->checksum;
 
                 while (n) {

Reply via email to