PebbleOS
Loading...
Searching...
No Matches
Data Structures | Macros | Typedefs | Enumerations | Functions
pfs.h File Reference
#include <inttypes.h>
#include <stddef.h>
#include <kernel/pebble_tasks.h>
#include <system/status_codes.h>
#include <pbl/util/list.h>

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.