Skip to content

How to correctly separate volume manager from file handles #220

@nsallis

Description

@nsallis

I keep running into this issue where I want to refactor to have a function like get_file_handle(path: &str). The idea is that I don't want to copy-paste all the volume manager code (selecting the volume, getting the root directory etc) all over the place. Instead, I want to get back a clean file handle that I can use to read/write etc.

Because file handles are derived from the volume manager, volume, and root_dir this this doesn't work since, upon returning from get_file_handle they would get killed. I've tried several ways of getting around this, but none seem to work. What's the "correct" way to do this.

Details:
I currently keep the volume manager in a shared, static state behind a mutex. This is because I'm using sdmmc with picoserve which uses tasks/threads. So far the threading seems to work fine.

I'm using the https://esp32.implrust.com/sdcard/write-sdcard.html as the basis of writing to my sd card.

Example of (very) POC function to do this:

Image

Error on return: cannot return value referencing local variable root_dir returns a value referencing data owned by the current function (and the same error for volume_mgr and vol0)

The APP_STATE field is defined like so: pub sd_volume_mgr: Mutex<CriticalSectionRawMutex, Option<Arc<Mutex<CriticalSectionRawMutex, VolumeManager<SdCard<CriticalSectionDevice<'static, Spi<'static, esp_hal::Blocking>, Output<'static>, EmbassyDelay>, EmbassyDelay>, Clock>>>>>,

I'm sure this has to be a common use-case and I'm probably misunderstanding how we should be using sdmmc. Some pointers might help here though!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions