diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c869ebc..cec8671 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,7 +19,7 @@ jobs: - name: Checkout code uses: actions/checkout@v4 - - name: Build dmdfs project + - name: Build dmdevfs project run: | mkdir -p build cd build diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 447993a..20bb6e3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -64,7 +64,7 @@ jobs: echo "version=$VERSION" >> $GITHUB_OUTPUT echo "Extracted version: $VERSION" - - name: Build dmdfs for ${{ matrix.arch_name }} + - name: Build dmdevfs for ${{ matrix.arch_name }} run: | set -e ARCH_DIR_NAME=$(echo "${{ matrix.arch_name }}" | sed 's|/|-|') @@ -91,12 +91,12 @@ jobs: DMF_DIR="$BUILD_DIR/dmf" DMFC_DIR="$BUILD_DIR/dmfc" - cp $DMF_DIR/dmdfs.dmf release_package/ - cp $DMF_DIR/dmdfs_version.txt release_package/ - cp $DMFC_DIR/dmdfs.dmfc release_package/ + cp $DMF_DIR/dmdevfs.dmf release_package/ + cp $DMF_DIR/dmdevfs_version.txt release_package/ + cp $DMFC_DIR/dmdevfs.dmfc release_package/ # Copy .dmd file if it exists - if [ -f $DMF_DIR/dmdfs.dmd ]; then - cp $DMF_DIR/dmdfs.dmd release_package/ + if [ -f $DMF_DIR/dmdevfs.dmd ]; then + cp $DMF_DIR/dmdevfs.dmd release_package/ fi # Copy documentation and license @@ -112,16 +112,16 @@ jobs: - name: Create release archive run: | cd release_package - zip -r ../dmdfs-${{ github.event.release.tag_name }}-$ARCH_DIR_NAME.zip . + zip -r ../dmdevfs-${{ github.event.release.tag_name }}-$ARCH_DIR_NAME.zip . cd .. echo "Created archive:" - ls -lh dmdfs-*.zip + ls -lh dmdevfs-*.zip - name: Upload artifact uses: actions/upload-artifact@v4 with: name: ${{ env.ARTIFACT_NAME }} - path: dmdfs-${{ github.event.release.tag_name }}-*.zip + path: dmdevfs-${{ github.event.release.tag_name }}-*.zip retention-days: 1 generate-versions-manifest: @@ -140,7 +140,7 @@ jobs: - name: Generate versions.dmm run: | set -e - echo "# List of available versions for dmdfs modules" > versions.dmm + echo "# List of available versions for dmdevfs modules" > versions.dmm echo "# Generated automatically by CI" >> versions.dmm echo "" >> versions.dmm @@ -158,8 +158,8 @@ jobs: echo "Found versions: $VERSIONS" - # Add $version-available directive for dmdfs module - echo "\$version-available dmdfs $VERSIONS" >> versions.dmm + # Add $version-available directive for dmdevfs module + echo "\$version-available dmdevfs $VERSIONS" >> versions.dmm echo "Generated versions.dmm:" cat versions.dmm diff --git a/CMakeLists.txt b/CMakeLists.txt index b4606aa..21ffc8e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,7 +33,7 @@ set(DMOD_BUILD_TEMPLATES OFF CACHE BOOL "Build templates") FetchContent_MakeAvailable(dmod) -project(dmdfs +project(dmdevfs VERSION ${DMOD_MODULE_VERSION} DESCRIPTION "DMOD Driver File System" LANGUAGES C CXX) @@ -57,10 +57,10 @@ FetchContent_Declare( FetchContent_MakeAvailable(dmfsi) # ====================================================================== -# DMDFS Module Configuration +# DMDEVFS Module Configuration # ====================================================================== # Name of the module -set(DMOD_MODULE_NAME dmdfs) +set(DMOD_MODULE_NAME dmdevfs) # Version is already set above and used in project() # No need to set it again here @@ -79,7 +79,7 @@ set(DMOD_STACK_SIZE 1024) # dmod_add_library(${DMOD_MODULE_NAME} ${DMOD_MODULE_VERSION} # List of source files - can include C and C++ files - src/dmdfs.c + src/dmdevfs.c ) target_include_directories(${DMOD_MODULE_NAME} PRIVATE diff --git a/README.md b/README.md index f224991..7ed15b0 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ -# dmdfs +# dmdevfs DMOD Driver File System - A driver-based file system module for embedded systems. ## Overview -`dmdfs` (DMOD Driver File System) is a file system implementation that provides an interface to access files through hardware drivers or external storage. It is built on the **DMOD (Dynamic Modules)** framework and implements the **DMFSI (DMOD File System Interface)**, making it compatible with **DMVFS (DMOD Virtual File System)** and other DMOD-based applications. +`dmdevfs` (DMOD Driver File System) is a file system implementation that provides an interface to access files through hardware drivers or external storage. It is built on the **DMOD (Dynamic Modules)** framework and implements the **DMFSI (DMOD File System Interface)**, making it compatible with **DMVFS (DMOD Virtual File System)** and other DMOD-based applications. ### Key Features @@ -15,7 +15,7 @@ DMOD Driver File System - A driver-based file system module for embedded systems ## Architecture -DMDFS is part of a modular embedded file system architecture built on DMOD: +DMDEVFS is part of a modular embedded file system architecture built on DMOD: ``` ┌─────────────────────────────────────────────────────────────┐ @@ -43,7 +43,7 @@ DMDFS is part of a modular embedded file system architecture built on DMOD: ┌─────────────────┼─────────────────┐ ▼ ▼ ▼ ┌────────────────┐ ┌─────────────┐ ┌─────────────┐ -│ DMDFS (Driver) │ │ DMFFS (Flash│ │ DMRAMFS (RAM│ +│ DMDEVFS (Driver│ │ DMFFS (Flash│ │ DMRAMFS (RAM│ │ Driver-based │ │ Read-only │ │ Temporary │ │ (This Project) │ │ │ │ │ └────────────────┘ └─────────────┘ └─────────────┘ @@ -57,9 +57,9 @@ DMDFS is part of a modular embedded file system architecture built on DMOD: ### Component Relationships - **[DMOD](https://github.com/choco-technologies/dmod)**: The foundation providing dynamic module loading, inter-module communication, and resource management -- **[DMFSI](https://github.com/choco-technologies/dmfsi)**: Defines the standard file system interface that DMDFS implements -- **[DMVFS](https://github.com/choco-technologies/dmvfs)**: Virtual file system layer that can mount DMDFS at any path in a unified directory tree -- **DMDFS**: This project - implements DMFSI to provide access to driver-based storage +- **[DMFSI](https://github.com/choco-technologies/dmfsi)**: Defines the standard file system interface that DMDEVFS implements +- **[DMVFS](https://github.com/choco-technologies/dmvfs)**: Virtual file system layer that can mount DMDEVFS at any path in a unified directory tree +- **DMDEVFS**: This project - implements DMFSI to provide access to driver-based storage ## Building @@ -81,7 +81,7 @@ The module can be loaded and mounted using DMVFS: dmvfs_init(16, 32); // Mount the driver filesystem at /mnt -dmvfs_mount_fs("dmdfs", "/mnt", NULL); +dmvfs_mount_fs("dmdevfs", "/mnt", NULL); // Use standard file operations void* fp; @@ -127,11 +127,11 @@ The module implements the full DMFSI interface: ## Project Structure ``` -dmdfs/ +dmdevfs/ ├── include/ -│ └── dmdfs.h # Public header +│ └── dmdevfs.h # Public header ├── src/ -│ └── dmdfs.c # Main DMDFS implementation +│ └── dmdevfs.c # Main DMDEVFS implementation ├── CMakeLists.txt # CMake build configuration ├── manifest.dmm # DMOD manifest file ├── README.md # This file @@ -149,9 +149,9 @@ dmdfs/ ```cmake include(FetchContent) -# Fetch DMDFS +# Fetch DMDEVFS FetchContent_Declare( - dmdfs + dmdevfs GIT_REPOSITORY https://github.com/choco-technologies/dmdfs.git GIT_TAG main ) @@ -159,17 +159,17 @@ FetchContent_Declare( # Set DMOD mode set(DMOD_MODE "DMOD_MODULE" CACHE STRING "DMOD build mode") -FetchContent_MakeAvailable(dmdfs) +FetchContent_MakeAvailable(dmdevfs) # Link to your target -target_link_libraries(your_target PRIVATE dmdfs) +target_link_libraries(your_target PRIVATE dmdevfs) ``` ### Manual Integration 1. Clone the repository: `git clone https://github.com/choco-technologies/dmdfs.git` -2. Add as subdirectory: `add_subdirectory(dmdfs)` -3. Link library: `target_link_libraries(your_target dmdfs)` +2. Add as subdirectory: `add_subdirectory(dmdevfs)` +3. Link library: `target_link_libraries(your_target dmdevfs)` ## Contributing diff --git a/include/dmdfs.h b/include/dmdevfs.h similarity index 55% rename from include/dmdfs.h rename to include/dmdevfs.h index f4d2d69..f0d68f9 100644 --- a/include/dmdfs.h +++ b/include/dmdevfs.h @@ -1,22 +1,22 @@ /** - * @file dmdfs.h + * @file dmdevfs.h * @brief DMOD Driver File System - Public header * @author Patryk Kubiak */ -#ifndef DMDFS_H -#define DMDFS_H +#ifndef DMDEVFS_H +#define DMDEVFS_H #ifdef __cplusplus extern "C" { #endif // Module version -#define DMDFS_VERSION_MAJOR 0 -#define DMDFS_VERSION_MINOR 1 +#define DMDEVFS_VERSION_MAJOR 0 +#define DMDEVFS_VERSION_MINOR 1 #ifdef __cplusplus } #endif -#endif // DMDFS_H +#endif // DMDEVFS_H diff --git a/manifest.dmm b/manifest.dmm index 6485918..8b68cbe 100644 --- a/manifest.dmm +++ b/manifest.dmm @@ -2,4 +2,4 @@ $include https://github.com/choco-technologies/dmdfs/releases/download/vlatest/versions.dmm # Module entries with version placeholder - will be expanded by $version-available -dmdfs https://github.com/choco-technologies/dmdfs/releases/download/v/dmdfs-v-.zip +dmdevfs https://github.com/choco-technologies/dmdfs/releases/download/v/dmdevfs-v-.zip diff --git a/src/dmdevfs.c b/src/dmdevfs.c new file mode 100644 index 0000000..015e292 --- /dev/null +++ b/src/dmdevfs.c @@ -0,0 +1,408 @@ +/** + * @file dmdevfs.c + * @brief DMOD Driver File System - Implementation + * @author Patryk Kubiak + * + * This is a driver-based file system that provides an interface to access + * files through hardware drivers or external storage. + */ + +#define DMOD_ENABLE_REGISTRATION ON +#define ENABLE_DIF_REGISTRATIONS ON +#include "dmod.h" +#include "dmdevfs.h" +#include "dmfsi.h" +#include + +/** + * @brief Magic number for DMDEVFS context validation + */ +#define DMDEVFS_CONTEXT_MAGIC 0x444D4456 // 'DMDV' + +/** + * @brief File system context structure + */ +struct dmfsi_context +{ + uint32_t magic; + void* driver_context; // Driver-specific context +}; + +// ============================================================================ +// Module Interface Implementation +// ============================================================================ + +/** + * @brief Module pre-initialization (optional) + */ +void dmod_preinit(void) +{ + // Nothing to do +} + +/** + * @brief Module initialization + */ +int dmod_init(const Dmod_Config_t *Config) +{ + // Nothing to do + return 0; +} + +/** + * @brief Module deinitialization + */ +int dmod_deinit(void) +{ + // Nothing to do + return 0; +} + +// ============================================================================ +// DMFSI Interface Implementation +// ============================================================================ + +/** + * @brief Initialize the file system + */ +dmod_dmfsi_dif_api_declaration( 1.0, dmdevfs, dmfsi_context_t, _init, (const char* config) ) +{ + dmfsi_context_t ctx = Dmod_Malloc(sizeof(struct dmfsi_context)); + if (ctx == NULL) + { + DMOD_LOG_ERROR("dmdevfs: Failed to allocate memory for context\n"); + return NULL; + } + + ctx->magic = DMDEVFS_CONTEXT_MAGIC; + ctx->driver_context = NULL; + + // TODO: Initialize driver context based on config + + return ctx; +} + +/** + * @brief Deinitialize the file system + */ +dmod_dmfsi_dif_api_declaration( 1.0, dmdevfs, int, _deinit, (dmfsi_context_t ctx) ) +{ + if (ctx) + { + // TODO: Cleanup driver context + Dmod_Free(ctx); + } + return DMFSI_OK; +} + +/** + * @brief Validate the file system context + */ +dmod_dmfsi_dif_api_declaration( 1.0, dmdevfs, int, _context_is_valid, (dmfsi_context_t ctx) ) +{ + return (ctx && ctx->magic == DMDEVFS_CONTEXT_MAGIC) ? 1 : 0; +} + +/** + * @brief Open a file + */ +dmod_dmfsi_dif_api_declaration( 1.0, dmdevfs, int, _fopen, (dmfsi_context_t ctx, void** fp, const char* path, int mode, int attr) ) +{ + if(dmfsi_dmdevfs_context_is_valid(ctx) == 0) + { + DMOD_LOG_ERROR("dmdevfs: Invalid context in fopen\n"); + return DMFSI_ERR_INVALID; + } + + // TODO: Implement file opening through driver + DMOD_LOG_ERROR("dmdevfs: fopen not yet implemented\n"); + return DMFSI_ERR_GENERAL; +} + +/** + * @brief Close a file + */ +dmod_dmfsi_dif_api_declaration( 1.0, dmdevfs, int, _fclose, (dmfsi_context_t ctx, void* fp) ) +{ + if(dmfsi_dmdevfs_context_is_valid(ctx) == 0) + { + DMOD_LOG_ERROR("dmdevfs: Invalid context in fclose\n"); + return DMFSI_ERR_INVALID; + } + + // TODO: Implement file closing + DMOD_LOG_ERROR("dmdevfs: fclose not yet implemented\n"); + return DMFSI_ERR_GENERAL; +} + +/** + * @brief Read from a file + */ +dmod_dmfsi_dif_api_declaration( 1.0, dmdevfs, int, _fread, (dmfsi_context_t ctx, void* fp, void* buffer, size_t size, size_t* read) ) +{ + if(dmfsi_dmdevfs_context_is_valid(ctx) == 0) + { + DMOD_LOG_ERROR("dmdevfs: Invalid context in fread\n"); + return DMFSI_ERR_INVALID; + } + + // TODO: Implement file reading + if (read) *read = 0; + return DMFSI_ERR_GENERAL; +} + +/** + * @brief Write to a file + */ +dmod_dmfsi_dif_api_declaration( 1.0, dmdevfs, int, _fwrite, (dmfsi_context_t ctx, void* fp, const void* buffer, size_t size, size_t* written) ) +{ + if(dmfsi_dmdevfs_context_is_valid(ctx) == 0) + { + DMOD_LOG_ERROR("dmdevfs: Invalid context in fwrite\n"); + return DMFSI_ERR_INVALID; + } + + // TODO: Implement file writing + if (written) *written = 0; + return DMFSI_ERR_GENERAL; +} + +/** + * @brief Seek to a position in a file + */ +dmod_dmfsi_dif_api_declaration( 1.0, dmdevfs, int, _lseek, (dmfsi_context_t ctx, void* fp, long offset, int whence) ) +{ + if(dmfsi_dmdevfs_context_is_valid(ctx) == 0) + { + DMOD_LOG_ERROR("dmdevfs: Invalid context in lseek\n"); + return DMFSI_ERR_INVALID; + } + + // TODO: Implement file seeking + return DMFSI_ERR_GENERAL; +} + +/** + * @brief Get current position in a file + */ +dmod_dmfsi_dif_api_declaration( 1.0, dmdevfs, long, _tell, (dmfsi_context_t ctx, void* fp) ) +{ + if(dmfsi_dmdevfs_context_is_valid(ctx) == 0) + { + DMOD_LOG_ERROR("dmdevfs: Invalid context in tell\n"); + return -1; + } + + // TODO: Implement position retrieval + return -1; +} + +/** + * @brief Check if at end of file + */ +dmod_dmfsi_dif_api_declaration( 1.0, dmdevfs, int, _eof, (dmfsi_context_t ctx, void* fp) ) +{ + if(dmfsi_dmdevfs_context_is_valid(ctx) == 0) + { + DMOD_LOG_ERROR("dmdevfs: Invalid context in eof\n"); + return 1; + } + + // TODO: Implement EOF checking + return 1; +} + +/** + * @brief Get file size + */ +dmod_dmfsi_dif_api_declaration( 1.0, dmdevfs, long, _size, (dmfsi_context_t ctx, void* fp) ) +{ + if(dmfsi_dmdevfs_context_is_valid(ctx) == 0) + { + DMOD_LOG_ERROR("dmdevfs: Invalid context in size\n"); + return -1; + } + + // TODO: Implement size retrieval + return -1; +} + +/** + * @brief Read a single character + */ +dmod_dmfsi_dif_api_declaration( 1.0, dmdevfs, int, _getc, (dmfsi_context_t ctx, void* fp) ) +{ + if(dmfsi_dmdevfs_context_is_valid(ctx) == 0) + { + DMOD_LOG_ERROR("dmdevfs: Invalid context in getc\n"); + return -1; + } + + // TODO: Implement character reading + return -1; +} + +/** + * @brief Write a single character + */ +dmod_dmfsi_dif_api_declaration( 1.0, dmdevfs, int, _putc, (dmfsi_context_t ctx, void* fp, char c) ) +{ + if(dmfsi_dmdevfs_context_is_valid(ctx) == 0) + { + DMOD_LOG_ERROR("dmdevfs: Invalid context in putc\n"); + return -1; + } + + // TODO: Implement character writing + return DMFSI_ERR_GENERAL; +} + +/** + * @brief Flush file buffers + */ +dmod_dmfsi_dif_api_declaration( 1.0, dmdevfs, int, _fflush, (dmfsi_context_t ctx, void* fp) ) +{ + if(dmfsi_dmdevfs_context_is_valid(ctx) == 0) + { + DMOD_LOG_ERROR("dmdevfs: Invalid context in fflush\n"); + return DMFSI_ERR_INVALID; + } + + // TODO: Implement buffer flushing + return DMFSI_OK; +} + +/** + * @brief Sync file to storage + */ +dmod_dmfsi_dif_api_declaration( 1.0, dmdevfs, int, _sync, (dmfsi_context_t ctx, void* fp) ) +{ + if(dmfsi_dmdevfs_context_is_valid(ctx) == 0) + { + DMOD_LOG_ERROR("dmdevfs: Invalid context in sync\n"); + return DMFSI_ERR_INVALID; + } + + // TODO: Implement sync + return DMFSI_OK; +} + +/** + * @brief Open a directory + */ +dmod_dmfsi_dif_api_declaration( 1.0, dmdevfs, int, _opendir, (dmfsi_context_t ctx, void** dp, const char* path) ) +{ + if(dmfsi_dmdevfs_context_is_valid(ctx) == 0) + { + DMOD_LOG_ERROR("dmdevfs: Invalid context in opendir\n"); + return DMFSI_ERR_INVALID; + } + + // TODO: Implement directory opening + return DMFSI_ERR_GENERAL; +} + +/** + * @brief Read directory entry + */ +dmod_dmfsi_dif_api_declaration( 1.0, dmdevfs, int, _readdir, (dmfsi_context_t ctx, void* dp, dmfsi_dir_entry_t* entry) ) +{ + if(dmfsi_dmdevfs_context_is_valid(ctx) == 0) + { + DMOD_LOG_ERROR("dmdevfs: Invalid context in readdir\n"); + return DMFSI_ERR_INVALID; + } + + // TODO: Implement directory reading + return DMFSI_ERR_NOT_FOUND; +} + +/** + * @brief Close a directory + */ +dmod_dmfsi_dif_api_declaration( 1.0, dmdevfs, int, _closedir, (dmfsi_context_t ctx, void* dp) ) +{ + if(dmfsi_dmdevfs_context_is_valid(ctx) == 0) + { + DMOD_LOG_ERROR("dmdevfs: Invalid context in closedir\n"); + return DMFSI_ERR_INVALID; + } + + // TODO: Implement directory closing + return DMFSI_ERR_GENERAL; +} + +/** + * @brief Create a directory + */ +dmod_dmfsi_dif_api_declaration( 1.0, dmdevfs, int, _mkdir, (dmfsi_context_t ctx, const char* path) ) +{ + if(dmfsi_dmdevfs_context_is_valid(ctx) == 0) + { + DMOD_LOG_ERROR("dmdevfs: Invalid context in mkdir\n"); + return DMFSI_ERR_INVALID; + } + + // TODO: Implement directory creation + return DMFSI_ERR_GENERAL; +} + +/** + * @brief Check if directory exists + */ +dmod_dmfsi_dif_api_declaration( 1.0, dmdevfs, int, _direxists, (dmfsi_context_t ctx, const char* path) ) +{ + if(dmfsi_dmdevfs_context_is_valid(ctx) == 0) + { + DMOD_LOG_ERROR("dmdevfs: Invalid context in direxists\n"); + return 0; + } + + // TODO: Implement directory existence check + return 0; +} + +/** + * @brief Get file/directory statistics + */ +dmod_dmfsi_dif_api_declaration( 1.0, dmdevfs, int, _stat, (dmfsi_context_t ctx, const char* path, dmfsi_stat_t* stat) ) +{ + if(dmfsi_dmdevfs_context_is_valid(ctx) == 0) + { + DMOD_LOG_ERROR("dmdevfs: Invalid context in stat\n"); + return DMFSI_ERR_INVALID; + } + + // TODO: Implement stat + return DMFSI_ERR_GENERAL; +} + +/** + * @brief Delete a file + */ +dmod_dmfsi_dif_api_declaration( 1.0, dmdevfs, int, _unlink, (dmfsi_context_t ctx, const char* path) ) +{ + if(dmfsi_dmdevfs_context_is_valid(ctx) == 0) + { + DMOD_LOG_ERROR("dmdevfs: Invalid context in unlink\n"); + return DMFSI_ERR_INVALID; + } + + // TODO: Implement file deletion + return DMFSI_ERR_GENERAL; +} + +/** + * @brief Rename a file + */ +dmod_dmfsi_dif_api_declaration( 1.0, dmdevfs, int, _rename, (dmfsi_context_t ctx, const char* oldpath, const char* newpath) ) +{ + if(dmfsi_dmdevfs_context_is_valid(ctx) == 0) + { + DMOD_LOG_ERROR("dmdevfs: Invalid context in rename\n"); + return DMFSI_ERR_INVALID; + } + + // TODO: Implement file renaming + return DMFSI_ERR_GENERAL; +} diff --git a/src/dmdfs.c b/src/dmdfs.c deleted file mode 100644 index 66332e2..0000000 --- a/src/dmdfs.c +++ /dev/null @@ -1,408 +0,0 @@ -/** - * @file dmdfs.c - * @brief DMOD Driver File System - Implementation - * @author Patryk Kubiak - * - * This is a driver-based file system that provides an interface to access - * files through hardware drivers or external storage. - */ - -#define DMOD_ENABLE_REGISTRATION ON -#define ENABLE_DIF_REGISTRATIONS ON -#include "dmod.h" -#include "dmdfs.h" -#include "dmfsi.h" -#include - -/** - * @brief Magic number for DMDFS context validation - */ -#define DMDFS_CONTEXT_MAGIC 0x444D4446 // 'DMDF' - -/** - * @brief File system context structure - */ -struct dmfsi_context -{ - uint32_t magic; - void* driver_context; // Driver-specific context -}; - -// ============================================================================ -// Module Interface Implementation -// ============================================================================ - -/** - * @brief Module pre-initialization (optional) - */ -void dmod_preinit(void) -{ - // Nothing to do -} - -/** - * @brief Module initialization - */ -int dmod_init(const Dmod_Config_t *Config) -{ - // Nothing to do - return 0; -} - -/** - * @brief Module deinitialization - */ -int dmod_deinit(void) -{ - // Nothing to do - return 0; -} - -// ============================================================================ -// DMFSI Interface Implementation -// ============================================================================ - -/** - * @brief Initialize the file system - */ -dmod_dmfsi_dif_api_declaration( 1.0, dmdfs, dmfsi_context_t, _init, (const char* config) ) -{ - dmfsi_context_t ctx = Dmod_Malloc(sizeof(struct dmfsi_context)); - if (ctx == NULL) - { - DMOD_LOG_ERROR("dmdfs: Failed to allocate memory for context\n"); - return NULL; - } - - ctx->magic = DMDFS_CONTEXT_MAGIC; - ctx->driver_context = NULL; - - // TODO: Initialize driver context based on config - - return ctx; -} - -/** - * @brief Deinitialize the file system - */ -dmod_dmfsi_dif_api_declaration( 1.0, dmdfs, int, _deinit, (dmfsi_context_t ctx) ) -{ - if (ctx) - { - // TODO: Cleanup driver context - Dmod_Free(ctx); - } - return DMFSI_OK; -} - -/** - * @brief Validate the file system context - */ -dmod_dmfsi_dif_api_declaration( 1.0, dmdfs, int, _context_is_valid, (dmfsi_context_t ctx) ) -{ - return (ctx && ctx->magic == DMDFS_CONTEXT_MAGIC) ? 1 : 0; -} - -/** - * @brief Open a file - */ -dmod_dmfsi_dif_api_declaration( 1.0, dmdfs, int, _fopen, (dmfsi_context_t ctx, void** fp, const char* path, int mode, int attr) ) -{ - if(dmfsi_dmdfs_context_is_valid(ctx) == 0) - { - DMOD_LOG_ERROR("dmdfs: Invalid context in fopen\n"); - return DMFSI_ERR_INVALID; - } - - // TODO: Implement file opening through driver - DMOD_LOG_ERROR("dmdfs: fopen not yet implemented\n"); - return DMFSI_ERR_GENERAL; -} - -/** - * @brief Close a file - */ -dmod_dmfsi_dif_api_declaration( 1.0, dmdfs, int, _fclose, (dmfsi_context_t ctx, void* fp) ) -{ - if(dmfsi_dmdfs_context_is_valid(ctx) == 0) - { - DMOD_LOG_ERROR("dmdfs: Invalid context in fclose\n"); - return DMFSI_ERR_INVALID; - } - - // TODO: Implement file closing - DMOD_LOG_ERROR("dmdfs: fclose not yet implemented\n"); - return DMFSI_ERR_GENERAL; -} - -/** - * @brief Read from a file - */ -dmod_dmfsi_dif_api_declaration( 1.0, dmdfs, int, _fread, (dmfsi_context_t ctx, void* fp, void* buffer, size_t size, size_t* read) ) -{ - if(dmfsi_dmdfs_context_is_valid(ctx) == 0) - { - DMOD_LOG_ERROR("dmdfs: Invalid context in fread\n"); - return DMFSI_ERR_INVALID; - } - - // TODO: Implement file reading - if (read) *read = 0; - return DMFSI_ERR_GENERAL; -} - -/** - * @brief Write to a file - */ -dmod_dmfsi_dif_api_declaration( 1.0, dmdfs, int, _fwrite, (dmfsi_context_t ctx, void* fp, const void* buffer, size_t size, size_t* written) ) -{ - if(dmfsi_dmdfs_context_is_valid(ctx) == 0) - { - DMOD_LOG_ERROR("dmdfs: Invalid context in fwrite\n"); - return DMFSI_ERR_INVALID; - } - - // TODO: Implement file writing - if (written) *written = 0; - return DMFSI_ERR_GENERAL; -} - -/** - * @brief Seek to a position in a file - */ -dmod_dmfsi_dif_api_declaration( 1.0, dmdfs, int, _lseek, (dmfsi_context_t ctx, void* fp, long offset, int whence) ) -{ - if(dmfsi_dmdfs_context_is_valid(ctx) == 0) - { - DMOD_LOG_ERROR("dmdfs: Invalid context in lseek\n"); - return DMFSI_ERR_INVALID; - } - - // TODO: Implement file seeking - return DMFSI_ERR_GENERAL; -} - -/** - * @brief Get current position in a file - */ -dmod_dmfsi_dif_api_declaration( 1.0, dmdfs, long, _tell, (dmfsi_context_t ctx, void* fp) ) -{ - if(dmfsi_dmdfs_context_is_valid(ctx) == 0) - { - DMOD_LOG_ERROR("dmdfs: Invalid context in tell\n"); - return -1; - } - - // TODO: Implement position retrieval - return -1; -} - -/** - * @brief Check if at end of file - */ -dmod_dmfsi_dif_api_declaration( 1.0, dmdfs, int, _eof, (dmfsi_context_t ctx, void* fp) ) -{ - if(dmfsi_dmdfs_context_is_valid(ctx) == 0) - { - DMOD_LOG_ERROR("dmdfs: Invalid context in eof\n"); - return 1; - } - - // TODO: Implement EOF checking - return 1; -} - -/** - * @brief Get file size - */ -dmod_dmfsi_dif_api_declaration( 1.0, dmdfs, long, _size, (dmfsi_context_t ctx, void* fp) ) -{ - if(dmfsi_dmdfs_context_is_valid(ctx) == 0) - { - DMOD_LOG_ERROR("dmdfs: Invalid context in size\n"); - return -1; - } - - // TODO: Implement size retrieval - return -1; -} - -/** - * @brief Read a single character - */ -dmod_dmfsi_dif_api_declaration( 1.0, dmdfs, int, _getc, (dmfsi_context_t ctx, void* fp) ) -{ - if(dmfsi_dmdfs_context_is_valid(ctx) == 0) - { - DMOD_LOG_ERROR("dmdfs: Invalid context in getc\n"); - return -1; - } - - // TODO: Implement character reading - return -1; -} - -/** - * @brief Write a single character - */ -dmod_dmfsi_dif_api_declaration( 1.0, dmdfs, int, _putc, (dmfsi_context_t ctx, void* fp, char c) ) -{ - if(dmfsi_dmdfs_context_is_valid(ctx) == 0) - { - DMOD_LOG_ERROR("dmdfs: Invalid context in putc\n"); - return -1; - } - - // TODO: Implement character writing - return DMFSI_ERR_GENERAL; -} - -/** - * @brief Flush file buffers - */ -dmod_dmfsi_dif_api_declaration( 1.0, dmdfs, int, _fflush, (dmfsi_context_t ctx, void* fp) ) -{ - if(dmfsi_dmdfs_context_is_valid(ctx) == 0) - { - DMOD_LOG_ERROR("dmdfs: Invalid context in fflush\n"); - return DMFSI_ERR_INVALID; - } - - // TODO: Implement buffer flushing - return DMFSI_OK; -} - -/** - * @brief Sync file to storage - */ -dmod_dmfsi_dif_api_declaration( 1.0, dmdfs, int, _sync, (dmfsi_context_t ctx, void* fp) ) -{ - if(dmfsi_dmdfs_context_is_valid(ctx) == 0) - { - DMOD_LOG_ERROR("dmdfs: Invalid context in sync\n"); - return DMFSI_ERR_INVALID; - } - - // TODO: Implement sync - return DMFSI_OK; -} - -/** - * @brief Open a directory - */ -dmod_dmfsi_dif_api_declaration( 1.0, dmdfs, int, _opendir, (dmfsi_context_t ctx, void** dp, const char* path) ) -{ - if(dmfsi_dmdfs_context_is_valid(ctx) == 0) - { - DMOD_LOG_ERROR("dmdfs: Invalid context in opendir\n"); - return DMFSI_ERR_INVALID; - } - - // TODO: Implement directory opening - return DMFSI_ERR_GENERAL; -} - -/** - * @brief Read directory entry - */ -dmod_dmfsi_dif_api_declaration( 1.0, dmdfs, int, _readdir, (dmfsi_context_t ctx, void* dp, dmfsi_dir_entry_t* entry) ) -{ - if(dmfsi_dmdfs_context_is_valid(ctx) == 0) - { - DMOD_LOG_ERROR("dmdfs: Invalid context in readdir\n"); - return DMFSI_ERR_INVALID; - } - - // TODO: Implement directory reading - return DMFSI_ERR_NOT_FOUND; -} - -/** - * @brief Close a directory - */ -dmod_dmfsi_dif_api_declaration( 1.0, dmdfs, int, _closedir, (dmfsi_context_t ctx, void* dp) ) -{ - if(dmfsi_dmdfs_context_is_valid(ctx) == 0) - { - DMOD_LOG_ERROR("dmdfs: Invalid context in closedir\n"); - return DMFSI_ERR_INVALID; - } - - // TODO: Implement directory closing - return DMFSI_ERR_GENERAL; -} - -/** - * @brief Create a directory - */ -dmod_dmfsi_dif_api_declaration( 1.0, dmdfs, int, _mkdir, (dmfsi_context_t ctx, const char* path) ) -{ - if(dmfsi_dmdfs_context_is_valid(ctx) == 0) - { - DMOD_LOG_ERROR("dmdfs: Invalid context in mkdir\n"); - return DMFSI_ERR_INVALID; - } - - // TODO: Implement directory creation - return DMFSI_ERR_GENERAL; -} - -/** - * @brief Check if directory exists - */ -dmod_dmfsi_dif_api_declaration( 1.0, dmdfs, int, _direxists, (dmfsi_context_t ctx, const char* path) ) -{ - if(dmfsi_dmdfs_context_is_valid(ctx) == 0) - { - DMOD_LOG_ERROR("dmdfs: Invalid context in direxists\n"); - return 0; - } - - // TODO: Implement directory existence check - return 0; -} - -/** - * @brief Get file/directory statistics - */ -dmod_dmfsi_dif_api_declaration( 1.0, dmdfs, int, _stat, (dmfsi_context_t ctx, const char* path, dmfsi_stat_t* stat) ) -{ - if(dmfsi_dmdfs_context_is_valid(ctx) == 0) - { - DMOD_LOG_ERROR("dmdfs: Invalid context in stat\n"); - return DMFSI_ERR_INVALID; - } - - // TODO: Implement stat - return DMFSI_ERR_GENERAL; -} - -/** - * @brief Delete a file - */ -dmod_dmfsi_dif_api_declaration( 1.0, dmdfs, int, _unlink, (dmfsi_context_t ctx, const char* path) ) -{ - if(dmfsi_dmdfs_context_is_valid(ctx) == 0) - { - DMOD_LOG_ERROR("dmdfs: Invalid context in unlink\n"); - return DMFSI_ERR_INVALID; - } - - // TODO: Implement file deletion - return DMFSI_ERR_GENERAL; -} - -/** - * @brief Rename a file - */ -dmod_dmfsi_dif_api_declaration( 1.0, dmdfs, int, _rename, (dmfsi_context_t ctx, const char* oldpath, const char* newpath) ) -{ - if(dmfsi_dmdfs_context_is_valid(ctx) == 0) - { - DMOD_LOG_ERROR("dmdfs: Invalid context in rename\n"); - return DMFSI_ERR_INVALID; - } - - // TODO: Implement file renaming - return DMFSI_ERR_GENERAL; -}