00001 00002 /* 00003 * Copyright (c) 2006-2010 by Roland Riegel <feedback@roland-riegel.de> 00004 * 00005 * This file is free software; you can redistribute it and/or modify 00006 * it under the terms of either the GNU General Public License version 2 00007 * or the GNU Lesser General Public License version 2.1, both as 00008 * published by the Free Software Foundation. 00009 */ 00010 00011 #ifndef PARTITION_H 00012 #define PARTITION_H 00013 00014 #include <stdint.h> 00015 #include "sd_raw_config.h" 00016 #include "partition_config.h" 00017 00018 #ifdef __cplusplus 00019 extern "C" 00020 { 00021 #endif 00022 00023 /** 00024 * \addtogroup partition 00025 * 00026 * @{ 00027 */ 00028 /** 00029 * \file 00030 * Partition table header (license: GPLv2 or LGPLv2.1) 00031 * 00032 * \author Roland Riegel 00033 */ 00034 00035 /** 00036 * The partition table entry is not used. 00037 */ 00038 #define PARTITION_TYPE_FREE 0x00 00039 /** 00040 * The partition contains a FAT12 filesystem. 00041 */ 00042 #define PARTITION_TYPE_FAT12 0x01 00043 /** 00044 * The partition contains a FAT16 filesystem with 32MB maximum. 00045 */ 00046 #define PARTITION_TYPE_FAT16_32MB 0x04 00047 /** 00048 * The partition is an extended partition with its own partition table. 00049 */ 00050 #define PARTITION_TYPE_EXTENDED 0x05 00051 /** 00052 * The partition contains a FAT16 filesystem. 00053 */ 00054 #define PARTITION_TYPE_FAT16 0x06 00055 /** 00056 * The partition contains a FAT32 filesystem. 00057 */ 00058 #define PARTITION_TYPE_FAT32 0x0b 00059 /** 00060 * The partition contains a FAT32 filesystem with LBA. 00061 */ 00062 #define PARTITION_TYPE_FAT32_LBA 0x0c 00063 /** 00064 * The partition contains a FAT16 filesystem with LBA. 00065 */ 00066 #define PARTITION_TYPE_FAT16_LBA 0x0e 00067 /** 00068 * The partition is an extended partition with LBA. 00069 */ 00070 #define PARTITION_TYPE_EXTENDED_LBA 0x0f 00071 /** 00072 * The partition has an unknown type. 00073 */ 00074 #define PARTITION_TYPE_UNKNOWN 0xff 00075 00076 /** 00077 * A function pointer used to read from the partition. 00078 * 00079 * \param[in] offset The offset on the device where to start reading. 00080 * \param[out] buffer The buffer into which to place the data. 00081 * \param[in] length The count of bytes to read. 00082 */ 00083 typedef uint8_t (*device_read_t)(offset_t offset, uint8_t* buffer, uintptr_t length); 00084 /** 00085 * A function pointer passed to a \c device_read_interval_t. 00086 * 00087 * \param[in] buffer The buffer which contains the data just read. 00088 * \param[in] offset The offset from which the data in \c buffer was read. 00089 * \param[in] p An opaque pointer. 00090 * \see device_read_interval_t 00091 */ 00092 typedef uint8_t (*device_read_callback_t)(uint8_t* buffer, offset_t offset, void* p); 00093 /** 00094 * A function pointer used to continuously read units of \c interval bytes 00095 * and call a callback function. 00096 * 00097 * This function starts reading at the specified offset. Every \c interval bytes, 00098 * it calls the callback function with the associated data buffer. 00099 * 00100 * By returning zero, the callback may stop reading. 00101 * 00102 * \param[in] offset Offset from which to start reading. 00103 * \param[in] buffer Pointer to a buffer which is at least interval bytes in size. 00104 * \param[in] interval Number of bytes to read before calling the callback function. 00105 * \param[in] length Number of bytes to read altogether. 00106 * \param[in] callback The function to call every interval bytes. 00107 * \param[in] p An opaque pointer directly passed to the callback function. 00108 * \returns 0 on failure, 1 on success 00109 * \see device_read_t 00110 */ 00111 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); 00112 /** 00113 * A function pointer used to write to the partition. 00114 * 00115 * \param[in] offset The offset on the device where to start writing. 00116 * \param[in] buffer The buffer which to write. 00117 * \param[in] length The count of bytes to write. 00118 */ 00119 typedef uint8_t (*device_write_t)(offset_t offset, const uint8_t* buffer, uintptr_t length); 00120 /** 00121 * A function pointer passed to a \c device_write_interval_t. 00122 * 00123 * \param[in] buffer The buffer which receives the data to write. 00124 * \param[in] offset The offset to which the data in \c buffer will be written. 00125 * \param[in] p An opaque pointer. 00126 * \returns The number of bytes put into \c buffer 00127 * \see device_write_interval_t 00128 */ 00129 typedef uintptr_t (*device_write_callback_t)(uint8_t* buffer, offset_t offset, void* p); 00130 /** 00131 * A function pointer used to continuously write a data stream obtained from 00132 * a callback function. 00133 * 00134 * This function starts writing at the specified offset. To obtain the 00135 * next bytes to write, it calls the callback function. The callback fills the 00136 * provided data buffer and returns the number of bytes it has put into the buffer. 00137 * 00138 * By returning zero, the callback may stop writing. 00139 * 00140 * \param[in] offset Offset where to start writing. 00141 * \param[in] buffer Pointer to a buffer which is used for the callback function. 00142 * \param[in] length Number of bytes to write in total. May be zero for endless writes. 00143 * \param[in] callback The function used to obtain the bytes to write. 00144 * \param[in] p An opaque pointer directly passed to the callback function. 00145 * \returns 0 on failure, 1 on success 00146 * \see device_write_t 00147 */ 00148 typedef uint8_t (*device_write_interval_t)(offset_t offset, uint8_t* buffer, uintptr_t length, device_write_callback_t callback, void* p); 00149 00150 /** 00151 * Describes a partition. 00152 */ 00153 struct partition_struct 00154 { 00155 /** 00156 * The function which reads data from the partition. 00157 * 00158 * \note The offset given to this function is relative to the whole disk, 00159 * not to the start of the partition. 00160 */ 00161 device_read_t device_read; 00162 /** 00163 * The function which repeatedly reads a constant amount of data from the partition. 00164 * 00165 * \note The offset given to this function is relative to the whole disk, 00166 * not to the start of the partition. 00167 */ 00168 device_read_interval_t device_read_interval; 00169 /** 00170 * The function which writes data to the partition. 00171 * 00172 * \note The offset given to this function is relative to the whole disk, 00173 * not to the start of the partition. 00174 */ 00175 device_write_t device_write; 00176 /** 00177 * The function which repeatedly writes data to the partition. 00178 * 00179 * \note The offset given to this function is relative to the whole disk, 00180 * not to the start of the partition. 00181 */ 00182 device_write_interval_t device_write_interval; 00183 00184 /** 00185 * The type of the partition. 00186 * 00187 * Compare this value to the PARTITION_TYPE_* constants. 00188 */ 00189 uint8_t type; 00190 /** 00191 * The offset in blocks on the disk where this partition starts. 00192 */ 00193 uint32_t offset; 00194 /** 00195 * The length in blocks of this partition. 00196 */ 00197 uint32_t length; 00198 }; 00199 00200 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); 00201 uint8_t partition_close(struct partition_struct* partition); 00202 00203 /** 00204 * @} 00205 */ 00206 00207 #ifdef __cplusplus 00208 } 00209 #endif 00210 00211 #endif 00212
1.5.6