altos/test: Adjust CRC error rate after FEC fix
[fw/altos] / src / drivers / ao_fat.h
1 /*
2  * Copyright © 2013 Keith Packard <keithp@keithp.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18
19 #ifndef _AO_FAT_H_
20 #define _AO_FAT_H_
21
22 void
23 ao_fat_init(void);
24
25 #define AO_FAT_FILE_REGULAR             0x00
26 #define AO_FAT_FILE_READ_ONLY           0x01
27 #define AO_FAT_FILE_HIDDEN              0x02
28 #define AO_FAT_FILE_SYSTEM              0x04
29 #define AO_FAT_FILE_VOLUME_LABEL        0x08
30 #define AO_FAT_FILE_DIRECTORY           0x10
31 #define AO_FAT_FILE_ARCHIVE             0x20
32
33 #define AO_FAT_DENT_EMPTY               0xe5
34 #define AO_FAT_DENT_END                 0x00
35
36 #define AO_FAT_IS_FILE(attr)    (((attr) & (AO_FAT_FILE_VOLUME_LABEL|AO_FAT_FILE_DIRECTORY)) == 0)
37 #define AO_FAT_IS_DIR(attr)     (((attr) & (AO_FAT_FILE_DIRECTORY|AO_FAT_FILE_VOLUME_LABEL)) == AO_FAT_FILE_DIRECTORY)
38
39 /* API error codes */
40 #define AO_FAT_SUCCESS                  0
41 #define AO_FAT_EPERM                    1
42 #define AO_FAT_ENOENT                   2
43 #define AO_FAT_EIO                      4
44 #define AO_FAT_EBADF                    9
45 #define AO_FAT_EACCESS                  13
46 #define AO_FAT_EEXIST                   17
47 #define AO_FAT_ENOTDIR                  20
48 #define AO_FAT_EISDIR                   21
49 #define AO_FAT_EMFILE                   24
50 #define AO_FAT_EFBIG                    27
51 #define AO_FAT_ENOSPC                   28
52 #define AO_FAT_EDIREOF                  29
53
54 /* ao_fat_setup return values */
55 #define AO_FAT_FILESYSTEM_SUCCESS                       0
56 #define AO_FAT_FILESYSTEM_MBR_READ_FAILURE              1
57 #define AO_FAT_FILESYSTEM_INVALID_MBR_SIGNATURE         2
58 #define AO_FAT_FILESYSTEM_INVALID_PARTITION_TYPE        3
59 #define AO_FAT_FILESYSTEM_ZERO_SIZED_PARTITION          4
60
61 #define AO_FAT_FILESYSTEM_BOOT_READ_FAILURE             5
62 #define AO_FAT_FILESYSTEM_INVALID_BOOT_SIGNATURE        6
63 #define AO_FAT_FILESYSTEM_INVALID_SECTOR_SIZE           7
64
65 void
66 ao_fat_sync(void);
67
68 void
69 ao_fat_unmount(void);
70
71 int8_t
72 ao_fat_full(void);
73
74 int8_t
75 ao_fat_open(char name[11], uint8_t mode);
76
77 #define AO_FAT_OPEN_READ                0
78 #define AO_FAT_OPEN_WRITE               1
79 #define AO_FAT_OPEN_RW                  2
80
81 int8_t
82 ao_fat_creat(char name[11]);
83
84 int8_t
85 ao_fat_close(int8_t fd);
86
87 int
88 ao_fat_read(int8_t fd, void *dest, int len);
89
90 int
91 ao_fat_write(int8_t fd, void *src, int len);
92
93 #define AO_FAT_SEEK_SET 0
94 #define AO_FAT_SEEK_CUR 1
95 #define AO_FAT_SEEK_END 2
96
97 int32_t
98 ao_fat_seek(int8_t fd, int32_t pos, uint8_t whence);
99
100 int8_t
101 ao_fat_unlink(char name[11]);
102
103 int8_t
104 ao_fat_rename(char old[11], char new[11]);
105
106 /*
107  * Byte offset within a file. Supports files up to 2GB in size
108  */
109 typedef int32_t         ao_fat_offset_t;
110
111 /*
112  * Cluster index in partition data space
113  */
114 typedef uint32_t        ao_fat_cluster_t;
115
116 /*
117  * Sector offset within partition
118  */
119 typedef uint32_t        ao_fat_sector_t;
120
121 /*
122  * Index within the root directory
123  */
124 typedef uint16_t        ao_fat_dirent_t;
125
126 /*
127  * Offset within a cluster (or sector)
128  */
129 typedef uint16_t        ao_fat_cluster_offset_t;
130
131 struct ao_fat_dirent {
132         char                    name[11];
133         uint8_t                 attr;
134         uint32_t                size;
135         ao_fat_cluster_t        cluster;
136         uint16_t                entry;
137 };
138
139 int8_t
140 ao_fat_readdir(uint16_t *entry, struct ao_fat_dirent *dirent);
141
142 #endif /* _AO_FAT_H_ */