Flipper Zero Firmware
Loading...
Searching...
No Matches
storage.h
Go to the documentation of this file.
1
5#pragma once
6
7#include <stdint.h>
8#include "filesystem_api_defines.h"
9#include "storage_sd_api.h"
10
11#ifdef __cplusplus
12extern "C" {
13#endif
14
15#define STORAGE_INT_PATH_PREFIX "/int"
16#define STORAGE_EXT_PATH_PREFIX "/ext"
17#define STORAGE_ANY_PATH_PREFIX "/any"
18#define STORAGE_APP_DATA_PATH_PREFIX "/data"
19#define STORAGE_APP_ASSETS_PATH_PREFIX "/assets"
20
21#define INT_PATH(path) STORAGE_INT_PATH_PREFIX "/" path
22#define EXT_PATH(path) STORAGE_EXT_PATH_PREFIX "/" path
23#define ANY_PATH(path) STORAGE_ANY_PATH_PREFIX "/" path
24#define APP_DATA_PATH(path) STORAGE_APP_DATA_PATH_PREFIX "/" path
25#define APP_ASSETS_PATH(path) STORAGE_APP_ASSETS_PATH_PREFIX "/" path
26
27#define RECORD_STORAGE "storage"
28
29typedef struct Storage Storage;
30
38
45void storage_file_free(File* file);
46
57
61typedef struct {
64
74
75/******************* File Functions *******************/
76
89 File* file,
90 const char* path,
91 FS_AccessMode access_mode,
92 FS_OpenMode open_mode);
93
100bool storage_file_close(File* file);
101
108bool storage_file_is_open(File* file);
109
116bool storage_file_is_dir(File* file);
117
126size_t storage_file_read(File* file, void* buff, size_t bytes_to_read);
127
136size_t storage_file_write(File* file, const void* buff, size_t bytes_to_write);
137
146bool storage_file_seek(File* file, uint32_t offset, bool from_start);
147
154uint64_t storage_file_tell(File* file);
155
162bool storage_file_truncate(File* file);
163
170uint64_t storage_file_size(File* file);
171
178bool storage_file_sync(File* file);
179
186bool storage_file_eof(File* file);
187
195bool storage_file_exists(Storage* storage, const char* path);
196
210bool storage_file_copy_to_file(File* source, File* destination, size_t size);
211
212/******************* Directory Functions *******************/
213
225bool storage_dir_open(File* file, const char* path);
226
233bool storage_dir_close(File* file);
234
247bool storage_dir_read(File* file, FileInfo* fileinfo, char* name, uint16_t name_length);
248
255bool storage_dir_rewind(File* file);
256
264bool storage_dir_exists(Storage* storage, const char* path);
265
266/******************* Common Functions *******************/
267
276FS_Error storage_common_timestamp(Storage* storage, const char* path, uint32_t* timestamp);
277
286FS_Error storage_common_stat(Storage* storage, const char* path, FileInfo* fileinfo);
287
298FS_Error storage_common_remove(Storage* storage, const char* path);
299
314FS_Error storage_common_rename(Storage* storage, const char* old_path, const char* new_path);
315
326FS_Error storage_common_copy(Storage* storage, const char* old_path, const char* new_path);
327
336FS_Error storage_common_merge(Storage* storage, const char* old_path, const char* new_path);
337
345FS_Error storage_common_mkdir(Storage* storage, const char* path);
346
357 Storage* storage,
358 const char* fs_path,
359 uint64_t* total_space,
360 uint64_t* free_space);
361
371
382FS_Error storage_common_migrate(Storage* storage, const char* source, const char* dest);
383
391bool storage_common_exists(Storage* storage, const char* path);
392
415 Storage* storage,
416 const char* path1,
417 const char* path2,
418 bool truncate);
419
420/******************* Error Functions *******************/
421
428const char* storage_error_get_desc(FS_Error error_id);
429
438FS_Error storage_file_get_error(File* file);
439
449
458const char* storage_file_get_error_desc(File* file);
459
460/******************* SD Card Functions *******************/
461
468FS_Error storage_sd_format(Storage* storage);
469
480FS_Error storage_sd_unmount(Storage* storage);
481
488FS_Error storage_sd_mount(Storage* storage);
489
497FS_Error storage_sd_info(Storage* storage, SDInfo* info);
498
505FS_Error storage_sd_status(Storage* storage);
506
507/******************* Internal LFS Functions *******************/
508
509typedef void (*Storage_name_converter)(FuriString*);
510
518FS_Error storage_int_backup(Storage* storage, const char* dstname);
519
528FS_Error
529 storage_int_restore(Storage* storage, const char* dstname, Storage_name_converter converter);
530
531/***************** Simplified Functions ******************/
532
544bool storage_simply_remove(Storage* storage, const char* path);
545
555bool storage_simply_remove_recursive(Storage* storage, const char* path);
556
564bool storage_simply_mkdir(Storage* storage, const char* path);
565
601 Storage* storage,
602 const char* dirname,
603 const char* filename,
604 const char* fileextension,
605 FuriString* nextfilename,
606 uint8_t max_len);
607
608#ifdef __cplusplus
609}
610#endif
StorageEventType
Enumeration of events emitted by the storage through the PubSub system.
Definition storage.h:50
@ StorageEventTypeCardUnmount
SD card was unmounted.
Definition storage.h:52
@ StorageEventTypeDirClose
A directory was closed.
Definition storage.h:55
@ StorageEventTypeFileClose
A file was closed.
Definition storage.h:54
@ StorageEventTypeCardMountError
An error occurred during mounting of an SD card.
Definition storage.h:53
@ StorageEventTypeCardMount
SD card was mounted.
Definition storage.h:51
FS_Error storage_int_backup(Storage *storage, const char *dstname)
Back up the internal storage contents to a *.tar archive.
Definition storage_internal_api.c:5
bool storage_simply_remove(Storage *storage, const char *path)
Remove a file or a directory.
Definition storage_external_api.c:1021
bool storage_file_eof(File *file)
Check whether the current access position is at the end of the file.
Definition storage_external_api.c:274
bool storage_file_seek(File *file, uint32_t offset, bool from_start)
Change the current access position in a file.
Definition storage_external_api.c:222
FS_Error storage_common_remove(Storage *storage, const char *path)
Remove a file or a directory.
Definition storage_external_api.c:463
FS_Error storage_sd_status(Storage *storage)
Get SD card status.
Definition storage_external_api.c:908
bool storage_common_equivalent_path(Storage *storage, const char *path1, const char *path2, bool truncate)
Check whether two paths are equivalent.
Definition storage_external_api.c:819
bool storage_dir_rewind(File *file)
Change the access position to first item in the directory.
Definition storage_external_api.c:407
size_t storage_file_write(File *file, const void *buff, size_t bytes_to_write)
Write bytes from a buffer to a file.
Definition storage_external_api.c:203
FS_Error storage_sd_mount(Storage *storage)
Mount the SD card.
Definition storage_external_api.c:885
bool storage_simply_remove_recursive(Storage *storage, const char *path)
Recursively remove a file or a directory.
Definition storage_external_api.c:960
int32_t storage_file_get_internal_error(File *file)
Get the internal (storage-specific) numeric error identifier from a file instance.
Definition storage_external_api.c:853
FS_Error storage_common_copy(Storage *storage, const char *old_path, const char *new_path)
Copy the file to a new location.
Definition storage_external_api.c:579
void storage_file_free(File *file)
Free the file instance.
Definition storage_external_api.c:940
bool storage_file_close(File *file)
Close the file.
Definition storage_external_api.c:127
void storage_common_resolve_path_and_ensure_app_directory(Storage *storage, FuriString *path)
Parse aliases in a path and replace them with the real path.
Definition storage_external_api.c:781
FS_Error storage_common_stat(Storage *storage, const char *path, FileInfo *fileinfo)
Get information about a file or a directory.
Definition storage_external_api.c:447
FS_Error storage_sd_format(Storage *storage)
Format the SD Card.
Definition storage_external_api.c:865
bool storage_file_copy_to_file(File *source, File *destination, size_t size)
Copy data from a source file to the destination file.
Definition storage_external_api.c:297
FS_Error storage_common_fs_info(Storage *storage, const char *fs_path, uint64_t *total_space, uint64_t *free_space)
Get the general information about the storage.
Definition storage_external_api.c:759
const char * storage_error_get_desc(FS_Error error_id)
Get the textual description of a numeric error identifer.
Definition storage_external_api.c:844
bool storage_dir_close(File *file)
Close the directory.
Definition storage_external_api.c:372
bool storage_dir_exists(Storage *storage, const char *path)
Check whether a directory exists.
Definition storage_external_api.c:416
bool storage_file_open(File *file, const char *path, FS_AccessMode access_mode, FS_OpenMode open_mode)
Open an existing file or create a new one.
Definition storage_external_api.c:91
FS_Error storage_sd_unmount(Storage *storage)
Unmount the SD card.
Definition storage_external_api.c:875
FS_Error storage_file_get_error(File *file)
Get the numeric error identifier from a file instance.
Definition storage_external_api.c:848
bool storage_file_exists(Storage *storage, const char *path)
Check whether a file exists.
Definition storage_external_api.c:283
bool storage_dir_read(File *file, FileInfo *fileinfo, char *name, uint16_t name_length)
Get the next item in the directory.
Definition storage_external_api.c:390
bool storage_common_exists(Storage *storage, const char *path)
Check whether a file or a directory exists.
Definition storage_external_api.c:812
bool storage_file_truncate(File *file)
Truncate the file size to the current access position.
Definition storage_external_api.c:247
FS_Error storage_int_restore(Storage *storage, const char *dstname, Storage_name_converter converter)
Restore the internal storage contents from a *.tar archive.
Definition storage_internal_api.c:17
FS_Error storage_sd_info(Storage *storage, SDInfo *info)
Get SD card information.
Definition storage_external_api.c:895
bool storage_file_sync(File *file)
Synchronise the file cache with the actual storage.
Definition storage_external_api.c:265
FS_Error storage_common_merge(Storage *storage, const char *old_path, const char *new_path)
Copy the contents of one directory into another and rename all conflicting files.
Definition storage_external_api.c:674
bool storage_simply_mkdir(Storage *storage, const char *path)
Create a directory.
Definition storage_external_api.c:1029
bool storage_dir_open(File *file, const char *path)
Open a directory.
Definition storage_external_api.c:340
FS_Error storage_common_rename(Storage *storage, const char *old_path, const char *new_path)
Rename a file or a directory.
Definition storage_external_api.c:478
FS_Error storage_common_timestamp(Storage *storage, const char *path, uint32_t *timestamp)
Get the last access time in UNIX format.
Definition storage_external_api.c:431
FS_Error storage_common_mkdir(Storage *storage, const char *path)
Create a directory.
Definition storage_external_api.c:744
const char * storage_file_get_error_desc(File *file)
Get the textual description of a the last error associated with a file instance.
Definition storage_external_api.c:858
File * storage_file_alloc(Storage *storage)
Allocate and initialize a file instance.
Definition storage_external_api.c:918
size_t storage_file_read(File *file, void *buff, size_t bytes_to_read)
Read bytes from a file into a buffer.
Definition storage_external_api.c:186
void storage_get_next_filename(Storage *storage, const char *dirname, const char *filename, const char *fileextension, FuriString *nextfilename, uint8_t max_len)
Get the next free filename in a directory.
Definition storage_external_api.c:1037
uint64_t storage_file_size(File *file)
Get the file size.
Definition storage_external_api.c:256
bool storage_file_is_open(File *file)
Check whether the file is open.
Definition storage_external_api.c:930
FuriPubSub * storage_get_pubsub(Storage *storage)
Get the storage pubsub instance.
Definition storage_external_api.c:955
FS_Error storage_common_migrate(Storage *storage, const char *source, const char *dest)
Move the contents of source folder to destination one and rename all conflicting files.
Definition storage_external_api.c:796
uint64_t storage_file_tell(File *file)
Get the current access position.
Definition storage_external_api.c:238
bool storage_file_is_dir(File *file)
Check whether a file instance represents a directory.
Definition storage_external_api.c:935
Structure that hold file index and returned api errors.
Definition filesystem_api_internal.h:17
Structure that hold file info.
Definition filesystem_api_defines.h:48
Definition pubsub.c:14
Definition string.c:4
Definition storage_sd_api.h:19
Storage event (passed to the PubSub callback).
Definition storage.h:61
StorageEventType type
Type of the event.
Definition storage.h:62
Definition storage_i.h:23