Apps     Components     Interfaces     All Files     Source Tree     source: tos.lib.FS.FileWrite.nc

Interface: FileWrite

File reading interface, supports appending writes.

Components providing this interface:
tos.lib.FS.Matchbox
tos.lib.FS.Write

Components requiring this interface:
apps.TestMatchbox.Timing.TimingM
tos.lib.FS.Remote

Commands

Events

Commands - Details

open

result_t open(const char *filename, uint8_t flags)

open a file for sequential reads.

Parameters:

filename - Name of file to open. Must not be stack allocated.

flags: - open options, an or (|) of FS_Fxxx constants.
FS_FTRUNCATE Truncate file if it exists
FS_FCREATE Create file if it doesn't exist

truncate - TRUE if file should be truncated if it exists

Returns: SUCCESS: attempt proceeds, opened will be signaled
FAIL: filesystem is busy, another file is already open for writing, filename is ""

append

result_t append(void *buffer, filesize_t n)

Write bytes sequentially to end of open file.

Parameters:

buffer - Data to write

n - Number of bytes to write

Returns: SUCCESS: attempt proceeds, appended will be signaled
FAIL: no file was open for writing, or a close/append/reserve/sync is in progress

reserve

result_t reserve(filesize_t newSize)

Reserve space for the currently open file to be newSize bytes long. appends that do not make the file take more than newSize bytes will not fail with FS_ERROR_NOSPACE. Note: you can find the reserved size of a file by requesting a reserve with a newSize of 0. The reserved event will indicate the space currently reserved.

Parameters:

newSize - Size file is expected to grow to

Returns: SUCCESS: attempt proceeds, reserved will be signaled
FAIL: no file was open for writing, or a close/append/reserve/sync is in progress

sync

result_t sync(void)

Ensure data appended is comitted to stable storage.
Returns: SUCCESS: attempt proceeds, synced will be signaled
FAIL: no file was open for writing, or a close/append/reserve/sync is in progress

Events - Details

closed

result_t closed(fileresult_t result)

Signaled at the end of a file close. File is closed in all cases, including failure (but in case of failure some data may have been lost).

Parameters:

result - FS_OK: file was closed without problems. All data has been comitted to stable storage.
FS_ERROR_xxx: close failure cause

Returns: Ignored

appended

result_t appended(void *buffer, filesize_t nWritten, fileresult_t result)

Signaled when a append completes

Parameters:

buffer - Buffer that was passed to append

nWritten - Number of bytes actually written but result will still be FS_OK)

result - FS_OK: write was successful FS_ERROR_xxx: write failure cause. Some bytes may have been written (as reported by the value of nWritten

Returns: Ignored