Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers: disk: add fakefat disk driver #62286

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

jfischer-no
Copy link
Collaborator

@jfischer-no jfischer-no commented Sep 5, 2023

Fakefat disk emulates a disk formatted with the FAT file system.
The driver supports FAT16 and FAT32 emulation and multiple instances.
A backend can register at least 15 emulated files on a disk instance.
The file structure contain read and write callbacks that are called
when the filesystem driver accesses the volume. A backend can have
multiple files with read callbacks, but usually only one or zero with
write callbacks.

Fakefat disk can be used for testing or to map services such as
firmware updates to a file on the emulated disk.
Complementary to #53798

TODO:

  • sample README.rst
  • documentation
  • tests

@jfischer-no jfischer-no added area: Drivers area: USB Universal Serial Bus area: Disk Access Experimental Experimental features not enabled by default labels Sep 5, 2023
@github-actions github-actions bot added the Stale label Nov 5, 2023
@jfischer-no jfischer-no removed the Stale label Nov 8, 2023
@zephyrproject-rtos zephyrproject-rtos deleted a comment from github-actions bot Nov 8, 2023
@github-actions github-actions bot added the Stale label Jan 8, 2024
@zephyrproject-rtos zephyrproject-rtos deleted a comment from github-actions bot Jan 9, 2024
@jfischer-no jfischer-no removed the Stale label Jan 9, 2024
@jfischer-no
Copy link
Collaborator Author

@petejohanson You might find it useful for your fancy stuff.

@petejohanson
Copy link
Contributor

@petejohanson You might find it useful for your fancy stuff.

Interesting.. possibly useful for some of our testing scenarios or development with the posix targets.

Copy link

@desowin desowin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't expect this to work.

The "ffdisk" name is horrible because it looks like typo. Why are you using such ridiculously short names recently (that are completely unreadable)? What's wrong with just using "fakefatdisk"?

Comment on lines +627 to +631
/*
* For now, we ignore write accesses from the (host) filesystem driver
* to all sectors except the data area. Perhaps we can use some of these
* to implement a mounted/unmounted state indication callback.
*/
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How this is not leading to absolutely bizzare and pretty much impossible to debug issues?

The idea of abusing FAT file system for specific uses that can work is https://github.com/microsoft/uf2. Note that UF2 operates on different principle and is pretty much limited to write only.

The fakefat in my opinion cannot really work reliably, because host pretty much has complete control over MSC disks.

I believe MTP is the solution for exporting fixed amount of files, not MSC.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How this is not leading to absolutely bizzare and pretty much impossible to debug issues?

What issues and for what use cases? The write accesses can be ignored because we do not change e.g. the FAT, what is emulated anyway.

The idea of abusing FAT file system for specific uses that can work is https://github.com/microsoft/uf2. Note that UF2 operates on different principle and is pretty much limited to write only.

This PR uses a similar principle (also similar to virtual_fs in daplink). One of my intentions is to use it to provide similar functionality as the DAPLink firmware. And I am pretty sure you can read emulated files in UF2 (and daplink's virtual_fs).

The fakefat in my opinion cannot really work reliably, because host pretty much has complete control over MSC disks.

I believe MTP is the solution for exporting fixed amount of files, not MSC.

It works very reliably for what it was developed for. It is not there to export arbitrary file systems or to be something like MTP.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Virtual fs in daplink is actively checking for problems (e.g. data being sent sequential) while this implementation does not.

UF2 is operating on different principle. UF2 only assumes that files are written on sector boundary (i.e. file does not start in the middle of sector) and has plenty of padding.

@jfischer-no
Copy link
Collaborator Author

I don't expect this to work.

The "ffdisk" name is horrible because it looks like typo. Why are you using such ridiculously short names recently (that are completely unreadable)? What's wrong with just using "fakefatdisk"?

What exactly do you not expect to work? Or what is not working for you? Where did you find ffdisk? (Why would I use ridiculously long names?)

@jfischer-no jfischer-no requested review from de-nordic and removed request for kartben, nashif and galak October 21, 2024 16:19
Fakefat disk emulates a disk formatted with the FAT file system.
The driver supports FAT16 and FAT32 emulation and multiple instances.
A backend can register at least 15 emulated files on a disk instance.
The file structure contain read and write callbacks that are called
when the filesystem driver accesses the volume. A backend can have
multiple files with read callbacks, but usually only one or zero with
write callbacks.

Fakefat disk can be used for testing or to map services such as
firmware updates to a file on the emulated disk.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Add FAT16 and FAT32 tests for the FFAT disk using ELM FAT file system
support.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
This sample has two volumes, FAT16 and FAT32, exported via
new USB device MSC support.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
@tmon-nordic
Copy link
Contributor

What exactly do you not expect to work? Or what is not working for you?

When the host reorders the files, e.g. deletes a file and then creates a new one things will break.

Why would I use ridiculously long names?

Code is written for humans. It is annoying when something that can be mistaken as a typo has some very special meaning behind it. In my opinion longer names are generally better because such names avoid ambiguity and are especially helpful for newcomers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Devicetree area: Disk Access area: Drivers area: Samples Samples area: Storage Storage subsystem area: USB Universal Serial Bus Experimental Experimental features not enabled by default
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants