-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmsd.h
104 lines (71 loc) · 1.74 KB
/
msd.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
93
94
95
96
97
98
99
100
101
102
103
#ifndef MSD_H
#define MSD_H
#ifdef __cplusplus
extern "C" {
#endif
#include "config.h"
typedef uint16_t msd_size_t;
typedef uint64_t msd_addr_t;
#ifndef MSD_BLOCK_SIZE_MAX
#define MSD_BLOCK_SIZE_MAX 512
#endif
typedef enum
{
MSD_STATUS_READY,
MSD_STATUS_BUSY,
MSD_STATUS_NODEVICE
} msd_status_t;
typedef struct
{
unsigned int removable:1;
unsigned int volatile1:1;
unsigned int partial_read:1;
unsigned int partial_write:1;
unsigned int reserved:4;
} msd_flags_t;
typedef msd_addr_t
(*msd_probe_t)(void *handle);
typedef msd_size_t
(*msd_read_t)(void *handle, msd_addr_t addr, void *buffer, msd_size_t size);
typedef msd_size_t
(*msd_write_t)(void *handle, msd_addr_t addr, const void *buffer, msd_size_t size);
typedef msd_status_t
(*msd_status_get_t)(void *handle);
typedef void
(*msd_shutdown_t)(void *shutdown);
typedef struct msd_ops_struct
{
msd_probe_t probe;
msd_read_t read;
msd_write_t write;
msd_status_get_t status_get;
msd_shutdown_t shutdown;
} msd_ops_t;
typedef struct msd_struct
{
void *handle;
const msd_ops_t *ops;
msd_addr_t media_bytes;
msd_size_t block_bytes;
uint32_t reads;
uint32_t writes;
uint16_t read_errors;
uint16_t write_errors;
const char *name;
msd_flags_t flags;
} msd_t;
msd_addr_t msd_probe (msd_t *msd);
msd_size_t msd_read (msd_t *msd, msd_addr_t addr, void *buffer, msd_size_t size);
msd_size_t msd_write (msd_t *msd, msd_addr_t addr, const void *buffer, msd_size_t size);
msd_status_t msd_status_get (msd_t *msd);
void msd_shutdown (msd_t *msd);
static inline msd_addr_t msd_media_bytes_get (msd_t *msd)
{
if (!msd)
return 0;
return msd->media_bytes;
}
#ifdef __cplusplus
}
#endif
#endif