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

{

    BlockDriverState *bs;

    QEMUSnapshotInfo sn;

    char *filename, *snapshot_name = NULL;

    int c, ret;

    int action = 0;

    qemu_timeval tv;



    /* Parse commandline parameters */

    for(;;) {

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

        if (c == -1)

            break;

        switch(c) {

        case 'h':

            help();

            return;

        case 'l':

            if (action) {

                help();

                return;

            }

            action = SNAPSHOT_LIST;

            break;

        case 'a':

            if (action) {

                help();

                return;

            }

            action = SNAPSHOT_APPLY;

            snapshot_name = optarg;

            break;

        case 'c':

            if (action) {

                help();

                return;

            }

            action = SNAPSHOT_CREATE;

            snapshot_name = optarg;

            break;

        case 'd':

            if (action) {

                help();

                return;

            }

            action = SNAPSHOT_DELETE;

            snapshot_name = optarg;

            break;

        }

    }



    if (optind >= argc)

        help();

    filename = argv[optind++];



    /* Open the image */

    bs = bdrv_new("");

    if (!bs)

        error("Not enough memory");



    if (bdrv_open2(bs, filename, 0, NULL) < 0) {

        error("Could not open '%s'", filename);

    }



    /* 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("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("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("Could not delete snapshot '%s': %d (%s)",

                snapshot_name, ret, strerror(-ret));

        break;

    }



    /* Cleanup */

    bdrv_delete(bs);

}

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

{

    BlockDriverState *bs;

    QEMUSnapshotInfo sn;

    char *filename, *snapshot_name = NULL;

    int c, ret;

    int action = 0;

    qemu_timeval tv;



    

    for(;;) {

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

        if (c == -1)

            break;

        switch(c) {

        case 'h':

            help();

            return;

        case 'l':

            if (action) {

                help();

                return;

            }

            action = SNAPSHOT_LIST;

            break;

        case 'a':

            if (action) {

                help();

                return;

            }

            action = SNAPSHOT_APPLY;

            snapshot_name = optarg;

            break;

        case 'c':

            if (action) {

                help();

                return;

            }

            action = SNAPSHOT_CREATE;

            snapshot_name = optarg;

            break;

        case 'd':

            if (action) {

                help();

                return;

            }

            action = SNAPSHOT_DELETE;

            snapshot_name = optarg;

            break;

        }

    }



    if (optind >= argc)

        help();

    filename = argv[optind++];



    

    bs = bdrv_new("");

    if (!bs)

        error("Not enough memory");



    if (bdrv_open2(bs, filename, 0, NULL) < 0) {

        error("Could not open '%s'", filename);

    }



    

    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("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("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("Could not delete snapshot '%s': %d (%s)",

                snapshot_name, ret, strerror(-ret));

        break;

    }



    

    bdrv_delete(bs);

}

static void FUNC_0(int VAR_0, char **VAR_1)

{

    BlockDriverState *bs;

    QEMUSnapshotInfo sn;

    char *VAR_2, *VAR_3 = NULL;

    int VAR_4, VAR_5;

    int VAR_6 = 0;

    qemu_timeval tv;



    

    for(;;) {

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

        if (VAR_4 == -1)

            break;

        switch(VAR_4) {

        case 'h':

            help();

            return;

        case 'l':

            if (VAR_6) {

                help();

                return;

            }

            VAR_6 = SNAPSHOT_LIST;

            break;

        case 'a':

            if (VAR_6) {

                help();

                return;

            }

            VAR_6 = SNAPSHOT_APPLY;

            VAR_3 = optarg;

            break;

        case 'VAR_4':

            if (VAR_6) {

                help();

                return;

            }

            VAR_6 = SNAPSHOT_CREATE;

            VAR_3 = optarg;

            break;

        case 'd':

            if (VAR_6) {

                help();

                return;

            }

            VAR_6 = SNAPSHOT_DELETE;

            VAR_3 = optarg;

            break;

        }

    }



    if (optind >= VAR_0)

        help();

    VAR_2 = VAR_1[optind++];



    

    bs = bdrv_new("");

    if (!bs)

        error("Not enough memory");



    if (bdrv_open2(bs, VAR_2, 0, NULL) < 0) {

        error("Could not open '%s'", VAR_2);

    }



    

    switch(VAR_6) {

    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("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("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("Could not delete snapshot '%s': %d (%s)",

                VAR_3, VAR_5, strerror(-VAR_5));

        break;

    }



    

    bdrv_delete(bs);

}

static void FUNC_0(int VAR_0, char **VAR_1)
{ BlockDriverState *bs; QEMUSnapshotInfo sn; char *VAR_2, *VAR_3 = NULL; int VAR_4, VAR_5; int VAR_6 = 0; qemu_timeval tv; for(;;) { VAR_4 = getopt(VAR_0, VAR_1, "la:VAR_4:d:h"); if (VAR_4 == -1)
break; switch(VAR_4) { case 'h':
help(); return; case 'l':
if (VAR_6) { help(); return; } VAR_6 = SNAPSHOT_LIST; break; case 'a':
if (VAR_6) { help(); return; } VAR_6 = SNAPSHOT_APPLY; VAR_3 = optarg; break; case 'VAR_4':
if (VAR_6) { help(); return; } VAR_6 = SNAPSHOT_CREATE; VAR_3 = optarg; break; case 'd':
if (VAR_6) { help(); return; } VAR_6 = SNAPSHOT_DELETE; VAR_3 = optarg; break; } } if (optind >= VAR_0)
help(); VAR_2 = VAR_1[optind++]; bs = bdrv_new(""); if (!bs)
error("Not enough memory"); if (bdrv_open2(bs, VAR_2, 0, NULL) < 0) { error("Could not open '%s'", VAR_2); } switch(VAR_6) { 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("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("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("Could not delete snapshot '%s': %d (%s)",
VAR_3, VAR_5, strerror(-VAR_5)); break; } bdrv_delete(bs); }