altos: Clean up fat driver API. Improve fat test
[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; version 2 of the License.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
16  */
17
18 #ifndef _AO_FAT_H_
19 #define _AO_FAT_H_
20
21 void
22 ao_fat_init(void);
23
24 #define AO_FAT_FILE_REGULAR             0x00
25 #define AO_FAT_FILE_READ_ONLY           0x01
26 #define AO_FAT_FILE_HIDDEN              0x02
27 #define AO_FAT_FILE_SYSTEM              0x04
28 #define AO_FAT_FILE_VOLUME_LABEL        0x08
29 #define AO_FAT_FILE_DIRECTORY           0x10
30 #define AO_FAT_FILE_ARCHIVE             0x20
31
32 #define AO_FAT_DENT_EMPTY               0xe5
33 #define AO_FAT_DENT_END                 0x00
34
35 #define AO_FAT_IS_FILE(attr)    (((attr) & (AO_FAT_FILE_VOLUME_LABEL|AO_FAT_FILE_DIRECTORY|AO_FAT_FILE_ARCHIVE)) == 0)
36 #define AO_FAT_IS_DIR(attr)     (((attr) & (AO_FAT_FILE_DIRECTORY)) == AO_FAT_FILE_DIRECTORY)
37
38 #define AO_FAT_SUCCESS                  0
39 #define AO_FAT_EPERM                    1
40 #define AO_FAT_ENOENT                   2
41 #define AO_FAT_EIO                      4
42 #define AO_FAT_EBADF                    9
43 #define AO_FAT_EACCESS                  13
44 #define AO_FAT_EEXIST                   17
45 #define AO_FAT_ENOTDIR                  20
46 #define AO_FAT_EISDIR                   21
47 #define AO_FAT_EMFILE                   24
48 #define AO_FAT_EFBIG                    27
49 #define AO_FAT_ENOSPC                   28
50
51 int8_t
52 ao_fat_open(char name[11], uint8_t mode);
53
54 #define AO_FAT_OPEN_READ                0
55 #define AO_FAT_OPEN_WRITE               1
56 #define AO_FAT_OPEN_RW                  2
57
58 int8_t
59 ao_fat_creat(char name[11]);
60
61 int8_t
62 ao_fat_close(void);
63
64 int
65 ao_fat_read(void *dest, int len);
66
67 int
68 ao_fat_write(void *src, int len);
69
70 #define AO_FAT_SEEK_SET 0
71 #define AO_FAT_SEEK_CUR 1
72 #define AO_FAT_SEEK_END 2
73
74 int32_t
75 ao_fat_seek(int32_t pos, uint8_t whence);
76
77 int8_t
78 ao_fat_unlink(char name[11]);
79
80 int8_t
81 ao_fat_rename(char old[11], char new[11]);
82
83 struct ao_fat_dirent {
84         char            name[11];
85         uint8_t         attr;
86         uint32_t        size;
87         uint16_t        cluster;
88         uint16_t        entry;
89 };
90
91 int8_t
92 ao_fat_readdir(uint16_t *entry, struct ao_fat_dirent *dirent);
93
94 #endif /* _AO_FAT_H_ */