Ken Van Hoeylandt 79d3dd4fdb
Improvements for apps, filesystems, terminal and shell (#659)
app-module

- Apps now have support for:
  - environment variables (inherit from parent app)
  - current workdir
  - window size (when running in terminal)
- Add type aliases like `AppId` and `PackageId`
- Remove data duplication between ledger and app instance records: create `AppManifestSet`
- `AppManifest` usage safety improved: pass by value where needed, or use `AppId` instead of a manifest.

Terminal and shell

- Moved shell commands into coreutils-module as proper apps.
- Refine stack size for terminal and shell because apps now run with their own task and stack (including in-memory apps)

Platform

- Fix for listing root dir on ESP32: wrap posix directory functions and wire in file systems.
- Moved all platform-specific file system init code to platform subprojects

Other

- Fix for screenshot capture (issue with paths)
- Fixes for coreutils app correctness
- Memory optimizations (use more PSRAM where possible) in various locations such as app-module, shell and terminal.
- `ls` and `help` commands now use terminal width and show columns of data by default
- Created fs helpers at `TactilityKernel/include/tactility/filesystem/fs.h` (partially ported from `ShellFs`)
2026-09-25 08:29:27 +02:00

144 lines
4.5 KiB
C

// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <stdbool.h>
#include <stddef.h>
#include <tactility/error.h>
#ifdef __cplusplus
extern "C" {
#endif
struct FileSystem;
/**
* @brief File system API.
*
* Provides a set of function pointers to interact with a specific file system implementation.
*/
struct FileSystemApi {
/**
* @brief Mounts the file system.
* @param[in] data file system private data
* @return ERROR_NONE on success, or an error code
*/
error_t (*mount)(void* data);
/**
* @brief Unmounts the file system.
* @param[in] data file system private data
* @return ERROR_NONE on success, or an error code
*/
error_t (*unmount)(void* data);
/**
* @brief Checks if the file system is mounted.
* @param[in] data file system private data
* @return true if mounted, false otherwise
*/
bool (*is_mounted)(void* data);
/**
* @brief Gets the mount path.
* @param[in] data file system private data
* @param[out] out_path buffer to store the path
* @param[in] out_path_size size of the output buffer
* @return ERROR_NONE on success, or an error code
*/
error_t (*get_path)(void* data, char* out_path, size_t out_path_size);
};
/**
* @brief Registers a new file system.
* @param[in] name identifies this file system for file_system_find_by_name(), e.g. "data",
* "system", "sdcard". Not copied - must outlive the FileSystem (a string literal, typically).
* @param[in] fs_api the file system API implementation
* @param[in] data private data for the file system
* @return the registered FileSystem object
*/
struct FileSystem* file_system_add(const char* name, const struct FileSystemApi* fs_api, void* data);
/**
* @brief Finds a registered file system by the name it was added with.
* @param[in] name see file_system_add()
* @return the FileSystem, or NULL if no registered file system has this name
*/
struct FileSystem* file_system_find_by_name(const char* name);
/**
* @brief Gets the name a file system was registered with.
* @param[in] fs the FileSystem object
* @return the name passed to file_system_add() - never NULL for a valid FileSystem
*/
const char* file_system_get_name(struct FileSystem* fs);
/**
* @brief Removes a registered file system.
* @note The file system must be unmounted before removal.
* @param[in] fs the FileSystem object to remove
*/
void file_system_remove(struct FileSystem* fs);
/**
* @brief Iterates over all registered file systems.
* @param[in] callback_context context passed to the callback
* @param[in] callback function called for each file system. Return true to continue, false to stop.
*/
void file_system_for_each(void* callback_context, bool (*callback)(struct FileSystem* fs, void* context));
/**
* @brief Iterates over registered file systems that are currently mounted.
* @param[in] callback_context context passed to the callback
* @param[in] callback function called for each mounted file system. Return true to continue, false to stop.
*/
void file_system_for_each_mounted(void* callback_context, bool (*callback)(struct FileSystem* fs, void* context));
/**
* @brief Mounts the file system.
* @param[in] fs the FileSystem object
* @return ERROR_NONE on success, or an error code
*/
error_t file_system_mount(struct FileSystem* fs);
/**
* @warning Unmounting can fail (e.g. when the device is busy), so you might need to retry it.
* @brief Unmounts the file system.
* @param[in] fs the FileSystem object
* @return ERROR_NONE on success, or an error code
*/
error_t file_system_unmount(struct FileSystem* fs);
/**
* @brief Checks if the file system is mounted.
* @param[in] fs the FileSystem object
* @return true if mounted, false otherwise
*/
bool file_system_is_mounted(struct FileSystem* fs);
/**
* @brief Gets the mount path.
* @param[in] fs the FileSystem object
* @param[out] out_path buffer to store the path
* @param[in] out_path_size size of the output buffer
* @return ERROR_NONE on success, or an error code
*/
error_t file_system_get_path(struct FileSystem* fs, char* out_path, size_t out_path_size);
/**
* @brief Sets the owner device of the file system.
* @param[in] fs the FileSystem object
* @param[in] owner the owning device, or NULL
*/
void file_system_set_owner(struct FileSystem* fs, struct Device* owner);
/**
* @brief Gets the owner device of the file system.
* @param[in] fs the FileSystem object
* @return the owning device, or NULL if not set
*/
struct Device* file_system_get_owner(struct FileSystem* fs);
#ifdef __cplusplus
}
#endif