static int sd_snapshot_goto(BlockDriverState *bs, const char *snapshot_id)

{

    BDRVSheepdogState *s = bs->opaque;

    BDRVSheepdogState *old_s;

    char tag[SD_MAX_VDI_TAG_LEN];

    uint32_t snapid = 0;

    int ret = 0;



    old_s = g_malloc(sizeof(BDRVSheepdogState));



    memcpy(old_s, s, sizeof(BDRVSheepdogState));



    snapid = strtoul(snapshot_id, NULL, 10);

    if (snapid) {

        tag[0] = 0;

    } else {

        pstrcpy(tag, sizeof(tag), snapshot_id);

    }



    ret = reload_inode(s, snapid, tag);

    if (ret) {

        goto out;

    }



    ret = sd_create_branch(s);

    if (ret) {

        goto out;

    }



    g_free(old_s);



    return 0;

out:

    /* recover bdrv_sd_state */

    memcpy(s, old_s, sizeof(BDRVSheepdogState));

    g_free(old_s);



    error_report("failed to open. recover old bdrv_sd_state.");



    return ret;

}

static int sd_snapshot_goto(BlockDriverState *bs, const char *snapshot_id)

{

    BDRVSheepdogState *s = bs->opaque;

    BDRVSheepdogState *old_s;

    char tag[SD_MAX_VDI_TAG_LEN];

    uint32_t snapid = 0;

    int ret = 0;



    old_s = g_malloc(sizeof(BDRVSheepdogState));



    memcpy(old_s, s, sizeof(BDRVSheepdogState));



    snapid = strtoul(snapshot_id, NULL, 10);

    if (snapid) {

        tag[0] = 0;

    } else {

        pstrcpy(tag, sizeof(tag), snapshot_id);

    }



    ret = reload_inode(s, snapid, tag);

    if (ret) {

        goto out;

    }



    ret = sd_create_branch(s);

    if (ret) {

        goto out;

    }



    g_free(old_s);



    return 0;

out:

    

    memcpy(s, old_s, sizeof(BDRVSheepdogState));

    g_free(old_s);



    error_report("failed to open. recover old bdrv_sd_state.");



    return ret;

}

    old_s = g_malloc(sizeof(BDRVSheepdogState));
static int FUNC_0(BlockDriverState *VAR_0, const char *VAR_1)

{

    BDRVSheepdogState *s = VAR_0->opaque;

    BDRVSheepdogState *old_s;

    char VAR_2[SD_MAX_VDI_TAG_LEN];

    uint32_t snapid = 0;

    int VAR_3 = 0;



    old_s = g_malloc(sizeof(BDRVSheepdogState));



    memcpy(old_s, s, sizeof(BDRVSheepdogState));



    snapid = strtoul(VAR_1, NULL, 10);

    if (snapid) {

        VAR_2[0] = 0;

    } else {

        pstrcpy(VAR_2, sizeof(VAR_2), VAR_1);

    }



    VAR_3 = reload_inode(s, snapid, VAR_2);

    if (VAR_3) {

        goto out;

    }



    VAR_3 = sd_create_branch(s);

    if (VAR_3) {

        goto out;

    }



    g_free(old_s);



    return 0;

out:

    

    memcpy(s, old_s, sizeof(BDRVSheepdogState));

    g_free(old_s);



    error_report("failed to open. recover old bdrv_sd_state.");



    return VAR_3;

}

static int FUNC_0(BlockDriverState *VAR_0, const char *VAR_1)
{ BDRVSheepdogState *s = VAR_0->opaque; BDRVSheepdogState *old_s; char VAR_2[SD_MAX_VDI_TAG_LEN]; uint32_t snapid = 0; int VAR_3 = 0; old_s = g_malloc(sizeof(BDRVSheepdogState)); memcpy(old_s, s, sizeof(BDRVSheepdogState)); snapid = strtoul(VAR_1, NULL, 10); if (snapid) { VAR_2[0] = 0; } else { pstrcpy(VAR_2, sizeof(VAR_2), VAR_1); } VAR_3 = reload_inode(s, snapid, VAR_2); if (VAR_3) { goto out; } VAR_3 = sd_create_branch(s); if (VAR_3) { goto out; } g_free(old_s); return 0; out:
memcpy(s, old_s, sizeof(BDRVSheepdogState)); g_free(old_s); error_report("failed to open. recover old bdrv_sd_state."); return VAR_3; }