discoverpixy
filesystem.h
Go to the documentation of this file.
1 /**************************************************************************************************************************************
2 * Project: discoverpixy
3 * Website: https://github.com/t-moe/discoverpixy
4 * Authors: Aaron Schmocker, Timo Lang
5 * Institution: BFH Bern University of Applied Sciences
6 * File: common/filesystem/filesystem.h
7 *
8 * Version History:
9 * Date Autor Email SHA Changes
10 * 2015-04-03 timolang@gmail.com 51089aa Refactored Project Structure for use with emulator
11 * 2015-05-10 timolang@gmail.com e2bce8f Added filesystem module, tests and implementation for it in emulator.
12 * 2015-05-15 timolang@gmail.com 9a16865 Added doxgen comments to filesyste, checkbox, numupdown and screen module. And some minor changes to the other modules.
13 *
14 **************************************************************************************************************************************/
15 
16 #ifndef FILESYSTEM_H
17 #define FILESYSTEM_H
18 
19 #include <stdbool.h>
20 #include <stdint.h>
21 
27 
32 typedef enum {
33  F_RDO = 0x01,
34  F_HID = 0x02,
35  F_SYS = 0x04,
36  F_DIR = 0x10,
37  F_ARC = 0x20
39 
43 typedef struct {
44  unsigned year : 7;
45  unsigned month: 4;
46  unsigned day: 5;
48 
52 typedef struct {
53  unsigned hour : 5;
54  unsigned min: 6;
55  unsigned sec: 5;
57 
61 typedef struct {
62  uint32_t fsize;
65  uint8_t fattrib;
66  char* fname;
67 } FILE_STRUCT;
68 
72 typedef struct {
73  const char* path;
74  uint16_t num_files;
77 
81 typedef struct {
82  const char* fname;
83  uint32_t fpos;
84  uint32_t fsize;
85 } FILE_HANDLE;
86 
90 typedef enum {
91  F_OK,
96 } FILE_STATUS;
97 
103 bool filesystem_init();
104 
110 DIRECTORY_STRUCT* filesystem_dir_open(const char* path);
111 
117 
123 FILE_HANDLE* filesystem_file_open(const char* filename);
124 
129 void filesystem_file_close(FILE_HANDLE* handle);
130 
137 FILE_STATUS filesystem_file_seek(FILE_HANDLE* handle, uint32_t offset);
138 
146 FILE_STATUS filesystem_file_read(FILE_HANDLE* handle, uint8_t* buf, uint32_t size);
147 
156 FILE_STATUS filesystem_file_write(FILE_HANDLE* handle, uint8_t* buf, uint32_t size);
157 
158 
161 #endif /* FILESYSTEM_H */
FILE_STATUS filesystem_file_seek(FILE_HANDLE *handle, uint32_t offset)
Definition: filesystem.c:43
uint32_t fsize
The total file size in bytes.
Definition: filesystem.h:84
FILE_DATE_STRUCT fdate
Last modified date.
Definition: filesystem.h:63
The write/read operation tried to write/read past the end of the file. This is not a fatal error...
Definition: filesystem.h:92
uint8_t fattrib
File/Directory Attributes.
Definition: filesystem.h:65
You passed invalid parameters to the function.
Definition: filesystem.h:94
FILE_HANDLE * filesystem_file_open(const char *filename)
Definition: filesystem.c:33
void filesystem_file_close(FILE_HANDLE *handle)
Definition: filesystem.c:38
File has the archive flag set (probably unused)
Definition: filesystem.h:37
char * fname
File/Directory name.
Definition: filesystem.h:66
A lowlevel disk-error occoured. This is a fatal error.
Definition: filesystem.h:95
File is a system file.
Definition: filesystem.h:35
uint16_t num_files
Number of files/directories in this directory.
Definition: filesystem.h:74
FILE_STATUS filesystem_file_write(FILE_HANDLE *handle, uint8_t *buf, uint32_t size)
Definition: filesystem.c:53
uint32_t fpos
The current byte-position in the file.
Definition: filesystem.h:83
File is hidden.
Definition: filesystem.h:34
const char * path
Directory path (absolute)
Definition: filesystem.h:73
Everything ok.
Definition: filesystem.h:91
FILE_STRUCT * files
An array with num_files FILE_STRUCT entries.
Definition: filesystem.h:75
DIRECTORY_STRUCT * filesystem_dir_open(const char *path)
Definition: filesystem.c:23
It's a directory and not a file.
Definition: filesystem.h:36
The file can not be read/written due to access problems. This is a fatal error.
Definition: filesystem.h:93
bool filesystem_init()
Definition: filesystem.c:18
FILE_ATTRIBUTES
Definition: filesystem.h:32
File is readonly. You cannot write to it.
Definition: filesystem.h:33
const char * fname
The absolute file name.
Definition: filesystem.h:82
FILE_STATUS
Definition: filesystem.h:90
void filesystem_dir_close(DIRECTORY_STRUCT *dir)
Definition: filesystem.c:28
FILE_TIME_STRUCT ftime
Last modified time.
Definition: filesystem.h:64
FILE_STATUS filesystem_file_read(FILE_HANDLE *handle, uint8_t *buf, uint32_t size)
Definition: filesystem.c:48
uint32_t fsize
File size in bytes. 0 for directories.
Definition: filesystem.h:62