Partition table support

Collaboration diagram for Partition table support:

Files

file  partition.c
file  partition.h
file  partition_config.h

Modules

 Configuration of partition table support

Data Structures

struct  partition_struct

Defines

#define PARTITION_TYPE_FREE   0x00
#define PARTITION_TYPE_FAT12   0x01
#define PARTITION_TYPE_FAT16_32MB   0x04
#define PARTITION_TYPE_EXTENDED   0x05
#define PARTITION_TYPE_FAT16   0x06
#define PARTITION_TYPE_FAT32   0x0b
#define PARTITION_TYPE_FAT32_LBA   0x0c
#define PARTITION_TYPE_FAT16_LBA   0x0e
#define PARTITION_TYPE_EXTENDED_LBA   0x0f
#define PARTITION_TYPE_UNKNOWN   0xff

Typedefs

typedef uint8_t(* device_read_t )(offset_t offset, uint8_t *buffer, uintptr_t length)
typedef uint8_t(* device_read_callback_t )(uint8_t *buffer, offset_t offset, void *p)
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)
typedef uint8_t(* device_write_t )(offset_t offset, const uint8_t *buffer, uintptr_t length)
typedef uintptr_t(* device_write_callback_t )(uint8_t *buffer, offset_t offset, void *p)
typedef uint8_t(* device_write_interval_t )(offset_t offset, uint8_t *buffer, uintptr_t length, device_write_callback_t callback, void *p)

Functions

struct partition_structpartition_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)
uint8_t partition_close (struct partition_struct *partition)

Variables

static struct partition_struct partition_handles [PARTITION_COUNT]

Detailed Description

Support for reading partition tables and access to partitions.

Define Documentation

#define PARTITION_TYPE_EXTENDED   0x05

The partition is an extended partition with its own partition table.

Definition at line 50 of file partition.h.

#define PARTITION_TYPE_EXTENDED_LBA   0x0f

The partition is an extended partition with LBA.

Definition at line 70 of file partition.h.

#define PARTITION_TYPE_FAT12   0x01

The partition contains a FAT12 filesystem.

Definition at line 42 of file partition.h.

#define PARTITION_TYPE_FAT16   0x06

The partition contains a FAT16 filesystem.

Definition at line 54 of file partition.h.

Referenced by fat_get_fs_free(), and fat_read_header().

#define PARTITION_TYPE_FAT16_32MB   0x04

The partition contains a FAT16 filesystem with 32MB maximum.

Definition at line 46 of file partition.h.

#define PARTITION_TYPE_FAT16_LBA   0x0e

The partition contains a FAT16 filesystem with LBA.

Definition at line 66 of file partition.h.

#define PARTITION_TYPE_FAT32   0x0b

#define PARTITION_TYPE_FAT32_LBA   0x0c

The partition contains a FAT32 filesystem with LBA.

Definition at line 62 of file partition.h.

#define PARTITION_TYPE_FREE   0x00

The partition table entry is not used.

Definition at line 38 of file partition.h.

Referenced by partition_close(), and partition_open().

#define PARTITION_TYPE_UNKNOWN   0xff

The partition has an unknown type.

Definition at line 74 of file partition.h.


Typedef Documentation

typedef uint8_t(* device_read_callback_t)(uint8_t *buffer, offset_t offset, void *p)

A function pointer passed to a device_read_interval_t.

Parameters:
[in] buffer The buffer which contains the data just read.
[in] offset The offset from which the data in buffer was read.
[in] p An opaque pointer.
See also:
device_read_interval_t

Definition at line 92 of file partition.h.

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)

A function pointer used to continuously read units of interval bytes and call a callback function.

This function starts reading at the specified offset. Every interval bytes, it calls the callback function with the associated data buffer.

By returning zero, the callback may stop reading.

Parameters:
[in] offset Offset from which to start reading.
[in] buffer Pointer to a buffer which is at least interval bytes in size.
[in] interval Number of bytes to read before calling the callback function.
[in] length Number of bytes to read altogether.
[in] callback The function to call every interval bytes.
[in] p An opaque pointer directly passed to the callback function.
Returns:
0 on failure, 1 on success
See also:
device_read_t

Definition at line 111 of file partition.h.

typedef uint8_t(* device_read_t)(offset_t offset, uint8_t *buffer, uintptr_t length)

A function pointer used to read from the partition.

Parameters:
[in] offset The offset on the device where to start reading.
[out] buffer The buffer into which to place the data.
[in] length The count of bytes to read.

Definition at line 83 of file partition.h.

typedef uintptr_t(* device_write_callback_t)(uint8_t *buffer, offset_t offset, void *p)

A function pointer passed to a device_write_interval_t.

Parameters:
[in] buffer The buffer which receives the data to write.
[in] offset The offset to which the data in buffer will be written.
[in] p An opaque pointer.
Returns:
The number of bytes put into buffer
See also:
device_write_interval_t

Definition at line 129 of file partition.h.

typedef uint8_t(* device_write_interval_t)(offset_t offset, uint8_t *buffer, uintptr_t length, device_write_callback_t callback, void *p)

A function pointer used to continuously write a data stream obtained from a callback function.

This function starts writing at the specified offset. To obtain the next bytes to write, it calls the callback function. The callback fills the provided data buffer and returns the number of bytes it has put into the buffer.

By returning zero, the callback may stop writing.

Parameters:
[in] offset Offset where to start writing.
[in] buffer Pointer to a buffer which is used for the callback function.
[in] length Number of bytes to write in total. May be zero for endless writes.
[in] callback The function used to obtain the bytes to write.
[in] p An opaque pointer directly passed to the callback function.
Returns:
0 on failure, 1 on success
See also:
device_write_t

Definition at line 148 of file partition.h.

typedef uint8_t(* device_write_t)(offset_t offset, const uint8_t *buffer, uintptr_t length)

A function pointer used to write to the partition.

Parameters:
[in] offset The offset on the device where to start writing.
[in] buffer The buffer which to write.
[in] length The count of bytes to write.

Definition at line 119 of file partition.h.


Function Documentation

uint8_t partition_close ( struct partition_struct partition  ) 

Closes a partition.

This function destroys a partition descriptor which was previously obtained from a call to partition_open(). When this function returns, the given descriptor will be invalid.

Parameters:
[in] partition The partition descriptor to destroy.
Returns:
0 on failure, 1 on success.
See also:
partition_open

Definition at line 142 of file partition.c.

References PARTITION_TYPE_FREE, and partition_struct::type.

Referenced by WaspSD::close().

00143 {
00144     if(!partition)
00145         return 0;
00146 
00147     /* destroy partition descriptor */
00148 #if USE_DYNAMIC_MEMORY
00149     free(partition);
00150 #else
00151     partition->type = PARTITION_TYPE_FREE;
00152 #endif
00153 
00154     return 1;
00155 }

Here is the caller graph for this function:

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 
) [read]

Opens a partition.

Opens a partition by its index number and returns a partition handle which describes the opened partition.

Note:
This function does not support extended partitions.
Parameters:
[in] device_read A function pointer which is used to read from the disk.
[in] device_read_interval A function pointer which is used to read in constant intervals from the disk.
[in] device_write A function pointer which is used to write to the disk.
[in] device_write_interval A function pointer which is used to write a data stream to disk.
[in] index The index of the partition which should be opened, range 0 to 3. A negative value is allowed as well. In this case, the partition opened is not checked for existance, begins at offset zero, has a length of zero and is of an unknown type. Use this in case you want to open the whole device as a single partition (e.g. for "super floppy" use).
Returns:
0 on failure, a partition descriptor on success.
See also:
partition_close

Definition at line 64 of file partition.c.

References partition_struct::device_read, partition_struct::device_read_interval, partition_struct::device_write, partition_struct::device_write_interval, partition_struct::length, partition_struct::offset, PARTITION_COUNT, partition_handles, PARTITION_TYPE_FREE, and partition_struct::type.

Referenced by WaspSD::init().

00065 {
00066     struct partition_struct* new_partition = 0;
00067     uint8_t buffer[0x10];
00068 
00069     if(!device_read || !device_read_interval || index >= 4)
00070         return 0;
00071 
00072     if(index >= 0)
00073     {
00074         /* read specified partition table index */
00075         if(!device_read(0x01be + index * 0x10, buffer, sizeof(buffer)))
00076             return 0;
00077 
00078         /* abort on empty partition entry */
00079         if(buffer[4] == 0x00)
00080             return 0;
00081     }
00082 
00083     /* allocate partition descriptor */
00084 #if USE_DYNAMIC_MEMORY
00085     new_partition = malloc(sizeof(*new_partition));
00086     if(!new_partition)
00087         return 0;
00088 #else
00089     new_partition = partition_handles;
00090     uint8_t i;
00091     for(i = 0; i < PARTITION_COUNT; ++i)
00092     {
00093         if(new_partition->type == PARTITION_TYPE_FREE)
00094             break;
00095 
00096         ++new_partition;
00097     }
00098     if(i >= PARTITION_COUNT)
00099         return 0;
00100 #endif
00101 
00102     memset(new_partition, 0, sizeof(*new_partition));
00103 
00104     /* fill partition descriptor */
00105     new_partition->device_read = device_read;
00106     new_partition->device_read_interval = device_read_interval;
00107     new_partition->device_write = device_write;
00108     new_partition->device_write_interval = device_write_interval;
00109 
00110     if(index >= 0)
00111     {
00112         new_partition->type = buffer[4];
00113         new_partition->offset = ((uint32_t) buffer[8]) |
00114                                 ((uint32_t) buffer[9] << 8) |
00115                                 ((uint32_t) buffer[10] << 16) |
00116                                 ((uint32_t) buffer[11] << 24);
00117         new_partition->length = ((uint32_t) buffer[12]) |
00118                                 ((uint32_t) buffer[13] << 8) |
00119                                 ((uint32_t) buffer[14] << 16) |
00120                                 ((uint32_t) buffer[15] << 24);
00121     }
00122     else
00123     {
00124         new_partition->type = 0xff;
00125     }
00126 
00127     return new_partition;
00128 }

Here is the caller graph for this function:


Variable Documentation

struct partition_struct partition_handles[PARTITION_COUNT] [static]

Definition at line 41 of file partition.c.

Referenced by partition_open().


Generated on Tue Jul 20 09:31:00 2010 for WaspmoteAPI by  doxygen 1.5.6