Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fs/fatfs: Add modlog to fatfs #3351

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions fs/fatfs/src/mynewt_glue.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
Expand All @@ -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);
}
Expand All @@ -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;
}

Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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) {
Expand All @@ -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);

Expand All @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand All @@ -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) {
Expand All @@ -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);
Expand Down
12 changes: 12 additions & 0 deletions fs/fatfs/syscfg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)