4# error("ZephyrSD only supported by zephyr")
8#include <zephyr/fs/fs.h>
9#include <zephyr/storage/disk_access.h>
11#include <zephyr/sys/util.h>
13BUILD_ASSERT(IS_ENABLED(CONFIG_FILE_SYSTEM),
"Filesystem required");
51 ZephyrFile open(
const char *path,
const char *mode =
"r",
bool create =
false) {
53 LOGE(
"SD not mounted");
66 LOGE(
"SD not mounted");
71 file.
open(path, mode);
75 bool exists(
const char *path)
const {
77 return fs_stat(path, &entry) == 0;
82 return logErr(ret,
"fs_unlink", path);
85 bool rename(
const char *from,
const char *to) {
87 return logErr(ret,
"fs_rename", from, to);
92 return logErr(ret,
"fs_mkdir", path);
97 return logErr(ret,
"fs_rmdir", path);
102 if (
fs_stat(path, &entry) == 0) {
139 if (mode[0] ==
'r') {
142 else if (mode[0] ==
'w') {
145 else if (mode[0] ==
'a') {
159 LOGE(
"disk_access_init(%s) failed: %d",
disk_name.c_str(), ret);
171 LOGI(
"SD: %llu MiB", (
unsigned long long)
mb);
181 LOGI(
"SD mounted at %s",
mp.mnt_point);
190 LOGE(
"fs_unmount failed: %d", ret);
196 bool logErr(
int ret,
const char *op,
const char *path) {
198 LOGE(
"%s(%s) failed: %d", op, path, ret);
204 bool logErr(
int ret,
const char *op,
const char *
a,
const char *
b) {
206 LOGE(
"%s(%s -> %s) failed: %d", op,
a,
b, ret);
#define LOGI(...)
Definition AudioLoggerIDF.h:28
#define LOGE(...)
Definition AudioLoggerIDF.h:30
BUILD_ASSERT(IS_ENABLED(CONFIG_FILE_SYSTEM), "Filesystem required")