forked from satiator/satiator-menu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
satiator.h
92 lines (78 loc) · 3.14 KB
/
satiator.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/* Copyright (c) 2017 James Laird-Wah
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at http://mozilla.org/MPL/2.0/. */
#include "satiator-types.h"
// XXX fatfs bits {{{
/* File access control and file status flags (FIL.flag) */
#define FA_READ 0x01
#define FA_OPEN_EXISTING 0x00
#define FA_WRITE 0x02
#define FA_CREATE_NEW 0x04
#define FA_CREATE_ALWAYS 0x08
#define FA_OPEN_ALWAYS 0x10
/* File attribute bits for directory entry */
#define AM_RDO 0x01 /* Read only */
#define AM_HID 0x02 /* Hidden */
#define AM_SYS 0x04 /* System */
#define AM_VOL 0x08 /* Volume label */
#define AM_LFN 0x0F /* LFN entry */
#define AM_DIR 0x10 /* Directory */
#define AM_ARC 0x20 /* Archive */
#define AM_MASK 0x3F /* Mask of defined bits */
typedef enum {
FR_OK = 0, /* (0) Succeeded */
FR_DISK_ERR, /* (1) A hard error occurred in the low level disk I/O layer */
FR_INT_ERR, /* (2) Assertion failed */
FR_NOT_READY, /* (3) The physical drive cannot work */
FR_NO_FILE, /* (4) Could not find the file */
FR_NO_PATH, /* (5) Could not find the path */
FR_INVALID_NAME, /* (6) The path name format is invalid */
FR_DENIED, /* (7) Access denied due to prohibited access or directory full */
FR_EXIST, /* (8) Access denied due to prohibited access */
FR_INVALID_OBJECT, /* (9) The file/directory object is invalid */
FR_WRITE_PROTECTED, /* (10) The physical drive is write protected */
FR_INVALID_DRIVE, /* (11) The logical drive number is invalid */
FR_NOT_ENABLED, /* (12) The volume has no work area */
FR_NO_FILESYSTEM, /* (13) There is no valid FAT volume */
FR_MKFS_ABORTED, /* (14) The f_mkfs() aborted due to any parameter error */
FR_TIMEOUT, /* (15) Could not get a grant to access the volume within defined period */
FR_LOCKED, /* (16) The operation is rejected according to the file sharing policy */
FR_NOT_ENOUGH_CORE, /* (17) LFN working buffer could not be allocated */
FR_TOO_MANY_OPEN_FILES, /* (18) Number of open files > _FS_SHARE */
FR_INVALID_PARAMETER /* (19) Given parameter is invalid */
} FRESULT;
// }}}
// API
typedef struct {
uint32_t size;
uint16_t date, time;
uint8_t attrib;
char name[];
} __attribute__((packed)) s_stat_t;
enum satiator_mode {
s_cdrom = 0,
s_api,
};
int s_open(const char *filename, int flags);
int s_close(int fd);
int s_seek(int fd, int offset, int whence);
int s_read(int fd, void *buf, int len);
int s_write(int fd, const void *buf, int len);
int s_sync(int fd);
int s_truncate(int fd);
int s_stat(const char *filename, s_stat_t *stat, int statsize);
int s_rename(const char *old, const char *new);
int s_mkdir(const char *filename);
int s_unlink(const char *filename);
int s_opendir(const char *filename);
int s_chdir(const char *filename);
int s_getcwd(char *filename, int buflen);
int s_settime(uint32_t fattime);
int s_emulate(const char *filename);
int s_mode(enum satiator_mode mode);
int s_get_fw_version(char *buf, int buflen);
#define S_MAXBUF 2048
#include <unistd.h>
#define dbgprintf(...) printf(__VA_ARGS__)