Changeset 9c2c7d2 in mainline for uspace/app/fdisk/fdisk.c


Ignore:
Timestamp:
2017-07-06T15:52:15Z (8 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
5cd1eb9a
Parents:
d858a660
Message:

Fdisk should be able to set volume label for newly created partitions.

File:
1 edited

Legend:

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

    rd858a660 r9c2c7d2  
    4242#include <fdisk.h>
    4343
     44#define NO_LABEL_CAPTION "(No name)"
     45
    4446static bool quit = false;
    4547static fdisk_t *fdisk;
     
    445447        fdisk_cap_t cap;
    446448        fdisk_cap_t mcap;
     449        vol_label_supp_t vlsupp;
    447450        vol_fstype_t fstype = 0;
    448451        tinput_t *tinput = NULL;
     
    450453        char *scap;
    451454        char *smcap = NULL;
     455        char *label = NULL;
    452456
    453457        if (pkind == lpk_logical)
     
    502506        }
    503507
     508        fdisk_get_vollabel_support(dev, fstype, &vlsupp);
     509        if (vlsupp.supported) {
     510                tinput = tinput_new();
     511                if (tinput == NULL) {
     512                        rc = ENOMEM;
     513                        goto error;
     514                }
     515
     516                rc = tinput_set_prompt(tinput, "?> ");
     517                if (rc != EOK)
     518                        goto error;
     519
     520                /* Ask for volume label */
     521                printf("Enter volume label for new partition.\n");
     522                rc = tinput_read_i(tinput, "No name", &label);
     523                if (rc != EOK)
     524                        goto error;
     525
     526                tinput_destroy(tinput);
     527                tinput = NULL;
     528        }
     529
    504530        fdisk_pspec_init(&pspec);
    505531        pspec.capacity = cap;
    506532        pspec.pkind = pkind;
    507533        pspec.fstype = fstype;
     534        pspec.label = label;
    508535
    509536        rc = fdisk_part_create(dev, &pspec, NULL);
     
    513540        }
    514541
     542        free(label);
    515543        return EOK;
    516544error:
    517545        free(smcap);
     546        free(label);
    518547        if (tinput != NULL)
    519548                tinput_destroy(tinput);
     
    530559        char *sfstype = NULL;
    531560        char *sdesc = NULL;
     561        const char *label;
    532562        bool confirm;
    533563        void *sel;
     
    577607                        }
    578608
    579                         rc = asprintf(&sdesc, "%s, %s, %s", scap, spkind, sfstype);
     609                        if (str_size(pinfo.label) > 0)
     610                                label = pinfo.label;
     611                        else
     612                                label = "(No name)";
     613
     614                        rc = asprintf(&sdesc, "%s %s, %s, %s", label,
     615                            scap, spkind, sfstype);
    580616                        if (rc < 0) {
    581617                                rc = ENOMEM;
     
    773809                        label = pinfo.label;
    774810                else
    775                         label = "(No label)";
     811                        label = "(No name)";
    776812
    777813                if (linfo.ltype == lt_none)
Note: See TracChangeset for help on using the changeset viewer.