L4Re/departure

Annotated fsaccess/fsaccess.c

391:bc65615a8fed
2022-06-30 Paul Boddie Added missing structure members. mmap-region-flags
paul@283 1
/*
paul@283 2
 * Access a filesystem.
paul@283 3
 *
paul@283 4
 * Copyright (C) 2019, 2022 Paul Boddie <paul@boddie.org.uk>
paul@283 5
 *
paul@283 6
 * This program is free software; you can redistribute it and/or
paul@283 7
 * modify it under the terms of the GNU General Public License as
paul@283 8
 * published by the Free Software Foundation; either version 2 of
paul@283 9
 * the License, or (at your option) any later version.
paul@283 10
 *
paul@283 11
 * This program is distributed in the hope that it will be useful,
paul@283 12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
paul@283 13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
paul@283 14
 * GNU General Public License for more details.
paul@283 15
 *
paul@283 16
 * You should have received a copy of the GNU General Public License
paul@283 17
 * along with this program; if not, write to the Free Software
paul@283 18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
paul@283 19
 * Boston, MA  02110-1301, USA
paul@283 20
 */
paul@283 21
paul@283 22
#include <stdio.h>
paul@294 23
#include <unistd.h>
paul@283 24
paul@283 25
#include "ops.h"
paul@294 26
#include "session.h"
paul@283 27
paul@283 28
paul@283 29
paul@283 30
/* Help message. */
paul@283 31
paul@283 32
char help_text[] = "\
paul@283 33
Usage: %s [ <options> ] <operation> <filename>...\n\
paul@283 34
\n\
paul@283 35
File permission options:\n\
paul@283 36
\n\
paul@283 37
  -m MASK       Set mode/permissions mask for new directories\n\
paul@283 38
\n\
paul@283 39
Transfer operations:\n\
paul@283 40
\n\
paul@283 41
  copy-in       Copy files into a directory within the image\n\
paul@283 42
\n\
paul@283 43
Image operations:\n\
paul@283 44
\n\
paul@283 45
  ls            List files and directories within the image\n\
paul@283 46
  mkdir         Make directories within the image\n\
paul@283 47
  rm            Remove non-directory objects from the image\n\
paul@283 48
  rmdir         Remove directories from the image\n\
paul@283 49
  stat          Show statistics for files and directories\n\
paul@283 50
\n\
paul@283 51
Script operations:\n\
paul@283 52
\n\
paul@283 53
  script        Read operations from a script file\n\
paul@283 54
";
paul@283 55
paul@283 56
/* Operations exposed by the program. */
paul@283 57
paul@283 58
struct operation operations[] = {
paul@299 59
    {"copy-in", copy_in},
paul@283 60
    {"ls", list_objects},
paul@294 61
    {"mkdir", make_dirs},
paul@283 62
    {"rm", remove_non_dirs},
paul@283 63
    {"rmdir", remove_dirs},
paul@283 64
    {"script", run_script},
paul@283 65
    {"stat", stat_objects},
paul@283 66
    {NULL, NULL},
paul@283 67
    };
paul@283 68
paul@283 69
/* Main program. */
paul@283 70
paul@283 71
int main(int argc, char *argv[])
paul@283 72
{
paul@283 73
    /* Program argument details. */
paul@283 74
paul@283 75
    char **args;
paul@283 76
    int num_args;
paul@283 77
    enum op_results op_result;
paul@283 78
paul@294 79
    /* Parse program options and initialise the argument details. */
paul@294 80
paul@294 81
    if (parse_options(argc, argv))
paul@294 82
        return 1;
paul@294 83
paul@294 84
    args = &argv[optind];
paul@294 85
    num_args = argc - optind;
paul@283 86
paul@283 87
    if (num_args < 2)
paul@283 88
    {
paul@283 89
        fprintf(stderr, help_text, argv[0]);
paul@283 90
        return 1;
paul@283 91
    }
paul@283 92
paul@283 93
    /* Perform the requested operation. */
paul@283 94
paul@283 95
    op_result = run_operation(args[0], num_args - 1, &args[1]);
paul@283 96
    return handle_op_result(args[0], op_result);
paul@283 97
}
paul@283 98
paul@283 99
/* vim: tabstop=4 expandtab shiftwidth=4
paul@283 100
*/