|
PebbleOS
|
Pebble File System (PFS) on the external NOR flash. More...
Modules | |
| App files | |
| Consistent naming of per-app files. | |
| Flash translation layer | |
| Contiguous virtual address space for PFS over several flash regions. | |
Data Structures | |
| struct | PFSFileListEntry |
| Entry of the list returned by pfs_create_file_list(). More... | |
Macros | |
| #define | OP_FLAG_READ (1 << 0) |
| Open for reading; fails if the file does not exist. | |
| #define | OP_FLAG_WRITE (1 << 1) |
| Open for writing, creating the file if it does not exist. | |
| #define | OP_FLAG_OVERWRITE (1 << 2) |
| Write a new version of an existing file, committed on pfs_close(). | |
| #define | OP_FLAG_SKIP_HDR_CRC_CHECK (1 << 3) |
| Skip checking the on-flash header CRCs. | |
| #define | OP_FLAG_USE_PAGE_CACHE (1 << 4) |
| Cache the translation from file pages to flash pages. | |
| #define | FILE_TYPE_STATIC (0xfe) |
| File type of regular files. | |
| #define | FILE_MAX_NAME_LEN (255) |
| Maximum length of a file name, without the NUL terminator. | |
| #define | FILE_CHANGED_EVENT_CLOSED (1 << 0) |
| pfs_watch_file() event: the file was closed after being opened for writing. | |
| #define | FILE_CHANGED_EVENT_REMOVED (1 << 1) |
| pfs_watch_file() event: the file was removed. | |
| #define | FILE_CHANGED_EVENT_ALL (FILE_CHANGED_EVENT_CLOSED | FILE_CHANGED_EVENT_REMOVED) |
| pfs_watch_file() events: all of them. | |
Typedefs | |
| typedef void(* | PFSFileChangedCallback) (void *data) |
| Callback of pfs_watch_file(). | |
| typedef void * | PFSCallbackHandle |
| Handle of a file watch, for pfs_unwatch_file(). | |
| typedef bool(* | PFSFilenameTestCallback) (const char *name) |
| File name filter of pfs_create_file_list() and pfs_remove_files(). | |
Enumerations | |
| enum | FSeekType { FSeekSet , FSeekCur } |
| Reference point of pfs_seek(). More... | |
Functions | |
| int | pfs_open (const char *name, uint8_t op_flags, uint8_t file_type, size_t start_size) |
| Open a file. | |
| int | pfs_write (int fd, const void *buf, size_t size) |
| Write at the current position, then advance it. | |
| int | pfs_read (int fd, void *buf, size_t size) |
| Read from the current position, then advance it. | |
| int | pfs_seek (int fd, int offset, FSeekType seek_type) |
| Set the current position. | |
| status_t | pfs_close (int fd) |
| Close a file. | |
| status_t | pfs_close_and_remove (int fd) |
| Close and remove a file. | |
| status_t | pfs_remove (const char *name) |
| Remove a file. | |
| size_t | pfs_get_file_size (int fd) |
| Get the size of a file, that is the number of bytes that can be read. | |
| status_t | pfs_init (bool run_filesystem_check) |
| Initialize PFS, before any other use. | |
| void | pfs_reboot_cleanup (void) |
| Clean up after a reboot, once and before any file operation. | |
| void | pfs_format (bool write_erase_headers) |
| Erase the whole filesystem and drop all open file descriptors. | |
| uint32_t | pfs_get_size (void) |
| Get the size of the filesystem. | |
| void | pfs_set_size (uint32_t new_size, bool new_region_erased) |
| Set the size of the filesystem, as regions are added to it. | |
| bool | pfs_active (void) |
| Check whether PFS is active on this device. | |
| bool | pfs_active_in_region (uint32_t start_address, uint32_t ending_address) |
| Check whether PFS is active in a range of the filesystem space. | |
| int | pfs_sector_optimal_size (int min_size, int namelen) |
| Get the optimal size of a file that can use space beyond a minimum. | |
| uint32_t | get_available_pfs_space (void) |
| Get the space available for new files. | |
| PFSCallbackHandle | pfs_watch_file (const char *filename, PFSFileChangedCallback callback, uint8_t event_flags, void *data) |
| Watch a file for changes. | |
| void | pfs_unwatch_file (PFSCallbackHandle cb_handle) |
| Stop watching a file. | |
| uint32_t | pfs_crc_calculate_file (int fd, uint32_t offset, uint32_t num_bytes) |
| Compute the legacy CRC-32 of a part of a file. | |
| PFSFileListEntry * | pfs_create_file_list (PFSFilenameTestCallback callback) |
| List the files whose name matches a filter. | |
| void | pfs_delete_file_list (PFSFileListEntry *list) |
| Free a list returned by pfs_create_file_list(). | |
| void | pfs_remove_files (PFSFilenameTestCallback callback) |
| Remove all files whose name matches a filter. | |
Pebble File System (PFS) on the external NOR flash.
| struct PFSFileListEntry |
Entry of the list returned by pfs_create_file_list().
| Data Fields | ||
|---|---|---|
| ListNode | list_node | List node. |
| char | name[] | NUL-terminated file name. |
| #define FILE_CHANGED_EVENT_ALL (FILE_CHANGED_EVENT_CLOSED | FILE_CHANGED_EVENT_REMOVED) |
pfs_watch_file() events: all of them.
| #define FILE_CHANGED_EVENT_CLOSED (1 << 0) |
pfs_watch_file() event: the file was closed after being opened for writing.
| #define FILE_CHANGED_EVENT_REMOVED (1 << 1) |
pfs_watch_file() event: the file was removed.
| #define FILE_MAX_NAME_LEN (255) |
Maximum length of a file name, without the NUL terminator.
| #define FILE_TYPE_STATIC (0xfe) |
File type of regular files.
| #define OP_FLAG_OVERWRITE (1 << 2) |
Write a new version of an existing file, committed on pfs_close().
| #define OP_FLAG_READ (1 << 0) |
Open for reading; fails if the file does not exist.
| #define OP_FLAG_SKIP_HDR_CRC_CHECK (1 << 3) |
Skip checking the on-flash header CRCs.
| #define OP_FLAG_USE_PAGE_CACHE (1 << 4) |
Cache the translation from file pages to flash pages.
| #define OP_FLAG_WRITE (1 << 1) |
Open for writing, creating the file if it does not exist.
| typedef void* PFSCallbackHandle |
Handle of a file watch, for pfs_unwatch_file().
| typedef void(* PFSFileChangedCallback) (void *data) |
Callback of pfs_watch_file().
Runs on the task that closed or removed the file, with the PFS lock held: it must not call PFS.
| data | Data passed to pfs_watch_file(). |
| typedef bool(* PFSFilenameTestCallback) (const char *name) |
File name filter of pfs_create_file_list() and pfs_remove_files().
| name | File name. |
| enum FSeekType |
Reference point of pfs_seek().
| Enumerator | |
|---|---|
| FSeekSet | Offset from the start of the file. |
| FSeekCur | Offset from the current position. |
|
extern |
Get the space available for new files.
Only 80% of the filesystem is considered usable, to leave room for wear leveling.
|
extern |
Check whether PFS is active on this device.
|
extern |
Check whether PFS is active in a range of the filesystem space.
| start_address | Start of the range. |
| ending_address | End of the range, exclusive. |
|
extern |
Close a file.
Commits an overwrite and notifies watchers if the file was opened for writing.
| fd | File descriptor. |
| S_SUCCESS | File closed. |
| E_INVALID_ARGUMENT | Invalid descriptor. |
|
extern |
Close and remove a file.
| fd | File descriptor. |
S_SUCCESS or negative status_t, as pfs_close() and pfs_remove().
|
extern |
Compute the legacy CRC-32 of a part of a file.
Moves the current position of fd.
| fd | File descriptor opened for reading. |
| offset | Start offset. |
| num_bytes | Number of bytes. |
|
extern |
List the files whose name matches a filter.
| callback | Name filter, or NULL to include all files. |
|
extern |
Free a list returned by pfs_create_file_list().
| list | Head of the list. |
|
extern |
Erase the whole filesystem and drop all open file descriptors.
Requires pfs_init() to have been called.
| write_erase_headers | Mark all pages as erased. |
|
extern |
Get the size of a file, that is the number of bytes that can be read.
| fd | File descriptor. |
|
extern |
Get the size of the filesystem.
|
extern |
Initialize PFS, before any other use.
Builds the flash translation layer, recovers from an interrupted garbage collection, and pre-erases some space.
| run_filesystem_check | Format the flash if PFS is not active on it. |
| S_SUCCESS | Always. |
|
extern |
Open a file.
Flags:
name returns the original file. There is always a valid version to read, and the caller can copy parts of the original file in chunks instead of allocating a lot of RAM.| name | File name, 1 to FILE_MAX_NAME_LEN characters. |
| op_flags | OP_FLAG_* flags. |
| file_type | File type, used only when the file is created or overwritten. |
| start_size | File size in bytes, used only when the file is created or overwritten. |
status_t on failure. | E_INVALID_ARGUMENT | Invalid name, or invalid type or zero size on creation. |
| E_DOES_NOT_EXIST | The file does not exist and was not to be created. |
| E_BUSY | The file is already open. |
| E_OUT_OF_RESOURCES | No free file descriptor. |
| E_OUT_OF_STORAGE | Not enough space to create the file. |
|
extern |
Read from the current position, then advance it.
| fd | File descriptor opened for reading. | |
| [out] | buf | Destination buffer. |
| size | Number of bytes to read, at most the size of buf. |
status_t on failure. | E_INVALID_ARGUMENT | Invalid descriptor, not readable, or empty buffer. |
| E_RANGE | The read goes past the end of the file. |
|
extern |
Clean up after a reboot, once and before any file operation.
Finishes or rolls back operations interrupted by the reboot.
|
extern |
Remove a file.
| name | File name. |
| S_SUCCESS | File removed. |
| E_INVALID_ARGUMENT | Invalid name. |
status_t on failure.
|
extern |
Remove all files whose name matches a filter.
| callback | Name filter. |
|
extern |
Get the optimal size of a file that can use space beyond a minimum.
Rounds min_size up to use all the space of the pages the file occupies anyway.
| min_size | Minimum file size in bytes. |
| namelen | Length of the file name. |
|
extern |
Set the current position.
| fd | File descriptor. |
| offset | Offset relative to seek_type. |
| seek_type | Reference point. |
status_t on failure. | E_INVALID_ARGUMENT | Invalid descriptor. |
| E_RANGE | Position outside 0 to the file size. |
|
extern |
Set the size of the filesystem, as regions are added to it.
| new_size | New size in bytes. |
| new_region_erased | The added pages are erased and should be marked as such. |
| void pfs_unwatch_file | ( | PFSCallbackHandle | cb_handle | ) |
Stop watching a file.
| cb_handle | Handle returned by pfs_watch_file(). |
| PFSCallbackHandle pfs_watch_file | ( | const char * | filename, |
| PFSFileChangedCallback | callback, | ||
| uint8_t | event_flags, | ||
| void * | data | ||
| ) |
Watch a file for changes.
| filename | Name of the file to watch. |
| callback | Function called on the selected events. |
| event_flags | FILE_CHANGED_EVENT_* flags selecting the events. |
| data | Pointer passed to callback. |
|
extern |
Write at the current position, then advance it.
| fd | File descriptor opened for writing or overwriting. |
| buf | Data to write. |
| size | Number of bytes to write, at most the size of buf. |
status_t on failure. | E_INVALID_ARGUMENT | Invalid descriptor, not writable, or empty buffer. |
| E_RANGE | The write goes past the end of the file. |