Changeset 30440ed in mainline for uspace/app/hdisk/func_gpt.c


Ignore:
Timestamp:
2013-04-08T23:15:42Z (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:
256cbfe
Parents:
271e24a
Message:

save progress

File:
1 edited

Legend:

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

    r271e24a r30440ed  
    3535#include <stdio.h>
    3636#include <errno.h>
     37#include <str_error.h>
    3738#include <sys/types.h>
    3839
    3940#include "func_gpt.h"
     41#include "input.h"
     42
     43static int set_gpt_partition(tinput_t *, gpt_part_t *);
    4044
    4145int add_gpt_part(tinput_t * in, union table_data * data)
    4246{
    43         int rc = EOK;
     47        gpt_part_t * p = gpt_alloc_partition(data->gpt.parts);
     48        if (p == NULL) {
     49                return ENOMEM;
     50        }
    4451       
    45         return rc;
     52        return set_gpt_partition(in, p);
    4653}
    4754
    4855int delete_gpt_part(tinput_t * in, union table_data * data)
    4956{
    50         int rc = EOK;
     57        size_t idx;
     58
     59        printf("Number of the partition to delete (counted from 0): ");
     60        idx = get_input_size_t(in);
    5161       
    52         return rc;
     62        if (gpt_remove_partition(data->gpt.parts, idx) == -1) {
     63                printf("Warning: running low on memory, not resizing...\n");
     64        }
     65       
     66        return EOK;
    5367}
    5468
    5569int print_gpt_parts(union table_data * data)
    5670{
    57         int rc = EOK;
     71        printf("Current partition scheme (GPT):\n");
     72        printf("\t\tStart:\tEnd:\tLength:\tType:\tName:\n");
     73       
     74        gpt_foreach(data->gpt.parts, i, iter) {
     75                printf("\t%10u %10u %10u %3d\n", iter->start_addr, iter->start_addr + iter->length,
     76                                iter->length, gpt_get_part_type(iter), gpt_get_part_name(iter));
     77        }
    5878       
    5979        return rc;
     
    6282int write_gpt_parts(service_id_t dev_handle, union table_data * data)
    6383{
    64         int rc = EOK;
     84        int rc;
    6585       
    66         return rc;
     86        rc = gpt_write_partitions(data->gpt.parts, data->gpt.gpt, dev_handle);
     87        if (rc != EOK) {
     88                printf("Error: Writing partitions failed: %d (%s)\n", rc, str_error(rc));
     89                return rc;
     90        }
     91       
     92        rc = gpt_write_gpt_header(data->gpt.gpt, dev_handle);
     93        if (rc != EOK) {
     94                printf("Error: Writing partitions failed: %d (%s)\n", rc, str_error(rc));
     95                return rc;
     96        }
     97       
     98        return EOK;
    6799}
    68100
     101int extra_gpt_funcs(tinput_t * in, service_id_t dev_handle, union table_data * data)
     102{
     103        return EOK;
     104}
     105
     106static int set_gpt_partition(tinput_t * in, gpt_part_t * p)
     107{
     108        int rc;
     109       
     110        uint64_t sa, ea;
     111       
     112        printf("Set starting address (number): ");
     113        sa = get_input_uint64(in);
     114
     115        printf("Set end addres (number): ");
     116        ea = get_input_uint64(in);
     117       
     118        if (ea <= sa) {
     119                printf("Invalid value.\n");
     120                return EINVAL;
     121        }
     122       
     123       
     124        p->start_addr = sa;
     125        p->length = ea - sa;
     126       
     127        return EOK;
     128}
     129
Note: See TracChangeset for help on using the changeset viewer.