Changeset 25444332 in mainline


Ignore:
Timestamp:
2026-04-06T14:26:00Z (22 hours ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master
Children:
4116579, 8bf4494
Parents:
4f16db1
Message:

Sysinst should be able to install to an existing MBR label.

Provided that the first partition slot is empty and the largest
free block is large enough.

Location:
uspace
Files:
3 edited

Legend:

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

    r4f16db1 r25444332  
    11/*
    2  * Copyright (c) 2025 Jiri Svoboda
     2 * Copyright (c) 2026 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    7575#define DEFAULT_DEV_2 "devices/\\hw\\sys\\00:01.0\\ide1\\c0d0"
    7676//#define DEFAULT_DEV "devices/\\hw\\pci0\\00:01.2\\uhci_rh\\usb01_a1\\mass-storage0\\l0"
     77/** Index of partition which we must install to (hardwired in load.cfg) */
     78#define INST_PART_IDX 1
    7779/** Volume label for the new file system */
    7880#define INST_VOL_LABEL "HelenOS"
     
    442444        fdisk_t *fdisk = NULL;
    443445        fdisk_dev_t *fdev = NULL;
     446        fdisk_label_info_t linfo;
    444447        fdisk_part_t *part;
    445448        fdisk_part_spec_t pspec;
    446449        fdisk_part_info_t pinfo;
     450        bool create_label = false;
    447451        bool dir_created = false;
    448452        bool label_created = false;
     
    483487        sysinst_debug(sysinst, "sysinst_label_dev(): create label");
    484488
    485         rc = fdisk_label_create(fdev, lt_mbr);
    486         if (rc != EOK) {
    487                 sysinst_error(sysinst, "Error creating label.");
    488                 goto error;
     489        rc = fdisk_label_get_info(fdev, &linfo);
     490        if (rc != EOK) {
     491                sysinst_error(sysinst, "Error analyzing device.");
     492                goto error;
     493        }
     494
     495        switch (linfo.ltype) {
     496        case lt_none:
     497                /* need to create label */
     498                create_label = true;
     499                break;
     500        case lt_mbr:
     501                /* MBR label already present */
     502                break;
     503        default:
     504                /* a different type of label already present */
     505                sysinst_error(sysinst, "Disk contains unusable label.");
     506                goto error;
     507        }
     508
     509        /* Need to create label? */
     510        if (create_label) {
     511                rc = fdisk_label_create(fdev, lt_mbr);
     512                if (rc != EOK) {
     513                        sysinst_error(sysinst, "Error creating label.");
     514                        goto error;
     515                }
    489516        }
    490517
     
    505532        pspec.fstype = fs_ext4; /* Cannot be changed without modifying core.img */
    506533        pspec.mountp = MOUNT_POINT;
     534        pspec.index = INST_PART_IDX; /* Cannot be changed without modifying core.img */
    507535        pspec.label = INST_VOL_LABEL;
    508536
  • uspace/lib/fdisk/include/types/fdisk.h

    r4f16db1 r25444332  
    11/*
    2  * Copyright (c) 2015 Jiri Svoboda
     2 * Copyright (c) 2026 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    155155        /** File system type */
    156156        vol_fstype_t fstype;
     157        /** Partition index, default/0 = assign automatically */
     158        int index;
    157159        /** Volume label */
    158160        const char *label;
     
    171173        /** File system type */
    172174        vol_fstype_t fstype;
     175        /** Partition index */
     176        int index;
    173177        /** Volume label */
    174178        char *label;
  • uspace/lib/fdisk/src/fdisk.c

    r4f16db1 r25444332  
    11/*
    2  * Copyright (c) 2025 Jiri Svoboda
     2 * Copyright (c) 2026 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    673673        info->fstype = part->fstype;
    674674        info->pkind = part->pkind;
     675        info->index = part->index;
    675676        info->label = part->label;
    676677        info->svc_id = part->svc_id;
     
    10311032
    10321033        if (pspec->pkind != lpk_logical) {
    1033                 rc = fdisk_part_get_free_idx(dev, &index);
    1034                 if (rc != EOK)
    1035                         return EIO;
     1034                if (pspec->index == 0) {
     1035                        /* allocate first free index */
     1036                        rc = fdisk_part_get_free_idx(dev, &index);
     1037                        if (rc != EOK)
     1038                                return EIO;
     1039                } else {
     1040                        /* user-specified index */
     1041                        index = pspec->index;
     1042                }
    10361043        } else {
    10371044                index = 0;
Note: See TracChangeset for help on using the changeset viewer.