This is an automated email from the ASF dual-hosted git repository.
jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
The following commit(s) were added to refs/heads/master by this push:
new 6fc066805 fs/fatfs: Add modlog to fatfs
6fc066805 is described below
commit 6fc066805b10e0499c6639c5bfd30d5769ec089a
Author: Jerzy Kasenberg <[email protected]>
AuthorDate: Wed Nov 20 21:29:12 2024 +0100
fs/fatfs: Add modlog to fatfs
This adds logging to fatfs.
Signed-off-by: Jerzy Kasenberg <[email protected]>
Signed-off-by: Jerzy Kasenberg <[email protected]>
---
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 643227b2c..47008c293 100644
--- a/fs/fatfs/src/mynewt_glue.c
+++ b/fs/fatfs/src/mynewt_glue.c
@@ -22,6 +22,7 @@
#include <stdlib.h>
#include <string.h>
#include "os/mynewt.h"
+#include <modlog/modlog.h>
#include <hal/hal_flash.h>
#include <disk/disk.h>
#include <flash_map/flash_map.h>
@@ -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", 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", path, rc);
+
if (file) free(file);
if (out_file) free(out_file);
+ } else {
+ FATFS_LOG_DEBUG("File %s opened %p", 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", 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", 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", 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", 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", 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", 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", 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", 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", 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", path, *out_fs_dir);
+
out:
free(fatfs_path);
if (rc != FS_EOK) {
+ FATFS_LOG_ERROR("Open dir %s failed %d", 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", 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", fs_dir);
+
res = f_closedir(dir);
free(dir);
free(fs_dir);
diff --git a/fs/fatfs/syscfg.yml b/fs/fatfs/syscfg.yml
index 5c5131aaa..a446eca8b 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)