Changeset aca1777 in mainline for uspace/app/sysinst/sysinst.c


Ignore:
Timestamp:
2025-05-08T17:12:05Z (2 months ago)
Author:
Miroslav Cimerman <mc@…>
Children:
2f21cd4
Parents:
1cfce3f (diff), 61f28c4 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge upstream into helenraid

File:
1 edited

Legend:

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

    r1cfce3f raca1777  
    7373#define DEFAULT_DEV_0 "devices/\\hw\\sys\\00:01.1\\c0d0"
    7474#define DEFAULT_DEV_1 "devices/\\hw\\sys\\ide1\\c0d0"
     75#define DEFAULT_DEV_2 "devices/\\hw\\sys\\00:01.0\\ide1\\c0d0"
    7576//#define DEFAULT_DEV "devices/\\hw\\pci0\\00:01.2\\uhci_rh\\usb01_a1\\mass-storage0\\l0"
    7677/** Volume label for the new file system */
     
    9596        DEFAULT_DEV_0,
    9697        DEFAULT_DEV_1,
     98        DEFAULT_DEV_2,
    9799        NULL
    98100};
     
    155157static void sysinst_futil_copy_file(void *, const char *, const char *);
    156158static void sysinst_futil_create_dir(void *, const char *);
     159static errno_t sysinst_eject_dev(sysinst_t *, service_id_t);
     160static errno_t sysinst_eject_phys_by_mp(sysinst_t *, const char *);
    157161
    158162static futil_cb_t sysinst_futil_cb = {
     
    269273        case 0:
    270274                /* OK */
     275                sysinst_action(sysinst, "Ejecting installation media.");
     276                (void)sysinst_eject_phys_by_mp(sysinst, CD_MOUNT_POINT);
    271277                (void)sysinst_restart(sysinst);
    272278                break;
     
    424430}
    425431
    426 /** Label the destination device.
     432/** Label and mount the destination device.
    427433 *
    428434 * @param sysinst System installer
     
    432438 * @return EOK on success or an error code
    433439 */
    434 static errno_t sysinst_label_dev(sysinst_t *sysinst, const char *dev,
    435     service_id_t *psvc_id)
    436 {
    437         fdisk_t *fdisk;
    438         fdisk_dev_t *fdev;
     440static errno_t sysinst_label_dev(sysinst_t *sysinst, const char *dev)
     441{
     442        fdisk_t *fdisk = NULL;
     443        fdisk_dev_t *fdev = NULL;
    439444        fdisk_part_t *part;
    440445        fdisk_part_spec_t pspec;
    441446        fdisk_part_info_t pinfo;
     447        bool dir_created = false;
     448        bool label_created = false;
    442449        capa_spec_t capa;
    443450        service_id_t sid;
     
    448455        rc = loc_service_get_id(dev, &sid, 0);
    449456        if (rc != EOK)
    450                 return rc;
     457                goto error;
    451458
    452459        sysinst_debug(sysinst, "sysinst_label_dev(): open device");
     
    455462        if (rc != EOK) {
    456463                sysinst_error(sysinst, "Error initializing fdisk.");
    457                 return rc;
     464                goto error;
    458465        }
    459466
     
    461468        if (rc != EOK) {
    462469                sysinst_error(sysinst, "Error opening device.");
    463                 return rc;
     470                goto error;
    464471        }
    465472
     
    469476        if (rc != EOK) {
    470477                sysinst_error(sysinst, "Error creating mount directory.");
    471                 return rc;
    472         }
     478                goto error;
     479        }
     480
     481        dir_created = true;
    473482
    474483        sysinst_debug(sysinst, "sysinst_label_dev(): create label");
     
    477486        if (rc != EOK) {
    478487                sysinst_error(sysinst, "Error creating label.");
    479                 return rc;
    480         }
     488                goto error;
     489        }
     490
     491        label_created = true;
    481492
    482493        sysinst_debug(sysinst, "sysinst_label_dev(): create partition");
     
    486497                sysinst_error(sysinst,
    487498                    "Error getting available capacity.");
    488                 return rc;
     499                goto error;
    489500        }
    490501
     
    499510        if (rc != EOK) {
    500511                sysinst_error(sysinst, "Error creating partition.");
    501                 return rc;
     512                goto error;
    502513        }
    503514
     
    505516        if (rc != EOK) {
    506517                sysinst_error(sysinst, "Error getting partition information.");
    507                 return rc;
     518                goto error;
    508519        }
    509520
    510521        sysinst_debug(sysinst, "sysinst_label_dev(): OK");
    511         *psvc_id = pinfo.svc_id;
     522        fdisk_dev_close(fdev);
     523        fdisk_destroy(fdisk);
     524        sysinst->psvc_id = pinfo.svc_id;
     525        return EOK;
     526error:
     527        if (label_created)
     528                fdisk_label_destroy(fdev);
     529        if (dir_created)
     530                (void)vfs_unlink_path(MOUNT_POINT);
     531        if (fdev != NULL)
     532                fdisk_dev_close(fdev);
     533        if (fdisk != NULL)
     534                fdisk_destroy(fdisk);
     535        return rc;
     536}
     537
     538/** Finish/unmount destination device.
     539 *
     540 * @param sysinst System installer
     541 *
     542 * @return EOK on success or an error code
     543 */
     544static errno_t sysinst_finish_dev(sysinst_t *sysinst)
     545{
     546        errno_t rc;
     547
     548        sysinst_debug(sysinst, "sysinst_finish_dev(): eject target volume");
     549        rc = sysinst_eject_dev(sysinst, sysinst->psvc_id);
     550        if (rc != EOK)
     551                return rc;
     552
     553        sysinst_debug(sysinst, "sysinst_finish_dev(): "
     554            "deleting mount directory");
     555        (void)vfs_unlink_path(MOUNT_POINT);
     556
    512557        return EOK;
    513558}
     
    550595        rc = futil_rcopy_contents(sysinst->futil, CFG_FILES_SRC,
    551596            CFG_FILES_DEST);
    552         if (rc != EOK)
    553                 return rc;
     597        if (rc != EOK) {
     598                sysinst_error(sysinst, "Error copying initial configuration "
     599                    "files.");
     600                return rc;
     601        }
    554602
    555603        return EOK;
     
    571619            "sysinst_copy_boot_files(): copy bootloader files");
    572620        rc = futil_rcopy_contents(sysinst->futil, BOOT_FILES_SRC, MOUNT_POINT);
    573         if (rc != EOK)
    574                 return rc;
     621        if (rc != EOK) {
     622                sysinst_error(sysinst, "Error copying bootloader "
     623                    "files.");
     624                return rc;
     625        }
    575626
    576627        sysinst_debug(sysinst, "sysinst_copy_boot_files(): OK");
     
    811862 *
    812863 * @param sysinst System installer
    813  * @param psvc_id Partition service ID
     864 * @param part_id Partition service ID
    814865 * @return EOK on success or an error code
    815866 */
     
    825876        }
    826877
    827         rc = vol_part_eject(vol, part_id, vef_physical);
     878        rc = vol_part_eject(vol, part_id, vef_none);
    828879        if (rc != EOK) {
    829880                sysinst_error(sysinst, "Error ejecting volume.");
     
    837888}
    838889
     890/** Physically eject volume by mount point.
     891 *
     892 * @param sysinst System installer
     893 * @param path Mount point
     894 * @return EOK on success or an error code
     895 */
     896static errno_t sysinst_eject_phys_by_mp(sysinst_t *sysinst, const char *path)
     897{
     898        vol_t *vol = NULL;
     899        sysarg_t part_id;
     900        errno_t rc;
     901
     902        log_msg(LOG_DEFAULT, LVL_NOTE,
     903            "sysinst_eject_phys_by_mp(%s)", path);
     904
     905        rc = vol_create(&vol);
     906        if (rc != EOK) {
     907                sysinst_error(sysinst, "Error contacting volume service.");
     908                goto out;
     909        }
     910
     911        log_msg(LOG_DEFAULT, LVL_NOTE, "vol_part_by_mp: mp='%s'\n",
     912            path);
     913        rc = vol_part_by_mp(vol, path, &part_id);
     914        if (rc != EOK) {
     915                sysinst_error(sysinst,
     916                    "Error finding installation media mount point.");
     917                goto out;
     918        }
     919
     920        log_msg(LOG_DEFAULT, LVL_NOTE, "eject svc_id %lu", (unsigned long)part_id);
     921        rc = vol_part_eject(vol, part_id, vef_physical);
     922        if (rc != EOK) {
     923                sysinst_error(sysinst, "Error ejecting volume.");
     924                goto out;
     925        }
     926
     927        rc = EOK;
     928out:
     929        vol_destroy(vol);
     930        return rc;
     931}
     932
    839933/** Restart the system.
    840934 *
     
    852946        shutdown_failed = false;
    853947
     948        sysinst_action(sysinst, "Restarting the system.");
     949
    854950        rc = system_open(SYSTEM_DEFAULT, &sysinst_system_cb, NULL, &system);
    855951        if (rc != EOK) {
     
    901997{
    902998        errno_t rc;
    903         service_id_t psvc_id;
     999        bool clean_dev = false;
    9041000
    9051001        sysinst_action(sysinst, "Creating device label and file system.");
    9061002
    907         rc = sysinst_label_dev(sysinst, dev, &psvc_id);
    908         if (rc != EOK)
    909                 return rc;
     1003        rc = sysinst_label_dev(sysinst, dev);
     1004        if (rc != EOK)
     1005                goto error;
     1006
     1007        clean_dev = true;
    9101008
    9111009        sysinst_action(sysinst, "Creating system directory structure.");
    9121010        rc = sysinst_setup_sysvol(sysinst);
    9131011        if (rc != EOK)
    914                 return rc;
     1012                goto error;
    9151013
    9161014        sysinst_action(sysinst, "Copying boot files.");
    9171015        rc = sysinst_copy_boot_files(sysinst);
    9181016        if (rc != EOK)
    919                 return rc;
     1017                goto error;
    9201018
    9211019        sysinst_action(sysinst, "Configuring the system.");
    9221020        rc = sysinst_customize_initrd(sysinst);
    9231021        if (rc != EOK)
    924                 return rc;
     1022                goto error;
     1023
     1024        sysinst_action(sysinst, "Finishing system volume.");
     1025        rc = sysinst_finish_dev(sysinst);
     1026        if (rc != EOK)
     1027                goto error;
     1028
     1029        clean_dev = false;
    9251030
    9261031        sysinst_action(sysinst, "Installing boot blocks.");
     
    9291034                return rc;
    9301035
    931         sysinst_action(sysinst, "Ejecting device.");
    932         rc = sysinst_eject_dev(sysinst, psvc_id);
    933         if (rc != EOK)
    934                 return rc;
    935 
    936         return EOK;
     1036        return EOK;
     1037error:
     1038        if (clean_dev)
     1039                (void)sysinst_finish_dev(sysinst);
     1040        return rc;
    9371041}
    9381042
     
    9691073
    9701074        sysinst_progress_destroy(sysinst->progress);
     1075        sysinst->progress = NULL;
     1076
    9711077        rc = sysinst_restart_dlg_create(sysinst);
    9721078        if (rc != EOK)
     
    11471253static void sysinst_action(sysinst_t *sysinst, const char *action)
    11481254{
     1255        log_msg(LOG_DEFAULT, LVL_NOTE, "%s", action);
     1256
    11491257        if (sysinst->progress == NULL)
    11501258                return;
     
    11521260        ui_label_set_text(sysinst->progress->action, action);
    11531261        ui_label_paint(sysinst->progress->action);
    1154         log_msg(LOG_DEFAULT, LVL_NOTE, "%s", action);
    11551262}
    11561263
Note: See TracChangeset for help on using the changeset viewer.