diff --git a/os/vfs/codegen/modules.xml b/os/vfs/codegen/modules.xml index 5854dc2aa..96f52e66e 100644 --- a/os/vfs/codegen/modules.xml +++ b/os/vfs/codegen/modules.xml @@ -1,11 +1,12 @@ - - - - - + + + + + + + ]> &vfs_driver_overlay; &vfs_driver_fatfs; + &vfs_driver_littlefs; &vfs_driver_streams; diff --git a/os/vfs/codegen/vfs_driver_littlefs.xml b/os/vfs/codegen/vfs_driver_littlefs.xml new file mode 100644 index 000000000..745f16324 --- /dev/null +++ b/os/vfs/codegen/vfs_driver_littlefs.xml @@ -0,0 +1,271 @@ + + + + + vfs_nodes.xml + vfs_drivers.xml + + + + oop_sequential_stream.h + + + + Maximum number of LittleFS file systems mounted. + + + + Number of directory nodes pre-allocated in the pool. + + + + Number of file nodes pre-allocated in the pool. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Global state of @p vfs_littlefs_driver_c + + + + + Module initialization. + + + + + Mounts a LittleFS volume. + + Immediate mount option. + + The operation result. + + + + + Unmounts a LittleFS volume. + Name of the volume to + be unmounted. + + The operation result. + + + + + + + + vfs.h + + + ff.h + + + + + + LittleFS inner @p lfs_dir_t structure. + + + + + Pointer to + the controlling driver. + Node mode flags. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + LittleFS inner @p lfs_file_t structure. + + + + + Pointer to + the controlling driver. + + Node mode flags. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Global state of @p vfs_littlefs_driver_c. + + + Pool of file system objects. + + + Pool of file info objects. + + + Pool of directory nodes. + + + Pool of file nodes. + + + Pool of file system objects. + + + Static storage of directory nodes. + + + Static storage of file nodes. + + + + + + \ No newline at end of file diff --git a/os/vfs/drivers/fatfs/drvfatfs.c b/os/vfs/drivers/fatfs/drvfatfs.c index ad166d179..4f0e9b2e8 100644 --- a/os/vfs/drivers/fatfs/drvfatfs.c +++ b/os/vfs/drivers/fatfs/drvfatfs.c @@ -1,5 +1,5 @@ /* - ChibiOS - Copyright (C) 2006..2023 Giovanni Di Sirio + ChibiOS - Copyright (C) 2006..2024 Giovanni Di Sirio Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/os/vfs/drivers/fatfs/drvfatfs.h b/os/vfs/drivers/fatfs/drvfatfs.h index 5d3eed2f1..9dfddaefd 100644 --- a/os/vfs/drivers/fatfs/drvfatfs.h +++ b/os/vfs/drivers/fatfs/drvfatfs.h @@ -1,5 +1,5 @@ /* - ChibiOS - Copyright (C) 2006..2023 Giovanni Di Sirio + ChibiOS - Copyright (C) 2006..2024 Giovanni Di Sirio Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/os/vfs/drivers/littlefs/drvlittlefs.c b/os/vfs/drivers/littlefs/drvlittlefs.c new file mode 100644 index 000000000..b21602097 --- /dev/null +++ b/os/vfs/drivers/littlefs/drvlittlefs.c @@ -0,0 +1,223 @@ +/* + ChibiOS - Copyright (C) 2006..2024 Giovanni Di Sirio + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +/** + * @file drvlittlefs.c + * @brief Generated VFS Little Driver source. + * @note This is a generated file, do not edit directly. + * + * @addtogroup DRVLITTLEFS + * @{ + */ + +#include "vfs.h" + +#if (VFS_CFG_ENABLE_DRV_LITTLEFS == TRUE) || defined(__DOXYGEN__) + +#include "ff.h" + +/*===========================================================================*/ +/* Module local definitions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local macros. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module exported variables. */ +/*===========================================================================*/ + +/** + * @brief Global state of @p vfs_littlefs_driver_c. + */ +struct vfs_littlefs_driver_static_struct vfs_littlefs_driver_static; + +/*===========================================================================*/ +/* Module local types. */ +/*===========================================================================*/ + +/** + * @class vfs_littlefs_dir_node_c + * @extends base_object_c, referenced_object_c, vfs_node_c, + * vfs_directory_node_c. + * + * + * @name Class @p vfs_littlefs_dir_node_c structures + * @{ + */ + +/** + * @brief Type of a VFS littlefs directory node class. + */ +typedef struct vfs_littlefs_dir_node vfs_littlefs_dir_node_c; + +/** + * @brief Class @p vfs_littlefs_dir_node_c virtual methods table. + */ +struct vfs_littlefs_dir_node_vmt { + /* From base_object_c.*/ + void (*dispose)(void *ip); + /* From referenced_object_c.*/ + void * (*addref)(void *ip); + object_references_t (*release)(void *ip); + /* From vfs_node_c.*/ + msg_t (*stat)(void *ip, vfs_stat_t *sp); + /* From vfs_directory_node_c.*/ + msg_t (*first)(void *ip, vfs_direntry_info_t *dip); + msg_t (*next)(void *ip, vfs_direntry_info_t *dip); + /* From vfs_littlefs_dir_node_c.*/ +}; + +/** + * @brief Structure representing a VFS littlefs directory node class. + */ +struct vfs_littlefs_dir_node { + /** + * @brief Virtual Methods Table. + */ + const struct vfs_littlefs_dir_node_vmt *vmt; + /** + * @brief Number of references to the object. + */ + object_references_t references; + /** + * @brief Driver handling this node. + */ + vfs_driver_c *driver; + /** + * @brief Node mode information. + */ + vfs_mode_t mode; + /** + * @brief LittleFS inner @p lfs_dir_t structure. + */ + lfs_dir_t dir; +}; +/** @} */ + +/** + * @class vfs_littlefs_file_node_c + * @extends base_object_c, referenced_object_c, vfs_node_c, + * vfs_file_node_c. + * @implements sequential_stream_i + * + * + * @name Class @p vfs_littlefs_file_node_c structures + * @{ + */ + +/** + * @brief Type of a VFS littlefs file node class. + */ +typedef struct vfs_littlefs_file_node vfs_littlefs_file_node_c; + +/** + * @brief Class @p vfs_littlefs_file_node_c virtual methods table. + */ +struct vfs_littlefs_file_node_vmt { + /* From base_object_c.*/ + void (*dispose)(void *ip); + /* From referenced_object_c.*/ + void * (*addref)(void *ip); + object_references_t (*release)(void *ip); + /* From vfs_node_c.*/ + msg_t (*stat)(void *ip, vfs_stat_t *sp); + /* From vfs_file_node_c.*/ + ssize_t (*read)(void *ip, uint8_t *buf, size_t n); + ssize_t (*write)(void *ip, const uint8_t *buf, size_t n); + msg_t (*setpos)(void *ip, vfs_offset_t offset, vfs_seekmode_t whence); + vfs_offset_t (*getpos)(void *ip); + sequential_stream_i * (*getstream)(void *ip); + /* From vfs_littlefs_file_node_c.*/ +}; + +/** + * @brief Structure representing a VFS littlefs file node class. + */ +struct vfs_littlefs_file_node { + /** + * @brief Virtual Methods Table. + */ + const struct vfs_littlefs_file_node_vmt *vmt; + /** + * @brief Number of references to the object. + */ + object_references_t references; + /** + * @brief Driver handling this node. + */ + vfs_driver_c *driver; + /** + * @brief Node mode information. + */ + vfs_mode_t mode; + /** + * @brief Implemented interface @p sequential_stream_i. + */ + sequential_stream_i stm; + /** + * @brief LittleFS inner @p lfs_file_t structure. + */ + lfs_file_t file; +}; +/** @} */ + +/** + * @brief Global state of @p vfs_littlefs_driver_c. + */ +struct vfs_littlefs_driver_static_struct { + /** + * @brief Pool of file system objects. + */ + memory_pool_t fs_pool; + /** + * @brief Pool of file info objects. + */ + memory_pool_t info_nodes_pool; + /** + * @brief Pool of directory nodes. + */ + memory_pool_t dir_nodes_pool; + /** + * @brief Pool of file nodes. + */ + memory_pool_t file_nodes_pool; + /** + * @brief Pool of file system objects. + */ + lfs_t fs[DRV_CFG_LITTLEFS_FS_NUM]; + /** + * @brief Static storage of directory nodes. + */ + vfs_littlefs_dir_node_c dir_nodes[DRV_CFG_LITTLEFS_DIR_NODES_NUM]; + /** + * @brief Static storage of file nodes. + */ + vfs_littlefs_file_node_c file_nodes[DRV_CFG_LITTLEFS_FILE_NODES_NUM]; +}; + +/*===========================================================================*/ +/* Module local variables. */ +/*===========================================================================*/ + +/* Module code has been generated into an hand-editable file and included + here.*/ +#include "drvlittlefs_impl.inc" + +#endif /* VFS_CFG_ENABLE_DRV_LITTLEFS == TRUE */ + +/** @} */ diff --git a/os/vfs/drivers/littlefs/drvlittlefs.h b/os/vfs/drivers/littlefs/drvlittlefs.h new file mode 100644 index 000000000..ee48586ab --- /dev/null +++ b/os/vfs/drivers/littlefs/drvlittlefs.h @@ -0,0 +1,201 @@ +/* + ChibiOS - Copyright (C) 2006..2024 Giovanni Di Sirio + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +/** + * @file drvlittlefs.h + * @brief Generated VFS Little Driver header. + * @note This is a generated file, do not edit directly. + * + * @addtogroup DRVLITTLEFS + * @{ + */ + +#ifndef DRVLITTLEFS_H +#define DRVLITTLEFS_H + +#if (VFS_CFG_ENABLE_DRV_LITTLEFS == TRUE) || defined(__DOXYGEN__) + +#include "oop_sequential_stream.h" + +/*===========================================================================*/ +/* Module constants. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module pre-compile time settings. */ +/*===========================================================================*/ + +/** + * @name Configuration options + * @{ + */ +/** + * @brief Maximum number of LittleFS file systems mounted. + */ +#if !defined(DRV_CFG_LITTLEFS_FS_NUM) || defined(__DOXYGEN__) +#define DRV_CFG_LITTLEFS_FS_NUM 1 +#endif + +/** + * @brief Number of directory nodes pre-allocated in the pool. + */ +#if !defined(DRV_CFG_LITTLEFS_DIR_NODES_NUM) || defined(__DOXYGEN__) +#define DRV_CFG_LITTLEFS_DIR_NODES_NUM 1 +#endif + +/** + * @brief Number of file nodes pre-allocated in the pool. + */ +#if !defined(DRV_CFG_LITTLEFS_FILE_NODES_NUM) || defined(__DOXYGEN__) +#define DRV_CFG_LITTLEFS_FILE_NODES_NUM 1 +#endif +/** @} */ + +/*===========================================================================*/ +/* Derived constants and error checks. */ +/*===========================================================================*/ + +/* Checks on DRV_CFG_LITTLEFS_FS_NUM configuration.*/ +#if DRV_CFG_LITTLEFS_FS_NUM < 1 +#error "invalid DRV_CFG_LITTLEFS_FS_NUM value" +#endif + +/* Checks on DRV_CFG_LITTLEFS_DIR_NODES_NUM configuration.*/ +#if DRV_CFG_LITTLEFS_DIR_NODES_NUM < 1 +#error "invalid DRV_CFG_LITTLEFS_DIR_NODES_NUM value" +#endif + +/* Checks on DRV_CFG_LITTLEFS_FILE_NODES_NUM configuration.*/ +#if DRV_CFG_LITTLEFS_FILE_NODES_NUM < 1 +#error "invalid DRV_CFG_LITTLEFS_FILE_NODES_NUM value" +#endif + +/*===========================================================================*/ +/* Module macros. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module data structures and types. */ +/*===========================================================================*/ + +/** + * @class vfs_littlefs_driver_c + * @extends base_object_c, vfs_driver_c. + * + * + * @name Class @p vfs_littlefs_driver_c structures + * @{ + */ + +/** + * @brief Type of a VFS littlefs driver class. + */ +typedef struct vfs_littlefs_driver vfs_littlefs_driver_c; + +/** + * @brief Class @p vfs_littlefs_driver_c virtual methods table. + */ +struct vfs_littlefs_driver_vmt { + /* From base_object_c.*/ + void (*dispose)(void *ip); + /* From vfs_driver_c.*/ + msg_t (*setcwd)(void *ip, const char *path); + msg_t (*getcwd)(void *ip, char *buf, size_t size); + msg_t (*stat)(void *ip, const char *path, vfs_stat_t *sp); + msg_t (*opendir)(void *ip, const char *path, vfs_directory_node_c **vdnpp); + msg_t (*openfile)(void *ip, const char *path, int flags, vfs_file_node_c **vfnpp); + msg_t (*unlink)(void *ip, const char *path); + msg_t (*rename)(void *ip, const char *oldpath, const char *newpath); + msg_t (*mkdir)(void *ip, const char *path, vfs_mode_t mode); + msg_t (*rmdir)(void *ip, const char *path); + /* From vfs_littlefs_driver_c.*/ +}; + +/** + * @brief Structure representing a VFS littlefs driver class. + */ +struct vfs_littlefs_driver { + /** + * @brief Virtual Methods Table. + */ + const struct vfs_littlefs_driver_vmt *vmt; +}; +/** @} */ + +/*===========================================================================*/ +/* External declarations. */ +/*===========================================================================*/ + +extern struct vfs_littlefs_driver_static_struct vfs_littlefs_driver_static; + +#ifdef __cplusplus +extern "C" { +#endif + /* Methods of vfs_littlefs_driver_c.*/ + void *__lfsdrv_objinit_impl(void *ip, const void *vmt); + void __lfsdrv_dispose_impl(void *ip); + msg_t __lfsdrv_setcwd_impl(void *ip, const char *path); + msg_t __lfsdrv_getcwd_impl(void *ip, char *buf, size_t size); + msg_t __lfsdrv_stat_impl(void *ip, const char *path, vfs_stat_t *sp); + msg_t __lfsdrv_opendir_impl(void *ip, const char *path, + vfs_directory_node_c **vdnpp); + msg_t __lfsdrv_openfile_impl(void *ip, const char *path, int flags, + vfs_file_node_c **vfnpp); + msg_t __lfsdrv_unlink_impl(void *ip, const char *path); + msg_t __lfsdrv_rename_impl(void *ip, const char *oldpath, + const char *newpath); + msg_t __lfsdrv_mkdir_impl(void *ip, const char *path, vfs_mode_t mode); + msg_t __lfsdrv_rmdir_impl(void *ip, const char *path); + /* Regular functions.*/ + void __drv_littlefs_init(void); + msg_t lfsdrvMount(const char *name, bool mountnow); + msg_t lfsdrvUnmount(const char *name); +#ifdef __cplusplus +} +#endif + +/*===========================================================================*/ +/* Module inline functions. */ +/*===========================================================================*/ + +/** + * @name Default constructor of vfs_littlefs_driver_c + * @{ + */ +/** + * @memberof vfs_littlefs_driver_c + * + * @brief Default initialization function of @p vfs_littlefs_driver_c. + * + * @param[out] self Pointer to a @p vfs_littlefs_driver_c instance + * to be initialized. + * @return Pointer to the initialized object. + * + * @objinit + */ +CC_FORCE_INLINE +static inline vfs_littlefs_driver_c *lfsdrvObjectInit(vfs_littlefs_driver_c *self) { + extern const struct vfs_littlefs_driver_vmt __vfs_littlefs_driver_vmt; + + return __lfsdrv_objinit_impl(self, &__vfs_littlefs_driver_vmt); +} +/** @} */ + +#endif /* VFS_CFG_ENABLE_DRV_LITTLEFS == TRUE */ + +#endif /* DRVLITTLEFS_H */ + +/** @} */ diff --git a/os/vfs/drivers/littlefs/drvlittlefs_impl.inc b/os/vfs/drivers/littlefs/drvlittlefs_impl.inc new file mode 100644 index 000000000..586303aff --- /dev/null +++ b/os/vfs/drivers/littlefs/drvlittlefs_impl.inc @@ -0,0 +1,697 @@ +/* + ChibiOS - Copyright (C) 2006..2024 Giovanni Di Sirio + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +/* This is an, automatically generated, implementation file that can be + manually edited, it is not re-generated if already present.*/ + +/*===========================================================================*/ +/* Module local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module exported functions. */ +/*===========================================================================*/ + +/** + * @brief Module initialization. + * + * @init + */ +void __drv_littlefs_init(void) { + + /* Initializing pools.*/ + chPoolObjectInit(&vfs_littlefs_driver_static.dir_nodes_pool, + sizeof (vfs_littlefs_dir_node_c), + chCoreAllocAlignedI); + chPoolObjectInit(&vfs_littlefs_driver_static.file_nodes_pool, + sizeof (vfs_littlefs_file_node_c), + chCoreAllocAlignedI); + chPoolObjectInit(&vfs_littlefs_driver_static.info_nodes_pool, + sizeof (struct lfs_info), + chCoreAllocAlignedI); + chPoolObjectInit(&vfs_littlefs_driver_static.fs_pool, + sizeof (lfs_t), + chCoreAllocAlignedI); + + /* Preloading pools.*/ + chPoolLoadArray(&vfs_littlefs_driver_static.dir_nodes_pool, + &vfs_littlefs_driver_static.dir_nodes[0], + DRV_CFG_LITTLEFS_DIR_NODES_NUM); + chPoolLoadArray(&vfs_littlefs_driver_static.file_nodes_pool, + &vfs_littlefs_driver_static.file_nodes[0], + DRV_CFG_LITTLEFS_FILE_NODES_NUM); + chPoolLoadArray(&vfs_littlefs_driver_static.fs_pool, + &vfs_littlefs_driver_static.fs[0], + DRV_CFG_LITTLEFS_FS_NUM); +} + +/** + * @brief Mounts a LittleFS volume. + * + * @param[in] name Name to be assigned to the volume, see LittleFS + * @p f_mount() documentation because there are + * several options. + * @param[in] mountnow Immediate mount option. + * @return The operation result. + * + * @api + */ +msg_t lfsdrvMount(const char *name, bool mountnow) { +} + +/** + * @brief Unmounts a LittleFS volume. + * + * @param[in] name Name of the volume to be unmounted. + * @return The operation result. + * + * @api + */ +msg_t lfsdrvUnmount(const char *name) { +} + +/*===========================================================================*/ +/* Module class "vfs_littlefs_dir_node_c" methods. */ +/*===========================================================================*/ + +/** + * @name Methods implementations of vfs_littlefs_dir_node_c + * @{ + */ +/** + * @memberof vfs_littlefs_dir_node_c + * @protected + * + * @brief Implementation of object creation. + * @note This function is meant to be used by derived classes. + * + * @param[out] ip Pointer to a @p vfs_littlefs_dir_node_c + * instance to be initialized. + * @param[in] vmt VMT pointer for the new object. + * @param[in] driver Pointer to the controlling driver. + * @param[in] mode Node mode flags. + * @return A new reference to the object. + */ +static void *__ffdir_objinit_impl(void *ip, const void *vmt, + vfs_driver_c *driver, vfs_mode_t mode) { + vfs_littlefs_dir_node_c *self = (vfs_littlefs_dir_node_c *)ip; + + /* Initialization code.*/ + self = __vfsdir_objinit_impl(ip, vmt, (vfs_driver_c *)driver, mode); + + return self; +} + +/** + * @memberof vfs_littlefs_dir_node_c + * @protected + * + * @brief Implementation of object finalization. + * @note This function is meant to be used by derived classes. + * + * @param[in,out] ip Pointer to a @p vfs_littlefs_dir_node_c + * instance to be disposed. + */ +static void __ffdir_dispose_impl(void *ip) { + vfs_littlefs_dir_node_c *self = (vfs_littlefs_dir_node_c *)ip; + + /* No finalization code.*/ + (void)self; + + /* Finalization of the ancestors-defined parts.*/ + __vfsdir_dispose_impl(self); +} + +/** + * @memberof vfs_littlefs_dir_node_c + * @protected + * + * @brief Override of method @p vfsNodeStat(). + * + * @param[in,out] ip Pointer to a @p vfs_littlefs_dir_node_c + * instance. + * @param[out] sp Pointer to a @p vfs_stat_t structure. + * @return The operation result. + */ +static msg_t __ffdir_stat_impl(void *ip, vfs_stat_t *sp) { + vfs_littlefs_dir_node_c *self = (vfs_littlefs_dir_node_c *)ip; +} + +/** + * @memberof vfs_littlefs_dir_node_c + * @protected + * + * @brief Override of method @p vfsDirReadFirst(). + * + * @param[in,out] ip Pointer to a @p vfs_littlefs_dir_node_c + * instance. + * @param[out] dip Pointer to a @p vfs_direntry_info_t structure. + * @return The operation result. + */ +static msg_t __ffdir_first_impl(void *ip, vfs_direntry_info_t *dip) { + vfs_littlefs_dir_node_c *self = (vfs_littlefs_dir_node_c *)ip; +} + +/** + * @memberof vfs_littlefs_dir_node_c + * @protected + * + * @brief Override of method @p vfsDirReadNext(). + * + * @param[in,out] ip Pointer to a @p vfs_littlefs_dir_node_c + * instance. + * @param[out] dip Pointer to a @p vfs_direntry_info_t structure. + * @return The operation result. + */ +static msg_t __ffdir_next_impl(void *ip, vfs_direntry_info_t *dip) { + vfs_littlefs_dir_node_c *self = (vfs_littlefs_dir_node_c *)ip; +} +/** @} */ + +/** + * @brief VMT structure of VFS littlefs directory node class. + * @note It is public because accessed by the inlined constructor. + */ +static const struct vfs_littlefs_dir_node_vmt __vfs_littlefs_dir_node_vmt = { + .dispose = __ffdir_dispose_impl, + .addref = __ro_addref_impl, + .release = __ro_release_impl, + .stat = __ffdir_stat_impl, + .first = __ffdir_first_impl, + .next = __ffdir_next_impl +}; + +/** + * @name Default constructor of vfs_littlefs_dir_node_c + * @{ + */ +/** + * @memberof vfs_littlefs_dir_node_c + * + * @brief Default initialization function of @p vfs_littlefs_dir_node_c. + * + * @param[out] self Pointer to a @p vfs_littlefs_dir_node_c + * instance to be initialized. + * @param[in] driver Pointer to the controlling driver. + * @param[in] mode Node mode flags. + * @return Pointer to the initialized object. + * + * @objinit + */ +static vfs_littlefs_dir_node_c *ffdirObjectInit(vfs_littlefs_dir_node_c *self, + vfs_driver_c *driver, + vfs_mode_t mode) { + + return __ffdir_objinit_impl(self, &__vfs_littlefs_dir_node_vmt, driver, mode); +} +/** @} */ + +/*===========================================================================*/ +/* Module class "vfs_littlefs_file_node_c" methods. */ +/*===========================================================================*/ + +/** + * @name Interfaces implementation of vfs_littlefs_file_node_c + * @{ + */ +/** + * @memberof vfs_littlefs_file_node_c + * @private + * + * @brief Implementation of interface method @p stmWrite(). + * + * @param[in,out] ip Pointer to the @p sequential_stream_i class + * interface. + * @param[in] bp Pointer to the data buffer. + * @param[in] n The maximum amount of data to be transferred. + * @return The number of bytes transferred. The returned + * value can be less than the specified number of + * bytes if an end-of-file condition has been met. + */ +static size_t __fffile_stm_write_impl(void *ip, const uint8_t *bp, size_t n) { + vfs_littlefs_file_node_c *self = oopIfGetOwner(vfs_littlefs_file_node_c, ip); +} + +/** + * @memberof vfs_littlefs_file_node_c + * @private + * + * @brief Implementation of interface method @p stmRead(). + * + * @param[in,out] ip Pointer to the @p sequential_stream_i class + * interface. + * @param[out] bp Pointer to the data buffer. + * @param[in] n The maximum amount of data to be transferred. + * @return The number of bytes transferred. The returned + * value can be less than the specified number of + * bytes if an end-of-file condition has been met. + */ +static size_t __fffile_stm_read_impl(void *ip, uint8_t *bp, size_t n) { + vfs_littlefs_file_node_c *self = oopIfGetOwner(vfs_littlefs_file_node_c, ip); +} + +/** + * @memberof vfs_littlefs_file_node_c + * @private + * + * @brief Implementation of interface method @p stmPut(). + * + * @param[in,out] ip Pointer to the @p sequential_stream_i class + * interface. + * @param[in] b The byte value to be written to the stream. + * @return The operation status. + */ +static int __fffile_stm_put_impl(void *ip, uint8_t b) { + vfs_littlefs_file_node_c *self = oopIfGetOwner(vfs_littlefs_file_node_c, ip); +} + +/** + * @memberof vfs_littlefs_file_node_c + * @private + * + * @brief Implementation of interface method @p stmGet(). + * + * @param[in,out] ip Pointer to the @p sequential_stream_i class + * interface. + * @return A byte value from the stream. + */ +static int __fffile_stm_get_impl(void *ip) { + vfs_littlefs_file_node_c *self = oopIfGetOwner(vfs_littlefs_file_node_c, ip); +} +/** @} */ + +/** + * @name Methods implementations of vfs_littlefs_file_node_c + * @{ + */ +/** + * @memberof vfs_littlefs_file_node_c + * @protected + * + * @brief Implementation of object creation. + * @note This function is meant to be used by derived classes. + * + * @param[out] ip Pointer to a @p vfs_littlefs_file_node_c + * instance to be initialized. + * @param[in] vmt VMT pointer for the new object. + * @param[in] driver Pointer to the controlling driver. + * @param[in] mode Node mode flags. + * @return A new reference to the object. + */ +static void *__fffile_objinit_impl(void *ip, const void *vmt, + vfs_driver_c *driver, vfs_mode_t mode) { + vfs_littlefs_file_node_c *self = (vfs_littlefs_file_node_c *)ip; + + /* Initialization of interface sequential_stream_i.*/ + { + static const struct sequential_stream_vmt fffile_stm_vmt = { + .instance_offset = offsetof(vfs_littlefs_file_node_c, stm), + .write = __fffile_stm_write_impl, + .read = __fffile_stm_read_impl, + .put = __fffile_stm_put_impl, + .get = __fffile_stm_get_impl, + .unget = NULL /* Missing implementation.*/ + }; + oopIfObjectInit(&self->stm, &fffile_stm_vmt); + } + + /* Initialization code.*/ + self = __vfsfile_objinit_impl(ip, vmt, (vfs_driver_c *)driver, mode); + + return self; +} + +/** + * @memberof vfs_littlefs_file_node_c + * @protected + * + * @brief Implementation of object finalization. + * @note This function is meant to be used by derived classes. + * + * @param[in,out] ip Pointer to a @p vfs_littlefs_file_node_c + * instance to be disposed. + */ +static void __fffile_dispose_impl(void *ip) { + vfs_littlefs_file_node_c *self = (vfs_littlefs_file_node_c *)ip; + + /* No finalization code.*/ + (void)self; + + /* Finalization of the ancestors-defined parts.*/ + __vfsfile_dispose_impl(self); +} + +/** + * @memberof vfs_littlefs_file_node_c + * @protected + * + * @brief Override of method @p vfsNodeStat(). + * + * @param[in,out] ip Pointer to a @p vfs_littlefs_file_node_c + * instance. + * @param[out] sp Pointer to a @p vfs_stat_t structure. + * @return The operation result. + */ +static msg_t __fffile_stat_impl(void *ip, vfs_stat_t *sp) { + vfs_littlefs_file_node_c *self = (vfs_littlefs_file_node_c *)ip; +} + +/** + * @memberof vfs_littlefs_file_node_c + * @protected + * + * @brief Override of method @p vfsFileRead(). + * + * @param[in,out] ip Pointer to a @p vfs_littlefs_file_node_c + * instance. + * @param[out] buf Pointer to the data buffer. + * @param[in] n Maximum amount of data to be transferred. + * @return The transferred number of bytes or an error. + */ +static ssize_t __fffile_read_impl(void *ip, uint8_t *buf, size_t n) { + vfs_littlefs_file_node_c *self = (vfs_littlefs_file_node_c *)ip; +} + +/** + * @memberof vfs_littlefs_file_node_c + * @protected + * + * @brief Override of method @p vfsFileWrite(). + * + * @param[in,out] ip Pointer to a @p vfs_littlefs_file_node_c + * instance. + * @param[in] buf Pointer to the data buffer. + * @param[in] n Maximum amount of data to be transferred. + * @return The transferred number of bytes or an error. + */ +static ssize_t __fffile_write_impl(void *ip, const uint8_t *buf, size_t n) { + vfs_littlefs_file_node_c *self = (vfs_littlefs_file_node_c *)ip; +} + +/** + * @memberof vfs_littlefs_file_node_c + * @protected + * + * @brief Override of method @p vfsFileSetPosition(). + * + * @param[in,out] ip Pointer to a @p vfs_littlefs_file_node_c + * instance. + * @param[in] offset Offset to be applied. + * @param[in] whence Seek mode to be used. + * @return The operation result. + */ +static msg_t __fffile_setpos_impl(void *ip, vfs_offset_t offset, + vfs_seekmode_t whence) { + vfs_littlefs_file_node_c *self = (vfs_littlefs_file_node_c *)ip; +} + +/** + * @memberof vfs_littlefs_file_node_c + * @protected + * + * @brief Override of method @p vfsFileGetPosition(). + * + * @param[in,out] ip Pointer to a @p vfs_littlefs_file_node_c + * instance. + * @return The current file position. + */ +static vfs_offset_t __fffile_getpos_impl(void *ip) { + vfs_littlefs_file_node_c *self = (vfs_littlefs_file_node_c *)ip; +} + +/** + * @memberof vfs_littlefs_file_node_c + * @protected + * + * @brief Override of method @p vfsFileGetStream(). + * + * @param[in,out] ip Pointer to a @p vfs_littlefs_file_node_c + * instance. + * @return Pointer to the HAL stream interface. + */ +static sequential_stream_i *__fffile_getstream_impl(void *ip) { + vfs_littlefs_file_node_c *self = (vfs_littlefs_file_node_c *)ip; +} +/** @} */ + +/** + * @brief VMT structure of VFS littlefs file node class. + * @note It is public because accessed by the inlined constructor. + */ +static const struct vfs_littlefs_file_node_vmt __vfs_littlefs_file_node_vmt = { + .dispose = __fffile_dispose_impl, + .addref = __ro_addref_impl, + .release = __ro_release_impl, + .stat = __fffile_stat_impl, + .read = __fffile_read_impl, + .write = __fffile_write_impl, + .setpos = __fffile_setpos_impl, + .getpos = __fffile_getpos_impl, + .getstream = __fffile_getstream_impl +}; + +/** + * @name Default constructor of vfs_littlefs_file_node_c + * @{ + */ +/** + * @memberof vfs_littlefs_file_node_c + * + * @brief Default initialization function of @p vfs_littlefs_file_node_c. + * + * @param[out] self Pointer to a @p vfs_littlefs_file_node_c + * instance to be initialized. + * @param[in] driver Pointer to the controlling driver. + * @param[in] mode Node mode flags. + * @return Pointer to the initialized object. + * + * @objinit + */ +static vfs_littlefs_file_node_c *fffileObjectInit(vfs_littlefs_file_node_c *self, + vfs_driver_c *driver, + vfs_mode_t mode) { + + return __fffile_objinit_impl(self, &__vfs_littlefs_file_node_vmt, driver, + mode); +} +/** @} */ + +/*===========================================================================*/ +/* Module class "vfs_littlefs_driver_c" methods. */ +/*===========================================================================*/ + +/** + * @name Methods implementations of vfs_littlefs_driver_c + * @{ + */ +/** + * @memberof vfs_littlefs_driver_c + * @protected + * + * @brief Implementation of object creation. + * @note This function is meant to be used by derived classes. + * + * @param[out] ip Pointer to a @p vfs_littlefs_driver_c instance + * to be initialized. + * @param[in] vmt VMT pointer for the new object. + * @return A new reference to the object. + */ +void *__lfsdrv_objinit_impl(void *ip, const void *vmt) { + vfs_littlefs_driver_c *self = (vfs_littlefs_driver_c *)ip; + + /* Initialization of the ancestors-defined parts.*/ + __vfsdrv_objinit_impl(self, vmt); + + /* No initialization code.*/ + + return self; +} + +/** + * @memberof vfs_littlefs_driver_c + * @protected + * + * @brief Implementation of object finalization. + * @note This function is meant to be used by derived classes. + * + * @param[in,out] ip Pointer to a @p vfs_littlefs_driver_c instance + * to be disposed. + */ +void __lfsdrv_dispose_impl(void *ip) { + vfs_littlefs_driver_c *self = (vfs_littlefs_driver_c *)ip; + + /* No finalization code.*/ + (void)self; + + /* Finalization of the ancestors-defined parts.*/ + __vfsdrv_dispose_impl(self); +} + +/** + * @memberof vfs_littlefs_driver_c + * @protected + * + * @brief Override of method @p vfsDrvChangeCurrentDirectory(). + * + * @param[in,out] ip Pointer to a @p vfs_littlefs_driver_c instance. + * @param[in] path Path of the new current directory. + * @return The operation result. + */ +msg_t __lfsdrv_setcwd_impl(void *ip, const char *path) { + vfs_littlefs_driver_c *self = (vfs_littlefs_driver_c *)ip; +} + +/** + * @memberof vfs_littlefs_driver_c + * @protected + * + * @brief Override of method @p vfsDrvGetCurrentDirectory(). + * + * @param[in,out] ip Pointer to a @p vfs_littlefs_driver_c instance. + * @param[out] buf Buffer for the path string. + * @param[in] size Size of the buffer. + * @return The operation result. + */ +msg_t __lfsdrv_getcwd_impl(void *ip, char *buf, size_t size) { + vfs_littlefs_driver_c *self = (vfs_littlefs_driver_c *)ip; +} + +/** + * @memberof vfs_littlefs_driver_c + * @protected + * + * @brief Override of method @p vfsDrvStat(). + * + * @param[in,out] ip Pointer to a @p vfs_littlefs_driver_c instance. + * @param[in] path Absolute path of the node to be examined. + * @param[out] sp Pointer to a @p vfs_stat_t structure. + * @return The operation result. + */ +msg_t __lfsdrv_stat_impl(void *ip, const char *path, vfs_stat_t *sp) { + vfs_littlefs_driver_c *self = (vfs_littlefs_driver_c *)ip; +} + +/** + * @memberof vfs_littlefs_driver_c + * @protected + * + * @brief Override of method @p vfsDrvOpenDirectory(). + * + * @param[in,out] ip Pointer to a @p vfs_littlefs_driver_c instance. + * @param[in] path Absolute path of the directory to be opened. + * @param[out] vdnpp Pointer to the pointer to the instantiated @p + * vfs_directory_node_c object. + * @return The operation result. + */ +msg_t __lfsdrv_opendir_impl(void *ip, const char *path, + vfs_directory_node_c **vdnpp) { + vfs_littlefs_driver_c *self = (vfs_littlefs_driver_c *)ip; +} + +/** + * @memberof vfs_littlefs_driver_c + * @protected + * + * @brief Override of method @p vfsDrvOpenFile(). + * + * @param[in,out] ip Pointer to a @p vfs_littlefs_driver_c instance. + * @param[in] path Absolute path of the directory to be opened. + * @param[in] flags File open flags. + * @param[out] vfnpp Pointer to the pointer to the instantiated @p + * vfs_file_node_c object. + * @return The operation result. + */ +msg_t __lfsdrv_openfile_impl(void *ip, const char *path, int flags, + vfs_file_node_c **vfnpp) { + vfs_littlefs_driver_c *self = (vfs_littlefs_driver_c *)ip; +} + +/** + * @memberof vfs_littlefs_driver_c + * @protected + * + * @brief Override of method @p vfsDrvUnlink(). + * + * @param[in,out] ip Pointer to a @p vfs_littlefs_driver_c instance. + * @param[in] path Path of the file to be unlinked. + * @return The operation result. + */ +msg_t __lfsdrv_unlink_impl(void *ip, const char *path) { + vfs_littlefs_driver_c *self = (vfs_littlefs_driver_c *)ip; +} + +/** + * @memberof vfs_littlefs_driver_c + * @protected + * + * @brief Override of method @p vfsDrvRename(). + * + * @param[in,out] ip Pointer to a @p vfs_littlefs_driver_c instance. + * @param[in] oldpath Path of the node to be renamed. + * @param[in] newpath New path of the renamed node. + * @return The operation result. + */ +msg_t __lfsdrv_rename_impl(void *ip, const char *oldpath, const char *newpath) { + vfs_littlefs_driver_c *self = (vfs_littlefs_driver_c *)ip; +} + +/** + * @memberof vfs_littlefs_driver_c + * @protected + * + * @brief Override of method @p vfsDrvMkdir(). + * + * @param[in,out] ip Pointer to a @p vfs_littlefs_driver_c instance. + * @param[in] path Path of the directory to be created. + * @param[in] mode Mode flags for the directory. + * @return The operation result. + */ +msg_t __lfsdrv_mkdir_impl(void *ip, const char *path, vfs_mode_t mode) { + vfs_littlefs_driver_c *self = (vfs_littlefs_driver_c *)ip; +} + +/** + * @memberof vfs_littlefs_driver_c + * @protected + * + * @brief Override of method @p vfsDrvRmdir(). + * + * @param[in,out] ip Pointer to a @p vfs_littlefs_driver_c instance. + * @param[in] path Path of the directory to be removed. + * @return The operation result. + */ +msg_t __lfsdrv_rmdir_impl(void *ip, const char *path) { + vfs_littlefs_driver_c *self = (vfs_littlefs_driver_c *)ip; +} +/** @} */ + +/** + * @brief VMT structure of VFS littlefs driver class. + * @note It is public because accessed by the inlined constructor. + */ +const struct vfs_littlefs_driver_vmt __vfs_littlefs_driver_vmt = { + .dispose = __lfsdrv_dispose_impl, + .setcwd = __lfsdrv_setcwd_impl, + .getcwd = __lfsdrv_getcwd_impl, + .stat = __lfsdrv_stat_impl, + .opendir = __lfsdrv_opendir_impl, + .openfile = __lfsdrv_openfile_impl, + .unlink = __lfsdrv_unlink_impl, + .rename = __lfsdrv_rename_impl, + .mkdir = __lfsdrv_mkdir_impl, + .rmdir = __lfsdrv_rmdir_impl +}; + diff --git a/os/vfs/drivers/overlay/drvoverlay.c b/os/vfs/drivers/overlay/drvoverlay.c index 20c32bd17..a49ccd69c 100644 --- a/os/vfs/drivers/overlay/drvoverlay.c +++ b/os/vfs/drivers/overlay/drvoverlay.c @@ -1,5 +1,5 @@ /* - ChibiOS - Copyright (C) 2006..2023 Giovanni Di Sirio + ChibiOS - Copyright (C) 2006..2024 Giovanni Di Sirio Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/os/vfs/drivers/overlay/drvoverlay.h b/os/vfs/drivers/overlay/drvoverlay.h index 403375367..c8d80dc23 100644 --- a/os/vfs/drivers/overlay/drvoverlay.h +++ b/os/vfs/drivers/overlay/drvoverlay.h @@ -1,5 +1,5 @@ /* - ChibiOS - Copyright (C) 2006..2023 Giovanni Di Sirio + ChibiOS - Copyright (C) 2006..2024 Giovanni Di Sirio Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/os/vfs/drivers/streams/drvstreams.c b/os/vfs/drivers/streams/drvstreams.c index fb88557a5..68d678790 100644 --- a/os/vfs/drivers/streams/drvstreams.c +++ b/os/vfs/drivers/streams/drvstreams.c @@ -1,5 +1,5 @@ /* - ChibiOS - Copyright (C) 2006..2023 Giovanni Di Sirio + ChibiOS - Copyright (C) 2006..2024 Giovanni Di Sirio Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/os/vfs/drivers/streams/drvstreams.h b/os/vfs/drivers/streams/drvstreams.h index b11154bbc..d9da36f3d 100644 --- a/os/vfs/drivers/streams/drvstreams.h +++ b/os/vfs/drivers/streams/drvstreams.h @@ -1,5 +1,5 @@ /* - ChibiOS - Copyright (C) 2006..2023 Giovanni Di Sirio + ChibiOS - Copyright (C) 2006..2024 Giovanni Di Sirio Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/os/vfs/include/vfs.h b/os/vfs/include/vfs.h index 2770272d4..4d243eb0e 100644 --- a/os/vfs/include/vfs.h +++ b/os/vfs/include/vfs.h @@ -103,6 +103,15 @@ #include "drvfatfs.h" #endif +/* TODO temporary */ +#define VFS_CFG_ENABLE_DRV_LITTLEFS FALSE +#define DRV_CFG_LITTLEFS_DIR_NODES_NUM 1 +#define DRV_CFG_LITTLEFS_FILE_NODES_NUM 1 +#define DRV_CFG_LITTLEFS_FS_NUM 1 +#if VFS_CFG_ENABLE_DRV_LITTLEFS == TRUE +#include "drvlittlefs.h" +#endif + /* TODO temporary */ #define VFS_CFG_ENABLE_DRV_SFS FALSE #define DRV_CFG_SFS_DIR_NODES_NUM 1 diff --git a/os/vfs/include/vfsdrivers.h b/os/vfs/include/vfsdrivers.h index 0ae0af50e..6233ec190 100644 --- a/os/vfs/include/vfsdrivers.h +++ b/os/vfs/include/vfsdrivers.h @@ -1,5 +1,5 @@ /* - ChibiOS - Copyright (C) 2006..2023 Giovanni Di Sirio + ChibiOS - Copyright (C) 2006..2024 Giovanni Di Sirio Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/os/vfs/include/vfsnodes.h b/os/vfs/include/vfsnodes.h index 71fd959fa..348fcba96 100644 --- a/os/vfs/include/vfsnodes.h +++ b/os/vfs/include/vfsnodes.h @@ -1,5 +1,5 @@ /* - ChibiOS - Copyright (C) 2006..2023 Giovanni Di Sirio + ChibiOS - Copyright (C) 2006..2024 Giovanni Di Sirio Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/os/vfs/src/vfsdrivers.c b/os/vfs/src/vfsdrivers.c index 82b03e291..e43c39fb4 100644 --- a/os/vfs/src/vfsdrivers.c +++ b/os/vfs/src/vfsdrivers.c @@ -1,5 +1,5 @@ /* - ChibiOS - Copyright (C) 2006..2023 Giovanni Di Sirio + ChibiOS - Copyright (C) 2006..2024 Giovanni Di Sirio Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/os/vfs/src/vfsnodes.c b/os/vfs/src/vfsnodes.c index 4db9c6259..886ca4113 100644 --- a/os/vfs/src/vfsnodes.c +++ b/os/vfs/src/vfsnodes.c @@ -1,5 +1,5 @@ /* - ChibiOS - Copyright (C) 2006..2023 Giovanni Di Sirio + ChibiOS - Copyright (C) 2006..2024 Giovanni Di Sirio Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/os/vfs/vfs.mk b/os/vfs/vfs.mk index 862d19dda..42cb23ea4 100644 --- a/os/vfs/vfs.mk +++ b/os/vfs/vfs.mk @@ -8,6 +8,7 @@ VFSSRC := $(CHIBIOS)/os/vfs/src/vfspaths.c \ $(CHIBIOS)/os/vfs/drivers/template/drvtemplate.c \ $(CHIBIOS)/os/vfs/drivers/sfs/drvsfs.c \ $(CHIBIOS)/os/vfs/drivers/fatfs/drvfatfs.c \ + $(CHIBIOS)/os/vfs/drivers/littlefs/drvlittlefs.c \ $(CHIBIOS)/os/vfs/drivers/overlay/drvoverlay.c \ $(CHIBIOS)/os/vfs/drivers/streams/drvstreams.c @@ -17,6 +18,7 @@ VFSINC := $(CHIBIOS)/os/common/include \ $(CHIBIOS)/os/vfs/drivers/template \ $(CHIBIOS)/os/vfs/drivers/sfs \ $(CHIBIOS)/os/vfs/drivers/fatfs \ + $(CHIBIOS)/os/vfs/drivers/littlefs \ $(CHIBIOS)/os/vfs/drivers/overlay \ $(CHIBIOS)/os/vfs/drivers/streams