1 |
|
1 |
|
2 |
/* |
2 |
/* |
3 |
* Copyright (c) 2006-2007 by Roland Riegel <feedback@roland-riegel.de> |
3 |
* Copyright (c) 2006-2007 by Roland Riegel <feedback@roland-riegel.de> |
4 |
* |
4 |
* |
5 |
* This file is free software; you can redistribute it and/or modify |
5 |
* This file is free software; you can redistribute it and/or modify |
6 |
* it under the terms of either the GNU General Public License version 2 |
6 |
* it under the terms of either the GNU General Public License version 2 |
7 |
* or the GNU Lesser General Public License version 2.1, both as |
7 |
* or the GNU Lesser General Public License version 2.1, both as |
8 |
* published by the Free Software Foundation. |
8 |
* published by the Free Software Foundation. |
9 |
*/ |
9 |
*/ |
10 |
|
10 |
|
11 |
#ifndef PARTITION_H |
11 |
#ifndef PARTITION_H |
12 |
#define PARTITION_H |
12 |
#define PARTITION_H |
13 |
|
13 |
|
14 |
#include <stdint.h> |
14 |
#include <stdint.h> |
15 |
|
15 |
|
16 |
/** |
16 |
/** |
17 |
* \addtogroup partition |
17 |
* \addtogroup partition |
18 |
* |
18 |
* |
19 |
* @{ |
19 |
* @{ |
20 |
*/ |
20 |
*/ |
21 |
/** |
21 |
/** |
22 |
* \file |
22 |
* \file |
23 |
* Partition table header (license: GPLv2 or LGPLv2.1) |
23 |
* Partition table header (license: GPLv2 or LGPLv2.1) |
24 |
* |
24 |
* |
25 |
* \author Roland Riegel |
25 |
* \author Roland Riegel |
26 |
*/ |
26 |
*/ |
27 |
|
27 |
|
28 |
/** |
28 |
/** |
29 |
* The partition table entry is not used. |
29 |
* The partition table entry is not used. |
30 |
*/ |
30 |
*/ |
31 |
#define PARTITION_TYPE_FREE 0x00 |
31 |
#define PARTITION_TYPE_FREE 0x00 |
32 |
/** |
32 |
/** |
33 |
* The partition contains a FAT12 filesystem. |
33 |
* The partition contains a FAT12 filesystem. |
34 |
*/ |
34 |
*/ |
35 |
#define PARTITION_TYPE_FAT12 0x01 |
35 |
#define PARTITION_TYPE_FAT12 0x01 |
36 |
/** |
36 |
/** |
37 |
* The partition contains a FAT16 filesystem with 32MB maximum. |
37 |
* The partition contains a FAT16 filesystem with 32MB maximum. |
38 |
*/ |
38 |
*/ |
39 |
#define PARTITION_TYPE_FAT16_32MB 0x04 |
39 |
#define PARTITION_TYPE_FAT16_32MB 0x04 |
40 |
/** |
40 |
/** |
41 |
* The partition is an extended partition with its own partition table. |
41 |
* The partition is an extended partition with its own partition table. |
42 |
*/ |
42 |
*/ |
43 |
#define PARTITION_TYPE_EXTENDED 0x05 |
43 |
#define PARTITION_TYPE_EXTENDED 0x05 |
44 |
/** |
44 |
/** |
45 |
* The partition contains a FAT16 filesystem. |
45 |
* The partition contains a FAT16 filesystem. |
46 |
*/ |
46 |
*/ |
47 |
#define PARTITION_TYPE_FAT16 0x06 |
47 |
#define PARTITION_TYPE_FAT16 0x06 |
48 |
/** |
48 |
/** |
49 |
* The partition contains a FAT32 filesystem. |
49 |
* The partition contains a FAT32 filesystem. |
50 |
*/ |
50 |
*/ |
51 |
#define PARTITION_TYPE_FAT32 0x0b |
51 |
#define PARTITION_TYPE_FAT32 0x0b |
52 |
/** |
52 |
/** |
53 |
* The partition contains a FAT32 filesystem with LBA. |
53 |
* The partition contains a FAT32 filesystem with LBA. |
54 |
*/ |
54 |
*/ |
55 |
#define PARTITION_TYPE_FAT32_LBA 0x0c |
55 |
#define PARTITION_TYPE_FAT32_LBA 0x0c |
56 |
/** |
56 |
/** |
57 |
* The partition contains a FAT16 filesystem with LBA. |
57 |
* The partition contains a FAT16 filesystem with LBA. |
58 |
*/ |
58 |
*/ |
59 |
#define PARTITION_TYPE_FAT16_LBA 0x0e |
59 |
#define PARTITION_TYPE_FAT16_LBA 0x0e |
60 |
/** |
60 |
/** |
61 |
* The partition is an extended partition with LBA. |
61 |
* The partition is an extended partition with LBA. |
62 |
*/ |
62 |
*/ |
63 |
#define PARTITION_TYPE_EXTENDED_LBA 0x0f |
63 |
#define PARTITION_TYPE_EXTENDED_LBA 0x0f |
64 |
/** |
64 |
/** |
65 |
* The partition has an unknown type. |
65 |
* The partition has an unknown type. |
66 |
*/ |
66 |
*/ |
67 |
#define PARTITION_TYPE_UNKNOWN 0xff |
67 |
#define PARTITION_TYPE_UNKNOWN 0xff |
68 |
|
68 |
|
69 |
/** |
69 |
/** |
70 |
* A function pointer used to read from the partition. |
70 |
* A function pointer used to read from the partition. |
71 |
* |
71 |
* |
72 |
* \param[in] offset The offset on the device where to start reading. |
72 |
* \param[in] offset The offset on the device where to start reading. |
73 |
* \param[out] buffer The buffer into which to place the data. |
73 |
* \param[out] buffer The buffer into which to place the data. |
74 |
* \param[in] length The count of bytes to read. |
74 |
* \param[in] length The count of bytes to read. |
75 |
*/ |
75 |
*/ |
76 |
typedef uint8_t (*device_read_t)(uint32_t offset, uint8_t* buffer, uint16_t length); |
76 |
typedef uint8_t (*device_read_t)(uint32_t offset, uint8_t* buffer, uint16_t length); |
77 |
/** |
77 |
/** |
78 |
* A function pointer passed to a \c device_read_interval_t. |
78 |
* A function pointer passed to a \c device_read_interval_t. |
79 |
* |
79 |
* |
80 |
* \param[in] buffer The buffer which contains the data just read. |
80 |
* \param[in] buffer The buffer which contains the data just read. |
81 |
* \param[in] offset The offset from which the data in \c buffer was read. |
81 |
* \param[in] offset The offset from which the data in \c buffer was read. |
82 |
* \param[in] p An opaque pointer. |
82 |
* \param[in] p An opaque pointer. |
83 |
* \see device_read_interval_t |
83 |
* \see device_read_interval_t |
84 |
*/ |
84 |
*/ |
85 |
typedef uint8_t (*device_read_callback_t)(uint8_t* buffer, uint32_t offset, void* p); |
85 |
typedef uint8_t (*device_read_callback_t)(uint8_t* buffer, uint32_t offset, void* p); |
86 |
/** |
86 |
/** |
87 |
* A function pointer used to continuously read units of \c interval bytes |
87 |
* A function pointer used to continuously read units of \c interval bytes |
88 |
* and call a callback function. |
88 |
* and call a callback function. |
89 |
* |
89 |
* |
90 |
* This function starts reading at the specified offset. Every \c interval bytes, |
90 |
* This function starts reading at the specified offset. Every \c interval bytes, |
91 |
* it calls the callback function with the associated data buffer. |
91 |
* it calls the callback function with the associated data buffer. |
92 |
* |
92 |
* |
93 |
* By returning zero, the callback may stop reading. |
93 |
* By returning zero, the callback may stop reading. |
94 |
* |
94 |
* |
95 |
* \param[in] offset Offset from which to start reading. |
95 |
* \param[in] offset Offset from which to start reading. |
96 |
* \param[in] buffer Pointer to a buffer which is at least interval bytes in size. |
96 |
* \param[in] buffer Pointer to a buffer which is at least interval bytes in size. |
97 |
* \param[in] interval Number of bytes to read before calling the callback function. |
97 |
* \param[in] interval Number of bytes to read before calling the callback function. |
98 |
* \param[in] length Number of bytes to read altogether. |
98 |
* \param[in] length Number of bytes to read altogether. |
99 |
* \param[in] callback The function to call every interval bytes. |
99 |
* \param[in] callback The function to call every interval bytes. |
100 |
* \param[in] p An opaque pointer directly passed to the callback function. |
100 |
* \param[in] p An opaque pointer directly passed to the callback function. |
101 |
* \returns 0 on failure, 1 on success |
101 |
* \returns 0 on failure, 1 on success |
102 |
* \see device_read_t |
102 |
* \see device_read_t |
103 |
*/ |
103 |
*/ |
104 |
typedef uint8_t (*device_read_interval_t)(uint32_t offset, uint8_t* buffer, uint16_t interval, uint16_t length, device_read_callback_t callback, void* p); |
104 |
typedef uint8_t (*device_read_interval_t)(uint32_t offset, uint8_t* buffer, uint16_t interval, uint16_t length, device_read_callback_t callback, void* p); |
105 |
/** |
105 |
/** |
106 |
* A function pointer used to write to the partition. |
106 |
* A function pointer used to write to the partition. |
107 |
* |
107 |
* |
108 |
* \param[in] offset The offset on the device where to start writing. |
108 |
* \param[in] offset The offset on the device where to start writing. |
109 |
* \param[in] buffer The buffer which to write. |
109 |
* \param[in] buffer The buffer which to write. |
110 |
* \param[in] length The count of bytes to write. |
110 |
* \param[in] length The count of bytes to write. |
111 |
*/ |
111 |
*/ |
112 |
typedef uint8_t (*device_write_t)(uint32_t offset, const uint8_t* buffer, uint16_t length); |
112 |
typedef uint8_t (*device_write_t)(uint32_t offset, const uint8_t* buffer, uint16_t length); |
113 |
/** |
113 |
/** |
114 |
* A function pointer passed to a \c device_write_interval_t. |
114 |
* A function pointer passed to a \c device_write_interval_t. |
115 |
* |
115 |
* |
116 |
* \param[in] buffer The buffer which receives the data to write. |
116 |
* \param[in] buffer The buffer which receives the data to write. |
117 |
* \param[in] offset The offset to which the data in \c buffer will be written. |
117 |
* \param[in] offset The offset to which the data in \c buffer will be written. |
118 |
* \param[in] p An opaque pointer. |
118 |
* \param[in] p An opaque pointer. |
119 |
* \returns The number of bytes put into \c buffer |
119 |
* \returns The number of bytes put into \c buffer |
120 |
* \see device_write_interval_t |
120 |
* \see device_write_interval_t |
121 |
*/ |
121 |
*/ |
122 |
typedef uint16_t (*device_write_callback_t)(uint8_t* buffer, uint32_t offset, void* p); |
122 |
typedef uint16_t (*device_write_callback_t)(uint8_t* buffer, uint32_t offset, void* p); |
123 |
/** |
123 |
/** |
124 |
* A function pointer used to continuously write a data stream obtained from |
124 |
* A function pointer used to continuously write a data stream obtained from |
125 |
* a callback function. |
125 |
* a callback function. |
126 |
* |
126 |
* |
127 |
* This function starts writing at the specified offset. To obtain the |
127 |
* This function starts writing at the specified offset. To obtain the |
128 |
* next bytes to write, it calls the callback function. The callback fills the |
128 |
* next bytes to write, it calls the callback function. The callback fills the |
129 |
* provided data buffer and returns the number of bytes it has put into the buffer. |
129 |
* provided data buffer and returns the number of bytes it has put into the buffer. |
130 |
* |
130 |
* |
131 |
* By returning zero, the callback may stop writing. |
131 |
* By returning zero, the callback may stop writing. |
132 |
* |
132 |
* |
133 |
* \param[in] offset Offset where to start writing. |
133 |
* \param[in] offset Offset where to start writing. |
134 |
* \param[in] buffer Pointer to a buffer which is used for the callback function. |
134 |
* \param[in] buffer Pointer to a buffer which is used for the callback function. |
135 |
* \param[in] length Number of bytes to write in total. May be zero for endless writes. |
135 |
* \param[in] length Number of bytes to write in total. May be zero for endless writes. |
136 |
* \param[in] callback The function used to obtain the bytes to write. |
136 |
* \param[in] callback The function used to obtain the bytes to write. |
137 |
* \param[in] p An opaque pointer directly passed to the callback function. |
137 |
* \param[in] p An opaque pointer directly passed to the callback function. |
138 |
* \returns 0 on failure, 1 on success |
138 |
* \returns 0 on failure, 1 on success |
139 |
* \see device_write_t |
139 |
* \see device_write_t |
140 |
*/ |
140 |
*/ |
141 |
typedef uint8_t (*device_write_interval_t)(uint32_t offset, uint8_t* buffer, uint16_t length, device_write_callback_t callback, void* p); |
141 |
typedef uint8_t (*device_write_interval_t)(uint32_t offset, uint8_t* buffer, uint16_t length, device_write_callback_t callback, void* p); |
142 |
|
142 |
|
143 |
/** |
143 |
/** |
144 |
* Describes a partition. |
144 |
* Describes a partition. |
145 |
*/ |
145 |
*/ |
146 |
struct partition_struct |
146 |
struct partition_struct |
147 |
{ |
147 |
{ |
148 |
/** |
148 |
/** |
149 |
* The function which reads data from the partition. |
149 |
* The function which reads data from the partition. |
150 |
* |
150 |
* |
151 |
* \note The offset given to this function is relative to the whole disk, |
151 |
* \note The offset given to this function is relative to the whole disk, |
152 |
* not to the start of the partition. |
152 |
* not to the start of the partition. |
153 |
*/ |
153 |
*/ |
154 |
device_read_t device_read; |
154 |
device_read_t device_read; |
155 |
/** |
155 |
/** |
156 |
* The function which repeatedly reads a constant amount of data from the partition. |
156 |
* The function which repeatedly reads a constant amount of data from the partition. |
157 |
* |
157 |
* |
158 |
* \note The offset given to this function is relative to the whole disk, |
158 |
* \note The offset given to this function is relative to the whole disk, |
159 |
* not to the start of the partition. |
159 |
* not to the start of the partition. |
160 |
*/ |
160 |
*/ |
161 |
device_read_interval_t device_read_interval; |
161 |
device_read_interval_t device_read_interval; |
162 |
/** |
162 |
/** |
163 |
* The function which writes data to the partition. |
163 |
* The function which writes data to the partition. |
164 |
* |
164 |
* |
165 |
* \note The offset given to this function is relative to the whole disk, |
165 |
* \note The offset given to this function is relative to the whole disk, |
166 |
* not to the start of the partition. |
166 |
* not to the start of the partition. |
167 |
*/ |
167 |
*/ |
168 |
device_write_t device_write; |
168 |
device_write_t device_write; |
169 |
/** |
169 |
/** |
170 |
* The function which repeatedly writes data to the partition. |
170 |
* The function which repeatedly writes data to the partition. |
171 |
* |
171 |
* |
172 |
* \note The offset given to this function is relative to the whole disk, |
172 |
* \note The offset given to this function is relative to the whole disk, |
173 |
* not to the start of the partition. |
173 |
* not to the start of the partition. |
174 |
*/ |
174 |
*/ |
175 |
device_write_interval_t device_write_interval; |
175 |
device_write_interval_t device_write_interval; |
176 |
|
176 |
|
177 |
/** |
177 |
/** |
178 |
* The type of the partition. |
178 |
* The type of the partition. |
179 |
* |
179 |
* |
180 |
* Compare this value to the PARTITION_TYPE_* constants. |
180 |
* Compare this value to the PARTITION_TYPE_* constants. |
181 |
*/ |
181 |
*/ |
182 |
uint8_t type; |
182 |
uint8_t type; |
183 |
/** |
183 |
/** |
184 |
* The offset in bytes on the disk where this partition starts. |
184 |
* The offset in bytes on the disk where this partition starts. |
185 |
*/ |
185 |
*/ |
186 |
uint32_t offset; |
186 |
uint32_t offset; |
187 |
/** |
187 |
/** |
188 |
* The length in bytes of this partition. |
188 |
* The length in bytes of this partition. |
189 |
*/ |
189 |
*/ |
190 |
uint32_t length; |
190 |
uint32_t length; |
191 |
}; |
191 |
}; |
192 |
|
192 |
|
193 |
struct partition_struct* partition_open(device_read_t device_read, device_read_interval_t device_read_interval, device_write_t device_write, device_write_interval_t device_write_interval, int8_t index); |
193 |
struct partition_struct* partition_open(device_read_t device_read, device_read_interval_t device_read_interval, device_write_t device_write, device_write_interval_t device_write_interval, int8_t index); |
194 |
uint8_t partition_close(struct partition_struct* partition); |
194 |
uint8_t partition_close(struct partition_struct* partition); |
195 |
|
195 |
|
196 |
/** |
196 |
/** |
197 |
* @} |
197 |
* @} |
198 |
*/ |
198 |
*/ |
199 |
|
199 |
|
200 |
#endif |
200 |
#endif |
201 |
|
201 |
|