| 1 | /*
|
|---|
| 2 | * Copyright (c) 2015 Jiri Svoboda
|
|---|
| 3 | * All rights reserved.
|
|---|
| 4 | *
|
|---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 6 | * modification, are permitted provided that the following conditions
|
|---|
| 7 | * are met:
|
|---|
| 8 | *
|
|---|
| 9 | * - Redistributions of source code must retain the above copyright
|
|---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
|---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 13 | * documentation and/or other materials provided with the distribution.
|
|---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
|---|
| 15 | * derived from this software without specific prior written permission.
|
|---|
| 16 | *
|
|---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 27 | */
|
|---|
| 28 |
|
|---|
| 29 | /** @addtogroup fdisk
|
|---|
| 30 | * @brief Disk management tool
|
|---|
| 31 | * @{
|
|---|
| 32 | */
|
|---|
| 33 | /**
|
|---|
| 34 | * @file
|
|---|
| 35 | */
|
|---|
| 36 |
|
|---|
| 37 | #include <errno.h>
|
|---|
| 38 | #include <nchoice.h>
|
|---|
| 39 | #include <stdbool.h>
|
|---|
| 40 | #include <stdio.h>
|
|---|
| 41 | #include <stdlib.h>
|
|---|
| 42 | #include <fdisk.h>
|
|---|
| 43 |
|
|---|
| 44 | static bool quit = false;
|
|---|
| 45 | static fdisk_t *fdisk;
|
|---|
| 46 |
|
|---|
| 47 | /** Device menu actions */
|
|---|
| 48 | typedef enum {
|
|---|
| 49 | /** Create label */
|
|---|
| 50 | devac_create_label,
|
|---|
| 51 | /** Delete label */
|
|---|
| 52 | devac_delete_label,
|
|---|
| 53 | /** Erase disk */
|
|---|
| 54 | devac_erase_disk,
|
|---|
| 55 | /** Create (primary) partition */
|
|---|
| 56 | devac_create_pri_part,
|
|---|
| 57 | /** Create extended partition */
|
|---|
| 58 | devac_create_ext_part,
|
|---|
| 59 | /** Create logical partition */
|
|---|
| 60 | devac_create_log_part,
|
|---|
| 61 | /** Delete partition */
|
|---|
| 62 | devac_delete_part,
|
|---|
| 63 | /** Exit */
|
|---|
| 64 | devac_exit
|
|---|
| 65 | } devac_t;
|
|---|
| 66 |
|
|---|
| 67 | /** Confirm user selection. */
|
|---|
| 68 | static int fdsk_confirm(const char *msg, bool *rconfirm)
|
|---|
| 69 | {
|
|---|
| 70 | tinput_t *tinput = NULL;
|
|---|
| 71 | char *answer;
|
|---|
| 72 | int rc;
|
|---|
| 73 |
|
|---|
| 74 | tinput = tinput_new();
|
|---|
| 75 | if (tinput == NULL) {
|
|---|
| 76 | rc = ENOMEM;
|
|---|
| 77 | goto error;
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 | rc = tinput_set_prompt(tinput, "y/n> ");
|
|---|
| 81 | if (rc != EOK)
|
|---|
| 82 | goto error;
|
|---|
| 83 |
|
|---|
| 84 | while (true) {
|
|---|
| 85 | printf("%s\n", msg);
|
|---|
| 86 |
|
|---|
| 87 | rc = tinput_read(tinput, &answer);
|
|---|
| 88 | if (rc == ENOENT) {
|
|---|
| 89 | *rconfirm = false;
|
|---|
| 90 | free(answer);
|
|---|
| 91 | break;
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | if (rc != EOK)
|
|---|
| 95 | goto error;
|
|---|
| 96 |
|
|---|
| 97 | if (str_cmp(answer, "y") == 0) {
|
|---|
| 98 | *rconfirm = true;
|
|---|
| 99 | free(answer);
|
|---|
| 100 | break;
|
|---|
| 101 | } else if (str_cmp(answer, "n") == 0) {
|
|---|
| 102 | *rconfirm = false;
|
|---|
| 103 | free(answer);
|
|---|
| 104 | break;
|
|---|
| 105 | }
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 | tinput_destroy(tinput);
|
|---|
| 109 | return EOK;
|
|---|
| 110 | error:
|
|---|
| 111 | if (tinput != NULL)
|
|---|
| 112 | tinput_destroy(tinput);
|
|---|
| 113 | return rc;
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | /** Device selection */
|
|---|
| 117 | static int fdsk_dev_sel_choice(service_id_t *rsvcid)
|
|---|
| 118 | {
|
|---|
| 119 | fdisk_dev_list_t *devlist = NULL;
|
|---|
| 120 | fdisk_dev_info_t *info;
|
|---|
| 121 | nchoice_t *choice = NULL;
|
|---|
| 122 | char *svcname = NULL;
|
|---|
| 123 | fdisk_cap_t cap;
|
|---|
| 124 | fdisk_dev_info_t *sdev;
|
|---|
| 125 | char *scap = NULL;
|
|---|
| 126 | char *dtext = NULL;
|
|---|
| 127 | service_id_t svcid;
|
|---|
| 128 | void *sel;
|
|---|
| 129 | int ndevs;
|
|---|
| 130 | int rc;
|
|---|
| 131 |
|
|---|
| 132 | rc = nchoice_create(&choice);
|
|---|
| 133 | if (rc != EOK) {
|
|---|
| 134 | assert(rc == ENOMEM);
|
|---|
| 135 | printf("Out of memory.\n");
|
|---|
| 136 | goto error;
|
|---|
| 137 | }
|
|---|
| 138 |
|
|---|
| 139 | rc = nchoice_set_prompt(choice, "Select device");
|
|---|
| 140 | if (rc != EOK) {
|
|---|
| 141 | assert(rc == ENOMEM);
|
|---|
| 142 | printf("Out of memory.\n");
|
|---|
| 143 | goto error;
|
|---|
| 144 | }
|
|---|
| 145 |
|
|---|
| 146 | rc = fdisk_dev_list_get(fdisk, &devlist);
|
|---|
| 147 | if (rc != EOK) {
|
|---|
| 148 | printf("Error getting device list.\n");
|
|---|
| 149 | goto error;
|
|---|
| 150 | }
|
|---|
| 151 |
|
|---|
| 152 | info = fdisk_dev_first(devlist);
|
|---|
| 153 | ndevs = 0;
|
|---|
| 154 | while (info != NULL) {
|
|---|
| 155 | ++ndevs;
|
|---|
| 156 |
|
|---|
| 157 | rc = fdisk_dev_info_get_svcname(info, &svcname);
|
|---|
| 158 | if (rc != EOK) {
|
|---|
| 159 | printf("Error getting device service name.\n");
|
|---|
| 160 | goto error;
|
|---|
| 161 | }
|
|---|
| 162 |
|
|---|
| 163 | rc = fdisk_dev_info_capacity(info, &cap);
|
|---|
| 164 | if (rc != EOK) {
|
|---|
| 165 | printf("Error getting device capacity.\n");
|
|---|
| 166 | goto error;
|
|---|
| 167 | }
|
|---|
| 168 |
|
|---|
| 169 | fdisk_cap_simplify(&cap);
|
|---|
| 170 |
|
|---|
| 171 | rc = fdisk_cap_format(&cap, &scap);
|
|---|
| 172 | if (rc != EOK) {
|
|---|
| 173 | assert(rc == ENOMEM);
|
|---|
| 174 | printf("Out of memory.\n");
|
|---|
| 175 | goto error;
|
|---|
| 176 | }
|
|---|
| 177 |
|
|---|
| 178 | rc = asprintf(&dtext, "%s (%s)", svcname, scap);
|
|---|
| 179 | if (rc < 0) {
|
|---|
| 180 | rc = ENOMEM;
|
|---|
| 181 | printf("Out of memory.\n");
|
|---|
| 182 | goto error;
|
|---|
| 183 | }
|
|---|
| 184 |
|
|---|
| 185 | free(svcname);
|
|---|
| 186 | svcname = NULL;
|
|---|
| 187 | free(scap);
|
|---|
| 188 | scap = NULL;
|
|---|
| 189 |
|
|---|
| 190 | rc = nchoice_add(choice, dtext, info, 0);
|
|---|
| 191 | if (rc != EOK) {
|
|---|
| 192 | assert(rc == ENOMEM);
|
|---|
| 193 | printf("Out of memory.\n");
|
|---|
| 194 | goto error;
|
|---|
| 195 | }
|
|---|
| 196 |
|
|---|
| 197 | free(dtext);
|
|---|
| 198 | dtext = NULL;
|
|---|
| 199 |
|
|---|
| 200 | info = fdisk_dev_next(info);
|
|---|
| 201 | }
|
|---|
| 202 |
|
|---|
| 203 | if (ndevs == 0) {
|
|---|
| 204 | printf("No disk devices found.\n");
|
|---|
| 205 | rc = ENOENT;
|
|---|
| 206 | goto error;
|
|---|
| 207 | }
|
|---|
| 208 |
|
|---|
| 209 | rc = nchoice_add(choice, "Exit", NULL, 0);
|
|---|
| 210 | if (rc != EOK) {
|
|---|
| 211 | assert(rc == ENOMEM);
|
|---|
| 212 | printf("Out of memory.\n");
|
|---|
| 213 | goto error;
|
|---|
| 214 | }
|
|---|
| 215 |
|
|---|
| 216 | rc = nchoice_get(choice, &sel);
|
|---|
| 217 | if (rc != EOK) {
|
|---|
| 218 | printf("Error getting user selection.\n");
|
|---|
| 219 | return rc;
|
|---|
| 220 | }
|
|---|
| 221 |
|
|---|
| 222 | sdev = (fdisk_dev_info_t *)sel;
|
|---|
| 223 | if (sdev != NULL) {
|
|---|
| 224 | fdisk_dev_info_get_svcid(sdev, &svcid);
|
|---|
| 225 | } else {
|
|---|
| 226 | svcid = 0;
|
|---|
| 227 | }
|
|---|
| 228 |
|
|---|
| 229 | fdisk_dev_list_free(devlist);
|
|---|
| 230 |
|
|---|
| 231 | nchoice_destroy(choice);
|
|---|
| 232 | *rsvcid = svcid;
|
|---|
| 233 | return EOK;
|
|---|
| 234 | error:
|
|---|
| 235 | if (devlist != NULL)
|
|---|
| 236 | fdisk_dev_list_free(devlist);
|
|---|
| 237 | if (choice != NULL)
|
|---|
| 238 | nchoice_destroy(choice);
|
|---|
| 239 | free(dtext);
|
|---|
| 240 | free(svcname);
|
|---|
| 241 | free(scap);
|
|---|
| 242 | return rc;
|
|---|
| 243 | }
|
|---|
| 244 |
|
|---|
| 245 | static int fdsk_create_label(fdisk_dev_t *dev)
|
|---|
| 246 | {
|
|---|
| 247 | nchoice_t *choice = NULL;
|
|---|
| 248 | void *sel;
|
|---|
| 249 | char *sltype = NULL;
|
|---|
| 250 | int i;
|
|---|
| 251 | int rc;
|
|---|
| 252 |
|
|---|
| 253 | rc = nchoice_create(&choice);
|
|---|
| 254 | if (rc != EOK) {
|
|---|
| 255 | assert(rc == ENOMEM);
|
|---|
| 256 | printf("Out of memory.\n");
|
|---|
| 257 | goto error;
|
|---|
| 258 | }
|
|---|
| 259 |
|
|---|
| 260 | rc = nchoice_set_prompt(choice, "Select label type");
|
|---|
| 261 | if (rc != EOK) {
|
|---|
| 262 | assert(rc == ENOMEM);
|
|---|
| 263 | printf("Out of memory.\n");
|
|---|
| 264 | goto error;
|
|---|
| 265 | }
|
|---|
| 266 |
|
|---|
| 267 | for (i = LT_FIRST; i < LT_LIMIT; i++) {
|
|---|
| 268 | rc = fdisk_ltype_format(i, &sltype);
|
|---|
| 269 | if (rc != EOK)
|
|---|
| 270 | goto error;
|
|---|
| 271 |
|
|---|
| 272 | rc = nchoice_add(choice, sltype, (void *)(uintptr_t)i,
|
|---|
| 273 | i == LT_DEFAULT);
|
|---|
| 274 | if (rc != EOK) {
|
|---|
| 275 | assert(rc == ENOMEM);
|
|---|
| 276 | printf("Out of memory.\n");
|
|---|
| 277 | goto error;
|
|---|
| 278 | }
|
|---|
| 279 |
|
|---|
| 280 | free(sltype);
|
|---|
| 281 | sltype = NULL;
|
|---|
| 282 | }
|
|---|
| 283 |
|
|---|
| 284 | rc = nchoice_get(choice, &sel);
|
|---|
| 285 | if (rc != EOK) {
|
|---|
| 286 | printf("Error getting user selection.\n");
|
|---|
| 287 | goto error;
|
|---|
| 288 | }
|
|---|
| 289 |
|
|---|
| 290 | rc = fdisk_label_create(dev, (label_type_t)sel);
|
|---|
| 291 | if (rc != EOK) {
|
|---|
| 292 | printf("Error creating label.\n");
|
|---|
| 293 | goto error;
|
|---|
| 294 | }
|
|---|
| 295 |
|
|---|
| 296 | nchoice_destroy(choice);
|
|---|
| 297 | return EOK;
|
|---|
| 298 | error:
|
|---|
| 299 | free(sltype);
|
|---|
| 300 | if (choice != NULL)
|
|---|
| 301 | nchoice_destroy(choice);
|
|---|
| 302 | return rc;
|
|---|
| 303 | }
|
|---|
| 304 |
|
|---|
| 305 | static int fdsk_delete_label(fdisk_dev_t *dev)
|
|---|
| 306 | {
|
|---|
| 307 | bool confirm;
|
|---|
| 308 | int rc;
|
|---|
| 309 |
|
|---|
| 310 | rc = fdsk_confirm("Warning. Any data on disk will be lost. "
|
|---|
| 311 | "Really delete label?", &confirm);
|
|---|
| 312 | if (rc != EOK) {
|
|---|
| 313 | printf("Error getting user confirmation.\n");
|
|---|
| 314 | return rc;
|
|---|
| 315 | }
|
|---|
| 316 |
|
|---|
| 317 | if (!confirm)
|
|---|
| 318 | return EOK;
|
|---|
| 319 |
|
|---|
| 320 | rc = fdisk_label_destroy(dev);
|
|---|
| 321 | if (rc != EOK) {
|
|---|
| 322 | printf("Error deleting label.\n");
|
|---|
| 323 | return rc;
|
|---|
| 324 | }
|
|---|
| 325 |
|
|---|
| 326 | return EOK;
|
|---|
| 327 | }
|
|---|
| 328 |
|
|---|
| 329 | static int fdsk_erase_disk(fdisk_dev_t *dev)
|
|---|
| 330 | {
|
|---|
| 331 | bool confirm;
|
|---|
| 332 | int rc;
|
|---|
| 333 |
|
|---|
| 334 | rc = fdsk_confirm("Warning. Any data on disk will be lost. "
|
|---|
| 335 | "Really erase disk?", &confirm);
|
|---|
| 336 | if (rc != EOK) {
|
|---|
| 337 | printf("Error getting user confirmation.\n");
|
|---|
| 338 | return rc;
|
|---|
| 339 | }
|
|---|
| 340 |
|
|---|
| 341 | if (!confirm)
|
|---|
| 342 | return EOK;
|
|---|
| 343 |
|
|---|
| 344 | rc = fdisk_dev_erase(dev);
|
|---|
| 345 | if (rc != EOK) {
|
|---|
| 346 | printf("Error erasing disk.\n");
|
|---|
| 347 | return rc;
|
|---|
| 348 | }
|
|---|
| 349 |
|
|---|
| 350 | return EOK;
|
|---|
| 351 | }
|
|---|
| 352 |
|
|---|
| 353 | static int fdsk_select_fstype(vol_fstype_t *fstype)
|
|---|
| 354 | {
|
|---|
| 355 | nchoice_t *choice = NULL;
|
|---|
| 356 | void *sel;
|
|---|
| 357 | char *sfstype;
|
|---|
| 358 | int i;
|
|---|
| 359 | int rc;
|
|---|
| 360 |
|
|---|
| 361 | rc = nchoice_create(&choice);
|
|---|
| 362 | if (rc != EOK) {
|
|---|
| 363 | assert(rc == ENOMEM);
|
|---|
| 364 | printf("Out of memory.\n");
|
|---|
| 365 | goto error;
|
|---|
| 366 | }
|
|---|
| 367 |
|
|---|
| 368 | rc = nchoice_set_prompt(choice, "Select file system type");
|
|---|
| 369 | if (rc != EOK) {
|
|---|
| 370 | assert(rc == ENOMEM);
|
|---|
| 371 | printf("Out of memory.\n");
|
|---|
| 372 | goto error;
|
|---|
| 373 | }
|
|---|
| 374 |
|
|---|
| 375 | for (i = 0; i < VOL_FSTYPE_LIMIT; i++) {
|
|---|
| 376 | rc = fdisk_fstype_format(i, &sfstype);
|
|---|
| 377 | if (rc != EOK)
|
|---|
| 378 | goto error;
|
|---|
| 379 |
|
|---|
| 380 | rc = nchoice_add(choice, sfstype, (void *)(uintptr_t)i,
|
|---|
| 381 | i == VOL_FSTYPE_DEFAULT);
|
|---|
| 382 | if (rc != EOK) {
|
|---|
| 383 | assert(rc == ENOMEM);
|
|---|
| 384 | printf("Out of memory.\n");
|
|---|
| 385 | goto error;
|
|---|
| 386 | }
|
|---|
| 387 |
|
|---|
| 388 | free(sfstype);
|
|---|
| 389 | sfstype = NULL;
|
|---|
| 390 | }
|
|---|
| 391 |
|
|---|
| 392 | rc = nchoice_get(choice, &sel);
|
|---|
| 393 | if (rc != EOK) {
|
|---|
| 394 | printf("Error getting user selection.\n");
|
|---|
| 395 | goto error;
|
|---|
| 396 | }
|
|---|
| 397 |
|
|---|
| 398 | nchoice_destroy(choice);
|
|---|
| 399 | *fstype = (vol_fstype_t)sel;
|
|---|
| 400 | return EOK;
|
|---|
| 401 | error:
|
|---|
| 402 | free(sfstype);
|
|---|
| 403 | if (choice != NULL)
|
|---|
| 404 | nchoice_destroy(choice);
|
|---|
| 405 | return rc;
|
|---|
| 406 | }
|
|---|
| 407 |
|
|---|
| 408 | static int fdsk_create_part(fdisk_dev_t *dev, label_pkind_t pkind)
|
|---|
| 409 | {
|
|---|
| 410 | int rc;
|
|---|
| 411 | fdisk_part_spec_t pspec;
|
|---|
| 412 | fdisk_cap_t cap;
|
|---|
| 413 | fdisk_cap_t mcap;
|
|---|
| 414 | vol_fstype_t fstype = 0;
|
|---|
| 415 | tinput_t *tinput = NULL;
|
|---|
| 416 | fdisk_spc_t spc;
|
|---|
| 417 | char *scap;
|
|---|
| 418 | char *smcap = NULL;
|
|---|
| 419 |
|
|---|
| 420 | if (pkind == lpk_logical)
|
|---|
| 421 | spc = spc_log;
|
|---|
| 422 | else
|
|---|
| 423 | spc = spc_pri;
|
|---|
| 424 |
|
|---|
| 425 | rc = fdisk_part_get_max_avail(dev, spc, &mcap);
|
|---|
| 426 | if (rc != EOK) {
|
|---|
| 427 | rc = EIO;
|
|---|
| 428 | goto error;
|
|---|
| 429 | }
|
|---|
| 430 |
|
|---|
| 431 | rc = fdisk_cap_format(&mcap, &smcap);
|
|---|
| 432 | if (rc != EOK) {
|
|---|
| 433 | rc = ENOMEM;
|
|---|
| 434 | goto error;
|
|---|
| 435 | }
|
|---|
| 436 |
|
|---|
| 437 | tinput = tinput_new();
|
|---|
| 438 | if (tinput == NULL) {
|
|---|
| 439 | rc = ENOMEM;
|
|---|
| 440 | goto error;
|
|---|
| 441 | }
|
|---|
| 442 |
|
|---|
| 443 | rc = tinput_set_prompt(tinput, "?> ");
|
|---|
| 444 | if (rc != EOK)
|
|---|
| 445 | goto error;
|
|---|
| 446 |
|
|---|
| 447 | while (true) {
|
|---|
| 448 | printf("Enter capacity of new partition.\n");
|
|---|
| 449 | rc = tinput_read_i(tinput, smcap, &scap);
|
|---|
| 450 | if (rc != EOK)
|
|---|
| 451 | goto error;
|
|---|
| 452 |
|
|---|
| 453 | rc = fdisk_cap_parse(scap, &cap);
|
|---|
| 454 | if (rc == EOK)
|
|---|
| 455 | break;
|
|---|
| 456 | }
|
|---|
| 457 |
|
|---|
| 458 | tinput_destroy(tinput);
|
|---|
| 459 | tinput = NULL;
|
|---|
| 460 | free(smcap);
|
|---|
| 461 | smcap = NULL;
|
|---|
| 462 |
|
|---|
| 463 | if (pkind != lpk_extended) {
|
|---|
| 464 | rc = fdsk_select_fstype(&fstype);
|
|---|
| 465 | if (rc != EOK)
|
|---|
| 466 | goto error;
|
|---|
| 467 | }
|
|---|
| 468 |
|
|---|
| 469 | fdisk_pspec_init(&pspec);
|
|---|
| 470 | pspec.capacity = cap;
|
|---|
| 471 | pspec.pkind = pkind;
|
|---|
| 472 | pspec.fstype = fstype;
|
|---|
| 473 |
|
|---|
| 474 | rc = fdisk_part_create(dev, &pspec, NULL);
|
|---|
| 475 | if (rc != EOK) {
|
|---|
| 476 | printf("Error creating partition.\n");
|
|---|
| 477 | goto error;
|
|---|
| 478 | }
|
|---|
| 479 |
|
|---|
| 480 | return EOK;
|
|---|
| 481 | error:
|
|---|
| 482 | free(smcap);
|
|---|
| 483 | if (tinput != NULL)
|
|---|
| 484 | tinput_destroy(tinput);
|
|---|
| 485 | return rc;
|
|---|
| 486 | }
|
|---|
| 487 |
|
|---|
| 488 | static int fdsk_delete_part(fdisk_dev_t *dev)
|
|---|
| 489 | {
|
|---|
| 490 | nchoice_t *choice = NULL;
|
|---|
| 491 | fdisk_part_t *part;
|
|---|
| 492 | fdisk_part_info_t pinfo;
|
|---|
| 493 | char *scap = NULL;
|
|---|
| 494 | char *spkind = NULL;
|
|---|
| 495 | char *sfstype = NULL;
|
|---|
| 496 | char *sdesc = NULL;
|
|---|
| 497 | bool confirm;
|
|---|
| 498 | void *sel;
|
|---|
| 499 | int rc;
|
|---|
| 500 |
|
|---|
| 501 | rc = nchoice_create(&choice);
|
|---|
| 502 | if (rc != EOK) {
|
|---|
| 503 | assert(rc == ENOMEM);
|
|---|
| 504 | printf("Out of memory.\n");
|
|---|
| 505 | goto error;
|
|---|
| 506 | }
|
|---|
| 507 |
|
|---|
| 508 | rc = nchoice_set_prompt(choice, "Select partition to delete");
|
|---|
| 509 | if (rc != EOK) {
|
|---|
| 510 | assert(rc == ENOMEM);
|
|---|
| 511 | printf("Out of memory.\n");
|
|---|
| 512 | goto error;
|
|---|
| 513 | }
|
|---|
| 514 |
|
|---|
| 515 | part = fdisk_part_first(dev);
|
|---|
| 516 | while (part != NULL) {
|
|---|
| 517 | rc = fdisk_part_get_info(part, &pinfo);
|
|---|
| 518 | if (rc != EOK) {
|
|---|
| 519 | printf("Error getting partition information.\n");
|
|---|
| 520 | goto error;
|
|---|
| 521 | }
|
|---|
| 522 |
|
|---|
| 523 | fdisk_cap_simplify(&pinfo.capacity);
|
|---|
| 524 |
|
|---|
| 525 | rc = fdisk_cap_format(&pinfo.capacity, &scap);
|
|---|
| 526 | if (rc != EOK) {
|
|---|
| 527 | printf("Out of memory.\n");
|
|---|
| 528 | goto error;
|
|---|
| 529 | }
|
|---|
| 530 |
|
|---|
| 531 | rc = fdisk_pkind_format(pinfo.pkind, &spkind);
|
|---|
| 532 | if (rc != EOK) {
|
|---|
| 533 | printf("\nOut of memory.\n");
|
|---|
| 534 | goto error;
|
|---|
| 535 | }
|
|---|
| 536 |
|
|---|
| 537 | if (pinfo.pkind != lpk_extended) {
|
|---|
| 538 | rc = fdisk_fstype_format(pinfo.fstype, &sfstype);
|
|---|
| 539 | if (rc != EOK) {
|
|---|
| 540 | printf("Out of memory.\n");
|
|---|
| 541 | goto error;
|
|---|
| 542 | }
|
|---|
| 543 |
|
|---|
| 544 | rc = asprintf(&sdesc, "%s, %s, %s", scap, spkind, sfstype);
|
|---|
| 545 | if (rc < 0) {
|
|---|
| 546 | rc = ENOMEM;
|
|---|
| 547 | goto error;
|
|---|
| 548 | }
|
|---|
| 549 |
|
|---|
| 550 | } else {
|
|---|
| 551 | rc = asprintf(&sdesc, "%s, %s", scap, spkind);
|
|---|
| 552 | if (rc < 0) {
|
|---|
| 553 | rc = ENOMEM;
|
|---|
| 554 | goto error;
|
|---|
| 555 | }
|
|---|
| 556 | }
|
|---|
| 557 |
|
|---|
| 558 | rc = nchoice_add(choice, sdesc, (void *)part, 0);
|
|---|
| 559 | if (rc != EOK) {
|
|---|
| 560 | assert(rc == ENOMEM);
|
|---|
| 561 | printf("Out of memory.\n");
|
|---|
| 562 | goto error;
|
|---|
| 563 | }
|
|---|
| 564 |
|
|---|
| 565 | free(scap);
|
|---|
| 566 | scap = NULL;
|
|---|
| 567 | free(spkind);
|
|---|
| 568 | spkind = NULL;
|
|---|
| 569 | free(sfstype);
|
|---|
| 570 | sfstype = NULL;
|
|---|
| 571 | free(sdesc);
|
|---|
| 572 | sdesc = NULL;
|
|---|
| 573 |
|
|---|
| 574 | part = fdisk_part_next(part);
|
|---|
| 575 | }
|
|---|
| 576 |
|
|---|
| 577 | rc = nchoice_add(choice, "Cancel", NULL, 0);
|
|---|
| 578 | if (rc != EOK) {
|
|---|
| 579 | assert(rc == ENOMEM);
|
|---|
| 580 | printf("Out of memory.\n");
|
|---|
| 581 | goto error;
|
|---|
| 582 | }
|
|---|
| 583 |
|
|---|
| 584 | rc = nchoice_get(choice, &sel);
|
|---|
| 585 | if (rc == ENOENT)
|
|---|
| 586 | return EOK;
|
|---|
| 587 | if (rc != EOK) {
|
|---|
| 588 | printf("Error getting user selection.\n");
|
|---|
| 589 | goto error;
|
|---|
| 590 | }
|
|---|
| 591 |
|
|---|
| 592 |
|
|---|
| 593 | nchoice_destroy(choice);
|
|---|
| 594 | choice = NULL;
|
|---|
| 595 |
|
|---|
| 596 | if (sel == NULL)
|
|---|
| 597 | return EOK;
|
|---|
| 598 |
|
|---|
| 599 | rc = fdsk_confirm("Warning. Any data in partition will be lost. "
|
|---|
| 600 | "Really delete partition?", &confirm);
|
|---|
| 601 | if (rc != EOK) {
|
|---|
| 602 | printf("Error getting user confirmation.\n");
|
|---|
| 603 | goto error;
|
|---|
| 604 | }
|
|---|
| 605 |
|
|---|
| 606 | if (!confirm)
|
|---|
| 607 | return EOK;
|
|---|
| 608 |
|
|---|
| 609 | rc = fdisk_part_destroy((fdisk_part_t *)sel);
|
|---|
| 610 | if (rc != EOK) {
|
|---|
| 611 | printf("Error deleting partition.\n");
|
|---|
| 612 | return rc;
|
|---|
| 613 | }
|
|---|
| 614 |
|
|---|
| 615 | return EOK;
|
|---|
| 616 | error:
|
|---|
| 617 | free(scap);
|
|---|
| 618 | free(spkind);
|
|---|
| 619 | free(sfstype);
|
|---|
| 620 | free(sdesc);
|
|---|
| 621 |
|
|---|
| 622 | if (choice != NULL)
|
|---|
| 623 | nchoice_destroy(choice);
|
|---|
| 624 | return rc;
|
|---|
| 625 | }
|
|---|
| 626 |
|
|---|
| 627 | /** Device menu */
|
|---|
| 628 | static int fdsk_dev_menu(fdisk_dev_t *dev)
|
|---|
| 629 | {
|
|---|
| 630 | nchoice_t *choice = NULL;
|
|---|
| 631 | fdisk_label_info_t linfo;
|
|---|
| 632 | fdisk_part_t *part;
|
|---|
| 633 | fdisk_part_info_t pinfo;
|
|---|
| 634 | fdisk_cap_t cap;
|
|---|
| 635 | fdisk_cap_t mcap;
|
|---|
| 636 | fdisk_dev_flags_t dflags;
|
|---|
| 637 | char *sltype = NULL;
|
|---|
| 638 | char *sdcap = NULL;
|
|---|
| 639 | char *scap = NULL;
|
|---|
| 640 | char *smcap = NULL;
|
|---|
| 641 | char *sfstype = NULL;
|
|---|
| 642 | char *svcname = NULL;
|
|---|
| 643 | char *spkind;
|
|---|
| 644 | int rc;
|
|---|
| 645 | int npart;
|
|---|
| 646 | void *sel;
|
|---|
| 647 |
|
|---|
| 648 | rc = nchoice_create(&choice);
|
|---|
| 649 | if (rc != EOK) {
|
|---|
| 650 | assert(rc == ENOMEM);
|
|---|
| 651 | printf("Out of memory.\n");
|
|---|
| 652 | goto error;
|
|---|
| 653 | }
|
|---|
| 654 |
|
|---|
| 655 | rc = nchoice_set_prompt(choice, "Select action");
|
|---|
| 656 | if (rc != EOK) {
|
|---|
| 657 | assert(rc == ENOMEM);
|
|---|
| 658 | printf("Out of memory.\n");
|
|---|
| 659 | goto error;
|
|---|
| 660 | }
|
|---|
| 661 |
|
|---|
| 662 | rc = fdisk_dev_capacity(dev, &cap);
|
|---|
| 663 | if (rc != EOK) {
|
|---|
| 664 | printf("Error getting device capacity.\n");
|
|---|
| 665 | goto error;
|
|---|
| 666 | }
|
|---|
| 667 |
|
|---|
| 668 | fdisk_cap_simplify(&cap);
|
|---|
| 669 |
|
|---|
| 670 | rc = fdisk_cap_format(&cap, &sdcap);
|
|---|
| 671 | if (rc != EOK) {
|
|---|
| 672 | printf("Out of memory.\n");
|
|---|
| 673 | goto error;
|
|---|
| 674 | }
|
|---|
| 675 |
|
|---|
| 676 | rc = fdisk_dev_get_svcname(dev, &svcname);
|
|---|
| 677 | if (rc != EOK) {
|
|---|
| 678 | printf("Error getting device service name.\n");
|
|---|
| 679 | goto error;
|
|---|
| 680 | }
|
|---|
| 681 |
|
|---|
| 682 | fdisk_dev_get_flags(dev, &dflags);
|
|---|
| 683 |
|
|---|
| 684 | printf("Device: %s, %s\n", sdcap, svcname);
|
|---|
| 685 | free(sdcap);
|
|---|
| 686 | sdcap = NULL;
|
|---|
| 687 |
|
|---|
| 688 | rc = fdisk_label_get_info(dev, &linfo);
|
|---|
| 689 | if (rc != EOK) {
|
|---|
| 690 | printf("Error getting label information.\n");
|
|---|
| 691 | goto error;
|
|---|
| 692 | }
|
|---|
| 693 |
|
|---|
| 694 | switch (linfo.ltype) {
|
|---|
| 695 | case lt_none:
|
|---|
| 696 | printf("Disk contains no label.\n");
|
|---|
| 697 | break;
|
|---|
| 698 | default:
|
|---|
| 699 | rc = fdisk_ltype_format(linfo.ltype, &sltype);
|
|---|
| 700 | if (rc != EOK) {
|
|---|
| 701 | assert(rc == ENOMEM);
|
|---|
| 702 | printf("Out of memory.\n");
|
|---|
| 703 | goto error;
|
|---|
| 704 | }
|
|---|
| 705 |
|
|---|
| 706 | printf("Label type: %s\n", sltype);
|
|---|
| 707 | free(sltype);
|
|---|
| 708 | sltype = NULL;
|
|---|
| 709 | break;
|
|---|
| 710 | }
|
|---|
| 711 |
|
|---|
| 712 | part = fdisk_part_first(dev);
|
|---|
| 713 | npart = 0;
|
|---|
| 714 | while (part != NULL) {
|
|---|
| 715 | ++npart;
|
|---|
| 716 | rc = fdisk_part_get_info(part, &pinfo);
|
|---|
| 717 | if (rc != EOK) {
|
|---|
| 718 | printf("Error getting partition information.\n");
|
|---|
| 719 | goto error;
|
|---|
| 720 | }
|
|---|
| 721 |
|
|---|
| 722 | fdisk_cap_simplify(&pinfo.capacity);
|
|---|
| 723 |
|
|---|
| 724 | rc = fdisk_cap_format(&pinfo.capacity, &scap);
|
|---|
| 725 | if (rc != EOK) {
|
|---|
| 726 | printf("Out of memory.\n");
|
|---|
| 727 | goto error;
|
|---|
| 728 | }
|
|---|
| 729 |
|
|---|
| 730 | rc = fdisk_fstype_format(pinfo.fstype, &sfstype);
|
|---|
| 731 | if (rc != EOK) {
|
|---|
| 732 | printf("Out of memory.\n");
|
|---|
| 733 | goto error;
|
|---|
| 734 | }
|
|---|
| 735 |
|
|---|
| 736 | if (linfo.ltype == lt_none)
|
|---|
| 737 | printf("Entire disk: %s", scap);
|
|---|
| 738 | else
|
|---|
| 739 | printf("Partition %d: %s", npart, scap);
|
|---|
| 740 |
|
|---|
| 741 | if ((linfo.flags & lf_ext_supp) != 0) {
|
|---|
| 742 | rc = fdisk_pkind_format(pinfo.pkind, &spkind);
|
|---|
| 743 | if (rc != EOK) {
|
|---|
| 744 | printf("\nOut of memory.\n");
|
|---|
| 745 | goto error;
|
|---|
| 746 | }
|
|---|
| 747 |
|
|---|
| 748 | printf(", %s", spkind);
|
|---|
| 749 | free(spkind);
|
|---|
| 750 | }
|
|---|
| 751 |
|
|---|
| 752 | if (pinfo.pkind != lpk_extended) {
|
|---|
| 753 | switch (pinfo.pcnt) {
|
|---|
| 754 | case vpc_empty:
|
|---|
| 755 | printf(", Empty");
|
|---|
| 756 | break;
|
|---|
| 757 | case vpc_fs:
|
|---|
| 758 | printf(", %s", sfstype);
|
|---|
| 759 | break;
|
|---|
| 760 | case vpc_unknown:
|
|---|
| 761 | printf(", Unknown");
|
|---|
| 762 | break;
|
|---|
| 763 | }
|
|---|
| 764 | }
|
|---|
| 765 |
|
|---|
| 766 | printf("\n");
|
|---|
| 767 |
|
|---|
| 768 | free(scap);
|
|---|
| 769 | scap = NULL;
|
|---|
| 770 | free(sfstype);
|
|---|
| 771 | sfstype = NULL;
|
|---|
| 772 |
|
|---|
| 773 | part = fdisk_part_next(part);
|
|---|
| 774 | }
|
|---|
| 775 |
|
|---|
| 776 | /* Display available space */
|
|---|
| 777 | if ((linfo.flags & lf_can_create_pri) != 0) {
|
|---|
| 778 | rc = fdisk_part_get_max_avail(dev, spc_pri, &mcap);
|
|---|
| 779 | if (rc != EOK) {
|
|---|
| 780 | rc = EIO;
|
|---|
| 781 | goto error;
|
|---|
| 782 | }
|
|---|
| 783 |
|
|---|
| 784 | fdisk_cap_simplify(&mcap);
|
|---|
| 785 |
|
|---|
| 786 | rc = fdisk_cap_format(&mcap, &smcap);
|
|---|
| 787 | if (rc != EOK) {
|
|---|
| 788 | rc = ENOMEM;
|
|---|
| 789 | goto error;
|
|---|
| 790 | }
|
|---|
| 791 |
|
|---|
| 792 | if ((linfo.flags & lf_ext_supp) != 0)
|
|---|
| 793 | printf("Maximum free primary block: %s\n", smcap);
|
|---|
| 794 | else
|
|---|
| 795 | printf("Maximum free block: %s\n", smcap);
|
|---|
| 796 |
|
|---|
| 797 | free(smcap);
|
|---|
| 798 | smcap = NULL;
|
|---|
| 799 |
|
|---|
| 800 | rc = fdisk_part_get_tot_avail(dev, spc_pri, &mcap);
|
|---|
| 801 | if (rc != EOK) {
|
|---|
| 802 | rc = EIO;
|
|---|
| 803 | goto error;
|
|---|
| 804 | }
|
|---|
| 805 |
|
|---|
| 806 | fdisk_cap_simplify(&mcap);
|
|---|
| 807 |
|
|---|
| 808 | rc = fdisk_cap_format(&mcap, &smcap);
|
|---|
| 809 | if (rc != EOK) {
|
|---|
| 810 | rc = ENOMEM;
|
|---|
| 811 | goto error;
|
|---|
| 812 | }
|
|---|
| 813 |
|
|---|
| 814 | if ((linfo.flags & lf_ext_supp) != 0)
|
|---|
| 815 | printf("Total free primary space: %s\n", smcap);
|
|---|
| 816 | else
|
|---|
| 817 | printf("Total free space: %s\n", smcap);
|
|---|
| 818 |
|
|---|
| 819 | free(smcap);
|
|---|
| 820 | smcap = NULL;
|
|---|
| 821 | }
|
|---|
| 822 |
|
|---|
| 823 | /* Display available space */
|
|---|
| 824 | if ((linfo.flags & lf_can_create_log) != 0) {
|
|---|
| 825 | rc = fdisk_part_get_max_avail(dev, spc_log, &mcap);
|
|---|
| 826 | if (rc != EOK) {
|
|---|
| 827 | rc = EIO;
|
|---|
| 828 | goto error;
|
|---|
| 829 | }
|
|---|
| 830 |
|
|---|
| 831 | fdisk_cap_simplify(&mcap);
|
|---|
| 832 |
|
|---|
| 833 | rc = fdisk_cap_format(&mcap, &smcap);
|
|---|
| 834 | if (rc != EOK) {
|
|---|
| 835 | rc = ENOMEM;
|
|---|
| 836 | goto error;
|
|---|
| 837 | }
|
|---|
| 838 |
|
|---|
| 839 | printf("Maximum free logical block: %s\n", smcap);
|
|---|
| 840 | free(smcap);
|
|---|
| 841 | smcap = NULL;
|
|---|
| 842 |
|
|---|
| 843 | rc = fdisk_part_get_tot_avail(dev, spc_log, &mcap);
|
|---|
| 844 | if (rc != EOK) {
|
|---|
| 845 | rc = EIO;
|
|---|
| 846 | goto error;
|
|---|
| 847 | }
|
|---|
| 848 |
|
|---|
| 849 | fdisk_cap_simplify(&mcap);
|
|---|
| 850 |
|
|---|
| 851 | rc = fdisk_cap_format(&mcap, &smcap);
|
|---|
| 852 | if (rc != EOK) {
|
|---|
| 853 | rc = ENOMEM;
|
|---|
| 854 | goto error;
|
|---|
| 855 | }
|
|---|
| 856 |
|
|---|
| 857 | printf("Total free logical space: %s\n", smcap);
|
|---|
| 858 | free(smcap);
|
|---|
| 859 | smcap = NULL;
|
|---|
| 860 | }
|
|---|
| 861 |
|
|---|
| 862 | rc = nchoice_set_prompt(choice, "Select action");
|
|---|
| 863 | if (rc != EOK) {
|
|---|
| 864 | assert(rc == ENOMEM);
|
|---|
| 865 | printf("Out of memory.\n");
|
|---|
| 866 | goto error;
|
|---|
| 867 | }
|
|---|
| 868 |
|
|---|
| 869 | if ((linfo.flags & lf_ext_supp) != 0) {
|
|---|
| 870 | if ((linfo.flags & lf_can_create_pri) != 0) {
|
|---|
| 871 | rc = nchoice_add(choice, "Create primary "
|
|---|
| 872 | "partition",
|
|---|
| 873 | (void *)devac_create_pri_part, 0);
|
|---|
| 874 | if (rc != EOK) {
|
|---|
| 875 | assert(rc == ENOMEM);
|
|---|
| 876 | printf("Out of memory.\n");
|
|---|
| 877 | goto error;
|
|---|
| 878 | }
|
|---|
| 879 | }
|
|---|
| 880 |
|
|---|
| 881 | if ((linfo.flags & lf_can_create_ext) != 0) {
|
|---|
| 882 | rc = nchoice_add(choice, "Create extended "
|
|---|
| 883 | "partition",
|
|---|
| 884 | (void *)devac_create_ext_part, 0);
|
|---|
| 885 | if (rc != EOK) {
|
|---|
| 886 | assert(rc == ENOMEM);
|
|---|
| 887 | printf("Out of memory.\n");
|
|---|
| 888 | goto error;
|
|---|
| 889 | }
|
|---|
| 890 | }
|
|---|
| 891 |
|
|---|
| 892 | if ((linfo.flags & lf_can_create_log) != 0) {
|
|---|
| 893 | rc = nchoice_add(choice, "Create logical "
|
|---|
| 894 | "partition",
|
|---|
| 895 | (void *)devac_create_log_part, 0);
|
|---|
| 896 | if (rc != EOK) {
|
|---|
| 897 | assert(rc == ENOMEM);
|
|---|
| 898 | printf("Out of memory.\n");
|
|---|
| 899 | goto error;
|
|---|
| 900 | }
|
|---|
| 901 | }
|
|---|
| 902 | } else { /* (linfo.flags & lf_ext_supp) == 0 */
|
|---|
| 903 | if ((linfo.flags & lf_can_create_pri) != 0) {
|
|---|
| 904 | rc = nchoice_add(choice, "Create partition",
|
|---|
| 905 | (void *)devac_create_pri_part, 0);
|
|---|
| 906 | if (rc != EOK) {
|
|---|
| 907 | assert(rc == ENOMEM);
|
|---|
| 908 | printf("Out of memory.\n");
|
|---|
| 909 | goto error;
|
|---|
| 910 | }
|
|---|
| 911 | }
|
|---|
| 912 | }
|
|---|
| 913 |
|
|---|
| 914 | if ((linfo.flags & lf_can_delete_part) != 0) {
|
|---|
| 915 | rc = nchoice_add(choice, "Delete partition",
|
|---|
| 916 | (void *)devac_delete_part, 0);
|
|---|
| 917 | if (rc != EOK) {
|
|---|
| 918 | assert(rc == ENOMEM);
|
|---|
| 919 | printf("Out of memory.\n");
|
|---|
| 920 | goto error;
|
|---|
| 921 | }
|
|---|
| 922 | }
|
|---|
| 923 |
|
|---|
| 924 | if ((dflags & fdf_can_create_label) != 0) {
|
|---|
| 925 | rc = nchoice_add(choice, "Create label",
|
|---|
| 926 | (void *)devac_create_label, 0);
|
|---|
| 927 | if (rc != EOK) {
|
|---|
| 928 | assert(rc == ENOMEM);
|
|---|
| 929 | printf("Out of memory.\n");
|
|---|
| 930 | goto error;
|
|---|
| 931 | }
|
|---|
| 932 | }
|
|---|
| 933 |
|
|---|
| 934 | if ((dflags & fdf_can_delete_label) != 0) {
|
|---|
| 935 | rc = nchoice_add(choice, "Delete label",
|
|---|
| 936 | (void *)devac_delete_label, 0);
|
|---|
| 937 | if (rc != EOK) {
|
|---|
| 938 | assert(rc == ENOMEM);
|
|---|
| 939 | printf("Out of memory.\n");
|
|---|
| 940 | goto error;
|
|---|
| 941 | }
|
|---|
| 942 | }
|
|---|
| 943 |
|
|---|
| 944 | if ((dflags & fdf_can_erase_dev) != 0) {
|
|---|
| 945 | rc = nchoice_add(choice, "Erase disk",
|
|---|
| 946 | (void *)devac_erase_disk, 0);
|
|---|
| 947 | if (rc != EOK) {
|
|---|
| 948 | assert(rc == ENOMEM);
|
|---|
| 949 | printf("Out of memory.\n");
|
|---|
| 950 | goto error;
|
|---|
| 951 | }
|
|---|
| 952 | }
|
|---|
| 953 |
|
|---|
| 954 | rc = nchoice_add(choice, "Exit", (void *)devac_exit, 0);
|
|---|
| 955 | if (rc != EOK) {
|
|---|
| 956 | assert(rc == ENOMEM);
|
|---|
| 957 | printf("Out of memory.\n");
|
|---|
| 958 | goto error;
|
|---|
| 959 | }
|
|---|
| 960 |
|
|---|
| 961 | rc = nchoice_get(choice, &sel);
|
|---|
| 962 | if (rc != EOK) {
|
|---|
| 963 | printf("Error getting user selection.\n");
|
|---|
| 964 | return rc;
|
|---|
| 965 | }
|
|---|
| 966 |
|
|---|
| 967 | switch ((devac_t)sel) {
|
|---|
| 968 | case devac_create_label:
|
|---|
| 969 | (void) fdsk_create_label(dev);
|
|---|
| 970 | break;
|
|---|
| 971 | case devac_delete_label:
|
|---|
| 972 | (void) fdsk_delete_label(dev);
|
|---|
| 973 | break;
|
|---|
| 974 | case devac_erase_disk:
|
|---|
| 975 | (void) fdsk_erase_disk(dev);
|
|---|
| 976 | break;
|
|---|
| 977 | case devac_create_pri_part:
|
|---|
| 978 | (void) fdsk_create_part(dev, lpk_primary);
|
|---|
| 979 | break;
|
|---|
| 980 | case devac_create_ext_part:
|
|---|
| 981 | (void) fdsk_create_part(dev, lpk_extended);
|
|---|
| 982 | break;
|
|---|
| 983 | case devac_create_log_part:
|
|---|
| 984 | (void) fdsk_create_part(dev, lpk_logical);
|
|---|
| 985 | break;
|
|---|
| 986 | case devac_delete_part:
|
|---|
| 987 | (void) fdsk_delete_part(dev);
|
|---|
| 988 | break;
|
|---|
| 989 | case devac_exit:
|
|---|
| 990 | quit = true;
|
|---|
| 991 | break;
|
|---|
| 992 | }
|
|---|
| 993 |
|
|---|
| 994 | nchoice_destroy(choice);
|
|---|
| 995 | return EOK;
|
|---|
| 996 | error:
|
|---|
| 997 | free(sdcap);
|
|---|
| 998 | free(scap);
|
|---|
| 999 | free(smcap);
|
|---|
| 1000 | free(sfstype);
|
|---|
| 1001 | free(svcname);
|
|---|
| 1002 | if (choice != NULL)
|
|---|
| 1003 | nchoice_destroy(choice);
|
|---|
| 1004 | return rc;
|
|---|
| 1005 | }
|
|---|
| 1006 |
|
|---|
| 1007 | int main(int argc, char *argv[])
|
|---|
| 1008 | {
|
|---|
| 1009 | service_id_t svcid;
|
|---|
| 1010 | fdisk_dev_t *dev;
|
|---|
| 1011 | int rc;
|
|---|
| 1012 |
|
|---|
| 1013 | rc = fdisk_create(&fdisk);
|
|---|
| 1014 | if (rc != EOK) {
|
|---|
| 1015 | printf("Error initializing Fdisk.\n");
|
|---|
| 1016 | return 1;
|
|---|
| 1017 | }
|
|---|
| 1018 |
|
|---|
| 1019 | rc = fdsk_dev_sel_choice(&svcid);
|
|---|
| 1020 | if (rc != EOK)
|
|---|
| 1021 | return 1;
|
|---|
| 1022 |
|
|---|
| 1023 | if (svcid == 0)
|
|---|
| 1024 | return 0;
|
|---|
| 1025 |
|
|---|
| 1026 | rc = fdisk_dev_open(fdisk, svcid, &dev);
|
|---|
| 1027 | if (rc != EOK) {
|
|---|
| 1028 | printf("Error opening device.\n");
|
|---|
| 1029 | return 1;
|
|---|
| 1030 | }
|
|---|
| 1031 |
|
|---|
| 1032 | while (!quit) {
|
|---|
| 1033 | rc = fdsk_dev_menu(dev);
|
|---|
| 1034 | if (rc != EOK) {
|
|---|
| 1035 | fdisk_dev_close(dev);
|
|---|
| 1036 | return 1;
|
|---|
| 1037 | }
|
|---|
| 1038 | }
|
|---|
| 1039 |
|
|---|
| 1040 | fdisk_dev_close(dev);
|
|---|
| 1041 | fdisk_destroy(fdisk);
|
|---|
| 1042 |
|
|---|
| 1043 | return 0;
|
|---|
| 1044 | }
|
|---|
| 1045 |
|
|---|
| 1046 |
|
|---|
| 1047 | /** @}
|
|---|
| 1048 | */
|
|---|