Changeset dc76f4a in mainline for uspace/lib/mbr


Ignore:
Timestamp:
2013-07-29T00:48:51Z (12 years ago)
Author:
Dominik Taborsky (AT DOT) <brembyseznamcz>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
675de6d
Parents:
c3cbbb2
Message:

libmbr, libgpt polishing

Location:
uspace/lib/mbr
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/mbr/libmbr.c

    rc3cbbb2 rdc76f4a  
    4242#include <stdio.h>
    4343#include <stdlib.h>
     44#include <str_error.h>
    4445
    4546#include "libmbr.h"
     
    4950static int decode_logical(mbr_label_t *, mbr_part_t *);
    5051static void encode_part(mbr_part_t *, pt_entry_t *, uint32_t, bool);
    51 static int check_overlap(mbr_part_t *, mbr_part_t *);
    52 static int check_encaps(mbr_part_t *, mbr_part_t *);
    53 static int check_preceeds(mbr_part_t *, mbr_part_t *);
    54 static mbr_err_val mbr_add_primary(mbr_label_t *label, mbr_part_t *p);
    55 static mbr_err_val mbr_add_logical(mbr_label_t *label, mbr_part_t *p);
     52static bool check_overlap(mbr_part_t *, mbr_part_t *);
     53static bool check_encaps(mbr_part_t *, mbr_part_t *);
     54static bool check_preceeds(mbr_part_t *, mbr_part_t *);
     55static mbr_err_val mbr_add_primary(mbr_label_t *, mbr_part_t *);
     56static mbr_err_val mbr_add_logical(mbr_label_t *, mbr_part_t *);
    5657
    5758/** Allocate and initialize mbr_label_t structure */
     
    759760/** Check whether two partitions overlap
    760761 *
    761  * @return              1 for yes, 0 for no
    762  */
    763 static int check_overlap(mbr_part_t * p1, mbr_part_t * p2)
     762 * @return              true/false
     763 */
     764static bool check_overlap(mbr_part_t * p1, mbr_part_t * p2)
    764765{
    765766        if (p1->start_addr < p2->start_addr && p1->start_addr + p1->length <= p2->start_addr) {
    766                 return 0;
     767                return false;
    767768        } else if (p1->start_addr > p2->start_addr && p2->start_addr + p2->length <= p1->start_addr) {
    768                 return 0;
    769         }
    770 
    771         return 1;
     769                return false;
     770        }
     771
     772        return true;
    772773}
    773774
    774775/** Check whether one partition encapsulates the other
    775776 *
    776  * @return              1 for yes, 0 for no
    777  */
    778 static int check_encaps(mbr_part_t * inner, mbr_part_t * outer)
     777 * @return              true/false
     778 */
     779static bool check_encaps(mbr_part_t * inner, mbr_part_t * outer)
    779780{
    780781        if (inner->start_addr <= outer->start_addr || outer->start_addr + outer->length <= inner->start_addr) {
    781                 return 0;
     782                return false;
    782783        } else if (outer->start_addr + outer->length < inner->start_addr + inner->length) {
    783                 return 0;
    784         }
    785 
    786         return 1;
     784                return false;
     785        }
     786
     787        return true;
    787788}
    788789
    789790/** Check whether one partition preceeds the other
    790791 *
    791  * @return              1 for yes, 0 for no
    792  */
    793 static int check_preceeds(mbr_part_t * preceeder, mbr_part_t * precedee)
     792 * @return              true/false
     793 */
     794static bool check_preceeds(mbr_part_t * preceeder, mbr_part_t * precedee)
    794795{
    795796        return preceeder->start_addr < precedee->start_addr;
  • uspace/lib/mbr/libmbr.h

    rc3cbbb2 rdc76f4a  
    3838
    3939#include <sys/types.h>
     40#include "mbr.h"
    4041
    4142#define LIBMBR_NAME     "libmbr"
    42 
    43 #ifdef DEBUG_CONFIG
    44 #include <stdio.h>
    45 #include <str_error.h>
    46 #define DEBUG_PRINT_0(str) \
    47         printf("%s:%d: " str, __FILE__, __LINE__)
    48 #define DEBUG_PRINT_1(str, arg1) \
    49         printf("%s:%d: " str, __FILE__, __LINE__, arg1)
    50 #define DEBUG_PRINT_2(str, arg1, arg2) \
    51         printf("%s:%d: " str, __FILE__, __LINE__, arg1, arg2)
    52 #define DEBUG_PRINT_3(str, arg1, arg2, arg3) \
    53         printf("%s:%d: " str, __FILE__, __LINE__, arg1, arg2, arg3)
    54 #else
    55 #define DEBUG_PRINT_0(str)
    56 #define DEBUG_PRINT_1(str, arg1)
    57 #define DEBUG_PRINT_2(str, arg1, arg2)
    58 #define DEBUG_PRINT_3(str, arg1, arg2, arg3)
    59 #endif
    60 
    61 /** Number of primary partition records */
    62 #define N_PRIMARY               4
    63 
    64 /** Boot record signature */
    65 #define BR_SIGNATURE    0xAA55
    66 
    67 enum {
    68         /** Non-bootable */
    69         B_INACTIVE = 0x00,
    70         /** Bootable */
    71         B_ACTIVE = 0x80,
    72         /** Anything else means invalid */
    73 };
    7443
    7544typedef enum {
     
    8049        ST_LOGIC = 8
    8150} MBR_FLAGS;
    82 
    83 enum {
    84         /** Unused partition entry */
    85         PT_UNUSED       = 0x00,
    86         /** Extended partition */
    87         PT_EXTENDED     = 0x05,
    88         /** Extended partition with LBA */
    89         PT_EXTENDED_LBA = 0x0F,
    90         /** GPT Protective partition */
    91         PT_GPT  = 0xEE,
    92 };
    9351
    9452typedef enum {
     
    11270        ERR_LIBBLOCK,
    11371} mbr_err_val;
    114 
    115 
    116 /** Structure of a partition table entry */
    117 typedef struct {
    118         uint8_t status;
    119         /** CHS of fist block in partition */
    120         uint8_t first_chs[3];
    121         /** Partition type */
    122         uint8_t ptype;
    123         /** CHS of last block in partition */
    124         uint8_t last_chs[3];
    125         /** LBA of first block in partition */
    126         uint32_t first_lba;
    127         /** Number of blocks in partition */
    128         uint32_t length;
    129 } __attribute__((packed)) pt_entry_t;
    130 
    131 /** Structure of a boot-record block */
    132 typedef struct {
    133         /** Area for boot code */
    134         uint8_t code_area[440];
    135         /** Optional media ID */
    136         uint32_t media_id;
    137         /** Padding */
    138         uint16_t pad0;
    139         /** Partition table entries */
    140         pt_entry_t pte[N_PRIMARY];
    141         /** Boot record block signature (@c BR_SIGNATURE) */
    142         uint16_t signature;
    143 } __attribute__((packed)) br_block_t;
    14472
    14573/** MBR header */
Note: See TracChangeset for help on using the changeset viewer.