Contiki-Inga 3.x
Files | Data Structures | Functions | Variables
Master Boot Record Support

Files

file  mbr.c
 
 MBR Support implementation

 
file  mbr.h
 
    MBR Support definitions

 

Data Structures

struct  mbr_primary_partition
 Represents a primary partition in the mbr. More...
 
struct  mbr
 Represents the MBR of a disk, without the code portion and the constant bytes. More...
 

Functions

void mbr_init (struct mbr *mbr)
 Initializes a mbr structure. More...
 
int mbr_read (struct diskio_device_info *from, struct mbr *to)
 Reads the MBR from the specified device. More...
 
int mbr_write (struct mbr *from, struct diskio_device_info *to)
 Write the MBR to the specified device. More...
 
int mbr_addPartition (struct mbr *mbr, uint8_t part_num, uint8_t part_type, uint32_t start, uint32_t len)
 Adds a Partition to the mbr-structure. More...
 
int mbr_delPartition (struct mbr *mbr, uint8_t part_num)
 Deletes a Partition from the mbr-structure. More...
 
int mbr_hasPartition (struct mbr *mbr, uint8_t part_num)
 Checks if the given Partition exists. More...
 

Variables

uint8_t mbr_primary_partition::status
 0x00 non-bootable, 0x80 bootable, other values indicate that it is invalid
 
uint8_t mbr_primary_partition::chs_first_sector [3]
 Saves the first sector of the partition in the old CHS format (cylinder, head, sector) More...
 
uint8_t mbr_primary_partition::type
 The type of partition this is, like FAT16 or FAT32; type = 0 means it's unused.
 
uint8_t mbr_primary_partition::chs_last_sector [3]
 Stores the last sector of the partition in the old CHS format.
 
uint32_t mbr_primary_partition::lba_first_sector
 Stores the absolute address of the first sector of the partition.
 
uint32_t mbr_primary_partition::lba_num_sectors
 Stores the number of sectors the partition is long.
 
struct mbr_primary_partition mbr::partition [4]
 The MBR supports max 4 Primary partitions. More...
 

Detailed Description

Function Documentation

int mbr_addPartition ( struct mbr mbr,
uint8_t  part_num,
uint8_t  part_type,
uint32_t  start,
uint32_t  len 
)

Adds a Partition to the mbr-structure.

Parameters
*mbrThe mbr-structure in which to insert the partition.
part_numNumber of the Partition which should be added.
part_typeType of the partition.
startLBA-style start of the partition.
lenLBA-style length of the partition.
Returns
MBR_SUCCESS on success or MBR_ERROR_PARTITION_EXISTS.

Definition at line 101 of file mbr.c.

References mbr_primary_partition::chs_first_sector, mbr_primary_partition::chs_last_sector, mbr_primary_partition::lba_first_sector, mbr_primary_partition::lba_num_sectors, mbr_hasPartition(), mbr::partition, mbr_primary_partition::status, and mbr_primary_partition::type.

int mbr_delPartition ( struct mbr mbr,
uint8_t  part_num 
)

Deletes a Partition from the mbr-structure.

Parameters
*mbrThe mbr-structure which should be edited.
part_numNumber of the partition which should be removed.
Returns
MBR_SUCCESS on success or MBR_ERROR_INVALID_PARTITION.

Definition at line 140 of file mbr.c.

References mbr::partition, and mbr_primary_partition::status.

int mbr_hasPartition ( struct mbr mbr,
uint8_t  part_num 
)

Checks if the given Partition exists.

Parameters
part_numNumber of the Partition which should be checked.
Returns
1 if there is a Partition with the given number, otherwise 0.

Definition at line 154 of file mbr.c.

References mbr::partition, mbr_primary_partition::status, and mbr_primary_partition::type.

Referenced by diskio_detect_devices(), and mbr_addPartition().

void mbr_init ( struct mbr mbr)

Initializes a mbr structure.

Should be called first on a new mbr structure.

Parameters
*mbrthe mbr which should be initialized
disk_sizethe size of the disk on which the mbr will reside

Definition at line 51 of file mbr.c.

References mbr::partition, and mbr_primary_partition::status.

Referenced by diskio_detect_devices().

int mbr_read ( struct diskio_device_info from,
struct mbr to 
)

Reads the MBR from the specified device.

The MBR is 512 Bytes long. That is normally one block to be read.

Parameters
*fromdevice from which the mbr is read
*towhe mbr structure in which the data is parsed
Returns
MBR_SUCCESS on success, MBR_ERROR_DISKIO_ERROR if there was a problem reading the block or MBR_ERROR_NO_MBR_FOUND when there is no MBR on this device.

Definition at line 62 of file mbr.c.

References diskio_read_block(), and mbr::partition.

Referenced by diskio_detect_devices().

int mbr_write ( struct mbr from,
struct diskio_device_info to 
)

Write the MBR to the specified device.

Parameters
*fromthe mbr structure which should be written on the device
*tothe device pointer to which we will write the mbr
Returns
MBR_SUCCESS on success, !0 on a diskio error which is returned, see diskio_write_block for more information

Definition at line 84 of file mbr.c.

References diskio_write_block(), and mbr::partition.

Variable Documentation

uint8_t mbr_primary_partition::chs_first_sector[3]

Saves the first sector of the partition in the old CHS format (cylinder, head, sector)

First byte stores the head value. Second byte stores the sector in the positions 0 - 5 and the upper to bits of the cylinder (Bits 8 and 9) Third byte stores the lower 8 bits of the cylinder value (0 - 7)

Definition at line 77 of file mbr.h.

Referenced by mbr_addPartition().

struct mbr_primary_partition mbr::partition[4]

The MBR supports max 4 Primary partitions.

For the sake of simplicity Extended partitions are not implemented.

Definition at line 95 of file mbr.h.

Referenced by diskio_detect_devices(), mbr_addPartition(), mbr_delPartition(), mbr_hasPartition(), mbr_init(), mbr_read(), and mbr_write().