Changeset 29e7cc7 in mainline for uspace/app


Ignore:
Timestamp:
2025-04-18T15:14:10Z (12 months ago)
Author:
Miroslav Cimerman <mc@…>
Children:
e77c3ed
Parents:
800d188 (diff), 25fdb2d (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 branch 'upstream/master' into helenraid

Location:
uspace/app
Files:
12 edited
1 moved

Legend:

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

    r800d188 r29e7cc7  
    11/*
    2  * Copyright (c) 2024 Jiri Svoboda
     2 * Copyright (c) 2025 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    13551355        }
    13561356
    1357         if (i >= argc || str_cmp(argv[i], "display") == 0) {
    1358                 rc = demo_display(display_svc);
     1357        if (i >= argc || str_cmp(argv[i], "ui") == 0) {
     1358                rc = demo_ui(ui_display_spec);
    13591359                if (rc != EOK)
    13601360                        return 1;
     
    13631363                if (rc != EOK)
    13641364                        return 1;
    1365         } else if (str_cmp(argv[i], "ui") == 0) {
    1366                 rc = demo_ui(ui_display_spec);
     1365        } else if (str_cmp(argv[i], "display") == 0) {
     1366                rc = demo_display(display_svc);
    13671367                if (rc != EOK)
    13681368                        return 1;
  • uspace/app/hbench/env.c

    r800d188 r29e7cc7  
    3434 */
    3535
     36#include <adt/hash.h>
    3637#include <stdlib.h>
    3738#include <stdio.h>
     
    4243        ht_link_t link;
    4344
     45        size_t hash;
    4446        char *key;
    4547        char *value;
     
    4951{
    5052        param_t *param = hash_table_get_inst(item, param_t, link);
    51         return str_size(param->key);
     53        return param->hash;
    5254}
    5355
    5456static size_t param_key_hash(const void *key)
    5557{
    56         const char *key_str = key;
    57         return str_size(key_str);
     58        return hash_string(key);
    5859}
    5960
    60 static bool param_key_equal(const void *key, const ht_link_t *item)
     61static bool param_key_equal(const void *key, size_t hash, const ht_link_t *item)
    6162{
    6263        param_t *param = hash_table_get_inst(item, param_t, link);
     64
     65        if (param->hash != hash)
     66                return false;
     67
    6368        const char *key_str = key;
    64 
    6569        return str_cmp(param->key, key_str) == 0;
    6670}
     
    7175        param_t *b = hash_table_get_inst(link_b, param_t, link);
    7276
    73         return str_cmp(a->key, b->key) == 0;
     77        return a->hash == b->hash && str_cmp(a->key, b->key) == 0;
    7478}
    7579
     
    116120        param->key = str_dup(key);
    117121        param->value = str_dup(value);
     122        param->hash = hash_string(key);
    118123
    119124        if ((param->key == NULL) || (param->value == NULL)) {
     
    132137const char *bench_env_param_get(bench_env_t *env, const char *key, const char *default_value)
    133138{
    134         ht_link_t *item = hash_table_find(&env->parameters, (char *) key);
     139        ht_link_t *item = hash_table_find(&env->parameters, key);
    135140
    136141        if (item == NULL) {
  • uspace/app/kio/kio.c

    r800d188 r29e7cc7  
    11/*
    22 * Copyright (c) 2006 Ondrej Palkovsky
     3 * Copyright (c) 2025 Jiří Zárevúcky
    34 * All rights reserved.
    45 *
     
    3435 */
    3536
     37#include <_bits/decls.h>
     38#include <libarch/config.h>
    3639#include <stdio.h>
    3740#include <async.h>
     
    4750#include <adt/prodcons.h>
    4851#include <tinput.h>
     52#include <uchar.h>
    4953#include <vfs/vfs.h>
    5054
     
    5559typedef struct {
    5660        link_t link;
    57         size_t length;
    58         char32_t *data;
     61        size_t bytes;
     62        char *data;
    5963} item_t;
    6064
    6165static prodcons_t pc;
    62 
    63 /* Pointer to kio area */
    64 static char32_t *kio = (char32_t *) AS_AREA_ANY;
    65 static size_t kio_length;
    6666
    6767/* Notification mutex */
    6868static FIBRIL_MUTEX_INITIALIZE(mtx);
    6969
     70#define READ_BUFFER_SIZE PAGE_SIZE
     71
     72static size_t current_at;
     73static char read_buffer[READ_BUFFER_SIZE];
     74
    7075/** Klog producer
    7176 *
     
    7782 *
    7883 */
    79 static void producer(size_t length, char32_t *data)
    80 {
    81         item_t *item = (item_t *) malloc(sizeof(item_t));
     84static void producer(size_t bytes, char *data)
     85{
     86        item_t *item = malloc(sizeof(item_t));
    8287        if (item == NULL)
    8388                return;
    8489
    85         size_t sz = sizeof(char32_t) * length;
    86         char32_t *buf = (char32_t *) malloc(sz);
    87         if (buf == NULL) {
     90        item->bytes = bytes;
     91        item->data = malloc(bytes);
     92        if (!item->data) {
    8893                free(item);
    8994                return;
    9095        }
    9196
    92         memcpy(buf, data, sz);
     97        memcpy(item->data, data, bytes);
    9398
    9499        link_initialize(&item->link);
    95         item->length = length;
    96         item->data = buf;
    97100        prodcons_produce(&pc, &item->link);
    98101}
     
    120123                item_t *item = list_get_instance(link, item_t, link);
    121124
    122                 for (size_t i = 0; i < item->length; i++)
    123                         putuchar(item->data[i]);
    124 
    125                 if (log != NULL) {
    126                         for (size_t i = 0; i < item->length; i++)
    127                                 fputuc(item->data[i], log);
    128 
     125                fwrite(item->data, 1, item->bytes, stdout);
     126
     127                if (log) {
     128                        fwrite(item->data, 1, item->bytes, log);
    129129                        fflush(log);
    130130                        vfs_sync(fileno(log));
     
    149149static void kio_notification_handler(ipc_call_t *call, void *arg)
    150150{
     151        size_t kio_written = (size_t) ipc_get_arg1(call);
     152
    151153        /*
    152154         * Make sure we process only a single notification
    153155         * at any time to limit the chance of the consumer
    154156         * starving.
    155          *
    156          * Note: Usually the automatic masking of the kio
    157          * notifications on the kernel side does the trick
    158          * of limiting the chance of accidentally copying
    159          * the same data multiple times. However, due to
    160          * the non-blocking architecture of kio notifications,
    161          * this possibility cannot be generally avoided.
    162157         */
    163158
    164159        fibril_mutex_lock(&mtx);
    165160
    166         size_t kio_start = (size_t) ipc_get_arg1(call);
    167         size_t kio_len = (size_t) ipc_get_arg2(call);
    168         size_t kio_stored = (size_t) ipc_get_arg3(call);
    169 
    170         size_t offset = (kio_start + kio_len - kio_stored) % kio_length;
    171 
    172         /* Copy data from the ring buffer */
    173         if (offset + kio_stored >= kio_length) {
    174                 size_t split = kio_length - offset;
    175 
    176                 producer(split, kio + offset);
    177                 producer(kio_stored - split, kio);
    178         } else
    179                 producer(kio_stored, kio + offset);
     161        while (current_at != kio_written) {
     162                size_t read = kio_read(read_buffer, READ_BUFFER_SIZE, current_at);
     163                if (read == 0)
     164                        break;
     165
     166                current_at += read;
     167
     168                if (read > READ_BUFFER_SIZE) {
     169                        /* We missed some data. */
     170                        // TODO: Send a message with the number of lost characters to the consumer.
     171                        read = READ_BUFFER_SIZE;
     172                }
     173
     174                producer(read, read_buffer);
     175        }
    180176
    181177        async_event_unmask(EVENT_KIO);
     
    185181int main(int argc, char *argv[])
    186182{
    187         size_t pages;
    188         errno_t rc = sysinfo_get_value("kio.pages", &pages);
    189         if (rc != EOK) {
    190                 fprintf(stderr, "%s: Unable to get number of kio pages\n",
    191                     NAME);
    192                 return rc;
    193         }
    194 
    195         uintptr_t faddr;
    196         rc = sysinfo_get_value("kio.faddr", &faddr);
    197         if (rc != EOK) {
    198                 fprintf(stderr, "%s: Unable to get kio physical address\n",
    199                     NAME);
    200                 return rc;
    201         }
    202 
    203         size_t size = pages * PAGE_SIZE;
    204         kio_length = size / sizeof(char32_t);
    205 
    206         rc = physmem_map(faddr, pages, AS_AREA_READ | AS_AREA_CACHEABLE,
    207             (void *) &kio);
    208         if (rc != EOK) {
    209                 fprintf(stderr, "%s: Unable to map kio\n", NAME);
    210                 return rc;
    211         }
    212 
    213183        prodcons_initialize(&pc);
    214         rc = async_event_subscribe(EVENT_KIO, kio_notification_handler, NULL);
     184        errno_t rc = async_event_subscribe(EVENT_KIO, kio_notification_handler, NULL);
    215185        if (rc != EOK) {
    216186                fprintf(stderr, "%s: Unable to register kio notifications\n",
  • uspace/app/shutdown-dlg/shutdown-dlg.c

    r800d188 r29e7cc7  
    238238 *
    239239 * @param dialog Message dialog
    240  * @param arg Argument (ui_demo_t *)
     240 * @param arg Argument (shutdown_dlg_t *)
    241241 * @param earg Entry argument
    242242 */
     
    254254 *
    255255 * @param dialog Message dialog
    256  * @param arg Argument (ui_demo_t *)
     256 * @param arg Argument (shutdown_dlg_t *)
    257257 */
    258258static void shutdown_confirm_bcancel(ui_select_dialog_t *dialog, void *arg)
     
    267267 *
    268268 * @param dialog Message dialog
    269  * @param arg Argument (ui_demo_t *)
     269 * @param arg Argument (shutdown_dlg_t *)
    270270 */
    271271static void shutdown_confirm_close(ui_select_dialog_t *dialog, void *arg)
     
    280280 *
    281281 * @param dialog Message dialog
    282  * @param arg Argument (ui_demo_t *)
     282 * @param arg Argument (shutdown_dlg_t *)
    283283 * @param bnum Button number
    284284 */
     
    295295 *
    296296 * @param dialog Message dialog
    297  * @param arg Argument (ui_demo_t *)
     297 * @param arg Argument (shutdown_dlg_t *)
    298298 */
    299299static void shutdown_failed_msg_close(ui_msg_dialog_t *dialog, void *arg)
     
    480480
    481481        ui_wnd_params_init(&params);
    482         params.caption = "Shut down background";
     482        params.caption = "Shutdown";
    483483        params.style &= ~ui_wds_decorated;
    484484        params.placement = ui_wnd_place_full_screen;
    485485        params.flags |= ui_wndf_topmost | ui_wndf_nofocus;
    486         /*
    487          * params.rect.p0.x = 0;
    488          * params.rect.p0.y = 0;
    489          * params.rect.p1.x = 1;
    490          * params.rect.p1.y = 1;
    491          */
    492486
    493487        rc = ui_window_create(sddlg.ui, &params, &sddlg.bgwindow);
  • uspace/app/shutdown-dlg/shutdown-dlg.h

    r800d188 r29e7cc7  
    2727 */
    2828
    29 /** @addtogroup hello
     29/** @addtogroup shutdown-dlg
    3030 * @{
    3131 */
  • uspace/app/sysinst/meson.build

    r800d188 r29e7cc7  
    11#
    2 # Copyright (c) 2014 Jiri Svoboda
     2# Copyright (c) 2025 Jiri Svoboda
    33# All rights reserved.
    44#
     
    2727#
    2828
    29 deps = [ 'block', 'fdisk', 'futil', 'sif' ]
     29deps = [ 'block', 'fdisk', 'futil', 'sif', 'system', 'ui' ]
    3030src = files(
    3131        'rdimg.c',
  • uspace/app/sysinst/rdimg.c

    r800d188 r29e7cc7  
    3535#include <errno.h>
    3636#include <fibril.h>
     37#include <io/log.h>
    3738#include <stdio.h>
    3839#include <stdlib.h>
     
    6061        rc = vol_get_parts(vol, &part_ids, &nparts);
    6162        if (rc != EOK) {
    62                 printf("Error getting list of volumes.\n");
     63                log_msg(LOG_DEFAULT, LVL_ERROR,
     64                    "Error getting list of volumes.");
    6365                goto out;
    6466        }
     
    6769                rc = vol_part_info(vol, part_ids[i], &vinfo);
    6870                if (rc != EOK) {
    69                         printf("Error getting volume information.\n");
     71                        log_msg(LOG_DEFAULT, LVL_ERROR,
     72                            "Error getting volume information.");
    7073                        rc = EIO;
    7174                        goto out;
     
    106109        int cnt;
    107110
    108         printf("rd_img_open: begin\n");
     111        log_msg(LOG_DEFAULT, LVL_NOTE, "rd_img_open: begin");
     112
    109113        rdpath = str_dup("/vol/" RD_LABEL);
    110114        if (rdpath == NULL) {
     
    119123        }
    120124
    121         printf("rd_img_open: spawn file_bd\n");
     125        log_msg(LOG_DEFAULT, LVL_NOTE, "rd_img_open: spawn file_bd");
    122126        rc = task_spawnl(&id, &wait, FILE_BD, FILE_BD, imgpath, RD_SVC, NULL);
    123127        if (rc != EOK) {
     
    126130        }
    127131
    128         printf("rd_img_open: wait for file_bd\n");
     132        log_msg(LOG_DEFAULT, LVL_NOTE, "rd_img_open: wait for file_bd");
    129133        rc = task_wait(&wait, &texit, &retval);
    130134        if (rc != EOK || texit != TASK_EXIT_NORMAL) {
     
    134138
    135139        /* Wait for the RAM disk to become available */
    136         printf("rd_img_open: wait for RAM disk to be mounted\n");
     140        log_msg(LOG_DEFAULT, LVL_NOTE,
     141            "rd_img_open: wait for RAM disk to be mounted");
    137142        cnt = 10;
    138143        while (cnt > 0) {
     
    146151
    147152        if (cnt == 0) {
    148                 printf("rd_img_open: ran out of time\n");
     153                log_msg(LOG_DEFAULT, LVL_ERROR, "rd_img_open: ran out of time");
    149154                rc = EIO;
    150155                goto error;
     
    154159        *rimg = img;
    155160        *rpath = rdpath;
    156         printf("rd_img_open: success\n");
     161        log_msg(LOG_DEFAULT, LVL_NOTE, "rd_img_open: success");
    157162        return EOK;
    158163error:
     
    173178        vol_t *vol = NULL;
    174179
    175         printf("rd_img_close: begin\n");
     180        log_msg(LOG_DEFAULT, LVL_NOTE, "rd_img_close: begin");
    176181
    177182        rc = vol_create(&vol);
    178183        if (rc != EOK) {
    179                 printf("Error opening volume management service.\n");
    180                 rc = EIO;
    181                 goto error;
    182         }
    183 
    184         printf("rd_img_close: Find RAM disk volume.\n");
     184                log_msg(LOG_DEFAULT, LVL_ERROR,
     185                    "Error opening volume management service.");
     186                rc = EIO;
     187                goto error;
     188        }
     189
     190        log_msg(LOG_DEFAULT, LVL_NOTE, "rd_img_close: Find RAM disk volume.");
    185191        rc = rd_img_part_by_label(vol, RD_LABEL, &rd_svcid);
    186192        if (rc != EOK) {
    187                 printf("Error getting RAM disk service ID.\n");
    188                 rc = EIO;
    189                 goto error;
    190         }
    191 
    192         printf("rd_img_close: eject RAM disk volume\n");
     193                log_msg(LOG_DEFAULT, LVL_ERROR,
     194                    "Error getting RAM disk service ID.");
     195                rc = EIO;
     196                goto error;
     197        }
     198
     199        log_msg(LOG_DEFAULT, LVL_NOTE, "rd_img_close: eject RAM disk volume");
    193200        rc = vol_part_eject(vol, rd_svcid, vef_none);
    194201        if (rc != EOK) {
    195                 printf("Error ejecting RAM disk volume.\n");
     202                log_msg(LOG_DEFAULT, LVL_ERROR,
     203                    "Error ejecting RAM disk volume.");
    196204                rc = EIO;
    197205                goto error;
     
    202210        rc = task_kill(img->filebd_tid);
    203211        if (rc != EOK) {
    204                 printf("Error killing file_bd.\n");
     212                log_msg(LOG_DEFAULT, LVL_ERROR, "Error killing file_bd.");
    205213                rc = EIO;
    206214                goto error;
     
    208216
    209217        free(img);
    210         printf("rd_img_close: success\n");
     218        log_msg(LOG_DEFAULT, LVL_NOTE, "rd_img_close: success");
    211219        return EOK;
    212220error:
  • uspace/app/sysinst/sysinst.c

    r800d188 r29e7cc7  
    4242#include <fdisk.h>
    4343#include <futil.h>
     44#include <gfx/render.h>
     45#include <io/log.h>
    4446#include <loc.h>
    4547#include <stdio.h>
     
    4749#include <str.h>
    4850#include <str_error.h>
     51#include <system.h>
     52#include <ui/msgdialog.h>
     53#include <ui/ui.h>
     54#include <ui/window.h>
    4955#include <vfs/vfs.h>
    5056#include <vol.h>
     
    5359#include "rdimg.h"
    5460#include "volume.h"
     61#include "sysinst.h"
     62
     63#define NAME "sysinst"
    5564
    5665/** Device to install to
     
    6372 */
    6473#define DEFAULT_DEV_0 "devices/\\hw\\sys\\00:01.1\\c0d0"
    65 #define DEFAULT_DEV_1 "devices/\\hw\\sys\\00:01.0\\ata1\\c0d0"
     74#define DEFAULT_DEV_1 "devices/\\hw\\sys\\ide1\\c0d0"
    6675//#define DEFAULT_DEV "devices/\\hw\\pci0\\00:01.2\\uhci_rh\\usb01_a1\\mass-storage0\\l0"
    6776/** Volume label for the new file system */
     
    95104};
    96105
     106static fibril_mutex_t shutdown_lock;
     107static fibril_condvar_t shutdown_cv;
     108static bool shutdown_stopped;
     109static bool shutdown_failed;
     110
     111static void sysinst_shutdown_complete(void *);
     112static void sysinst_shutdown_failed(void *);
     113
     114static system_cb_t sysinst_system_cb = {
     115        .shutdown_complete = sysinst_shutdown_complete,
     116        .shutdown_failed = sysinst_shutdown_failed
     117};
     118
     119static void wnd_close(ui_window_t *, void *);
     120static errno_t bg_wnd_paint(ui_window_t *, void *);
     121
     122static ui_window_cb_t bg_window_cb = {
     123        .close = wnd_close,
     124        .paint = bg_wnd_paint
     125};
     126
     127static ui_window_cb_t progress_window_cb = {
     128        .close = wnd_close
     129};
     130
     131static void sysinst_confirm_button(ui_msg_dialog_t *, void *, unsigned);
     132static void sysinst_confirm_close(ui_msg_dialog_t *, void *);
     133
     134static ui_msg_dialog_cb_t sysinst_confirm_cb = {
     135        .button = sysinst_confirm_button,
     136        .close = sysinst_confirm_close
     137};
     138
     139static errno_t sysinst_restart_dlg_create(sysinst_t *);
     140static void sysinst_restart_dlg_button(ui_msg_dialog_t *, void *, unsigned);
     141static void sysinst_restart_dlg_close(ui_msg_dialog_t *, void *);
     142
     143static ui_msg_dialog_cb_t sysinst_restart_dlg_cb = {
     144        .button = sysinst_restart_dlg_button,
     145        .close = sysinst_restart_dlg_close
     146};
     147
     148static int sysinst_start(sysinst_t *);
     149static errno_t sysinst_restart(sysinst_t *);
     150static void sysinst_progress_destroy(sysinst_progress_t *);
     151static void sysinst_action(sysinst_t *, const char *);
     152static void sysinst_error(sysinst_t *, const char *);
     153static void sysinst_debug(sysinst_t *, const char *);
     154
     155static void sysinst_futil_copy_file(void *, const char *, const char *);
     156static void sysinst_futil_create_dir(void *, const char *);
     157
     158static futil_cb_t sysinst_futil_cb = {
     159        .copy_file = sysinst_futil_copy_file,
     160        .create_dir = sysinst_futil_create_dir
     161};
     162
     163static void sysinst_error_msg_button(ui_msg_dialog_t *, void *, unsigned);
     164static void sysinst_error_msg_close(ui_msg_dialog_t *, void *);
     165
     166static ui_msg_dialog_cb_t sysinst_error_msg_cb = {
     167        .button = sysinst_error_msg_button,
     168        .close = sysinst_error_msg_close
     169};
     170
     171/** Close window.
     172 *
     173 * @param window Window
     174 * @param arg Argument (sysinst_t *)
     175 */
     176static void wnd_close(ui_window_t *window, void *arg)
     177{
     178        (void)window;
     179        (void)arg;
     180}
     181
     182/** Paint background window.
     183 *
     184 * @param window Window
     185 * @param arg Argument (sysinst_t *)
     186 */
     187static errno_t bg_wnd_paint(ui_window_t *window, void *arg)
     188{
     189        sysinst_t *sysinst = (sysinst_t *)arg;
     190        gfx_rect_t app_rect;
     191        gfx_context_t *gc;
     192        errno_t rc;
     193
     194        gc = ui_window_get_gc(window);
     195
     196        rc = gfx_set_color(gc, sysinst->bg_color);
     197        if (rc != EOK)
     198                return rc;
     199
     200        ui_window_get_app_rect(window, &app_rect);
     201
     202        rc = gfx_fill_rect(gc, &app_rect);
     203        if (rc != EOK)
     204                return rc;
     205
     206        rc = gfx_update(gc);
     207        if (rc != EOK)
     208                return rc;
     209
     210        return EOK;
     211}
     212
     213/** Installation confirm dialog OK button press.
     214 *
     215 * @param dialog Message dialog
     216 * @param arg Argument (sysinst_t *)
     217 * @param btn Button number
     218 * @param earg Entry argument
     219 */
     220static void sysinst_confirm_button(ui_msg_dialog_t *dialog, void *arg,
     221    unsigned btn)
     222{
     223        sysinst_t *sysinst = (sysinst_t *) arg;
     224
     225        ui_msg_dialog_destroy(dialog);
     226
     227        switch (btn) {
     228        case 0:
     229                /* OK */
     230                sysinst_start(sysinst);
     231                break;
     232        default:
     233                /* Cancel */
     234                ui_quit(sysinst->ui);
     235                break;
     236        }
     237}
     238
     239/** Installation confirm dialog close request.
     240 *
     241 * @param dialog Message dialog
     242 * @param arg Argument (sysinst_t *)
     243 */
     244static void sysinst_confirm_close(ui_msg_dialog_t *dialog, void *arg)
     245{
     246        sysinst_t *sysinst = (sysinst_t *) arg;
     247
     248        ui_msg_dialog_destroy(dialog);
     249        ui_quit(sysinst->ui);
     250}
     251
     252/** Restart system dialog OK button press.
     253 *
     254 * @param dialog Message dialog
     255 * @param arg Argument (sysinst_t *)
     256 * @param btn Button number
     257 * @param earg Entry argument
     258 */
     259static void sysinst_restart_dlg_button(ui_msg_dialog_t *dialog, void *arg,
     260    unsigned btn)
     261{
     262        sysinst_t *sysinst = (sysinst_t *) arg;
     263
     264        ui_msg_dialog_destroy(dialog);
     265
     266        (void)sysinst;
     267
     268        switch (btn) {
     269        case 0:
     270                /* OK */
     271                (void)sysinst_restart(sysinst);
     272                break;
     273        default:
     274                /* Cancel */
     275                ui_quit(sysinst->ui);
     276                break;
     277        }
     278}
     279
     280/** Restat system dialog close request.
     281 *
     282 * @param dialog Message dialog
     283 * @param arg Argument (sysinst_t *)
     284 */
     285static void sysinst_restart_dlg_close(ui_msg_dialog_t *dialog, void *arg)
     286{
     287        sysinst_t *sysinst = (sysinst_t *) arg;
     288
     289        ui_msg_dialog_destroy(dialog);
     290        ui_quit(sysinst->ui);
     291}
     292
     293/** Installation error message dialog button press.
     294 *
     295 * @param dialog Message dialog
     296 * @param arg Argument (sysinst_t *)
     297 * @param bnum Button number
     298 */
     299static void sysinst_error_msg_button(ui_msg_dialog_t *dialog,
     300    void *arg, unsigned bnum)
     301{
     302        sysinst_t *sysinst = (sysinst_t *) arg;
     303
     304        ui_msg_dialog_destroy(dialog);
     305        ui_quit(sysinst->ui);
     306}
     307
     308/** Installation error message dialog close request.
     309 *
     310 * @param dialog Message dialog
     311 * @param arg Argument (shutdown_dlg_t *)
     312 */
     313static void sysinst_error_msg_close(ui_msg_dialog_t *dialog, void *arg)
     314{
     315        sysinst_t *sysinst = (sysinst_t *) arg;
     316
     317        ui_msg_dialog_destroy(dialog);
     318        ui_quit(sysinst->ui);
     319}
     320
     321/** Create error message dialog.
     322 *
     323 * @param sysinst System installer
     324 * @return EOK on success or an error code
     325 */
     326static errno_t sysinst_error_msg_create(sysinst_t *sysinst)
     327{
     328        ui_msg_dialog_params_t params;
     329        ui_msg_dialog_t *dialog;
     330        errno_t rc;
     331
     332        ui_msg_dialog_params_init(&params);
     333        params.caption = "Error";
     334        params.text = sysinst->errmsg;
     335        params.flags |= umdf_topmost | umdf_center;
     336
     337        rc = ui_msg_dialog_create(sysinst->ui, &params, &dialog);
     338        if (rc != EOK)
     339                return rc;
     340
     341        ui_msg_dialog_set_cb(dialog, &sysinst_error_msg_cb, (void *)sysinst);
     342
     343        return EOK;
     344}
     345
     346/** Called when futil is starting to copy a file.
     347 *
     348 * @param arg Argument (sysinst_t *)
     349 * @param src Source path
     350 * @param dest Destination path
     351 */
     352static void sysinst_futil_copy_file(void *arg, const char *src,
     353    const char *dest)
     354{
     355        sysinst_t *sysinst = (sysinst_t *)arg;
     356        char buf[128];
     357
     358        (void)src;
     359        snprintf(buf, sizeof(buf), "Copying %s.", dest);
     360        sysinst_action(sysinst, buf);
     361}
     362
     363/** Called when futil is about to create a directory.
     364 *
     365 * @param arg Argument (sysinst_t *)
     366 * @param dest Destination path
     367 */
     368static void sysinst_futil_create_dir(void *arg, const char *dest)
     369{
     370        sysinst_t *sysinst = (sysinst_t *)arg;
     371        char buf[128];
     372
     373        snprintf(buf, sizeof(buf), "Creating %s.", dest);
     374        sysinst_action(sysinst, buf);
     375}
     376
     377/** System shutdown complete.
     378 *
     379 * @param arg Argument (shutdown_t *)
     380 */
     381static void sysinst_shutdown_complete(void *arg)
     382{
     383        (void)arg;
     384
     385        fibril_mutex_lock(&shutdown_lock);
     386        shutdown_stopped = true;
     387        shutdown_failed = false;
     388        fibril_condvar_broadcast(&shutdown_cv);
     389        fibril_mutex_unlock(&shutdown_lock);
     390}
     391
     392/** System shutdown failed.
     393 *
     394 * @param arg Argument (not used)
     395 */
     396static void sysinst_shutdown_failed(void *arg)
     397{
     398        (void)arg;
     399
     400        fibril_mutex_lock(&shutdown_lock);
     401        shutdown_stopped = true;
     402        shutdown_failed = true;
     403        fibril_condvar_broadcast(&shutdown_cv);
     404        fibril_mutex_unlock(&shutdown_lock);
     405}
     406
    97407/** Check the if the destination device exists.
    98408 *
     
    116426/** Label the destination device.
    117427 *
     428 * @param sysinst System installer
    118429 * @param dev Disk device to label
    119430 * @param psvc_id Place to store service ID of the created partition
     
    121432 * @return EOK on success or an error code
    122433 */
    123 static errno_t sysinst_label_dev(const char *dev, service_id_t *psvc_id)
     434static errno_t sysinst_label_dev(sysinst_t *sysinst, const char *dev,
     435    service_id_t *psvc_id)
    124436{
    125437        fdisk_t *fdisk;
     
    132444        errno_t rc;
    133445
    134         printf("sysinst_label_dev(): get service ID '%s'\n", dev);
     446        sysinst_debug(sysinst, "sysinst_label_dev(): get service ID");
     447
    135448        rc = loc_service_get_id(dev, &sid, 0);
    136449        if (rc != EOK)
    137450                return rc;
    138451
    139         printf("sysinst_label_dev(): open device\n");
     452        sysinst_debug(sysinst, "sysinst_label_dev(): open device");
    140453
    141454        rc = fdisk_create(&fdisk);
    142455        if (rc != EOK) {
    143                 printf("Error initializing fdisk.\n");
     456                sysinst_error(sysinst, "Error initializing fdisk.");
    144457                return rc;
    145458        }
     
    147460        rc = fdisk_dev_open(fdisk, sid, &fdev);
    148461        if (rc != EOK) {
    149                 printf("Error opening device.\n");
    150                 return rc;
    151         }
    152 
    153         printf("sysinst_label_dev(): create mount directory\n");
     462                sysinst_error(sysinst, "Error opening device.");
     463                return rc;
     464        }
     465
     466        sysinst_debug(sysinst, "sysinst_label_dev(): create mount directory");
    154467
    155468        rc = vfs_link_path(MOUNT_POINT, KIND_DIRECTORY, NULL);
    156         if (rc != EOK)
    157                 return rc;
    158 
    159         printf("sysinst_label_dev(): create label\n");
     469        if (rc != EOK) {
     470                sysinst_error(sysinst, "Error creating mount directory.");
     471                return rc;
     472        }
     473
     474        sysinst_debug(sysinst, "sysinst_label_dev(): create label");
    160475
    161476        rc = fdisk_label_create(fdev, lt_mbr);
    162477        if (rc != EOK) {
    163                 printf("Error creating label: %s.\n", str_error(rc));
    164                 return rc;
    165         }
    166 
    167         printf("sysinst_label_dev(): create partition\n");
     478                sysinst_error(sysinst, "Error creating label.");
     479                return rc;
     480        }
     481
     482        sysinst_debug(sysinst, "sysinst_label_dev(): create partition");
    168483
    169484        rc = fdisk_part_get_max_avail(fdev, spc_pri, &capa);
    170485        if (rc != EOK) {
    171                 printf("Error getting available capacity: %s.\n", str_error(rc));
     486                sysinst_error(sysinst,
     487                    "Error getting available capacity.");
    172488                return rc;
    173489        }
     
    182498        rc = fdisk_part_create(fdev, &pspec, &part);
    183499        if (rc != EOK) {
    184                 printf("Error creating partition.\n");
     500                sysinst_error(sysinst, "Error creating partition.");
    185501                return rc;
    186502        }
     
    188504        rc = fdisk_part_get_info(part, &pinfo);
    189505        if (rc != EOK) {
    190                 printf("Error getting partition information.\n");
    191                 return rc;
    192         }
    193 
    194         printf("sysinst_label_dev(): OK\n");
     506                sysinst_error(sysinst, "Error getting partition information.");
     507                return rc;
     508        }
     509
     510        sysinst_debug(sysinst, "sysinst_label_dev(): OK");
    195511        *psvc_id = pinfo.svc_id;
    196512        return EOK;
     
    199515/** Set up system volume structure.
    200516 *
    201  * @return EOK on success or an error code
    202  */
    203 static errno_t sysinst_setup_sysvol(void)
     517 * @param sysinst System installer
     518 * @return EOK on success or an error code
     519 */
     520static errno_t sysinst_setup_sysvol(sysinst_t *sysinst)
    204521{
    205522        errno_t rc;
     
    218535                rc = vfs_link_path(path, KIND_DIRECTORY, NULL);
    219536                if (rc != EOK) {
    220                         printf("Error creating directory '%s'.\n", path);
     537                        sysinst_error(sysinst, "Error creating directory.");
    221538                        goto error;
    222539                }
     
    231548
    232549        /* Copy initial configuration files */
    233         rc = futil_rcopy_contents(CFG_FILES_SRC, CFG_FILES_DEST);
     550        rc = futil_rcopy_contents(sysinst->futil, CFG_FILES_SRC,
     551            CFG_FILES_DEST);
    234552        if (rc != EOK)
    235553                return rc;
     
    246564 * @return EOK on success or an error code
    247565 */
    248 static errno_t sysinst_copy_boot_files(void)
    249 {
    250         errno_t rc;
    251 
    252         printf("sysinst_copy_boot_files(): copy bootloader files\n");
    253         rc = futil_rcopy_contents(BOOT_FILES_SRC, MOUNT_POINT);
    254         if (rc != EOK)
    255                 return rc;
    256 
    257         printf("sysinst_copy_boot_files(): OK\n");
     566static errno_t sysinst_copy_boot_files(sysinst_t *sysinst)
     567{
     568        errno_t rc;
     569
     570        log_msg(LOG_DEFAULT, LVL_NOTE,
     571            "sysinst_copy_boot_files(): copy bootloader files");
     572        rc = futil_rcopy_contents(sysinst->futil, BOOT_FILES_SRC, MOUNT_POINT);
     573        if (rc != EOK)
     574                return rc;
     575
     576        sysinst_debug(sysinst, "sysinst_copy_boot_files(): OK");
    258577        return EOK;
    259578}
     
    261580/** Set up configuration in the initial RAM disk.
    262581 *
    263  * @return EOK on success or an error code
    264  */
    265 static errno_t sysinst_customize_initrd(void)
     582 * @param sysinst System installer
     583 * @return EOK on success or an error code
     584 */
     585static errno_t sysinst_customize_initrd(sysinst_t *sysinst)
    266586{
    267587        errno_t rc;
     
    275595        rc = rd_img_open(MOUNT_POINT "/boot/initrd.img", &rdpath, &rd);
    276596        if (rc != EOK) {
    277                 printf("Error opening initial RAM disk image.\n");
     597                sysinst_error(sysinst, "Error opening initial RAM disk image.");
    278598                goto error;
    279599        }
     
    285605        }
    286606
    287         printf("Configuring volume server.\n");
     607        sysinst_debug(sysinst, "Configuring volume server.");
     608
    288609        rc = vol_volumes_create(path, &volumes);
    289610        if (rc != EOK) {
    290                 printf("Error creating volume server configuration.\n");
     611                sysinst_error(sysinst,
     612                    "Error creating volume server configuration.");
    291613                rc = EIO;
    292614                goto error;
    293615        }
    294616
    295         printf("Configuring volume server: look up volume\n");
     617        sysinst_debug(sysinst, "Configuring volume server: look up volume");
    296618        rc = vol_volume_lookup_ref(volumes, INST_VOL_LABEL, &volume);
    297619        if (rc != EOK) {
    298                 printf("Error creating volume server configuration.\n");
     620                sysinst_error(sysinst,
     621                    "Error creating volume server configuration.");
    299622                rc = EIO;
    300623                goto error;
    301624        }
    302625
    303         printf("Configuring volume server: set mount point\n");
     626        sysinst_debug(sysinst, "Configuring volume server: set mount point");
    304627        rc = vol_volume_set_mountp(volume, INST_VOL_MP);
    305628        if (rc != EOK) {
    306                 printf("Error creating system partition configuration.\n");
     629                sysinst_error(sysinst,
     630                    "Error creating system partition configuration.");
    307631                rc = EIO;
    308632                goto error;
     
    311635        rc = vol_volumes_sync(volumes);
    312636        if (rc != EOK) {
    313                 printf("Error saving volume confiuration.\n");
    314                 goto error;
    315         }
    316 
    317         printf("Configuring volume server: delete reference\n");
     637                sysinst_error(sysinst, "Error saving volume confiuration.");
     638                goto error;
     639        }
     640
     641        log_msg(LOG_DEFAULT, LVL_NOTE,
     642            "Configuring volume server: delete reference");
    318643        vol_volume_del_ref(volume);
    319644        volume = NULL;
    320         printf("Configuring volume server: destroy volumes object\n");
     645        log_msg(LOG_DEFAULT, LVL_NOTE,
     646            "Configuring volume server: destroy volumes object");
    321647        vol_volumes_destroy(volumes);
    322648        volumes = NULL;
     
    324650        rc = rd_img_close(rd);
    325651        if (rc != EOK) {
    326                 printf("Error closing initial RAM disk image.\n");
     652                sysinst_error(sysinst, "Error closing initial RAM disk image.");
    327653                rc = EIO;
    328654                goto error;
     
    367693 * Install Grub's boot blocks.
    368694 *
     695 * @param sysinst System installer
    369696 * @param devp Disk device
    370697 * @return EOK on success or an error code
    371698 */
    372 static errno_t sysinst_copy_boot_blocks(const char *devp)
     699static errno_t sysinst_copy_boot_blocks(sysinst_t *sysinst, const char *devp)
    373700{
    374701        void *boot_img;
     
    384711        errno_t rc;
    385712
    386         printf("sysinst_copy_boot_blocks: Read boot block image.\n");
    387         rc = futil_get_file(BOOT_FILES_SRC "/boot/grub/i386-pc/boot.img",
     713        log_msg(LOG_DEFAULT, LVL_NOTE,
     714            "sysinst_copy_boot_blocks: Read boot block image.");
     715
     716        rc = futil_get_file(sysinst->futil,
     717            BOOT_FILES_SRC "/boot/grub/i386-pc/boot.img",
    388718            &boot_img, &boot_img_size);
    389719        if (rc != EOK || boot_img_size != 512)
    390720                return EIO;
    391721
    392         printf("sysinst_copy_boot_blocks: Read GRUB core image.\n");
    393         rc = futil_get_file(BOOT_FILES_SRC "/boot/grub/i386-pc/core.img",
     722        log_msg(LOG_DEFAULT, LVL_NOTE,
     723            "sysinst_copy_boot_blocks: Read GRUB core image.");
     724
     725        rc = futil_get_file(sysinst->futil,
     726            BOOT_FILES_SRC "/boot/grub/i386-pc/core.img",
    394727            &core_img, &core_img_size);
    395728        if (rc != EOK)
    396729                return EIO;
    397730
    398         printf("sysinst_copy_boot_blocks: get service ID.\n");
     731        log_msg(LOG_DEFAULT, LVL_NOTE,
     732            "sysinst_copy_boot_blocks: get service ID.");
     733
    399734        rc = loc_service_get_id(devp, &sid, 0);
    400735        if (rc != EOK)
    401736                return rc;
    402737
    403         printf("sysinst_copy_boot_blocks: block_init.\n");
     738        log_msg(LOG_DEFAULT, LVL_NOTE,
     739            "sysinst_copy_boot_blocks: block_init.");
     740
    404741        rc = block_init(sid);
    405742        if (rc != EOK)
    406743                return rc;
    407744
    408         printf("sysinst_copy_boot_blocks: get block size\n");
     745        log_msg(LOG_DEFAULT, LVL_NOTE,
     746            "sysinst_copy_boot_blocks: get block size");
     747
    409748        rc = block_get_bsize(sid, &bsize);
    410749        if (rc != EOK)
     
    412751
    413752        if (bsize != 512) {
    414                 printf("Device block size != 512.\n");
     753                sysinst_error(sysinst, "Device block size != 512.");
    415754                return EIO;
    416755        }
    417756
    418         printf("sysinst_copy_boot_blocks: read boot block\n");
     757        log_msg(LOG_DEFAULT, LVL_NOTE,
     758            "sysinst_copy_boot_blocks: read boot block");
     759
    419760        rc = block_read_direct(sid, BOOT_BLOCK_IDX, 1, bbuf);
    420761        if (rc != EOK)
     
    431772                --bl;
    432773                if ((void *)bl < core_img) {
    433                         printf("No block terminator in core image.\n");
     774                        sysinst_error(sysinst,
     775                            "No block terminator in core image.");
    434776                        return EIO;
    435777                }
     
    445787        set_unaligned_u64le(bbuf + grub_boot_machine_kernel_sector, core_start);
    446788
    447         printf("sysinst_copy_boot_blocks: write boot block\n");
     789        log_msg(LOG_DEFAULT, LVL_NOTE,
     790            "sysinst_copy_boot_blocks: write boot block");
     791
    448792        rc = block_write_direct(sid, BOOT_BLOCK_IDX, 1, bbuf);
    449793        if (rc != EOK)
    450794                return EIO;
    451795
    452         printf("sysinst_copy_boot_blocks: write core blocks\n");
     796        log_msg(LOG_DEFAULT, LVL_NOTE,
     797            "sysinst_copy_boot_blocks: write core blocks");
     798
    453799        /* XXX Must pad last block with zeros */
    454800        rc = block_write_direct(sid, core_start, core_blocks, core_img);
     
    456802                return EIO;
    457803
    458         printf("sysinst_copy_boot_blocks: OK.\n");
     804        log_msg(LOG_DEFAULT, LVL_NOTE,
     805            "sysinst_copy_boot_blocks: OK.");
     806
    459807        return EOK;
    460808}
     
    462810/** Eject installation volume.
    463811 *
     812 * @param sysinst System installer
    464813 * @param psvc_id Partition service ID
    465  */
    466 static errno_t sysinst_eject_dev(service_id_t part_id)
     814 * @return EOK on success or an error code
     815 */
     816static errno_t sysinst_eject_dev(sysinst_t *sysinst, service_id_t part_id)
    467817{
    468818        vol_t *vol = NULL;
     
    471821        rc = vol_create(&vol);
    472822        if (rc != EOK) {
    473                 printf("Error contacting volume service.\n");
     823                sysinst_error(sysinst, "Error contacting volume service.");
    474824                goto out;
    475825        }
     
    477827        rc = vol_part_eject(vol, part_id, vef_physical);
    478828        if (rc != EOK) {
    479                 printf("Error ejecting volume.\n");
     829                sysinst_error(sysinst, "Error ejecting volume.");
    480830                goto out;
    481831        }
     
    487837}
    488838
     839/** Restart the system.
     840 *
     841 * @param sysinst System installer
     842 * @return EOK on success or an error code
     843 */
     844static errno_t sysinst_restart(sysinst_t *sysinst)
     845{
     846        errno_t rc;
     847        system_t *system;
     848
     849        fibril_mutex_initialize(&shutdown_lock);
     850        fibril_condvar_initialize(&shutdown_cv);
     851        shutdown_stopped = false;
     852        shutdown_failed = false;
     853
     854        rc = system_open(SYSTEM_DEFAULT, &sysinst_system_cb, NULL, &system);
     855        if (rc != EOK) {
     856                sysinst_error(sysinst,
     857                    "Failed opening system control service.");
     858                return rc;
     859        }
     860
     861        rc = system_restart(system);
     862        if (rc != EOK) {
     863                system_close(system);
     864                sysinst_error(sysinst, "Failed requesting system restart.");
     865                return rc;
     866        }
     867
     868        fibril_mutex_lock(&shutdown_lock);
     869        sysinst_debug(sysinst, "The system is shutting down...");
     870
     871        while (!shutdown_stopped)
     872                fibril_condvar_wait(&shutdown_cv, &shutdown_lock);
     873
     874        if (shutdown_failed) {
     875                sysinst_error(sysinst, "Shutdown failed.");
     876                system_close(system);
     877                return rc;
     878        }
     879
     880        log_msg(LOG_DEFAULT, LVL_NOTE,
     881            "Shutdown complete. It is now safe to remove power.");
     882
     883        /* Sleep forever */
     884        while (true)
     885                fibril_condvar_wait(&shutdown_cv, &shutdown_lock);
     886
     887        fibril_mutex_unlock(&shutdown_lock);
     888
     889        system_close(system);
     890        return 0;
     891
     892}
     893
    489894/** Install system to a device.
    490895 *
     896 * @parma sysinst System installer
    491897 * @param dev Device to install to.
    492898 * @return EOK on success or an error code
    493899 */
    494 static errno_t sysinst_install(const char *dev)
     900static errno_t sysinst_install(sysinst_t *sysinst, const char *dev)
    495901{
    496902        errno_t rc;
    497903        service_id_t psvc_id;
    498904
    499         rc = sysinst_label_dev(dev, &psvc_id);
    500         if (rc != EOK)
    501                 return rc;
    502 
    503         printf("FS created and mounted. Creating system directory structure.\n");
    504         rc = sysinst_setup_sysvol();
    505         if (rc != EOK)
    506                 return rc;
    507 
    508         printf("Directories created. Copying boot files.\n");
    509         rc = sysinst_copy_boot_files();
    510         if (rc != EOK)
    511                 return rc;
    512 
    513         printf("Boot files done. Configuring the system.\n");
    514         rc = sysinst_customize_initrd();
    515         if (rc != EOK)
    516                 return rc;
    517 
    518         printf("Boot files done. Installing boot blocks.\n");
    519         rc = sysinst_copy_boot_blocks(dev);
    520         if (rc != EOK)
    521                 return rc;
    522 
    523         printf("Ejecting device.\n");
    524         rc = sysinst_eject_dev(psvc_id);
    525         if (rc != EOK)
    526                 return rc;
    527 
    528         return EOK;
    529 }
    530 
    531 int main(int argc, char *argv[])
    532 {
     905        sysinst_action(sysinst, "Creating device label and file system.");
     906
     907        rc = sysinst_label_dev(sysinst, dev, &psvc_id);
     908        if (rc != EOK)
     909                return rc;
     910
     911        sysinst_action(sysinst, "Creating system directory structure.");
     912        rc = sysinst_setup_sysvol(sysinst);
     913        if (rc != EOK)
     914                return rc;
     915
     916        sysinst_action(sysinst, "Copying boot files.");
     917        rc = sysinst_copy_boot_files(sysinst);
     918        if (rc != EOK)
     919                return rc;
     920
     921        sysinst_action(sysinst, "Configuring the system.");
     922        rc = sysinst_customize_initrd(sysinst);
     923        if (rc != EOK)
     924                return rc;
     925
     926        sysinst_action(sysinst, "Installing boot blocks.");
     927        rc = sysinst_copy_boot_blocks(sysinst, dev);
     928        if (rc != EOK)
     929                return rc;
     930
     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;
     937}
     938
     939/** Installation fibril.
     940 *
     941 * @param arg Argument (sysinst_t *)
     942 * @return EOK on success or an error code
     943 */
     944static errno_t sysinst_install_fibril(void *arg)
     945{
     946        sysinst_t *sysinst = (sysinst_t *)arg;
    533947        unsigned i;
    534948        errno_t rc;
     949
     950        (void)sysinst;
    535951
    536952        i = 0;
     
    539955                if (rc == EOK)
    540956                        break;
     957                ++i;
    541958        }
    542959
    543960        if (default_devs[i] == NULL) {
    544                 printf("Cannot determine installation device.\n");
     961                sysinst_error(sysinst, "Cannot determine installation device.");
     962                rc = ENOENT;
     963                goto error;
     964        }
     965
     966        rc = sysinst_install(sysinst, default_devs[i]);
     967        if (rc != EOK)
     968                goto error;
     969
     970        sysinst_progress_destroy(sysinst->progress);
     971        rc = sysinst_restart_dlg_create(sysinst);
     972        if (rc != EOK)
     973                goto error;
     974
     975        return EOK;
     976error:
     977        ui_lock(sysinst->ui);
     978        sysinst_progress_destroy(sysinst->progress);
     979        (void)sysinst_error_msg_create(sysinst);
     980        ui_unlock(sysinst->ui);
     981        return rc;
     982}
     983
     984/** Create installation progress window.
     985 *
     986 * @param sysinst System installer
     987 * @param rprogress Place to store pointer to new progress window
     988 * @return EOK on success or an error code
     989 */
     990static errno_t sysinst_progress_create(sysinst_t *sysinst,
     991    sysinst_progress_t **rprogress)
     992{
     993        ui_wnd_params_t params;
     994        ui_window_t *window = NULL;
     995        gfx_rect_t rect;
     996        gfx_rect_t arect;
     997        ui_resource_t *ui_res;
     998        sysinst_progress_t *progress;
     999        ui_fixed_t *fixed = NULL;
     1000        errno_t rc;
     1001
     1002        ui_wnd_params_init(&params);
     1003        params.caption = "System Installation";
     1004        params.style &= ~ui_wds_titlebar;
     1005        params.flags |= ui_wndf_topmost;
     1006        params.placement = ui_wnd_place_center;
     1007        if (ui_is_textmode(sysinst->ui)) {
     1008                params.rect.p0.x = 0;
     1009                params.rect.p0.y = 0;
     1010                params.rect.p1.x = 64;
     1011                params.rect.p1.y = 5;
     1012        } else {
     1013                params.rect.p0.x = 0;
     1014                params.rect.p0.y = 0;
     1015                params.rect.p1.x = 500;
     1016                params.rect.p1.y = 60;
     1017        }
     1018
     1019        progress = calloc(1, sizeof(sysinst_progress_t));
     1020        if (progress == NULL) {
     1021                rc = ENOMEM;
     1022                sysinst_error(sysinst, "Out of memory.");
     1023                goto error;
     1024        }
     1025
     1026        rc = ui_window_create(sysinst->ui, &params, &window);
     1027        if (rc != EOK) {
     1028                sysinst_error(sysinst, "Error creating window.");
     1029                goto error;
     1030        }
     1031
     1032        ui_window_set_cb(window, &progress_window_cb, (void *)sysinst);
     1033
     1034        ui_res = ui_window_get_res(window);
     1035
     1036        rc = ui_fixed_create(&fixed);
     1037        if (rc != EOK) {
     1038                sysinst_error(sysinst, "Error creating fixed layout.");
     1039                goto error;
     1040        }
     1041
     1042        rc = ui_label_create(ui_res, "Installing system. Please wait...",
     1043            &progress->label);
     1044        if (rc != EOK) {
     1045                sysinst_error(sysinst, "Error creating label.");
     1046                goto error;
     1047        }
     1048
     1049        ui_window_get_app_rect(window, &arect);
     1050
     1051        if (ui_is_textmode(sysinst->ui)) {
     1052                rect.p0.x = arect.p0.x;
     1053                rect.p0.y = arect.p0.y;
     1054                rect.p1.x = arect.p1.x;
     1055                rect.p1.y = 2;
     1056        } else {
     1057                rect.p0.x = arect.p0.x;
     1058                rect.p0.y = arect.p0.y;
     1059                rect.p1.x = arect.p1.x;
     1060                rect.p1.y = 30;
     1061        }
     1062        ui_label_set_rect(progress->label, &rect);
     1063        ui_label_set_halign(progress->label, gfx_halign_center);
     1064        ui_label_set_valign(progress->label, gfx_valign_center);
     1065
     1066        rc = ui_fixed_add(fixed, ui_label_ctl(progress->label));
     1067        if (rc != EOK) {
     1068                sysinst_error(sysinst, "Error adding control to layout.");
     1069                ui_label_destroy(progress->label);
     1070                progress->label = NULL;
     1071                goto error;
     1072        }
     1073
     1074        rc = ui_label_create(ui_res, "",
     1075            &progress->action);
     1076        if (rc != EOK) {
     1077                sysinst_error(sysinst, "Error creating label.");
     1078                goto error;
     1079        }
     1080
     1081        if (ui_is_textmode(sysinst->ui)) {
     1082                rect.p0.x = arect.p0.x;
     1083                rect.p0.y = 3;
     1084                rect.p1.x = arect.p1.x;
     1085                rect.p1.y = arect.p1.y;
     1086        } else {
     1087                rect.p0.x = arect.p0.x;
     1088                rect.p0.y = 30;
     1089                rect.p1.x = arect.p1.x;
     1090                rect.p1.y = arect.p1.y;
     1091        }
     1092        ui_label_set_rect(progress->action, &rect);
     1093        ui_label_set_halign(progress->action, gfx_halign_center);
     1094        ui_label_set_valign(progress->action, gfx_valign_center);
     1095
     1096        rc = ui_fixed_add(fixed, ui_label_ctl(progress->action));
     1097        if (rc != EOK) {
     1098                sysinst_error(sysinst, "Error adding control to layout.");
     1099                ui_label_destroy(progress->label);
     1100                progress->label = NULL;
     1101                goto error;
     1102        }
     1103
     1104        ui_window_add(window, ui_fixed_ctl(fixed));
     1105        fixed = NULL;
     1106
     1107        rc = ui_window_paint(window);
     1108        if (rc != EOK) {
     1109                sysinst_error(sysinst, "Error painting window.");
     1110                goto error;
     1111        }
     1112
     1113        progress->window = window;
     1114        progress->fixed = fixed;
     1115        *rprogress = progress;
     1116        return EOK;
     1117error:
     1118        if (progress != NULL && progress->fixed != NULL)
     1119                ui_fixed_destroy(progress->fixed);
     1120        if (window != NULL)
     1121                ui_window_destroy(window);
     1122        if (progress != NULL)
     1123                free(progress);
     1124        return rc;
     1125}
     1126
     1127/** Destroy installation progress window.
     1128 *
     1129 * @param sysinst System installer
     1130 * @param rprogress Place to store pointer to new progress window
     1131 * @return EOK on success or an error code
     1132 */
     1133static void sysinst_progress_destroy(sysinst_progress_t *progress)
     1134{
     1135        if (progress == NULL)
     1136                return;
     1137
     1138        ui_window_destroy(progress->window);
     1139        free(progress);
     1140}
     1141
     1142/** Set current action message.
     1143 *
     1144 * @param sysinst System installer
     1145 * @param action Action text
     1146 */
     1147static void sysinst_action(sysinst_t *sysinst, const char *action)
     1148{
     1149        if (sysinst->progress == NULL)
     1150                return;
     1151
     1152        ui_label_set_text(sysinst->progress->action, action);
     1153        ui_label_paint(sysinst->progress->action);
     1154        log_msg(LOG_DEFAULT, LVL_NOTE, "%s", action);
     1155}
     1156
     1157/** Set current error message.
     1158 *
     1159 * @param sysinst System installer
     1160 * @param errmsg Error message
     1161 */
     1162static void sysinst_error(sysinst_t *sysinst, const char *errmsg)
     1163{
     1164        str_cpy(sysinst->errmsg, sizeof(sysinst->errmsg), errmsg);
     1165        log_msg(LOG_DEFAULT, LVL_ERROR, errmsg);
     1166}
     1167
     1168/** Log a debug message.
     1169 *
     1170 * @param sysinst System installer
     1171 * @param errmsg Error message
     1172 */
     1173static void sysinst_debug(sysinst_t *sysinst, const char *msg)
     1174{
     1175        log_msg(LOG_DEFAULT, LVL_ERROR, msg);
     1176}
     1177
     1178/** Start system installation.
     1179 *
     1180 * @param sysinst System installer
     1181 * @return EOK on success or an error code
     1182 */
     1183static int sysinst_start(sysinst_t *sysinst)
     1184{
     1185        errno_t rc;
     1186        fid_t fid;
     1187
     1188        rc = sysinst_progress_create(sysinst, &sysinst->progress);
     1189        if (rc != EOK)
     1190                return rc;
     1191
     1192        fid = fibril_create(sysinst_install_fibril, (void *)sysinst);
     1193        if (fid == 0) {
     1194                sysinst_error(sysinst, "Out of memory.");
     1195                return ENOMEM;
     1196        }
     1197
     1198        fibril_add_ready(fid);
     1199        return EOK;
     1200}
     1201
     1202/** Create installation confirmation dialog.
     1203 *
     1204 * @param sysinst System installer
     1205 * @return EOK on success or an error code
     1206 */
     1207static errno_t sysinst_confirm_create(sysinst_t *sysinst)
     1208{
     1209        ui_msg_dialog_params_t params;
     1210        ui_msg_dialog_t *dialog;
     1211        errno_t rc;
     1212
     1213        ui_msg_dialog_params_init(&params);
     1214        params.caption = "System installation";
     1215        params.text = "This will install HelenOS to your computer. Continue?";
     1216        params.choice = umdc_ok_cancel;
     1217        params.flags |= umdf_topmost | umdf_center;
     1218
     1219        rc = ui_msg_dialog_create(sysinst->ui, &params, &dialog);
     1220        if (rc != EOK)
     1221                return rc;
     1222
     1223        ui_msg_dialog_set_cb(dialog, &sysinst_confirm_cb, sysinst);
     1224        return EOK;
     1225}
     1226
     1227/** Create restart dialog.
     1228 *
     1229 * @param sysinst System installer
     1230 * @return EOK on success or an error code
     1231 */
     1232static errno_t sysinst_restart_dlg_create(sysinst_t *sysinst)
     1233{
     1234        ui_msg_dialog_params_t params;
     1235        ui_msg_dialog_t *dialog;
     1236        errno_t rc;
     1237
     1238        ui_msg_dialog_params_init(&params);
     1239        params.caption = "Restart System";
     1240        params.text = "Installation complete. Restart the system?";
     1241        params.choice = umdc_ok_cancel;
     1242        params.flags |= umdf_topmost | umdf_center;
     1243
     1244        rc = ui_msg_dialog_create(sysinst->ui, &params, &dialog);
     1245        if (rc != EOK)
     1246                return rc;
     1247
     1248        ui_msg_dialog_set_cb(dialog, &sysinst_restart_dlg_cb, sysinst);
     1249        return EOK;
     1250}
     1251
     1252/** Run system installer on display.
     1253 *
     1254 * @param display_spec Display specification
     1255 * @return EOK on success or an error code
     1256 */
     1257static errno_t sysinst_run(const char *display_spec)
     1258{
     1259        ui_t *ui = NULL;
     1260        sysinst_t *sysinst;
     1261        ui_wnd_params_t params;
     1262        errno_t rc;
     1263
     1264        sysinst = calloc(1, sizeof(sysinst_t));
     1265        if (sysinst == NULL)
     1266                return ENOMEM;
     1267
     1268        rc = futil_create(&sysinst_futil_cb, (void *)sysinst, &sysinst->futil);
     1269        if (rc != EOK) {
     1270                printf("Out of memory.\n");
     1271                goto error;
     1272        }
     1273
     1274        rc = ui_create(display_spec, &ui);
     1275        if (rc != EOK) {
     1276                printf("Error creating UI on display %s.\n", display_spec);
     1277                goto error;
     1278        }
     1279
     1280        sysinst->ui = ui;
     1281
     1282        ui_wnd_params_init(&params);
     1283        params.caption = "System Installation";
     1284        params.style &= ~ui_wds_decorated;
     1285        params.placement = ui_wnd_place_full_screen;
     1286        params.flags |= ui_wndf_topmost | ui_wndf_nofocus;
     1287
     1288        rc = ui_window_create(sysinst->ui, &params, &sysinst->bgwindow);
     1289        if (rc != EOK) {
     1290                printf("Error creating window.\n");
     1291                goto error;
     1292        }
     1293
     1294        ui_window_set_cb(sysinst->bgwindow, &bg_window_cb, (void *)sysinst);
     1295
     1296        if (ui_is_textmode(sysinst->ui)) {
     1297                rc = gfx_color_new_ega(0x17, &sysinst->bg_color);
     1298                if (rc != EOK) {
     1299                        printf("Error allocating color.\n");
     1300                        goto error;
     1301                }
     1302        } else {
     1303                rc = gfx_color_new_rgb_i16(0x8000, 0xc800, 0xffff, &sysinst->bg_color);
     1304                if (rc != EOK) {
     1305                        printf("Error allocating color.\n");
     1306                        goto error;
     1307                }
     1308        }
     1309
     1310        rc = ui_window_paint(sysinst->bgwindow);
     1311        if (rc != EOK) {
     1312                printf("Error painting window.\n");
     1313                goto error;
     1314        }
     1315
     1316        (void)sysinst_confirm_create(sysinst);
     1317
     1318        ui_run(ui);
     1319
     1320        if (sysinst->bgwindow != NULL)
     1321                ui_window_destroy(sysinst->bgwindow);
     1322        if (sysinst->system != NULL)
     1323                system_close(sysinst->system);
     1324        gfx_color_delete(sysinst->bg_color);
     1325        ui_destroy(ui);
     1326        free(sysinst);
     1327        return EOK;
     1328error:
     1329        if (sysinst->futil != NULL)
     1330                futil_destroy(sysinst->futil);
     1331        if (sysinst->system != NULL)
     1332                system_close(sysinst->system);
     1333        if (sysinst->bg_color != NULL)
     1334                gfx_color_delete(sysinst->bg_color);
     1335        if (sysinst->bgwindow != NULL)
     1336                ui_window_destroy(sysinst->bgwindow);
     1337        if (ui != NULL)
     1338                ui_destroy(ui);
     1339        free(sysinst);
     1340        return rc;
     1341}
     1342
     1343static void print_syntax(void)
     1344{
     1345        printf("Syntax: " NAME " [-d <display-spec>]\n");
     1346}
     1347
     1348int main(int argc, char *argv[])
     1349{
     1350        const char *display_spec = UI_ANY_DEFAULT;
     1351        errno_t rc;
     1352        int i;
     1353
     1354        i = 1;
     1355        while (i < argc && argv[i][0] == '-') {
     1356                if (str_cmp(argv[i], "-d") == 0) {
     1357                        ++i;
     1358                        if (i >= argc) {
     1359                                printf("Argument missing.\n");
     1360                                print_syntax();
     1361                                return 1;
     1362                        }
     1363
     1364                        display_spec = argv[i++];
     1365                } else {
     1366                        printf("Invalid option '%s'.\n", argv[i]);
     1367                        print_syntax();
     1368                        return 1;
     1369                }
     1370        }
     1371
     1372        if (i < argc) {
     1373                print_syntax();
    5451374                return 1;
    5461375        }
    5471376
    548         return sysinst_install(default_devs[i]);
     1377        if (log_init(NAME) != EOK) {
     1378                printf(NAME ": Failed to initialize logging.\n");
     1379                return 1;
     1380        }
     1381
     1382        rc = sysinst_run(display_spec);
     1383        if (rc != EOK)
     1384                return 1;
     1385
     1386        return 0;
    5491387}
    5501388
  • uspace/app/sysinst/sysinst.h

    r800d188 r29e7cc7  
    11/*
    2  * Copyright (c) 2006 Josef Cejka
     2 * Copyright (c) 2025 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 /** @file
     29/** @addtogroup sysinst
     30 * @{
     31 */
     32/**
     33 * @file System installer
    3034 */
    3135
    32 #ifndef BOOT_PRINTF_CORE_H_
    33 #define BOOT_PRINTF_CORE_H_
     36#ifndef SYSINST_H
     37#define SYSINST_H
    3438
    35 #include <stddef.h>
    36 #include <stdarg.h>
     39#include <futil.h>
     40#include <gfx/color.h>
     41#include <system.h>
     42#include <ui/fixed.h>
     43#include <ui/label.h>
     44#include <ui/ui.h>
     45#include <ui/window.h>
    3746
    38 /** Structure for specifying output methods for different printf clones. */
     47/** Installation progress window. */
    3948typedef struct {
    40         /* String output function, returns number of printed characters or EOF */
    41         int (*str_write)(const char *, size_t, void *);
     49        ui_window_t *window;
     50        ui_fixed_t *fixed;
     51        ui_label_t *label;
     52        ui_label_t *action;
     53} sysinst_progress_t;
    4254
    43         /* User data - output stream specification, state, locks, etc. */
    44         void *data;
    45 } printf_spec_t;
    46 
    47 extern int printf_core(const char *, printf_spec_t *, va_list);
     55/** System installer. */
     56typedef struct {
     57        ui_t *ui;
     58        ui_window_t *bgwindow;
     59        gfx_color_t *bg_color;
     60        sysinst_progress_t *progress;
     61        system_t *system;
     62        futil_t *futil;
     63        char errmsg[128];
     64} sysinst_t;
    4865
    4966#endif
  • uspace/app/taskbar/taskbar.sif

    r800d188 r29e7cc7  
    1515<entry caption="~U~I Demo" cmd="/app/uidemo -d %d" terminal="n">
    1616</entry>
    17 <entry caption="~G~FX Demo" cmd="/app/gfxdemo -d %d ui" terminal="n">
     17<entry caption="~G~FX Demo" cmd="/app/gfxdemo -d %d" terminal="n">
    1818</entry>
    1919<entry caption="~B~arber Pole" cmd="/app/barber -d %d" terminal="n">
     
    3333<entry caption="~F~disk Disk Editor" cmd="/app/fdisk" terminal="y">
    3434</entry>
     35<entry caption="Insta~l~l HelenOS to Disk" cmd="/app/sysinst -d %d" terminal="n">
     36</entry>
    3537<entry separator="y">
    3638</entry>
  • uspace/app/trace/ipcp.c

    r800d188 r29e7cc7  
    8484}
    8585
    86 static bool pending_call_key_equal(const void *key, const ht_link_t *item)
     86static bool pending_call_key_equal(const void *key, size_t hash, const ht_link_t *item)
    8787{
    8888        const cap_call_handle_t *chandle = key;
  • uspace/app/trace/proto.c

    r800d188 r29e7cc7  
    6969}
    7070
    71 static bool srv_proto_key_equal(const void *key, const ht_link_t *item)
     71static bool srv_proto_key_equal(const void *key, size_t hash, const ht_link_t *item)
    7272{
    7373        const int *n = key;
     
    9696}
    9797
    98 static bool method_oper_key_equal(const void *key, const ht_link_t *item)
     98static bool method_oper_key_equal(const void *key, size_t hash, const ht_link_t *item)
    9999{
    100100        const int *n = key;
  • uspace/app/trace/syscalls.c

    r800d188 r29e7cc7  
    115115        [SYS_DEBUG_CONSOLE] = { "debug_console", 0, V_ERRNO },
    116116
    117         [SYS_KLOG] = { "klog", 5, V_ERRNO }
     117        [SYS_KLOG] = { "klog", 5, V_ERRNO },
     118        [SYS_KIO_READ] = { "kio_read", 3, V_INTEGER },
    118119};
    119120
Note: See TracChangeset for help on using the changeset viewer.