Changeset 6453e306 in mainline for uspace/app/hdisk/hdisk.c


Ignore:
Timestamp:
2013-12-25T16:09:43Z (10 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ac36aed
Parents:
d51beba3
Message:

basic code review and coding style cleanup

File:
1 edited

Legend:

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

    rd51beba3 r6453e306  
    11/*
    2  * Copyright (c) 2012, 2013 Dominik Taborsky
     2 * Copyright (c) 2012-2013 Dominik Taborsky
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29  /** @addtogroup hdisk
     29/** @addtogroup hdisk
    3030 * @{
    3131 */
     
    4747#include <tinput.h>
    4848#include <str_error.h>
    49 
    5049#include "hdisk.h"
    5150#include "input.h"
     
    5453#include "func_none.h"
    5554
    56 int interact(void);
    57 void print_help(void);
    58 void select_label_format(tinput_t *);
    59 void construct_label(layouts_t);
    60 void free_label(void);
    61 int try_read(void);
    62 int try_read_mbr(void);
    63 int try_read_gpt(void);
    64 void set_alignment(tinput_t *);
    65 
     55static int interact(void);
     56static void print_help(void);
     57static void select_label_format(tinput_t *);
     58static void construct_label(layouts_t);
     59static void free_label(void);
     60static int try_read(void);
     61static int try_read_mbr(void);
     62static int try_read_gpt(void);
     63static void set_alignment(tinput_t *);
    6664
    6765static label_t label;
    6866
    69 int main(int argc, char ** argv)
     67int main(int argc, char *argv[])
    7068{
    7169        if (argc == 1) {
    7270                printf("Missing argument. Please specify a device to operate on.\n");
    73                 return -1;
    74         }
    75        
    76         int rc;
     71                return 1;
     72        }
     73       
    7774        service_id_t dev_handle;
    78        
    79         rc = loc_service_get_id(argv[1], &dev_handle, IPC_FLAG_BLOCKING);
     75        int rc = loc_service_get_id(argv[1], &dev_handle, IPC_FLAG_BLOCKING);
    8076        if (rc != EOK) {
    8177                printf("Unknown device. Exiting.\n");
    82                 return -1;
     78                return 2;
    8379        }
    8480       
     
    8985        if (rc != EOK) {
    9086                printf("Error during libblock init: %d - %s.\n", rc, str_error(rc));
    91                 return -1;
    92         }
    93        
    94         aoff64_t nblocks;
    95         rc = block_get_nblocks(dev_handle, &nblocks);
     87                return 3;
     88        }
     89       
     90        aoff64_t blocks;
     91        rc = block_get_nblocks(dev_handle, &blocks);
    9692        block_fini(dev_handle);
    9793        if (rc != EOK) {
    98                 printf(LIBMBR_NAME ": Error while getting number of blocks: %d - %s.\n", rc, str_error(rc));
    99                 return -1;
    100         }
    101        
    102         label.nblocks = nblocks;
     94                printf("Error while getting number of blocks: %d - %s.\n",
     95                    rc, str_error(rc));
     96                return 4;
     97        }
     98       
     99        label.blocks = blocks;
    103100       
    104101        rc = try_read_mbr();
     
    116113       
    117114interact:
    118        
    119         rc = interact();
    120        
    121         return rc;
     115        return interact();
    122116}
    123117
    124118/** Interact with user */
    125 int interact()
    126 {
    127         int input;
    128         tinput_t *in;
    129        
    130         in = tinput_new();
     119int interact(void)
     120{
     121        tinput_t *in = tinput_new();
    131122        if (in == NULL) {
    132123                printf("Failed initing input. Free some memory.\n");
     
    137128        printf("Welcome to hdisk.\nType 'h' for help.\n");
    138129       
    139         while (1) {
     130        while (true) {
    140131                printf("# ");
    141                 input = getchar();
     132                int input = getchar();
    142133                printf("%c\n", input);
    143134               
     
    187178end:
    188179        tinput_destroy(in);
    189        
    190180        return EOK;
    191181}
     
    194184{
    195185        printf(
    196                 "\t 'a' \t\t Add partition.\n"
    197                 "\t 'd' \t\t Delete partition.\n"
    198                 "\t 'e' \t\t Extra functions (per label format).\n"
    199                 "\t 'f' \t\t Switch the format of the partition label.\n"
    200                 "\t 'h' \t\t Prints help. See help for more.\n"
    201                 "\t 'l' \t\t Set alignment.\n"
    202                 "\t 'n' \t\t Create new label (discarding the old one).\n"
    203                 "\t 'p' \t\t Prints label contents.\n"
    204                 "\t 'q' \t\t Quit.\n"
    205                 "\t 'r' \t\t Read label from disk.\n"
    206                 "\t 'w' \t\t Write label to disk.\n"
    207                 );
    208 
    209 }
    210 
    211 void select_label_format(tinput_t * in)
     186            "\t 'a' \t\t Add partition.\n"
     187            "\t 'd' \t\t Delete partition.\n"
     188            "\t 'e' \t\t Extra functions (per label format).\n"
     189            "\t 'f' \t\t Switch the format of the partition label.\n"
     190            "\t 'h' \t\t Prints help. See help for more.\n"
     191            "\t 'l' \t\t Set alignment.\n"
     192            "\t 'n' \t\t Create new label (discarding the old one).\n"
     193            "\t 'p' \t\t Prints label contents.\n"
     194            "\t 'q' \t\t Quit.\n"
     195            "\t 'r' \t\t Read label from disk.\n"
     196            "\t 'w' \t\t Write label to disk.\n");
     197}
     198
     199void select_label_format(tinput_t *in)
    212200{
    213201        printf("Available formats are: \n"
    214                         "1) MBR\n"
    215                         "2) GPT\n"
    216               );
     202            "1) MBR\n"
     203            "2) GPT\n");
    217204       
    218205        uint8_t val = get_input_uint8(in);
     
    253240}
    254241
    255 int try_read()
    256 {
    257        
     242int try_read(void)
     243{
    258244        return label.read_parts(&label);
    259245}
    260246
    261 int try_read_mbr()
     247int try_read_mbr(void)
    262248{
    263249        construct_label(LYT_MBR);
     
    265251}
    266252
    267 int try_read_gpt()
     253int try_read_gpt(void)
    268254{
    269255        construct_label(LYT_GPT);
     
    277263        printf("Alignment set to %u sectors.\n", label.alignment);
    278264}
    279 
    280 
    281 
Note: See TracChangeset for help on using the changeset viewer.