Ignore:
File:
1 edited

Legend:

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

    r90ee338 rca127f37  
    11/*
    2  * Copyright (c) 2025 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    4747#include <str.h>
    4848#include <str_error.h>
    49 #include <system.h>
    5049#include <vfs/vfs.h>
    5150#include <vol.h>
     
    6463 */
    6564#define DEFAULT_DEV_0 "devices/\\hw\\sys\\00:01.1\\c0d0"
    66 #define DEFAULT_DEV_1 "devices/\\hw\\sys\\00:01.0\\ide1\\c0d0"
     65#define DEFAULT_DEV_1 "devices/\\hw\\sys\\00:01.0\\ata1\\c0d0"
    6766//#define DEFAULT_DEV "devices/\\hw\\pci0\\00:01.2\\uhci_rh\\usb01_a1\\mass-storage0\\l0"
    6867/** Volume label for the new file system */
     
    9594        NULL
    9695};
    97 
    98 static bool restart = false;
    99 
    100 static fibril_mutex_t shutdown_lock;
    101 static fibril_condvar_t shutdown_cv;
    102 static bool shutdown_stopped;
    103 static bool shutdown_failed;
    104 
    105 static void sysinst_shutdown_complete(void *);
    106 static void sysinst_shutdown_failed(void *);
    107 
    108 static system_cb_t sysinst_system_cb = {
    109         .shutdown_complete = sysinst_shutdown_complete,
    110         .shutdown_failed = sysinst_shutdown_failed
    111 };
    112 
    113 /** System shutdown complete.
    114  *
    115  * @param arg Argument (shutdown_t *)
    116  */
    117 static void sysinst_shutdown_complete(void *arg)
    118 {
    119         (void)arg;
    120 
    121         fibril_mutex_lock(&shutdown_lock);
    122         shutdown_stopped = true;
    123         shutdown_failed = false;
    124         fibril_condvar_broadcast(&shutdown_cv);
    125         fibril_mutex_unlock(&shutdown_lock);
    126 }
    127 
    128 /** System shutdown failed.
    129  *
    130  * @param arg Argument (not used)
    131  */
    132 static void sysinst_shutdown_failed(void *arg)
    133 {
    134         (void)arg;
    135 
    136         fibril_mutex_lock(&shutdown_lock);
    137         shutdown_stopped = true;
    138         shutdown_failed = true;
    139         fibril_condvar_broadcast(&shutdown_cv);
    140         fibril_mutex_unlock(&shutdown_lock);
    141 }
    14296
    14397/** Check the if the destination device exists.
     
    521475        }
    522476
    523         rc = vol_part_eject(vol, part_id, vef_physical);
     477        rc = vol_part_eject(vol, part_id);
    524478        if (rc != EOK) {
    525479                printf("Error ejecting volume.\n");
     
    533487}
    534488
    535 /** Restart the system.
    536  *
    537  * @return EOK on success or an error code
    538  */
    539 static errno_t sysinst_restart(void)
    540 {
    541         errno_t rc;
    542         system_t *system;
    543 
    544         fibril_mutex_initialize(&shutdown_lock);
    545         fibril_condvar_initialize(&shutdown_cv);
    546         shutdown_stopped = false;
    547         shutdown_failed = false;
    548 
    549         rc = system_open(SYSTEM_DEFAULT, &sysinst_system_cb, NULL, &system);
    550         if (rc != EOK) {
    551                 printf("Failed opening system control service.\n");
    552                 return rc;
    553         }
    554 
    555         rc = system_restart(system);
    556         if (rc != EOK) {
    557                 system_close(system);
    558                 printf("Failed requesting system restart.\n");
    559                 return rc;
    560         }
    561 
    562         fibril_mutex_lock(&shutdown_lock);
    563         printf("The system is shutting down...\n");
    564         while (!shutdown_stopped)
    565                 fibril_condvar_wait(&shutdown_cv, &shutdown_lock);
    566 
    567         if (shutdown_failed) {
    568                 printf("Shutdown failed.\n");
    569                 system_close(system);
    570                 return rc;
    571         }
    572 
    573         printf("Shutdown complete. It is now safe to remove power.\n");
    574 
    575         /* Sleep forever */
    576         while (true)
    577                 fibril_condvar_wait(&shutdown_cv, &shutdown_lock);
    578 
    579         fibril_mutex_unlock(&shutdown_lock);
    580 
    581         system_close(system);
    582         return 0;
    583 
    584 }
    585 
    586489/** Install system to a device.
    587490 *
     
    623526                return rc;
    624527
    625         rc = sysinst_restart();
    626         if (rc != EOK)
    627                 return rc;
    628 
    629528        return EOK;
    630529}
     
    634533        unsigned i;
    635534        errno_t rc;
    636 
    637         if (argc > 1 && str_cmp(argv[1], "-r") == 0)
    638                 restart = true;
    639535
    640536        i = 0;
     
    643539                if (rc == EOK)
    644540                        break;
    645                 ++i;
    646541        }
    647542
Note: See TracChangeset for help on using the changeset viewer.