This commit is contained in:
Wiesner András 2023-09-28 10:00:34 +02:00
commit ce607a0452
5 changed files with 53 additions and 0 deletions

9
CMakeLists.txt Normal file
View File

@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 3.22)
project(libembpart C)
set(CMAKE_C_STANDARD 11)
add_library(embpart embpart.c
mbr/mbr.c
mbr/mbr.h
../test/main.c)

7
embpart.c Normal file
View File

@ -0,0 +1,7 @@
#include "embpart.h"
#include <stdio.h>
void hello(void) {
printf("Hello, World!\n");
}

6
embpart.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef EMBPART_EMBPART_H
#define EMBPART_EMBPART_H
#include "mbr/mbr.h"
#endif //EMBPART_EMBPART_H

7
mbr/mbr.c Normal file
View File

@ -0,0 +1,7 @@
#include "mbr.h"
#define MBR_PART_TABLE_OFFSET (446)
const PartEntry *mbr_get_partitions(const uint8_t *mbr_sec) {
return (PartEntry *)(mbr_sec + MBR_PART_TABLE_OFFSET);
}

24
mbr/mbr.h Normal file
View File

@ -0,0 +1,24 @@
#ifndef EMBPART_MBR_H
#define EMBPART_MBR_H
#include <stdint.h>
// partition entry
typedef struct {
uint8_t status; // partition status
uint8_t chsa_fa[3]; // CHS address of first absolute sector in partition
uint8_t part_type; // partition type
uint8_t chsa_la[3]; // CHS address of last absolute sector in partition
uint32_t lba_fa; // LBA of first absolute sector
uint32_t sector_count; // number of sectors the partition includes
} PartEntry;
/**
* Get pointer to partition table
* @param mbr_sec pointer to the sector containing the MBR, MUST BE DWORD ALIGNED
* @return pointer to first partition entry
*/
const PartEntry * mbr_get_partitions(const uint8_t * mbr_sec);
#endif //EMBPART_MBR_H