Ignore:
File:
1 edited

Legend:

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

    rca127f37 r90ee338  
    11/*
    2  * Copyright (c) 2024 Jiri Svoboda
     2 * Copyright (c) 2025 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    4747#include <str.h>
    4848#include <str_error.h>
     49#include <system.h>
    4950#include <vfs/vfs.h>
    5051#include <vol.h>
     
    6364 */
    6465#define DEFAULT_DEV_0 "devices/\\hw\\sys\\00:01.1\\c0d0"
    65 #define DEFAULT_DEV_1 "devices/\\hw\\sys\\00:01.0\\ata1\\c0d0"
     66#define DEFAULT_DEV_1 "devices/\\hw\\sys\\00:01.0\\ide1\\c0d0"
    6667//#define DEFAULT_DEV "devices/\\hw\\pci0\\00:01.2\\uhci_rh\\usb01_a1\\mass-storage0\\l0"
    6768/** Volume label for the new file system */
     
    9495        NULL
    9596};
     97
     98static bool restart = false;
     99
     100static fibril_mutex_t shutdown_lock;
     101static fibril_condvar_t shutdown_cv;
     102static bool shutdown_stopped;
     103static bool shutdown_failed;
     104
     105static void sysinst_shutdown_complete(void *);
     106static void sysinst_shutdown_failed(void *);
     107
     108static 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 */
     117static 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 */
     132static 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}
    96142
    97143/** Check the if the destination device exists.
     
    475521        }
    476522
    477         rc = vol_part_eject(vol, part_id);
     523        rc = vol_part_eject(vol, part_id, vef_physical);
    478524        if (rc != EOK) {
    479525                printf("Error ejecting volume.\n");
     
    487533}
    488534
     535/** Restart the system.
     536 *
     537 * @return EOK on success or an error code
     538 */
     539static 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
    489586/** Install system to a device.
    490587 *
     
    526623                return rc;
    527624
     625        rc = sysinst_restart();
     626        if (rc != EOK)
     627                return rc;
     628
    528629        return EOK;
    529630}
     
    533634        unsigned i;
    534635        errno_t rc;
     636
     637        if (argc > 1 && str_cmp(argv[1], "-r") == 0)
     638                restart = true;
    535639
    536640        i = 0;
     
    539643                if (rc == EOK)
    540644                        break;
     645                ++i;
    541646        }
    542647
Note: See TracChangeset for help on using the changeset viewer.