SatNOGS-COMMS  4.1.0
A COMMS subsystem for CubeSats
Loading...
Searching...
No Matches
satnogs::comms::storage Class Reference

#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 storageget_instance ()

Static Public Attributes

static constexpr size_t SECTOR_SIZE = CONFIG_EMMC_SECTOR_SIZE

Detailed Description

Definition at line 33 of file storage.hpp.

Constructor & Destructor Documentation

◆ storage()

satnogs::comms::storage::storage ( storage const & )
delete

Member Function Documentation

◆ du()

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.

Parameters
pathThe file or directory path
Returns
Total size in bytes of the file or all files within the directory
Exceptions
not_ready_exceptionIf the storage subsystem is not initialized
max_path_exceptionIf the provided path exceeds maximum length
fs_exceptionIf the path does not exist or any other filesystem operation fails

Definition at line 562 of file storage.cpp.

◆ enable()

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.

Parameters
entrue to enable, false to disable

Definition at line 125 of file storage.cpp.

◆ enabled()

bool satnogs::comms::storage::enabled ( ) const

Checks if the storage subsystem is enabled.

Returns
true if the storage subsystem is enabled
false otherwise

Definition at line 183 of file storage.cpp.

◆ erase_sectors()

void satnogs::comms::storage::erase_sectors ( size_t start_sector,
size_t sectors )

Erase a specific number of sectors.

Warning
This method does not respect in any way any underlying filesystem, data, or the dedicated littleFS portion of the storage. Use it with extreme caution.
Note
The erase procedure is performed by setting all bits to 1.
Parameters
start_sector
sectors

Definition at line 887 of file storage.cpp.

◆ get_dir()

lib::emmc::dir satnogs::comms::storage::get_dir ( ) const

Get the direction of the eMMC.

Returns
lib::emmc::dir the current direction of the eMMC

Definition at line 218 of file storage.cpp.

◆ get_instance()

storage & satnogs::comms::storage::get_instance ( )
inlinestatic

Definition at line 94 of file storage.hpp.

◆ is_dir()

bool satnogs::comms::storage::is_dir ( const etl::istring & path)

Check if a path is a directory.

Parameters
paththe path to check
Returns
true if the path is a directory
false if the path is not a directory
Exceptions
fs_exceptionif the path does not exist or any other filesystem operation fails
See also
storage::is_file()

Definition at line 714 of file storage.cpp.

◆ is_file()

bool satnogs::comms::storage::is_file ( const etl::istring & path)

Check if a path is a file.

Parameters
paththe path to check
Returns
true if the path is a file
false if the path is not a file
Exceptions
fs_exceptionif the path does not exist or any other filesystem operation fails

Definition at line 692 of file storage.cpp.

◆ ls() [1/2]

void satnogs::comms::storage::ls ( const etl::istring & path,
etl::istring & res )

Lists the contents of a directory.

Parameters
paththe path to the directory to list
resthe string to hold the directory listing
Note
The contents of the directory are appended to res. It is responsibility of the caller to clear it if needed.

Definition at line 624 of file storage.cpp.

◆ ls() [2/2]

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.

Note
The directory may contain also subdirectories. Caller should check the fs_dir_entry_type of the returned entry.
Parameters
dirthe directory to list
entryreference to hold the result. Valid only if this method returns true.
Returns
true if a valid entry was returned
false if the directory is empty or all entries have been listed

Definition at line 669 of file storage.cpp.

◆ mkdir()

void satnogs::comms::storage::mkdir ( const etl::istring & path)

Creates a directory at the specified path.

Parameters
paththe path to the directory to create
Exceptions
not_ready_exceptionif storage is not ready
max_path_exceptionif path exceeds maximum allowed length
fs_exceptionif directory creation fails

Definition at line 248 of file storage.cpp.

◆ mounted()

bool satnogs::comms::storage::mounted ( ) const

Checks if the storage subsystem is mounted.

Returns
true if the storage subsystem is mounted
false otherwise

Definition at line 195 of file storage.cpp.

◆ operator=()

void satnogs::comms::storage::operator= ( storage const & )
delete

◆ read() [1/3]

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.

Parameters
paththe path to the file to read from
bthe buffer to hold the read data
lenthe number of bytes to read
offsetthe offset to start reading with respect to the start of the file
Returns
size_t the number of bytes actually read

Definition at line 730 of file storage.cpp.

◆ read() [2/3]

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.

Parameters
fthe file to read from
bthe buffer to hold the read data
lenthe number of bytes to read
Returns
size_t the number of bytes actually read

Definition at line 770 of file storage.cpp.

◆ read() [3/3]

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.

Parameters
fthe file to read from
bthe buffer to hold the read data
lenthe number of bytes to read
offsetthe offset to start reading with respect to the start of the file
Returns
size_t

Definition at line 747 of file storage.cpp.

◆ read_raw()

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.

Parameters
bthe buffer to hold the read data
start_sectorthe sector to start reading from
sectorsthe number of sectors to read
Returns
size_t the number of sectors actually read

Definition at line 855 of file storage.cpp.

◆ ready()

bool satnogs::comms::storage::ready ( ) const

Checks if the storage subsystem is ready to accept filesystem operations for the MCU side.

Returns
true if the storage subsystem is enabled, the filesystem is mounted and the direction is MCU
false otherwise

Definition at line 234 of file storage.cpp.

◆ rm()

void satnogs::comms::storage::rm ( const etl::istring & path)

Removes a file from the filesystem.

Parameters
paththe path to the file to remove
Exceptions
not_ready_exceptionif storage is not ready
max_path_exceptionif path exceeds maximum allowed length
delete_file_exceptionif file removal fails

Definition at line 295 of file storage.cpp.

◆ rmdir()

void satnogs::comms::storage::rmdir ( const etl::istring & path)

Removes a directory and all its contents.

Parameters
paththe path to the directory to remove
Exceptions
not_ready_exceptionif storage is not ready
max_path_exceptionif path exceeds maximum allowed length
delete_dir_exceptionif directory removal fails
fs_exceptionif filesystem operations fail

Definition at line 329 of file storage.cpp.

◆ sectors_num()

size_t satnogs::comms::storage::sectors_num ( ) const

Returns the number of total sectors of the eMMC.

Returns
size_t the number of total sectors of the eMMC

Definition at line 906 of file storage.cpp.

◆ set_dir()

void satnogs::comms::storage::set_dir ( lib::emmc::dir d)

Set the direction of the eMMC.

Parameters
dthe direction to set

Definition at line 206 of file storage.cpp.

◆ truncate()

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).

Parameters
pathPath to the file to truncate.
lenNumber of bytes to remove from the end of the file.
Precondition
Storage must be ready and mounted for MCU-side access.
Exceptions
not_ready_exceptionIf the storage subsystem is not ready.
max_path_exceptionIf path exceeds the maximum allowed length.
fs_exceptionIf stat/open/truncate/sync operations fail.

Definition at line 445 of file storage.cpp.

◆ utilization()

float satnogs::comms::storage::utilization ( )

Get eMMC storage utilization of the partition used by the MCU.

Exceptions
not_ready_exceptionif storage is not ready.
Returns
Utilization percentage (a value between 0.0f and 1.0f).

Definition at line 80 of file storage.cpp.

◆ write() [1/2]

size_t satnogs::comms::storage::write ( const etl::istring & path,
const uint8_t * b,
size_t len )

Writes data to a file.

Parameters
paththe path to the file to write to
bthe buffer holding the data to write
lenthe number of bytes to write
Returns
size_t the number of bytes actually written

Definition at line 395 of file storage.cpp.

◆ write() [2/2]

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.

Parameters
paththe path to the file to write to
bthe buffer holding the data to write
lenthe number of bytes to write
offsetthe offset to start writing with respect to the start of the file
Returns
size_t the number of bytes actually written
Note
If the offset is beyond the current end of file, the data is appended at the end of the file.

Definition at line 501 of file storage.cpp.

◆ write_raw()

size_t satnogs::comms::storage::write_raw ( const uint8_t * b,
size_t start_sector,
size_t len )

Writes raw bytes on the eMMC.

Warning
This method uses the raw disk access API, directly applying the data to the eMMC. It does not respect any underlying data or file system at the affected sectors. Use it with extreme caution. However it guarantees that the littleFS filesystem is not affected.
Parameters
bthe buffer containing the data to write
start_sectorthe sector to start writing
lenthe number of bytes to write
Returns
size_t the number of bytes written

Definition at line 796 of file storage.cpp.

Member Data Documentation

◆ SECTOR_SIZE

size_t satnogs::comms::storage::SECTOR_SIZE = CONFIG_EMMC_SECTOR_SIZE
staticconstexpr

Definition at line 36 of file storage.hpp.


The documentation for this class was generated from the following files: