static int img_snapshot(int argc, char **argv)

{

    BlockDriverState *bs;

    QEMUSnapshotInfo sn;

    char *filename, *snapshot_name = NULL;

    int c, ret = 0, bdrv_oflags;

    int action = 0;

    qemu_timeval tv;

    bool quiet = false;



    bdrv_oflags = BDRV_O_FLAGS | BDRV_O_RDWR;

    /* Parse commandline parameters */

    for(;;) {

        c = getopt(argc, argv, "la:c:d:hq");

        if (c == -1) {

            break;

        }

        switch(c) {

        case '?':

        case 'h':

            help();

            return 0;

        case 'l':

            if (action) {

                help();

                return 0;

            }

            action = SNAPSHOT_LIST;

            bdrv_oflags &= ~BDRV_O_RDWR; /* no need for RW */

            break;

        case 'a':

            if (action) {

                help();

                return 0;

            }

            action = SNAPSHOT_APPLY;

            snapshot_name = optarg;

            break;

        case 'c':

            if (action) {

                help();

                return 0;

            }

            action = SNAPSHOT_CREATE;

            snapshot_name = optarg;

            break;

        case 'd':

            if (action) {

                help();

                return 0;

            }

            action = SNAPSHOT_DELETE;

            snapshot_name = optarg;

            break;

        case 'q':

            quiet = true;

            break;

        }

    }



    if (optind != argc - 1) {

        help();

    }

    filename = argv[optind++];



    /* Open the image */

    bs = bdrv_new_open(filename, NULL, bdrv_oflags, true, quiet);

    if (!bs) {

        return 1;

    }



    /* Perform the requested action */

    switch(action) {

    case SNAPSHOT_LIST:

        dump_snapshots(bs);

        break;



    case SNAPSHOT_CREATE:

        memset(&sn, 0, sizeof(sn));

        pstrcpy(sn.name, sizeof(sn.name), snapshot_name);



        qemu_gettimeofday(&tv);

        sn.date_sec = tv.tv_sec;

        sn.date_nsec = tv.tv_usec * 1000;



        ret = bdrv_snapshot_create(bs, &sn);

        if (ret) {

            error_report("Could not create snapshot '%s': %d (%s)",

                snapshot_name, ret, strerror(-ret));

        }

        break;



    case SNAPSHOT_APPLY:

        ret = bdrv_snapshot_goto(bs, snapshot_name);

        if (ret) {

            error_report("Could not apply snapshot '%s': %d (%s)",

                snapshot_name, ret, strerror(-ret));

        }

        break;



    case SNAPSHOT_DELETE:

        ret = bdrv_snapshot_delete(bs, snapshot_name);

        if (ret) {

            error_report("Could not delete snapshot '%s': %d (%s)",

                snapshot_name, ret, strerror(-ret));

        }

        break;

    }



    /* Cleanup */

    bdrv_unref(bs);

    if (ret) {

        return 1;

    }

    return 0;

}

static int img_snapshot(int argc, char **argv)

{

    BlockDriverState *bs;

    QEMUSnapshotInfo sn;

    char *filename, *snapshot_name = NULL;

    int c, ret = 0, bdrv_oflags;

    int action = 0;

    qemu_timeval tv;

    bool quiet = false;



    bdrv_oflags = BDRV_O_FLAGS | BDRV_O_RDWR;

    

    for(;;) {

        c = getopt(argc, argv, "la:c:d:hq");

        if (c == -1) {

            break;

        }

        switch(c) {

        case '?':

        case 'h':

            help();

            return 0;

        case 'l':

            if (action) {

                help();

                return 0;

            }

            action = SNAPSHOT_LIST;

            bdrv_oflags &= ~BDRV_O_RDWR; 

            break;

        case 'a':

            if (action) {

                help();

                return 0;

            }

            action = SNAPSHOT_APPLY;

            snapshot_name = optarg;

            break;

        case 'c':

            if (action) {

                help();

                return 0;

            }

            action = SNAPSHOT_CREATE;

            snapshot_name = optarg;

            break;

        case 'd':

            if (action) {

                help();

                return 0;

            }

            action = SNAPSHOT_DELETE;

            snapshot_name = optarg;

            break;

        case 'q':

            quiet = true;

            break;

        }

    }



    if (optind != argc - 1) {

        help();

    }

    filename = argv[optind++];



    

    bs = bdrv_new_open(filename, NULL, bdrv_oflags, true, quiet);

    if (!bs) {

        return 1;

    }



    

    switch(action) {

    case SNAPSHOT_LIST:

        dump_snapshots(bs);

        break;



    case SNAPSHOT_CREATE:

        memset(&sn, 0, sizeof(sn));

        pstrcpy(sn.name, sizeof(sn.name), snapshot_name);



        qemu_gettimeofday(&tv);

        sn.date_sec = tv.tv_sec;

        sn.date_nsec = tv.tv_usec * 1000;



        ret = bdrv_snapshot_create(bs, &sn);

        if (ret) {

            error_report("Could not create snapshot '%s': %d (%s)",

                snapshot_name, ret, strerror(-ret));

        }

        break;



    case SNAPSHOT_APPLY:

        ret = bdrv_snapshot_goto(bs, snapshot_name);

        if (ret) {

            error_report("Could not apply snapshot '%s': %d (%s)",

                snapshot_name, ret, strerror(-ret));

        }

        break;



    case SNAPSHOT_DELETE:

        ret = bdrv_snapshot_delete(bs, snapshot_name);

        if (ret) {

            error_report("Could not delete snapshot '%s': %d (%s)",

                snapshot_name, ret, strerror(-ret));

        }

        break;

    }



    

    bdrv_unref(bs);

    if (ret) {

        return 1;

    }

    return 0;

}

        ret = bdrv_snapshot_delete(bs, snapshot_name);         if (ret) {             error_report("Could not delete snapshot '%s': %d (%s)",                 snapshot_name, ret, strerror(-ret));
static int FUNC_0(int VAR_0, char **VAR_1)

{

    BlockDriverState *bs;

    QEMUSnapshotInfo sn;

    char *VAR_2, *VAR_3 = NULL;

    int VAR_4, VAR_5 = 0, VAR_6;

    int VAR_7 = 0;

    qemu_timeval tv;

    bool quiet = false;



    VAR_6 = BDRV_O_FLAGS | BDRV_O_RDWR;

    

    for(;;) {

        VAR_4 = getopt(VAR_0, VAR_1, "la:VAR_4:d:hq");

        if (VAR_4 == -1) {

            break;

        }

        switch(VAR_4) {

        case '?':

        case 'h':

            help();

            return 0;

        case 'l':

            if (VAR_7) {

                help();

                return 0;

            }

            VAR_7 = SNAPSHOT_LIST;

            VAR_6 &= ~BDRV_O_RDWR; 

            break;

        case 'a':

            if (VAR_7) {

                help();

                return 0;

            }

            VAR_7 = SNAPSHOT_APPLY;

            VAR_3 = optarg;

            break;

        case 'VAR_4':

            if (VAR_7) {

                help();

                return 0;

            }

            VAR_7 = SNAPSHOT_CREATE;

            VAR_3 = optarg;

            break;

        case 'd':

            if (VAR_7) {

                help();

                return 0;

            }

            VAR_7 = SNAPSHOT_DELETE;

            VAR_3 = optarg;

            break;

        case 'q':

            quiet = true;

            break;

        }

    }



    if (optind != VAR_0 - 1) {

        help();

    }

    VAR_2 = VAR_1[optind++];



    

    bs = bdrv_new_open(VAR_2, NULL, VAR_6, true, quiet);

    if (!bs) {

        return 1;

    }



    

    switch(VAR_7) {

    case SNAPSHOT_LIST:

        dump_snapshots(bs);

        break;



    case SNAPSHOT_CREATE:

        memset(&sn, 0, sizeof(sn));

        pstrcpy(sn.name, sizeof(sn.name), VAR_3);



        qemu_gettimeofday(&tv);

        sn.date_sec = tv.tv_sec;

        sn.date_nsec = tv.tv_usec * 1000;



        VAR_5 = bdrv_snapshot_create(bs, &sn);

        if (VAR_5) {

            error_report("Could not create snapshot '%s': %d (%s)",

                VAR_3, VAR_5, strerror(-VAR_5));

        }

        break;



    case SNAPSHOT_APPLY:

        VAR_5 = bdrv_snapshot_goto(bs, VAR_3);

        if (VAR_5) {

            error_report("Could not apply snapshot '%s': %d (%s)",

                VAR_3, VAR_5, strerror(-VAR_5));

        }

        break;



    case SNAPSHOT_DELETE:

        VAR_5 = bdrv_snapshot_delete(bs, VAR_3);

        if (VAR_5) {

            error_report("Could not delete snapshot '%s': %d (%s)",

                VAR_3, VAR_5, strerror(-VAR_5));

        }

        break;

    }



    

    bdrv_unref(bs);

    if (VAR_5) {

        return 1;

    }

    return 0;

}

static int FUNC_0(int VAR_0, char **VAR_1)
{ BlockDriverState *bs; QEMUSnapshotInfo sn; char *VAR_2, *VAR_3 = NULL; int VAR_4, VAR_5 = 0, VAR_6; int VAR_7 = 0; qemu_timeval tv; bool quiet = false; VAR_6 = BDRV_O_FLAGS | BDRV_O_RDWR; for(;;) { VAR_4 = getopt(VAR_0, VAR_1, "la:VAR_4:d:hq"); if (VAR_4 == -1) { break; } switch(VAR_4) { case '?':
case 'h':
help(); return 0; case 'l':
if (VAR_7) { help(); return 0; } VAR_7 = SNAPSHOT_LIST; VAR_6 &= ~BDRV_O_RDWR; break; case 'a':
if (VAR_7) { help(); return 0; } VAR_7 = SNAPSHOT_APPLY; VAR_3 = optarg; break; case 'VAR_4':
if (VAR_7) { help(); return 0; } VAR_7 = SNAPSHOT_CREATE; VAR_3 = optarg; break; case 'd':
if (VAR_7) { help(); return 0; } VAR_7 = SNAPSHOT_DELETE; VAR_3 = optarg; break; case 'q':
quiet = true; break; } } if (optind != VAR_0 - 1) { help(); } VAR_2 = VAR_1[optind++]; bs = bdrv_new_open(VAR_2, NULL, VAR_6, true, quiet); if (!bs) { return 1; } switch(VAR_7) { case SNAPSHOT_LIST:
dump_snapshots(bs); break; case SNAPSHOT_CREATE:
memset(&sn, 0, sizeof(sn)); pstrcpy(sn.name, sizeof(sn.name), VAR_3); qemu_gettimeofday(&tv); sn.date_sec = tv.tv_sec; sn.date_nsec = tv.tv_usec * 1000; VAR_5 = bdrv_snapshot_create(bs, &sn); if (VAR_5) { error_report("Could not create snapshot '%s': %d (%s)",
VAR_3, VAR_5, strerror(-VAR_5)); } break; case SNAPSHOT_APPLY:
VAR_5 = bdrv_snapshot_goto(bs, VAR_3); if (VAR_5) { error_report("Could not apply snapshot '%s': %d (%s)",
VAR_3, VAR_5, strerror(-VAR_5)); } break; case SNAPSHOT_DELETE:
VAR_5 = bdrv_snapshot_delete(bs, VAR_3); if (VAR_5) { error_report("Could not delete snapshot '%s': %d (%s)",
VAR_3, VAR_5, strerror(-VAR_5)); } break; } bdrv_unref(bs); if (VAR_5) { return 1; } return 0; }