|
hollyhock
|
Functions for interacting with the calculator's file system. More...
#include <stdint.h>#include <stddef.h>
Go to the source code of this file.
Classes | |
| struct | File_Stat |
Macros | |
| #define | constexpr |
| #define | cstr(x) |
| #define | ro(...) |
| #define | rw(...) |
| #define | wo(...) |
| #define | wu __attribute__((warn_unused_result)) |
Enumerations | |
| enum | File_Error { FILE_OK = 0 , FILE_ENOMEM = -1 , FILE_EINVAL = -2 , FILE_EDEVFAIL = -3 , FILE_EMOUNTED = -4 , FILE_EACCES = -5 , FILE_EBADFSID = -6 , FILE_ENOVOLUME = -7 , FILE_ENOPATH = -8 , FILE_EEXIST = -9 , FILE_ENAMETOOLONG = -10 , FILE_EOUTOFBOUND = -11 , FILE_EUNFORMAT = -12 , FILE_ENOSPC = -13 , FILE_ENOENT = -14 , FILE_EISDIRECTORY = -15 , FILE_ESHARE = -16 , FILE_EMFILE = -17 , FILE_EBADF = -18 , FILE_EEOF = -19 , FILE_ENOTEMPTY = -20 , FILE_ECLUSTERSIZEMISMATCH = -40 , FILE_ESYSTEM = -99 } |
| enum | File_Whence { FILE_SEEK_SET = 0 , FILE_SEEK_CUR = 1 , FILE_SEEK_END = 2 } |
| enum | File_Open { FILE_OPEN_READ = 1 << 0 , FILE_OPEN_WRITE = 1 << 1 , FILE_OPEN_CREATE = 1 << 2 , FILE_OPEN_APPEND = 1 << 4 } |
| enum | File_Attributes { FILE_ATTR_READ_ONLY = 0x01 , FILE_ATTR_HIDDEN = 0x02 , FILE_ATTR_SYSTEM = 0x04 , FILE_ATTR_DIRECTORY = 0x10 , FILE_ATTR_ARCHIVE = 0x20 , FILE_ATTR_SETTABLE_MASK = 0x37 } |
Functions | |
| struct | __attribute__ ((packed, aligned(4))) File_FsInfo |
Variables | |
| enum File_Error(* | File_Close )(int fd) |
| enum File_Error(* | File_Fstat )(int fd, struct File_Stat *buf) wu wo(2) |
| enum File_Error(* | File_GetAddr )(int fd, int offset, const void **addr) wu wo(3) |
| int(* | File_Lseek )(int fd, int offset, enum File_Whence whence) wu |
| enum File_Error(* | File_Mkdir )(const char *path) wu cstr(1) ro(1) |
| int(* | File_Open )(const char *path, int flags) wu cstr(1) ro(1) |
| int(* | File_Read )(int fd, void *buf, int count) wu wo(2 |
| int enum File_Error(* | File_Remove )(const char *path) cstr(1) ro(1) |
| enum File_Error(* | File_Rename )(const char *oldPath, const char *newPath) wu cstr(1) cstr(2) ro(1) ro(2) |
| enum File_Error(* | File_Stat )(const char *path, struct File_Stat *buf) wu cstr(1) ro(1) wo(2) |
| int(* | File_Write )(int fd, const void *buf, int count) wu ro(2 |
| int enum File_Error(* | File_Flush )(int fd) wu |
| enum File_Error(* | File_FsInfo )(const char *device, struct File_FsInfo *info) wu cstr(1) ro(1) wo(2) |
| enum File_Error(* | File_SetAttr )(const char *path, const struct File_Stat *info) wu cstr(1) ro(1) ro(2) |
| int(* | File_Reclaim )(const char *device, int workLimit) wu cstr(1) ro(1) |
| enum File_Error(* | File_Salvage )(const char *device) wu cstr(1) ro(1) |
Functions for interacting with the calculator's file system.
Exposes the Fugue atomic API, with byte-string paths, Fugue descriptors and Fugue error codes. Directory searches belong to sdk/os/bfile.h and use a different descriptor, path encoding and error namespace.
The storage which appears when the calculator is attached to a PC is found under the path \fls0\ (remember to escape the \ in strings!).
Example: reading 256 bytes from a file called test.txt from the USB flash
Example: writing 16 bytes to a non-existant file called f.bin in a folder test in the USB flash
| #define cstr | ( | x | ) |
| #define ro | ( | ... | ) |
| #define rw | ( | ... | ) |
| #define wo | ( | ... | ) |
| enum File_Attributes |
FAT attribute bits returned in File_Stat.attributes.
| Enumerator | |
|---|---|
| FILE_ATTR_SETTABLE_MASK | Clear other status bits before passing a stat record to File_SetAttr. |
| enum File_Error |
Errors returned by file system functions. All negative numbers.
| enum File_Open |
Values passed as the flags parameter to File_Open. Can be bitwise OR'd to combine effects.
| enum File_Whence |
Values passed as the whence parameter to File_Lseek.
| struct __attribute__ | ( | (packed, aligned(4)) | ) |
Capacity and geometry returned by File_FsInfo.
The firmware writes a 0x34-byte, 4-byte-aligned record. The three byte counts are 64-bit values in native byte order. Reserved words are output fields with OS-specific meanings; callers should not interpret them.
|
extern |
Closes an open file.
| fd | The file descriptor for the open file. |
|
extern |
Query a mounted device's capacity and geometry.
| device | Device root without a trailing separator, eg. "\\fls0". | |
| [out] | info | Capacity and geometry record. |
|
extern |
Retrieves information about an open file.
| fd | The file descriptor of an open file to retrieve the information of. | |
| [out] | buf | The retrieved information about the file. |
|
extern |
Retrieves the memory address of a file.
If the file is empty or the offset would point outside of the file, FILE_EINVAL is returned.
| fd | The file descriptor of an open file. | |
| offset | An offset to apply to the pointer to the file's data. | |
| [out] | addr | The address of the file's data. |
|
extern |
Repositions the file offset of the file descriptor. The new position depends on the value of both offset and whence. See lseek_whence_values.
| fd | The file descriptor of an open file to change the file offset of. |
| offset | The new offset, relative to some point. |
| whence | Where offset is relative to. |
|
extern |
Creates a directory.
| [in] | path | The path to the directory to be created. |
|
extern |
Opens a file on the file system.
The argument flags is fed a bitwise OR'd combination of flags. See open_flags_values.
| [in] | path | The path to the file to open. |
| flags | A bitfield describing the mode in which to open the file. |
|
extern |
Reads up to count bytes from a file, and stores them in buf.
If count bytes cannot be read from the file, as many bytes as possible are read (i.e. between 0 and count - 1 bytes are read and stored in buf).
| fd | The file descriptor of an open file to read from. | |
| [out] | buf | A buffer to place the read bytes into. |
| count | The maximum number of bytes to read. |
|
extern |
Run the mounted device's reclaim/garbage-collection operation.
| device | Device root without a trailing separator, eg. "\\fls0". |
| workLimit | Nonnegative OS-specific work limit; its unit is not known. |
|
extern |
Deletes a file or directory.
| [in] | path | The path to the file or directory to be deleted. |
|
extern |
Renames a file or directory.
| [in] | oldPath | The path to the file or directory to be renamed. |
| [in] | newPath | The path to the new name for the file or directory. |
|
extern |
Repair a mounted filesystem's allocation metadata.
This is a potentially long-running, metadata-changing maintenance operation. The filesystem must not be in use; busy states return FILE_EACCES.
| device | Device root without a trailing separator, eg. "\\fls0". |
|
extern |
Update FAT attributes and timestamps from a File_Stat record.
Obtain the record with File_Stat first so existing timestamps are preserved. Mask attributes with FILE_ATTR_SETTABLE_MASK and preserve the directory bit: this call cannot change a file into a directory or vice versa. fileSize is ignored; this operation does not resize the file.
|
extern |
Retrieves information about a file.
| [in] | path | The path to the file to retrieve the information of. |
| [out] | buf | The retrieved information about the file. |
|
extern |
Writes count bytes from buf to a file.
| fd | The file descriptor of an open file to write to. | |
| [in] | buf | A buffer of bytes to write to the file. |
| count | The number of bytes from buf to write to the file. |