Changeset 6453e306 in mainline for uspace/app/hdisk/hdisk.c
- Timestamp:
- 2013-12-25T16:09:43Z (10 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ac36aed
- Parents:
- d51beba3
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/hdisk/hdisk.c
rd51beba3 r6453e306 1 1 /* 2 * Copyright (c) 2012 ,2013 Dominik Taborsky2 * Copyright (c) 2012-2013 Dominik Taborsky 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 29 /** @addtogroup hdisk 30 30 * @{ 31 31 */ … … 47 47 #include <tinput.h> 48 48 #include <str_error.h> 49 50 49 #include "hdisk.h" 51 50 #include "input.h" … … 54 53 #include "func_none.h" 55 54 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 55 static int interact(void); 56 static void print_help(void); 57 static void select_label_format(tinput_t *); 58 static void construct_label(layouts_t); 59 static void free_label(void); 60 static int try_read(void); 61 static int try_read_mbr(void); 62 static int try_read_gpt(void); 63 static void set_alignment(tinput_t *); 66 64 67 65 static label_t label; 68 66 69 int main(int argc, char * * argv)67 int main(int argc, char *argv[]) 70 68 { 71 69 if (argc == 1) { 72 70 printf("Missing argument. Please specify a device to operate on.\n"); 73 return -1; 74 } 75 76 int rc; 71 return 1; 72 } 73 77 74 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); 80 76 if (rc != EOK) { 81 77 printf("Unknown device. Exiting.\n"); 82 return -1;78 return 2; 83 79 } 84 80 … … 89 85 if (rc != EOK) { 90 86 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); 96 92 block_fini(dev_handle); 97 93 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; 103 100 104 101 rc = try_read_mbr(); … … 116 113 117 114 interact: 118 119 rc = interact(); 120 121 return rc; 115 return interact(); 122 116 } 123 117 124 118 /** Interact with user */ 125 int interact() 126 { 127 int input; 128 tinput_t *in; 129 130 in = tinput_new(); 119 int interact(void) 120 { 121 tinput_t *in = tinput_new(); 131 122 if (in == NULL) { 132 123 printf("Failed initing input. Free some memory.\n"); … … 137 128 printf("Welcome to hdisk.\nType 'h' for help.\n"); 138 129 139 while ( 1) {130 while (true) { 140 131 printf("# "); 141 in put = getchar();132 int input = getchar(); 142 133 printf("%c\n", input); 143 134 … … 187 178 end: 188 179 tinput_destroy(in); 189 190 180 return EOK; 191 181 } … … 194 184 { 195 185 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 199 void select_label_format(tinput_t *in) 212 200 { 213 201 printf("Available formats are: \n" 214 "1) MBR\n" 215 "2) GPT\n" 216 ); 202 "1) MBR\n" 203 "2) GPT\n"); 217 204 218 205 uint8_t val = get_input_uint8(in); … … 253 240 } 254 241 255 int try_read() 256 { 257 242 int try_read(void) 243 { 258 244 return label.read_parts(&label); 259 245 } 260 246 261 int try_read_mbr( )247 int try_read_mbr(void) 262 248 { 263 249 construct_label(LYT_MBR); … … 265 251 } 266 252 267 int try_read_gpt( )253 int try_read_gpt(void) 268 254 { 269 255 construct_label(LYT_GPT); … … 277 263 printf("Alignment set to %u sectors.\n", label.alignment); 278 264 } 279 280 281
Note:
See TracChangeset
for help on using the changeset viewer.