Changeset 8c95dff in mainline for uspace/lib


Ignore:
Timestamp:
2013-11-30T17:49:09Z (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:
f4a47e52
Parents:
802898f
Message:

various bugfixes

Location:
uspace/lib
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/gpt/Makefile

    r802898f r8c95dff  
    2828
    2929USPACE_PREFIX = ../..
    30 EXTRA_CFLAGS = -I$(LIBBLOCK_PREFIX)
     30EXTRA_CFLAGS = -I$(LIBBLOCK_PREFIX) -I$(LIBMBR_PREFIX)
    3131LIBRARY = libgpt
    3232
  • uspace/lib/gpt/global.c

    r802898f r8c95dff  
    4040};
    4141
     42const uint8_t revision[4] = {
     43        00, 00, 01, 00
     44};
     45
    4246const struct partition_type gpt_ptypes[] = {
    4347        { "Unused entry",                                       "00000000" "0000" "0000" "0000000000000000" }, /* 0 */
     
    5559        { "HP-UX Data",                                         "75894C1E" "3AEB" "11D3" "B7C17B03A0000000" },
    5660        { "HP-UX Service",                                      "E2A1E728" "32E3" "11D6" "A6827B03A0000000" },
    57         { "Linux filesystem data",                      "EBD0A0A2" "B9E5" "4433" "87C068B6B72699C7" },
    5861        { "Linux filesystem data",                      "0FC63DAF" "8483" "4772" "8E793D69D8477DE4" },
    5962        { "Linux RAID",                                         "A19D880F" "05FC" "4D3B" "A006743F0F84911E" },
    6063        { "Linux Swap",                                         "0657FD6D" "A4AB" "43C4" "84E50933C84B4F4F" },
    6164        { "Linux LVM",                                          "E6D6D379" "F507" "44C2" "A23C238F2A3DF928" },
     65        { "Linux filesystem data",                      "933AC7E1" "2EB4" "4F13" "B8440E14E2AEF915" },
    6266        { "Linux Reserved",                                     "8DA63339" "0007" "60C0" "C436083AC8230908" },
    6367        { "FreeBSD Boot",                                       "83BD6B9D" "7F41" "11DC" "BE0B001560B84F0F" }, /* 20 */
  • uspace/lib/gpt/gpt.h

    r802898f r8c95dff  
    5050typedef struct {
    5151        uint8_t  efi_signature[8];
    52         uint32_t revision;
     52        uint8_t  revision[4];
    5353        uint32_t header_size;
    5454        uint32_t header_crc32;
  • uspace/lib/gpt/libgpt.c

    r802898f r8c95dff  
    4949#include <mem.h>
    5050#include <sys/typefmt.h>
     51#include <mbr.h>
    5152
    5253
     
    112113        }
    113114       
     115        /* Enter some sane defaults. */
    114116        memset(gpt->header, 0, final_size);
     117        memcpy(gpt->header->efi_signature, efi_signature, 8);
     118        memcpy(gpt->header->revision, revision, 4);
     119        gpt->header->header_size = host2uint32_t_le(final_size);
     120        gpt->header->entry_lba = host2uint64_t_le((uint64_t) 2);
     121        gpt->header->entry_size = host2uint32_t_le(sizeof(gpt_entry_t));
     122       
    115123       
    116124        return gpt;
     
    207215        uint64_t tmp;
    208216       
     217        gpt_set_random_uuid(label->gpt->header->disk_guid);
     218       
    209219        /* Prepare the backup header */
    210220        label->gpt->header->alternate_lba = label->gpt->header->my_lba;
     
    243253        /* Write to main GPT header location */
    244254        rc = block_write_direct(dev_handle, GPT_HDR_BA, GPT_HDR_BS, label->gpt->header);
     255        if (rc != EOK)
     256                return rc;
     257       
     258        /* Write Protective MBR */
     259        br_block_t mbr;
     260        memset(&mbr, 0, 512);
     261        memset(mbr.pte[0].first_chs, 1, 3);
     262        mbr.pte[0].ptype = 0xEE;
     263        memset(mbr.pte[0].last_chs, 0xFF, 3);
     264        mbr.pte[0].first_lba = host2uint32_t_le(1);
     265        mbr.pte[0].length = 0xFFFFFFFF;
     266        mbr.signature = host2uint16_t_le(BR_SIGNATURE);
     267       
     268        rc = block_write_direct(dev_handle, 0, 1, &mbr);
    245269        block_fini(dev_handle);
    246270        if (rc != EOK)
    247271                return rc;
    248        
    249272       
    250273        return 0;
     
    343366        int rc;
    344367        size_t b_size;
    345         uint32_t e_size = uint32_t_le2host(label->gpt->header->entry_size);
    346         size_t fillries = label->parts->fill > GPT_MIN_PART_NUM ? label->parts->fill : GPT_MIN_PART_NUM;
    347        
    348         if (e_size != sizeof(gpt_entry_t))
    349                 return ENOTSUP;
    350368       
    351369        /* comm_size of 4096 is ignored */
     
    363381                goto fail;
    364382       
     383        /* When we're creating a new label from scratch, we need to fill
     384         * the header with sensible defaults. */
     385        if (label->gpt == NULL) {
     386                label->gpt = gpt_alloc_header(b_size);
     387        }
     388       
     389        printf("test1.0\n");
     390        uint32_t e_size = uint32_t_le2host(label->gpt->header->entry_size);
     391        printf("test1.025\n");
     392        size_t fillries = label->parts->fill > GPT_MIN_PART_NUM ? label->parts->fill : GPT_MIN_PART_NUM;
     393        printf("test1.05\n");
     394        if (e_size != sizeof(gpt_entry_t))
     395                return ENOTSUP;
     396
    365397        label->gpt->header->fillries = host2uint32_t_le(fillries);
    366398        uint64_t arr_blocks = (fillries * sizeof(gpt_entry_t)) / b_size;
     
    368400        label->gpt->header->first_usable_lba = host2uint64_t_le(gpt_space);
    369401        label->gpt->header->last_usable_lba = host2uint64_t_le(n_blocks - gpt_space - 1);
    370        
     402        printf("test1.5\n");
    371403        /* Perform checks */
    372404        gpt_part_foreach (label, p) {
     
    395427                }
    396428        }
    397        
     429        printf("test1.6\n");
    398430        label->gpt->header->pe_array_crc32 = host2uint32_t_le(compute_crc32(
    399431                                       (uint8_t *) label->parts->part_array,
    400432                                       fillries * e_size));
    401433       
    402        
     434        printf("test1.7\n");
    403435        /* Write to backup GPT partition array location */
    404436        rc = block_write_direct(dev_handle, n_blocks - arr_blocks - 1,
     
    406438        if (rc != EOK)
    407439                goto fail;
    408        
     440        printf("test1.8\n");
    409441        /* Write to main GPT partition array location */
    410442        rc = block_write_direct(dev_handle, uint64_t_le2host(label->gpt->header->entry_lba),
     
    412444        if (rc != EOK)
    413445                goto fail;
    414        
     446        printf("test1.9\n");
    415447        return gpt_write_header(label, dev_handle);
    416448       
     
    594626       
    595627        for (i = 0; gpt_ptypes[i].guid != NULL; i++) {
     628                //printf("%x =?= %x\n", p->part_type[3], get_byte(gpt_ptypes[i].guid +0));
     629                //printf("%x =?= %x\n", p->part_type[2], get_byte(gpt_ptypes[i].guid +2));
     630                //printf("%x =?= %x\n", p->part_type[1], get_byte(gpt_ptypes[i].guid +4));
     631                //printf("%x =?= %x\n", p->part_type[0], get_byte(gpt_ptypes[i].guid +6));
     632                //getchar();
    596633                if (p->part_type[3] == get_byte(gpt_ptypes[i].guid +0) &&
    597634                        p->part_type[2] == get_byte(gpt_ptypes[i].guid +2) &&
     
    627664{
    628665        /* Beware: first 3 blocks are byteswapped! */
    629         p->part_type[3] = gpt_ptypes[type].guid[0];
    630         p->part_type[2] = gpt_ptypes[type].guid[1];
    631         p->part_type[1] = gpt_ptypes[type].guid[2];
    632         p->part_type[0] = gpt_ptypes[type].guid[3];
    633 
    634         p->part_type[5] = gpt_ptypes[type].guid[4];
    635         p->part_type[4] = gpt_ptypes[type].guid[5];
    636 
    637         p->part_type[7] = gpt_ptypes[type].guid[6];
    638         p->part_type[6] = gpt_ptypes[type].guid[7];
    639 
    640         p->part_type[8] = gpt_ptypes[type].guid[8];
    641         p->part_type[9] = gpt_ptypes[type].guid[9];
    642         p->part_type[10] = gpt_ptypes[type].guid[10];
    643         p->part_type[11] = gpt_ptypes[type].guid[11];
    644         p->part_type[12] = gpt_ptypes[type].guid[12];
    645         p->part_type[13] = gpt_ptypes[type].guid[13];
    646         p->part_type[14] = gpt_ptypes[type].guid[14];
    647         p->part_type[15] = gpt_ptypes[type].guid[15];
     666        p->part_type[3] = get_byte(gpt_ptypes[type].guid +0);
     667        p->part_type[2] = get_byte(gpt_ptypes[type].guid +2);
     668        p->part_type[1] = get_byte(gpt_ptypes[type].guid +4);
     669        p->part_type[0] = get_byte(gpt_ptypes[type].guid +6);
     670                       
     671        p->part_type[5] = get_byte(gpt_ptypes[type].guid +8);
     672        p->part_type[4] = get_byte(gpt_ptypes[type].guid +10);
     673                       
     674        p->part_type[7] = get_byte(gpt_ptypes[type].guid +12);
     675        p->part_type[6] = get_byte(gpt_ptypes[type].guid +14);
     676                       
     677        p->part_type[8] = get_byte(gpt_ptypes[type].guid +16);
     678        p->part_type[9] = get_byte(gpt_ptypes[type].guid +18);
     679        p->part_type[10] = get_byte(gpt_ptypes[type].guid +20);
     680        p->part_type[11] = get_byte(gpt_ptypes[type].guid +22);
     681        p->part_type[12] = get_byte(gpt_ptypes[type].guid +24);
     682        p->part_type[13] = get_byte(gpt_ptypes[type].guid +26);
     683        p->part_type[14] = get_byte(gpt_ptypes[type].guid +28);
     684        p->part_type[15] = get_byte(gpt_ptypes[type].guid +30);
    648685}
    649686
  • uspace/lib/gpt/libgpt.h

    r802898f r8c95dff  
    6060/** GPT header signature ("EFI PART" in ASCII) */
    6161extern const uint8_t efi_signature[8];
     62extern const uint8_t revision[4];
    6263
    6364typedef struct {
  • uspace/lib/mbr/libmbr.c

    r802898f r8c95dff  
    7070}
    7171
     72void mbr_set_device(mbr_label_t *label, service_id_t dev_handle)
     73{
     74        label->device = dev_handle;
     75}
     76
    7277/** Free mbr_label_t structure */
    7378void mbr_free_label(mbr_label_t *label)
     
    253258        }
    254259       
     260        label->mbr->raw_data.signature = host2uint16_t_le(BR_SIGNATURE);
     261       
    255262        /* Writing MBR */
    256263        rc = block_write_direct(dev_handle, 0, 1, &(label->mbr->raw_data));
     
    271278         * and implementation. If you don't have to change it, don't. Other
    272279         * designs have been tried, this came out as the least horror with
    273          * as much power over it as you can get. Thanks. */
     280         * as much power over it as you can get. */
    274281       
    275282        /* Encoding and writing first logical partition */
  • uspace/lib/mbr/libmbr.h

    r802898f r8c95dff  
    120120/* Alloc complete label structure */
    121121extern mbr_label_t * mbr_alloc_label(void);
     122extern void mbr_set_device(mbr_label_t *, service_id_t);
    122123
    123124/* Read/Write MBR header.
Note: See TracChangeset for help on using the changeset viewer.