comparison partition.h @ 19:5f9a40d6991b

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