USB MSC mount name

marcelstoer
Posts: 11
Joined: Sun Aug 23, 2020 8:09 pm

USB MSC mount name

Postby marcelstoer » Fri May 10, 2024 9:57 pm

Is there a way to set the USB MSC mount name the device shows up as? My device mounts as "NO NAME" (on macOS) and that's kind of annoying - especially if you have multiple MSC devices you're testing with. I'm already calling 'msc.vendorID()' and 'msc.productID()' but none of it appears to have an impact on the mount name. Also, I haven't found any documentation on this behavior.

lbernstone
Posts: 791
Joined: Mon Jul 22, 2019 3:20 pm

Re: USB MSC mount name

Postby lbernstone » Fri May 10, 2024 10:53 pm

The partition label is a filesystem function. On your Mac, go into the properties for the msc partition and see if you can change the label there, and if that sticks after removal and reinsertion. We can see about changing it on the esp side during format if that works.
On my linux machine, running the USBMSC.ino example, I get the label "ESP32S2 MSC" as expected.

marcelstoer
Posts: 11
Joined: Sun Aug 23, 2020 8:09 pm

Re: USB MSC mount name

Postby marcelstoer » Sat May 11, 2024 6:36 am

Thanks for the feedback. What part of that example should make it appear as "ESP32S2 MSC"? I see there's a "volume_label padded with spaces" option but that one is set to "TinyUSB MSC".

lbernstone
Posts: 791
Joined: Mon Jul 22, 2019 3:20 pm

Re: USB MSC mount name

Postby lbernstone » Sat May 11, 2024 4:22 pm

It is the first "file" entry in the index table.
https://github.com/espressif/arduino-es ... no#L87-L88
I'd recommend you set both the volume and partition label to the same thing. They have them set different in the example to demonstrate, but some (old) OS's may still use the volume label.

marcelstoer
Posts: 11
Joined: Sun Aug 23, 2020 8:09 pm

Re: USB MSC mount name

Postby marcelstoer » Sun May 12, 2024 5:57 pm

I see, thanks.

My code was inspired by https://github.com/Munsutari/esp32-s3-i ... h_test.ino using the EspClass class. Hence, it is much simpler (i.e. on a higher abstraction level) than the example you linked to and I use this with PlatformIO.

Given that for FAT12 the volume label is a trait of the root dir, I tried to manipulate the first 12 bytes of the root dir. However, `FFat.open("/", FILE_WRITE)` doesn't give me an FS object for which `availableForWrite()` is true. Hence, I can't manipulate it.

lbernstone
Posts: 791
Joined: Mon Jul 22, 2019 3:20 pm

Re: USB MSC mount name

Postby lbernstone » Sun May 12, 2024 8:34 pm

Oh, it is absolutely not a normal file (hence my quotes in the earlier post). It is normally set with the f_setlabel command, but this is not compiled into the arduino library. Let me fiddle around if it can be implemented stand-alone.

marcelstoer
Posts: 11
Joined: Sun Aug 23, 2020 8:09 pm

Re: USB MSC mount name

Postby marcelstoer » Sun May 12, 2024 9:02 pm

lbernstone wrote:
Sun May 12, 2024 8:34 pm
Oh, it is absolutely not a normal file
:D yes, I'm aware of that. I'm just surprised that I didn't find any information so far that would explain permissions or restrictions. It would be great if F_Fat::format also accepted a volume label in addition to the partition label.

lbernstone
Posts: 791
Joined: Mon Jul 22, 2019 3:20 pm

Re: USB MSC mount name

Postby lbernstone » Tue May 14, 2024 11:35 pm

Note this has very few guardrails

Code: Select all

uint32_t u8to32(const uint8_t d1, const uint8_t d2, const uint8_t d3, const uint8_t d4) {
  return (d4<<24) + (d3<<16) + (d2<<8) + d1;   
}

bool setVolName(const char* volname) {
  if (strlen(volname) > 11) {
    Serial.println("Volume name can only be 11 characters");
    return false;
  }
  const esp_partition_t* Part = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_FAT, NULL);
  uint32_t diskbuf[1024];
  if (esp_partition_read(Part, 0, diskbuf, 4096) != ESP_OK) {
    Serial.println("Unable to read ffat partition");
    return false;
  }
  char set_name[13];
  snprintf(set_name, 13, "%-11s%c", volname, 8);
// First grouping is old school partition name
  diskbuf[10] = (diskbuf[10] & 0x00FFFFFF) | (set_name[0]<<24);
  diskbuf[11] = u8to32(set_name[1],set_name[2],set_name[3],set_name[4]);
  diskbuf[12] = u8to32(set_name[5],set_name[6],set_name[7],set_name[8]);
  diskbuf[13] = (diskbuf[13] & 0xFFFF0000) | set_name[9] | (set_name[10]<<8);
  if (esp_partition_erase_range(Part, 0, 4096)) return false;
  if (esp_partition_write(Part, 0, diskbuf, 4096)) return false;
// Second grouping is the volume name that will likely be used
  esp_partition_read(Part, 0x2000, diskbuf, 4096);
  diskbuf[8] = u8to32(set_name[0],set_name[1],set_name[2],set_name[3]);
  diskbuf[9] = u8to32(set_name[4],set_name[5],set_name[6],set_name[7]);
  diskbuf[10] = u8to32(set_name[8],set_name[9],set_name[10],set_name[11]);
  esp_partition_erase_range(Part, 0x2000, 4096);
  if (esp_partition_write(Part, 0x2000, diskbuf, 4096)) return false;
  return true;
}

marcelstoer
Posts: 11
Joined: Sun Aug 23, 2020 8:09 pm

Re: USB MSC mount name

Postby marcelstoer » Sat May 18, 2024 10:16 am

Thanks Larry, works like a charm!

This is too good to be hidden away in some forum thread? I could integrate it into an example at https://github.com/espressif/arduino-es ... les/USBMSC or https://github.com/espressif/arduino-es ... t/examples. WDYT?

lbernstone
Posts: 791
Joined: Mon Jul 22, 2019 3:20 pm

Re: USB MSC mount name

Postby lbernstone » Sat May 18, 2024 6:02 pm

It's a bit too dangerous to be in an example. Anyhow, there is a CONFIG_ setting that would put the legit f_setlabel() function into the libraries (which works on FAT32 & ExFAT). I'll see about getting that into the lib-builder; then it would just be adding a one liner function to the FFat and SD libraries. I'm working on an example based on yours that will expose an SD card.

Who is online

Users browsing this forum: No registered users and 49 guests