From 83acd0aa2331f7b58ae6b728c89f484a1017917c Mon Sep 17 00:00:00 2001 From: Jerzy Kasenberg Date: Wed, 20 Nov 2024 21:29:12 +0100 Subject: [PATCH] fs/fatfs: Add modlog to fatfs This adds logging to fatfs. Signed-off-by: Jerzy Kasenberg --- fs/fatfs/src/mynewt_glue.c | 33 +++++++++++++++++++++++++++++++++ fs/fatfs/syscfg.yml | 12 ++++++++++++ 2 files changed, 45 insertions(+) diff --git a/fs/fatfs/src/mynewt_glue.c b/fs/fatfs/src/mynewt_glue.c index 643227b2c9..c02d1dd5ce 100644 --- a/fs/fatfs/src/mynewt_glue.c +++ b/fs/fatfs/src/mynewt_glue.c @@ -22,6 +22,7 @@ #include #include #include "os/mynewt.h" +#include #include #include #include @@ -261,6 +262,8 @@ fatfs_open(const char *path, uint8_t access_flags, struct fs_file **out_fs_file) char *fatfs_path = NULL; int rc; + FATFS_LOG_DEBUG("Open file %s\n", path); + file = malloc(sizeof(struct fatfs_file)); if (!file) { rc = FS_ENOMEM; @@ -307,8 +310,12 @@ fatfs_open(const char *path, uint8_t access_flags, struct fs_file **out_fs_file) out: free(fatfs_path); if (rc != FS_EOK) { + FATFS_LOG_ERROR("File %s open failed %d\n", path, rc); + if (file) free(file); if (out_file) free(out_file); + } else { + FATFS_LOG_DEBUG("File %s opened %p\n", path, *out_fs_file); } return rc; } @@ -319,6 +326,8 @@ fatfs_close(struct fs_file *fs_file) FRESULT res = FR_OK; FIL *file = ((struct fatfs_file *) fs_file)->file; + FATFS_LOG_DEBUG("Open file %p\n", fs_file); + if (file != NULL) { res = f_close(file); free(file); @@ -334,6 +343,8 @@ fatfs_seek(struct fs_file *fs_file, uint32_t offset) FRESULT res; FIL *file = ((struct fatfs_file *) fs_file)->file; + FATFS_LOG_DEBUG("File %p seek %u\n", fs_file, offset); + res = f_lseek(file, offset); return fatfs_to_vfs_error(res); } @@ -355,6 +366,8 @@ fatfs_file_len(const struct fs_file *fs_file, uint32_t *out_len) *out_len = (uint32_t) f_size(file); + FATFS_LOG_DEBUG("File %p len %u\n", fs_file, *out_len); + return FS_EOK; } @@ -366,6 +379,8 @@ fatfs_read(struct fs_file *fs_file, uint32_t len, void *out_data, FIL *file = ((struct fatfs_file *) fs_file)->file; UINT uint_len; + FATFS_LOG_DEBUG("File %p read %u\n", fs_file, len); + res = f_read(file, out_data, len, &uint_len); *out_len = uint_len; return fatfs_to_vfs_error(res); @@ -378,6 +393,8 @@ fatfs_write(struct fs_file *fs_file, const void *data, int len) UINT out_len; FIL *file = ((struct fatfs_file *) fs_file)->file; + FATFS_LOG_DEBUG("File %p write %u\n", fs_file, len); + res = f_write(file, data, len, &out_len); if (len != out_len) { return FS_EFULL; @@ -391,6 +408,8 @@ fatfs_flush(struct fs_file *fs_file) FRESULT res; FIL *file = ((struct fatfs_file *)fs_file)->file; + FATFS_LOG_DEBUG("Flush %p\n", fs_file); + res = f_sync(file); return fatfs_to_vfs_error(res); @@ -402,6 +421,8 @@ fatfs_unlink(const char *path) FRESULT res; char *fatfs_path; + FATFS_LOG_INFO("Unlink %s\n", path); + fatfs_path = fatfs_path_from_fs_path(path); if (fatfs_path == NULL) { @@ -420,6 +441,8 @@ fatfs_rename(const char *from, const char *to) char *fatfs_src_path; char *fatfs_dst_path; + FATFS_LOG_INFO("Rename %s to %s\n", from, to); + fatfs_src_path = fatfs_path_from_fs_path(from); fatfs_dst_path = fatfs_path_from_fs_path(to); @@ -442,6 +465,8 @@ fatfs_mkdir(const char *path) FRESULT res; char *fatfs_path; + FATFS_LOG_INFO("Mkdir %s\n", path); + fatfs_path = fatfs_path_from_fs_path(path); if (fatfs_path == NULL) { @@ -486,9 +511,13 @@ fatfs_opendir(const char *path, struct fs_dir **out_fs_dir) *out_fs_dir = (struct fs_dir *)dir; rc = FS_EOK; + FATFS_LOG_INFO("Open dir %s -> %p\n", path, *out_fs_dir); + out: free(fatfs_path); if (rc != FS_EOK) { + FATFS_LOG_ERROR("Open dir %s failed %d\n", path, rc); + if (dir) free(dir); if (out_dir) free(out_dir); } @@ -501,6 +530,8 @@ fatfs_readdir(struct fs_dir *fs_dir, struct fs_dirent **out_fs_dirent) FRESULT res; FATFS_DIR *dir = ((struct fatfs_dir *) fs_dir)->dir; + FATFS_LOG_DEBUG("Read dir %p\n", fs_dir); + dirent.fops = &fatfs_ops; res = f_readdir(dir, &dirent.filinfo); if (res != FR_OK) { @@ -520,6 +551,8 @@ fatfs_closedir(struct fs_dir *fs_dir) FRESULT res; FATFS_DIR *dir = ((struct fatfs_dir *) fs_dir)->dir; + FATFS_LOG_INFO("Close dir %p\n", fs_dir); + res = f_closedir(dir); free(dir); free(fs_dir); diff --git a/fs/fatfs/syscfg.yml b/fs/fatfs/syscfg.yml index 5c5131aaae..a446eca8b1 100644 --- a/fs/fatfs/syscfg.yml +++ b/fs/fatfs/syscfg.yml @@ -22,3 +22,15 @@ syscfg.defs: description: > Sysinit stage for FATFS functionality. value: 200 + + FATFS_LOG_MODULE: + description: 'Numeric module ID to use for FATFS log messages.' + value: 253 + FATFS_LOG_LVL: + description: 'Minimum level for the FATFS log.' + value: 2 + +syscfg.logs: + FATFS_LOG: + module: MYNEWT_VAL(FATFS_LOG_MODULE) + level: MYNEWT_VAL(FATFS_LOG_LVL)