Revision 153859be qemu-img.c

b/qemu-img.c
31 31
#include <windows.h>
32 32
#endif
33 33

  
34
typedef struct img_cmd_t {
35
    const char *name;
36
    int (*handler)(int argc, char **argv);
37
} img_cmd_t;
38

  
34 39
/* Default to cache=writeback as data integrity is not important for qemu-tcg. */
35 40
#define BRDV_O_FLAGS BDRV_O_CACHE_WB
36 41

  
......
58 63
           "QEMU disk image utility\n"
59 64
           "\n"
60 65
           "Command syntax:\n"
61
           "  check [-f fmt] filename\n"
62
           "  create [-F fmt] [-b base_image] [-f fmt] [-o options] filename [size]\n"
63
           "  commit [-f fmt] filename\n"
64
           "  convert [-c] [-f fmt] [-O output_fmt] [-o options] [-B output_base_image] filename [filename2 [...]] output_filename\n"
65
           "  info [-f fmt] filename\n"
66
           "  snapshot [-l | -a snapshot | -c snapshot | -d snapshot] filename\n"
66
#define DEF(option, callback, arg_string)        \
67
           "  " arg_string "\n"
68
#include "qemu-img-cmds.h"
69
#undef DEF
70
#undef GEN_DOCS
67 71
           "\n"
68 72
           "Command parameters:\n"
69 73
           "  'filename' is a disk image filename\n"
......
919 923
#define SNAPSHOT_APPLY  3
920 924
#define SNAPSHOT_DELETE 4
921 925

  
922
static void img_snapshot(int argc, char **argv)
926
static int img_snapshot(int argc, char **argv)
923 927
{
924 928
    BlockDriverState *bs;
925 929
    QEMUSnapshotInfo sn;
......
936 940
        switch(c) {
937 941
        case 'h':
938 942
            help();
939
            return;
943
            return 0;
940 944
        case 'l':
941 945
            if (action) {
942 946
                help();
943
                return;
947
                return 0;
944 948
            }
945 949
            action = SNAPSHOT_LIST;
946 950
            break;
947 951
        case 'a':
948 952
            if (action) {
949 953
                help();
950
                return;
954
                return 0;
951 955
            }
952 956
            action = SNAPSHOT_APPLY;
953 957
            snapshot_name = optarg;
......
955 959
        case 'c':
956 960
            if (action) {
957 961
                help();
958
                return;
962
                return 0;
959 963
            }
960 964
            action = SNAPSHOT_CREATE;
961 965
            snapshot_name = optarg;
......
963 967
        case 'd':
964 968
            if (action) {
965 969
                help();
966
                return;
970
                return 0;
967 971
            }
968 972
            action = SNAPSHOT_DELETE;
969 973
            snapshot_name = optarg;
......
1021 1025

  
1022 1026
    /* Cleanup */
1023 1027
    bdrv_delete(bs);
1028

  
1029
    return 0;
1024 1030
}
1025 1031

  
1032
static const img_cmd_t img_cmds[] = {
1033
#define DEF(option, callback, arg_string)        \
1034
    { option, callback },
1035
#include "qemu-img-cmds.h"
1036
#undef DEF
1037
#undef GEN_DOCS
1038
    { NULL, NULL, },
1039
};
1040

  
1026 1041
int main(int argc, char **argv)
1027 1042
{
1028
    const char *cmd;
1043
    const img_cmd_t *cmd;
1044
    const char *cmdname;
1029 1045

  
1030 1046
    bdrv_init();
1031 1047
    if (argc < 2)
1032 1048
        help();
1033
    cmd = argv[1];
1049
    cmdname = argv[1];
1034 1050
    argc--; argv++;
1035
    if (!strcmp(cmd, "create")) {
1036
        img_create(argc, argv);
1037
    } else if (!strcmp(cmd, "check")) {
1038
        img_check(argc, argv);
1039
    } else if (!strcmp(cmd, "commit")) {
1040
        img_commit(argc, argv);
1041
    } else if (!strcmp(cmd, "convert")) {
1042
        img_convert(argc, argv);
1043
    } else if (!strcmp(cmd, "info")) {
1044
        img_info(argc, argv);
1045
    } else if (!strcmp(cmd, "snapshot")) {
1046
        img_snapshot(argc, argv);
1047
    } else {
1048
        help();
1051

  
1052
    /* find the command */
1053
    for(cmd = img_cmds; cmd->name != NULL; cmd++) {
1054
        if (!strcmp(cmdname, cmd->name)) {
1055
            return cmd->handler(argc, argv);
1056
        }
1049 1057
    }
1058

  
1059
    /* not found */
1060
    help();
1050 1061
    return 0;
1051 1062
}

Also available in: Unified diff