00001
00038 #ifndef FS_TSFS_H
00039 #define FS_TSFS_H
00040
00041 #include <stdint.h>
00042 #include <mainloop.h>
00043 #include <status_codes.h>
00044
00045 #include <block/device.h>
00046
00047 #ifdef CONFIG_FS_TSFS_USE_HUGEMEM
00048 # include <hugemem.h>
00049 #endif
00050
00065
00066 #define TSFS_ID 0x17c1
00067
00068 #define TSFS_FILENAME_LEN 8
00069
00070 #ifdef CONFIG_FS_TSFS_USE_HUGEMEM
00071
00072 # define TSFS_MAX_FILES 256
00073 #else
00074
00075 # define TSFS_MAX_FILES 31
00076 #endif
00077
00079 #define TSFS_BLOCKSIZE 512
00080
00081 #define TSFS_FILETABLE_ENTRIES_PER_BLOCK \
00082 (TSFS_BLOCKSIZE / (sizeof(struct tsfs_filetable_entry)))
00083
00087 struct tsfs_file {
00089 uint32_t start;
00091 uint32_t end;
00093 uint32_t cursor;
00094 };
00095
00099 struct tsfs_header {
00101 uint16_t id;
00103 uint8_t version;
00105 uint8_t reserved1;
00107 uint32_t volume_size;
00109 uint32_t nr_files;
00111 uint32_t reserved2;
00112 };
00113
00117 struct tsfs_read_request {
00122 void *buffer;
00124 uint32_t cursor;
00126 uint32_t remaining_bytes;
00128 struct workqueue_task *task;
00129 };
00130
00134 struct tsfs_filetable_entry {
00136 uint32_t file_offset;
00138 uint32_t file_size;
00139
00147 uint8_t filename[TSFS_FILENAME_LEN];
00148 };
00149
00153 struct tsfs {
00155 enum status_code status;
00157 struct tsfs_header header;
00158
00160 #ifdef CONFIG_FS_TSFS_USE_HUGEMEM
00161 hugemem_ptr_t filetable_address;
00162 uint16_t filetable_entries_read;
00163 #else
00164 struct tsfs_filetable_entry filetable[TSFS_MAX_FILES];
00165 #endif
00166
00168 struct block_device *bdev;
00169
00171 struct block_request *current_breq;
00172
00174 uint8_t *buffer_data;
00175
00177 struct buffer buffer;
00178
00180 block_addr_t lba_in_buf;
00181
00183 struct tsfs_read_request current_read_request;
00184
00186 void(*page_read_callback)(struct tsfs *tsfs);
00187 };
00188
00193 enum tsfs_seek_origin {
00195 SEEK_SET,
00197 SEEK_CUR,
00199 SEEK_END,
00200 };
00201
00202 status_t tsfs_init(struct tsfs *tsfs, struct block_device *system_blockdevice,
00203 struct workqueue_task *system_ready_task);
00204
00205 status_t tsfs_open(struct tsfs *tsfs, const char *filename,
00206 struct tsfs_file *filehandle);
00207
00208 status_t tsfs_seek(struct tsfs_file *file, int32_t offset,
00209 enum tsfs_seek_origin origin);
00210
00211 status_t tsfs_read(struct tsfs *tsfs, struct tsfs_file *file,
00212 void *buffer, uint32_t length,
00213 struct workqueue_task *task);
00214
00215 void tsfs_get_filename(struct tsfs *tsfs, uint_fast8_t file_index,
00216 uint8_t *buffer);
00217
00223 static inline uint32_t tsfs_get_file_size(struct tsfs_file *file)
00224 {
00225 return (file->end - file->start);
00226 }
00227
00233 static inline uint32_t tsfs_nr_files(struct tsfs *tsfs)
00234 {
00235 return tsfs->header.nr_files;
00236 }
00237
00243 static inline uint32_t tsfs_volume_size(struct tsfs *tsfs)
00244 {
00245 return tsfs->header.volume_size;
00246 }
00247
00253 static inline uint32_t tsfs_is_ready(struct tsfs *tsfs)
00254 {
00255 return (tsfs->bdev && tsfs->status == STATUS_OK);
00256 }
00257
00259
00260 #endif