Changeset 1c8bfe8 in mainline for uspace/app/hdisk/func_gpt.c


Ignore:
Timestamp:
2013-06-25T00:27:47Z (11 years ago)
Author:
Dominik Taborsky (AT DOT) <brembyseznamcz>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6317b33, 9256d093
Parents:
6e8e4e19 (diff), cb328ab (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

GPT updates

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/hdisk/func_gpt.c

    r6e8e4e19 r1c8bfe8  
    3434
    3535#include <stdio.h>
     36#include <str.h>
    3637#include <errno.h>
    3738#include <str_error.h>
     
    6061}
    6162
    62 int add_gpt_part(label_t *this, tinput_t * in)
    63 {
    64         gpt_part_t * p = gpt_alloc_partition(this->data.gpt->parts);
     63int add_gpt_part(label_t *this, tinput_t *in)
     64{
     65        gpt_part_t * p = gpt_get_partition(this->data.gpt);
    6566        if (p == NULL) {
    6667                return ENOMEM;
    6768        }
    68 
     69       
    6970        return set_gpt_partition(in, p);
    7071}
    7172
    72 int delete_gpt_part(label_t *this, tinput_t * in)
    73 {
     73int delete_gpt_part(label_t *this, tinput_t *in)
     74{
     75        int rc;
    7476        size_t idx;
    75 
     77       
    7678        printf("Number of the partition to delete (counted from 0): ");
    7779        idx = get_input_size_t(in);
    78 
    79         if (gpt_remove_partition(this->data.gpt->parts, idx) == -1) {
     80       
     81        rc = gpt_remove_partition(this->data.gpt, idx);
     82        if (rc != EOK) {
    8083                printf("Warning: running low on memory, not resizing...\n");
    81         }
    82 
     84                return rc;
     85        }
     86       
    8387        return EOK;
    8488}
     
    8690int destroy_gpt_label(label_t *this)
    8791{
     92        gpt_free_label(this->data.gpt);
    8893        return EOK;
    8994}
     
    9196int new_gpt_label(label_t *this)
    9297{
    93         this->data.gpt->gpt = gpt_alloc_gpt_header();
    94         this->data.gpt->parts = gpt_alloc_partitions();
     98        this->data.gpt = gpt_alloc_label();
    9599        return EOK;
    96100}
     
    104108        size_t i = 0;
    105109       
    106         gpt_part_foreach(this->data.gpt->parts, iter) {
     110        gpt_part_foreach(this->data.gpt, iter) {
     111                i++;
    107112                //FIXMEE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    108                 if (gpt_get_part_type(iter) == 62)
     113                if (gpt_get_part_type(iter) == GPT_PTE_UNUSED)
    109114                        continue;
     115               
     116                if (i % 20 == 0)
     117                        printf("%15s %10s %10s Type: Name:\n", "Start:", "End:", "Length:");
    110118               
    111119                //printf("\t%10u %10u %10u %3d\n", iter->start_addr, iter->start_addr + iter->length,
    112120                //              iter->length, gpt_get_part_type(iter), gpt_get_part_name(iter));
    113                 printf("%3u\t%10llu %10llu %10llu %3d %s\n", i, gpt_get_start_lba(iter), gpt_get_end_lba(iter),
     121                printf("%3u  %10llu %10llu %10llu    %3d %s\n", i-1, gpt_get_start_lba(iter), gpt_get_end_lba(iter),
    114122                                gpt_get_end_lba(iter) - gpt_get_start_lba(iter), gpt_get_part_type(iter),
    115123                                gpt_get_part_name(iter));
    116                 i++;
    117         }
    118 
     124        }
     125       
    119126        //return rc;
    120127        return EOK;
     
    123130int read_gpt_parts(label_t *this, service_id_t dev_handle)
    124131{
     132        int rc;
     133       
     134        rc = gpt_read_header(this->data.gpt, dev_handle);
     135        if (rc != EOK) {
     136                printf("Error: Reading header failed: %d (%s)\n", rc, str_error(rc));
     137                return rc;
     138        }
     139       
     140        rc = gpt_read_partitions(this->data.gpt);
     141        if (rc != EOK) {
     142                printf("Error: Reading partitions failed: %d (%s)\n", rc, str_error(rc));
     143                return rc;
     144        }
     145       
    125146        return EOK;
    126147}
     
    129150{
    130151        int rc;
    131 
    132         rc = gpt_write_partitions(this->data.gpt->parts, this->data.gpt->gpt, dev_handle);
     152       
     153        rc = gpt_write_partitions(this->data.gpt, dev_handle);
    133154        if (rc != EOK) {
    134155                printf("Error: Writing partitions failed: %d (%s)\n", rc, str_error(rc));
    135156                return rc;
    136157        }
    137 
    138         rc = gpt_write_gpt_header(this->data.gpt->gpt, dev_handle);
    139         if (rc != EOK) {
    140                 printf("Error: Writing partitions failed: %d (%s)\n", rc, str_error(rc));
    141                 return rc;
    142         }
    143 
    144         return EOK;
    145 }
    146 
    147 int extra_gpt_funcs(label_t *this, tinput_t * in, service_id_t dev_handle)
     158       
     159        rc = gpt_write_header(this->data.gpt, dev_handle);
     160        if (rc != EOK) {
     161                printf("Error: Writing header failed: %d (%s)\n", rc, str_error(rc));
     162                return rc;
     163        }
     164       
     165        return EOK;
     166}
     167
     168int extra_gpt_funcs(label_t *this, tinput_t *in, service_id_t dev_handle)
    148169{
    149170        printf("Not implemented.\n");
     
    151172}
    152173
    153 static int set_gpt_partition(tinput_t * in, gpt_part_t * p)
    154 {
    155         //int rc;
    156 
     174static int set_gpt_partition(tinput_t *in, gpt_part_t *p)
     175{
     176        int rc;
     177       
    157178        uint64_t sa, ea;
    158 
     179       
    159180        printf("Set starting address (number): ");
    160181        sa = get_input_uint64(in);
    161 
     182       
    162183        printf("Set end addres (number): ");
    163184        ea = get_input_uint64(in);
    164 
     185       
    165186        if (ea <= sa) {
    166187                printf("Invalid value.\n");
    167188                return EINVAL;
    168189        }
    169 
    170 
    171         //p->start_addr = sa;
     190       
    172191        gpt_set_start_lba(p, sa);
    173         //p->length = ea - sa;
    174192        gpt_set_end_lba(p, ea);
    175 
    176         return EOK;
    177 }
    178 
     193       
     194       
     195        char *name;
     196        rc = get_input_line(in, &name);
     197        if (rc != EOK) {
     198                printf("Error reading name: %d (%s)\n", rc, str_error(rc));
     199                return rc;
     200        }
     201       
     202        gpt_set_part_name(p, name, str_size(name));
     203       
     204        return EOK;
     205}
     206
Note: See TracChangeset for help on using the changeset viewer.