![]() |
SatNOGS-COMMS
4.1.0
A COMMS subsystem for CubeSats
|
#include <storage.hpp>
Classes | |
| class | file |
| class | directory |
| class | open_dir_exception |
| class | delete_dir_exception |
| class | delete_file_exception |
| class | max_path_exception |
| class | mount_exception |
| class | not_ready_exception |
| class | read_exception |
| class | fs_exception |
Public Member Functions | |
| storage (storage const &)=delete | |
| void | operator= (storage const &)=delete |
| void | enable (bool en) |
| Enable or disable the storage subsystem. | |
| bool | enabled () const |
| Checks if the storage subsystem is enabled. | |
| bool | mounted () const |
| Checks if the storage subsystem is mounted. | |
| void | set_dir (lib::emmc::dir d) |
| Set the direction of the eMMC. | |
| lib::emmc::dir | get_dir () const |
| Get the direction of the eMMC. | |
| bool | ready () const |
| Checks if the storage subsystem is ready to accept filesystem operations for the MCU side. | |
| void | truncate (const etl::istring &path, size_t len) |
| Truncate a file by removing bytes from its end. | |
| void | mkdir (const etl::istring &path) |
| Creates a directory at the specified path. | |
| void | rm (const etl::istring &path) |
| Removes a file from the filesystem. | |
| void | rmdir (const etl::istring &path) |
| Removes a directory and all its contents. | |
| size_t | write (const etl::istring &path, const uint8_t *b, size_t len) |
| Writes data to a file. | |
| size_t | write (const etl::istring &path, const uint8_t *b, size_t len, size_t offset) |
| Writes to a file starting from specific offset. | |
| void | ls (const etl::istring &path, etl::istring &res) |
| Lists the contents of a directory. | |
| bool | ls (directory &dir, fs_dirent &entry) |
| Lists iteratively the contents of a directory. | |
| bool | is_file (const etl::istring &path) |
| Check if a path is a file. | |
| bool | is_dir (const etl::istring &path) |
| Check if a path is a directory. | |
| uint64_t | du (const etl::istring &path) |
| Calculate the disk usage of a file or directory likewise the 'du' command of Linux. | |
| size_t | read (const etl::istring &path, uint8_t *b, size_t len, size_t offset) |
| Reads from a file starting from specific offset. | |
| size_t | read (file &f, uint8_t *b, size_t len, size_t offset) |
| Reads from an already opened file starting from specific offset. | |
| size_t | read (file &f, uint8_t *b, size_t len) |
| Reads from an already opened file starting from the current read position. | |
| size_t | write_raw (const uint8_t *b, size_t start_sector, size_t len) |
| Writes raw bytes on the eMMC. | |
| size_t | read_raw (uint8_t *b, size_t start_sector, size_t sectors) |
| Reads directly raw sectors from the eMMC, bypassing any filesystem. | |
| void | erase_sectors (size_t start_sector, size_t sectors) |
| Erase a specific number of sectors. | |
| size_t | sectors_num () const |
| Returns the number of total sectors of the eMMC. | |
| float | utilization () |
| Get eMMC storage utilization of the partition used by the MCU. | |
Static Public Member Functions | |
| static storage & | get_instance () |
Static Public Attributes | |
| static constexpr size_t | SECTOR_SIZE = CONFIG_EMMC_SECTOR_SIZE |
Definition at line 33 of file storage.hpp.
|
delete |
| uint64_t satnogs::comms::storage::du | ( | const etl::istring & | path | ) |
Calculate the disk usage of a file or directory likewise the 'du' command of Linux.
This method returns the size of a file if the provided path is a file or the cumulative size of all files within a directory if the provided path is a directory. The nested directories are traversed breadth-first, summing file sizes up to CONFIG_STORAGE_MAX_DEPTH levels deep.
| path | The file or directory path |
| not_ready_exception | If the storage subsystem is not initialized |
| max_path_exception | If the provided path exceeds maximum length |
| fs_exception | If the path does not exist or any other filesystem operation fails |
Definition at line 562 of file storage.cpp.
| void satnogs::comms::storage::enable | ( | bool | en | ) |
Enable or disable the storage subsystem.
This method enables or disables the storage subsystem. When enabling, it powers on the eMMC, resets it, and mounts the filesystem. When disabling, it unmounts the filesystem and powers off the eMMC. When enabling, the default direction is set to MCU.
| en | true to enable, false to disable |
Definition at line 125 of file storage.cpp.
| bool satnogs::comms::storage::enabled | ( | ) | const |
Checks if the storage subsystem is enabled.
Definition at line 183 of file storage.cpp.
| void satnogs::comms::storage::erase_sectors | ( | size_t | start_sector, |
| size_t | sectors ) |
Erase a specific number of sectors.
| start_sector | |
| sectors |
Definition at line 887 of file storage.cpp.
| lib::emmc::dir satnogs::comms::storage::get_dir | ( | ) | const |
Get the direction of the eMMC.
Definition at line 218 of file storage.cpp.
|
inlinestatic |
Definition at line 94 of file storage.hpp.
| bool satnogs::comms::storage::is_dir | ( | const etl::istring & | path | ) |
Check if a path is a directory.
| path | the path to check |
| fs_exception | if the path does not exist or any other filesystem operation fails |
Definition at line 714 of file storage.cpp.
| bool satnogs::comms::storage::is_file | ( | const etl::istring & | path | ) |
Check if a path is a file.
| path | the path to check |
| fs_exception | if the path does not exist or any other filesystem operation fails |
Definition at line 692 of file storage.cpp.
| void satnogs::comms::storage::ls | ( | const etl::istring & | path, |
| etl::istring & | res ) |
Lists the contents of a directory.
| path | the path to the directory to list |
| res | the string to hold the directory listing |
res. It is responsibility of the caller to clear it if needed. Definition at line 624 of file storage.cpp.
| bool satnogs::comms::storage::ls | ( | directory & | dir, |
| fs_dirent & | entry ) |
Lists iteratively the contents of a directory.
This method allows the user to call it multiple times in order to retrieve the full listing of the directory. When all the files of the directory or if it is empty, this method returns false.
| dir | the directory to list |
| entry | reference to hold the result. Valid only if this method returns true. |
Definition at line 669 of file storage.cpp.
| void satnogs::comms::storage::mkdir | ( | const etl::istring & | path | ) |
Creates a directory at the specified path.
| path | the path to the directory to create |
| not_ready_exception | if storage is not ready |
| max_path_exception | if path exceeds maximum allowed length |
| fs_exception | if directory creation fails |
Definition at line 248 of file storage.cpp.
| bool satnogs::comms::storage::mounted | ( | ) | const |
Checks if the storage subsystem is mounted.
Definition at line 195 of file storage.cpp.
|
delete |
| size_t satnogs::comms::storage::read | ( | const etl::istring & | path, |
| uint8_t * | b, | ||
| size_t | len, | ||
| size_t | offset ) |
Reads from a file starting from specific offset.
| path | the path to the file to read from |
| b | the buffer to hold the read data |
| len | the number of bytes to read |
| offset | the offset to start reading with respect to the start of the file |
Definition at line 730 of file storage.cpp.
| size_t satnogs::comms::storage::read | ( | file & | f, |
| uint8_t * | b, | ||
| size_t | len ) |
Reads from an already opened file starting from the current read position.
| f | the file to read from |
| b | the buffer to hold the read data |
| len | the number of bytes to read |
Definition at line 770 of file storage.cpp.
| size_t satnogs::comms::storage::read | ( | file & | f, |
| uint8_t * | b, | ||
| size_t | len, | ||
| size_t | offset ) |
Reads from an already opened file starting from specific offset.
| f | the file to read from |
| b | the buffer to hold the read data |
| len | the number of bytes to read |
| offset | the offset to start reading with respect to the start of the file |
Definition at line 747 of file storage.cpp.
| size_t satnogs::comms::storage::read_raw | ( | uint8_t * | b, |
| size_t | start_sector, | ||
| size_t | sectors ) |
Reads directly raw sectors from the eMMC, bypassing any filesystem.
| b | the buffer to hold the read data |
| start_sector | the sector to start reading from |
| sectors | the number of sectors to read |
Definition at line 855 of file storage.cpp.
| bool satnogs::comms::storage::ready | ( | ) | const |
Checks if the storage subsystem is ready to accept filesystem operations for the MCU side.
Definition at line 234 of file storage.cpp.
| void satnogs::comms::storage::rm | ( | const etl::istring & | path | ) |
Removes a file from the filesystem.
| path | the path to the file to remove |
| not_ready_exception | if storage is not ready |
| max_path_exception | if path exceeds maximum allowed length |
| delete_file_exception | if file removal fails |
Definition at line 295 of file storage.cpp.
| void satnogs::comms::storage::rmdir | ( | const etl::istring & | path | ) |
Removes a directory and all its contents.
| path | the path to the directory to remove |
| not_ready_exception | if storage is not ready |
| max_path_exception | if path exceeds maximum allowed length |
| delete_dir_exception | if directory removal fails |
| fs_exception | if filesystem operations fail |
Definition at line 329 of file storage.cpp.
| size_t satnogs::comms::storage::sectors_num | ( | ) | const |
Returns the number of total sectors of the eMMC.
Definition at line 906 of file storage.cpp.
| void satnogs::comms::storage::set_dir | ( | lib::emmc::dir | d | ) |
Set the direction of the eMMC.
| d | the direction to set |
Definition at line 206 of file storage.cpp.
| void satnogs::comms::storage::truncate | ( | const etl::istring & | path, |
| size_t | len ) |
Truncate a file by removing bytes from its end.
Sets the file size to max(old_size-len,0). If len is greater than the current file size, the file becomes empty (size 0).
| path | Path to the file to truncate. |
| len | Number of bytes to remove from the end of the file. |
| not_ready_exception | If the storage subsystem is not ready. |
| max_path_exception | If path exceeds the maximum allowed length. |
| fs_exception | If stat/open/truncate/sync operations fail. |
Definition at line 445 of file storage.cpp.
| float satnogs::comms::storage::utilization | ( | ) |
Get eMMC storage utilization of the partition used by the MCU.
| not_ready_exception | if storage is not ready. |
Definition at line 80 of file storage.cpp.
| size_t satnogs::comms::storage::write | ( | const etl::istring & | path, |
| const uint8_t * | b, | ||
| size_t | len ) |
Writes data to a file.
| path | the path to the file to write to |
| b | the buffer holding the data to write |
| len | the number of bytes to write |
Definition at line 395 of file storage.cpp.
| size_t satnogs::comms::storage::write | ( | const etl::istring & | path, |
| const uint8_t * | b, | ||
| size_t | len, | ||
| size_t | offset ) |
Writes to a file starting from specific offset.
| path | the path to the file to write to |
| b | the buffer holding the data to write |
| len | the number of bytes to write |
| offset | the offset to start writing with respect to the start of the file |
Definition at line 501 of file storage.cpp.
| size_t satnogs::comms::storage::write_raw | ( | const uint8_t * | b, |
| size_t | start_sector, | ||
| size_t | len ) |
Writes raw bytes on the eMMC.
| b | the buffer containing the data to write |
| start_sector | the sector to start writing |
| len | the number of bytes to write |
Definition at line 796 of file storage.cpp.
|
staticconstexpr |
Definition at line 36 of file storage.hpp.