Data Structures | |
| struct | tsfs_file |
| Holds information about a specific file within a file system. More... | |
| struct | tsfs_header |
| Header structure. Holds generic information about the file system. More... | |
| struct | tsfs_read_request |
| Holds current read request being processed by a file system. More... | |
| struct | tsfs_filetable_entry |
| Holds information on one file in the file table. More... | |
| struct | tsfs |
| Holds information on a TSFS instance. More... | |
Defines | |
| #define | TSFS_ID 0x17c1 |
| Unique ID to identify TSFS. | |
| #define | TSFS_FILENAME_LEN 8 |
| Max characters in a filename. | |
| #define | TSFS_MAX_FILES 31 |
| Max number of files supported. | |
| #define | TSFS_BLOCKSIZE 512 |
| Size of block in bytes. | |
Enumerations | |
| enum | tsfs_seek_origin { SEEK_SET, SEEK_CUR, SEEK_END } |
The relative starting point of seek operations. More... | |
Functions | |
| status_t | tsfs_init (struct tsfs *tsfs, struct block_device *system_blockdevice, struct workqueue_task *system_ready_task) |
| Initiates a Tiny Simple File System. | |
| status_t | tsfs_open (struct tsfs *tsfs, const char *filename, struct tsfs_file *filehandle) |
| Opens a file by populating a file handle. | |
| status_t | tsfs_seek (struct tsfs_file *file, int32_t offset, enum tsfs_seek_origin origin) |
| Manualy move the file cursor. | |
| status_t | tsfs_read (struct tsfs *tsfs, struct tsfs_file *file, void *buffer, uint32_t length, struct workqueue_task *task) |
| Reads a chunk of data from a file to a buffer. | |
| void | tsfs_get_filename (struct tsfs *tsfs, uint_fast8_t file_index, uint8_t *buffer) |
| Reads the filename of an indexed file into a buffer. | |
| static uint32_t | tsfs_get_file_size (struct tsfs_file *file) |
| Get the file size in bytes for file file. | |
| static uint32_t | tsfs_nr_files (struct tsfs *tsfs) |
| Returns the number of files present in a file system. | |
| static uint32_t | tsfs_volume_size (struct tsfs *tsfs) |
| Returns the size of the entire volume. | |
| static uint32_t | tsfs_is_ready (struct tsfs *tsfs) |
| Check if file system is ready for use. | |
|
| |
| static void | tsfs_buf_list_done (struct block_device *bdev, struct block_request *breq, struct slist *buf_list) |
| Block device list complete callback. | |
| static void | tsfs_read_page_done (struct block_device *bdev, struct block_request *breq) |
| Block device request complete callback. | |
file system.
This module provides mechanisms for data stored in a TSFS file system. Note: All data is stored using big endigan encoding, and translated to CPU specific endianess after being read into the file system.
In order to improve execution times most functions in this module assume input parameters are clean. This means that there are no sanity on any parameters unless it is explisitly stated in this document.
| #define TSFS_BLOCKSIZE 512 |
Size of block in bytes.
Definition at line 79 of file tsfs.h.
Referenced by tsfs_init(), and tsfs_read().
| #define TSFS_FILENAME_LEN 8 |
Max characters in a filename.
Definition at line 68 of file tsfs.h.
Referenced by tsfs_get_filename().
| #define TSFS_MAX_FILES 31 |
| enum tsfs_seek_origin |
| static void tsfs_buf_list_done | ( | struct block_device * | bdev, | |
| struct block_request * | breq, | |||
| struct slist * | buf_list | |||
| ) | [static] |
Get the file size in bytes for file file.
Definition at line 223 of file tsfs.h.
References tsfs_file::end, and tsfs_file::start.
| void tsfs_get_filename | ( | struct tsfs * | tsfs, | |
| uint_fast8_t | file_index, | |||
| uint8_t * | buffer | |||
| ) |
Reads the filename of an indexed file into a buffer.
| tsfs | TSFS structure which holds file system information | |
| file_index | Index of file which name is to be fetched | |
| buffer | Buffer where filename will be written |
Definition at line 475 of file tsfs.c.
References tsfs_filetable_entry::filename, memcpy(), and TSFS_FILENAME_LEN.
| status_t tsfs_init | ( | struct tsfs * | tsfs, | |
| struct block_device * | bdev, | |||
| struct workqueue_task * | init_done_task | |||
| ) |
Initiates a Tiny Simple File System.
The block device specified by system_blockdevice has to have a block size of TSFS_BLOCKSIZE bytes.
Immediately after returning from this function, the file system will have status ERR_BUSY. The system is ready for use when the status changes to STATUS_OK. This can be polled for, or the parameter init_done_task can be used to specify a task to be scheduled when the system is ready.
In case the data loaded from the block device is not TSFS compatible the file system will not schedule the callback task, and set its own status to ERR_BAD_FORMAT. At this point the file system has to be re-initialized with a valid block device if it is to be used.
| tsfs | TSFS structure which holds file system information | |
| bdev | Block device to read data from | |
| init_done_task | Callback task for when system is ready for use |
Definition at line 232 of file tsfs.c.
References assert, tsfs::bdev, board_extram_pool, tsfs::buffer_data, CPU_DMA_ALIGN, tsfs::current_read_request, ERR_BUSY, ERR_NO_MEMORY, malloc(), physmem_alloc(), PHYSMEM_ALLOC_ERR, tsfs::status, STATUS_OK, tsfs_read_request::task, TSFS_BLOCKSIZE, and TSFS_MAX_FILES.
Check if file system is ready for use.
Definition at line 253 of file tsfs.h.
References tsfs::bdev, tsfs::status, and STATUS_OK.
Returns the number of files present in a file system.
Definition at line 233 of file tsfs.h.
References tsfs::header, and tsfs_header::nr_files.
Opens a file by populating a file handle.
Searches through the filetable of tsfs and opens the first file that matches the filename string. Note that this can be a pointer to any normal character array, even though TSFS filenames do not have a termchar
| tsfs | TSFS structure which holds file system information | |
| filename | Name of file to be opened | |
| filehandle | File structure to store results |
| \ref | STATUS_OK if successful. | |
| \ref | ERR_INVALID_ARG if file is not found. |
Definition at line 404 of file tsfs.c.
References tsfs_file::cursor, tsfs_file::end, ERR_INVALID_ARG, tsfs_filetable_entry::file_offset, tsfs_filetable_entry::file_size, tsfs::header, tsfs_header::nr_files, tsfs_file::start, and STATUS_OK.
| status_t tsfs_read | ( | struct tsfs * | tsfs, | |
| struct tsfs_file * | file, | |||
| void * | buffer, | |||
| uint32_t | length, | |||
| struct workqueue_task * | task | |||
| ) |
Reads a chunk of data from a file to a buffer.
Any file system can only issue one read request at a time, and hence if the system is busy reading another file tsfs_read will return ERR_BUSY. The user application should pick up on this and reschedule its read attempt.
The task is scheduled to execute once the copy operation is complete, but only if tsfs_read returns STATUS_OK. If it returns any error message, the task is not scheduled.
The length parameter is trimmed to never exceed the length of the file.
| tsfs | TSFS structure which holds file system information | |
| file | Handle of the file to be read from | |
| buffer | Pointer to buffer where data is read to | |
| length | Number of bytes to read | |
| task | Task to be scheduled upon successful completion |
| \ref | STATUS_OK if successful | |
| \ref | ERR_INVALID_ARG if trying to read at the end of a file, or trying to read 0 bytes. | |
| \ref | ERR_BUSY if file system is busy reading from another file. |
Definition at line 317 of file tsfs.c.
References tsfs_read_request::buffer, tsfs::current_read_request, tsfs_read_request::cursor, tsfs_file::cursor, tsfs_file::end, ERR_BUSY, ERR_INVALID_ARG, ilog2(), tsfs::lba_in_buf, tsfs_read_request::remaining_bytes, tsfs::status, STATUS_OK, tsfs_read_request::task, and TSFS_BLOCKSIZE.
| static void tsfs_read_page_done | ( | struct block_device * | bdev, | |
| struct block_request * | breq | |||
| ) | [static] |
Block device request complete callback.
Definition at line 76 of file tsfs.c.
References block_free_request(), block_request::context, tsfs::current_breq, and tsfs::page_read_callback.
| status_t tsfs_seek | ( | struct tsfs_file * | file, | |
| int32_t | offset, | |||
| enum tsfs_seek_origin | origin | |||
| ) |
Manualy move the file cursor.
Available offsets are found in tsfs_seek_origin. Note that to offset inwards from the end of the file, negative values should be used for offset. It is possible to seek the file cursor to any value, even invalid ones, so care should be taken when using this function. If an invalid value is passed for origin, the application will execute unhandled_case()
| file | File to seek in | |
| offset | Number of bytes to move the cursor | |
| origin | Position from which offset is counted |
Definition at line 442 of file tsfs.c.
References tsfs_file::cursor, tsfs_file::end, SEEK_CUR, SEEK_END, SEEK_SET, tsfs_file::start, STATUS_OK, and unhandled_case.
Returns the size of the entire volume.
Definition at line 243 of file tsfs.h.
References tsfs::header, and tsfs_header::volume_size.
1.6.3