Changeset bb4d0b5 in mainline for uspace/app/newfile


Ignore:
Timestamp:
2025-10-18T19:29:40Z (3 months ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master
Children:
3e41cc4
Parents:
856a7b49
Message:

Allow user to decide whether to retry or abort when I/O error occurs.

File:
1 edited

Legend:

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

    r856a7b49 rbb4d0b5  
    4949static bool newfile_abort_query(void *);
    5050static void newfile_progress(void *, fmgt_progress_t *);
     51static fmgt_error_action_t newfile_io_error_query(void *, fmgt_io_error_t *);
    5152
    5253static bool prog_upd = false;
     54static bool nonint = false;
    5355static bool quiet = false;
    5456
     
    5759static fmgt_cb_t newfile_fmgt_cb = {
    5860        .abort_query = newfile_abort_query,
    59         .progress = newfile_progress
     61        .io_error_query = newfile_io_error_query,
     62        .progress = newfile_progress,
    6063};
    6164
     
    121124}
    122125
     126/** Called by fmgt to let user choose I/O error recovery action.
     127 *
     128 * @param arg Argument (not used)
     129 * @param err I/O error report
     130 * @return Error recovery action.
     131 */
     132static fmgt_error_action_t newfile_io_error_query(void *arg,
     133    fmgt_io_error_t *err)
     134{
     135        cons_event_t event;
     136        kbd_event_t *ev;
     137        errno_t rc;
     138
     139        (void)arg;
     140
     141        if (nonint)
     142                return fmgt_er_abort;
     143
     144        if (prog_upd)
     145                putchar('\n');
     146
     147        fprintf(stderr, "I/O error %s file '%s' (%s).\n",
     148            err->optype == fmgt_io_write ? "writing" : "reading",
     149            err->fname, str_error(err->rc));
     150        fprintf(stderr, "[A]bort or [R]etry?\n");
     151
     152        if (con == NULL)
     153                return fmgt_er_abort;
     154
     155        while (true) {
     156                rc = console_get_event(con, &event);
     157                if (rc != EOK)
     158                        return fmgt_er_abort;
     159
     160                if (event.type == CEV_KEY && event.ev.key.type == KEY_PRESS) {
     161                        ev = &event.ev.key;
     162                        if ((ev->mods & KM_ALT) == 0 &&
     163                            (ev->mods & KM_CTRL) == 0) {
     164                                if (ev->c == 'r' || ev->c == 'R')
     165                                        return fmgt_er_retry;
     166                                if (ev->c == 'a' || ev->c == 'A')
     167                                        return fmgt_er_abort;
     168                        }
     169                }
     170
     171                if (event.type == CEV_KEY && event.ev.key.type == KEY_PRESS) {
     172                        ev = &event.ev.key;
     173                        if ((ev->mods & KM_ALT) == 0 &&
     174                            (ev->mods & KM_SHIFT) == 0 &&
     175                            (ev->mods & KM_CTRL) != 0) {
     176                                if (ev->key == KC_C)
     177                                        return fmgt_er_abort;
     178                        }
     179                }
     180        }
     181}
     182
    123183int main(int argc, char *argv[])
    124184{
     
    126186        errno_t rc;
    127187        int i;
    128         bool nonint = false;
    129188        bool sparse = false;
    130189        char *fsize = NULL;
     
    210269        rc = fmgt_new_file(fmgt, fname, nbytes, sparse ? nf_sparse : nf_none);
    211270        if (prog_upd)
    212                 printf("\n");
     271                putchar('\n');
    213272        if (rc != EOK) {
    214273                printf("Error creating file: %s.\n", str_error(rc));
Note: See TracChangeset for help on using the changeset viewer.