L4Re/departure

libe2access/host/ops.c

391:bc65615a8fed
2022-06-30 Paul Boddie Added missing structure members. mmap-region-flags
     1 /*     2  * Operation invocation.     3  *     4  * Copyright (C) 2019, 2022 Paul Boddie <paul@boddie.org.uk>     5  *     6  * This program is free software; you can redistribute it and/or     7  * modify it under the terms of the GNU General Public License as     8  * published by the Free Software Foundation; either version 2 of     9  * the License, or (at your option) any later version.    10  *    11  * This program is distributed in the hope that it will be useful,    12  * but WITHOUT ANY WARRANTY; without even the implied warranty of    13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    14  * GNU General Public License for more details.    15  *    16  * You should have received a copy of the GNU General Public License    17  * along with this program; if not, write to the Free Software    18  * Foundation, Inc., 51 Franklin Street, Fifth Floor,    19  * Boston, MA  02110-1301, USA    20  */    21     22 #include <stdio.h>    23 #include <string.h>    24     25 #include "ops.h"    26     27     28     29 /* Operations exposed by the program. */    30     31 extern struct operation operations[];    32     33     34     35 /* Produce a general result condition from the invocation of an operation. */    36     37 int handle_op_result(const char *operation, enum op_results op_result)    38 {    39     if (op_result == OP_UNKNOWN)    40     {    41         fprintf(stderr, "Operation not recognised: %s\n", operation);    42         return 1;    43     }    44     else if (op_result == OP_FAILED)    45     {    46         fprintf(stderr, "Operation failed: %s\n", operation);    47         return 1;    48     }    49     else    50         return 0;    51 }    52     53 /* Invocation of operations. */    54     55 enum op_results run_operation(ext2_filsys fs, const char *operation, int argc, char *argv[])    56 {    57     struct operation *op;    58     int exitcode;    59     60     for (op = &operations[0]; op->name != NULL; op++)    61     {    62         if (!strcmp(operation, op->name))    63         {    64             exitcode = op->fn(fs, argc, argv);    65             if (exitcode)    66                 return OP_FAILED;    67             break;    68         }    69     }    70     71     if (op->name == NULL)    72         return OP_UNKNOWN;    73     74     return OP_SUCCESS;    75 }    76     77 /* vim: tabstop=4 expandtab shiftwidth=4    78 */