Changeset 271e24a in mainline for uspace/lib/mbr/libmbr.c


Ignore:
Timestamp:
2013-03-24T00:12:25Z (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:
30440ed
Parents:
ec50ac4a
Message:

hdisk - testing libmbr

File:
1 edited

Legend:

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

    rec50ac4a r271e24a  
    1212 *   notice, this list of conditions and the following disclaimer in the
    1313 *   documentation and/or other materials provided with the distribution.
    14  * - The name of the author may not be used to endorse or promote products
     14 * - The LIBMBR_NAME of the author may not be used to endorse or promote products
    1515 *   derived from this software without specific prior written permission.
    1616 *
     
    4545
    4646static br_block_t * alloc_br(void);
    47 static int decode_part(pt_entry_t * src, part_t * trgt, uint32_t base);
    48 static int decode_logical(mbr_t * mbr, mbr_parts_t * p, part_t * ext);
    49 static void encode_part(part_t * src, pt_entry_t * trgt, uint32_t base);
     47static int decode_part(pt_entry_t * src, mbr_part_t * trgt, uint32_t base);
     48static int decode_logical(mbr_t * mbr, mbr_partitions_t * p, mbr_part_t * ext);
     49static void encode_part(mbr_part_t * src, pt_entry_t * trgt, uint32_t base);
    5050
    5151/** Read MBR from specific device
     
    123123 * @return              linked list of partitions or NULL on error
    124124 */
    125 mbr_parts_t * mbr_read_partitions(mbr_t * mbr)
     125mbr_partitions_t * mbr_read_partitions(mbr_t * mbr)
    126126{
    127127        int rc, i;
    128         part_t * p;
    129         part_t * ext = NULL;
    130         mbr_parts_t * parts;
     128        mbr_part_t * p;
     129        mbr_part_t * ext = NULL;
     130        mbr_partitions_t * parts;
    131131
    132132        if (mbr == NULL)
     
    143143                        continue;
    144144               
    145                 p = malloc(sizeof(part_t));
     145                p = malloc(sizeof(mbr_part_t));
    146146                if (p == NULL) {
    147                         printf(NAME ": Error on memory allocation.\n");
     147                        printf(LIBMBR_NAME ": Error on memory allocation.\n");
    148148                        free(p);
    149149                        mbr_free_partitions(parts);
     
    159159        rc = decode_logical(mbr, parts, ext);
    160160        if (rc != EOK) {
    161                 printf(NAME ": Error occured during decoding the MBR.\n" \
    162                            NAME ": Partition list may be incomplete.\n");
     161                printf(LIBMBR_NAME ": Error occured during decoding the MBR.\n" \
     162                           LIBMBR_NAME ": Partition list may be incomplete.\n");
    163163        }
    164164
     
    173173 * @return                              returns EOK on succes, specific error code otherwise
    174174 */
    175 int mbr_write_partitions(mbr_parts_t * parts, mbr_t * mbr, service_id_t dev_handle)
     175int mbr_write_partitions(mbr_partitions_t * parts, mbr_t * mbr, service_id_t dev_handle)
    176176{
    177177        bool logical = false;
    178178        int i = 0;
    179179        int rc;
    180         part_t * p;
    181         part_t * ext = (parts->l_extended == NULL) ? NULL
    182                                         : list_get_instance(parts->l_extended, part_t, link);
     180        mbr_part_t * p;
     181        mbr_part_t * ext = (parts->l_extended == NULL) ? NULL
     182                                        : list_get_instance(parts->l_extended, mbr_part_t, link);
    183183       
    184184        br_block_t * last_ebr = NULL;
     
    194194
    195195        aoff64_t addr = ext->start_addr;
    196         part_t * prev_part = NULL;
     196        mbr_part_t * prev_part = NULL;
    197197
    198198        list_foreach(parts->list, it) {
    199                 p = list_get_instance(it, part_t, link);
     199                p = list_get_instance(it, mbr_part_t, link);
    200200                if (mbr_get_flag(p, ST_LOGIC)) {
    201201                        // writing logical partition
     
    269269
    270270        list_foreach(parts->list, it) {
    271                 p = list_get_instance(it, part_t, link);
     271                p = list_get_instance(it, mbr_part_t, link);
    272272                if (mbr_get_flag(p, ST_LOGIC)) {
    273273                        // extended does not exist, fail
     
    295295                        ext = p;
    296296
    297                 //p = list_get_instance(p->link.next, mbr_parts_t, link);
     297                //p = list_get_instance(p->link.next, mbr_partitions_t, link);
    298298                p = p->next;
    299299        }
     
    357357}
    358358
    359 /** part_t constructor */
    360 part_t * mbr_alloc_partition(void)
    361 {
    362         part_t * p = malloc(sizeof(part_t));
     359/** mbr_part_t constructor */
     360mbr_part_t * mbr_alloc_partition(void)
     361{
     362        mbr_part_t * p = malloc(sizeof(mbr_part_t));
    363363        if (p == NULL) {
    364364                return NULL;
     
    374374}
    375375
    376 mbr_parts_t * mbr_alloc_partitions(void)
    377 {
    378         mbr_parts_t * parts = malloc(sizeof(mbr_parts_t));
     376mbr_partitions_t * mbr_alloc_partitions(void)
     377{
     378        mbr_partitions_t * parts = malloc(sizeof(mbr_partitions_t));
    379379        if (parts == NULL) {
    380380                return NULL;
     
    387387
    388388/** Add partition */
    389 void mbr_add_partition(mbr_parts_t * parts, part_t * partition)
     389int mbr_add_partition(mbr_partitions_t * parts, mbr_part_t * partition)
    390390{
    391391        list_append(&(partition->link), &(parts->list));
     392        return EOK;
    392393}
    393394
    394395/** Remove partition */
    395 void mbr_remove_partition(mbr_parts_t * parts, int idx)
     396int mbr_remove_partition(mbr_partitions_t * parts, size_t idx)
    396397{
    397398        link_t * l = list_nth(&(parts->list), idx);
    398399        list_remove(l);
    399         part_t * p = list_get_instance(l, part_t, link);
     400        mbr_part_t * p = list_get_instance(l, mbr_part_t, link);
    400401        mbr_free_partition(p);
    401 }
    402 
    403 /** part_t destructor */
    404 void mbr_free_partition(part_t * p)
     402       
     403        return EOK;
     404}
     405
     406/** mbr_part_t destructor */
     407void mbr_free_partition(mbr_part_t * p)
    405408{
    406409        if (p->ebr != NULL)
     
    410413
    411414/** Get flag bool value */
    412 int mbr_get_flag(part_t * p, MBR_FLAGS flag)
     415int mbr_get_flag(mbr_part_t * p, MBR_FLAGS flag)
    413416{
    414417        return (p->status & (1 << flag)) ? 1 : 0;
     
    416419
    417420/** Set a specifig status flag to a value */
    418 void mbr_set_flag(part_t * p, MBR_FLAGS flag, bool value)
     421void mbr_set_flag(mbr_part_t * p, MBR_FLAGS flag, bool value)
    419422{
    420423        uint8_t status = p->status;
     
    438441 * @param parts         partition list to be freed
    439442 */
    440 void mbr_free_partitions(mbr_parts_t * parts)
     443void mbr_free_partitions(mbr_partitions_t * parts)
    441444{
    442445        list_foreach_safe(parts->list, cur_link, next) {
    443                 part_t * p = list_get_instance(cur_link, part_t, link);
     446                mbr_part_t * p = list_get_instance(cur_link, mbr_part_t, link);
    444447                list_remove(cur_link);
    445448                mbr_free_partition(p);
     
    462465}
    463466
    464 /** Parse partition entry to part_t */
    465 static int decode_part(pt_entry_t * src, part_t * trgt, uint32_t base)
     467/** Parse partition entry to mbr_part_t */
     468static int decode_part(pt_entry_t * src, mbr_part_t * trgt, uint32_t base)
    466469{
    467470        trgt->type = src->ptype;
     
    477480}
    478481
    479 /** Parse MBR contents to part_t list
     482/** Parse MBR contents to mbr_part_t list
    480483 * parameter 'p' is allocated for only used primary partitions
    481484 */
    482 static int decode_logical(mbr_t * mbr, mbr_parts_t * parts, part_t * ext)
     485static int decode_logical(mbr_t * mbr, mbr_partitions_t * parts, mbr_part_t * ext)
    483486{
    484487        int rc;
    485         part_t * p;
     488        mbr_part_t * p;
    486489
    487490        if (mbr == NULL || parts == NULL)
     
    534537}
    535538
    536 /** Convert part_t to pt_entry_t */
    537 static void encode_part(part_t * src, pt_entry_t * trgt, uint32_t base)
     539/** Convert mbr_part_t to pt_entry_t */
     540static void encode_part(mbr_part_t * src, pt_entry_t * trgt, uint32_t base)
    538541{
    539542        if (src != NULL) {
Note: See TracChangeset for help on using the changeset viewer.