knob_os/src/hal/Storage.h

29 lines
795 B
C++
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#pragma once
// Storage.h —— TF 卡挂载与互斥
//
// TF 卡同一时刻只能被一个"持有者"访问:UI 线程读图、Web 线程传文件。
// 这里用递归互斥锁把并发访问串起来,锁粒度由调用方决定(整文件操作请持有到结束)。
#include <Arduino.h>
#include <vector>
namespace hal {
bool storageBegin(); // 挂载失败不阻塞启动,只记日志
bool storageReady();
uint64_t storageTotalBytes();
uint64_t storageUsedBytes();
void storageLock();
void storageUnlock();
// 目录列举(名字不含路径),失败返回空
std::vector<String> listDir(const String& dirPath);
// 带锁的 RAII 守卫
struct StorageLock {
StorageLock() { storageLock(); }
~StorageLock() { storageUnlock(); }
};
} // namespace hal