static int blkdebug_open(BlockDriverState *bs, const char *filename, int flags)

{

    BDRVBlkdebugState *s = bs->opaque;

    int ret;

    char *config, *c;



    /* Parse the blkdebug: prefix */

    if (strncmp(filename, "blkdebug:", strlen("blkdebug:"))) {

        return -EINVAL;

    }

    filename += strlen("blkdebug:");



    /* Read rules from config file */

    c = strchr(filename, ':');

    if (c == NULL) {

        return -EINVAL;

    }



    config = strdup(filename);

    config[c - filename] = '\0';

    ret = read_config(s, config);

    free(config);

    if (ret < 0) {

        return ret;

    }

    filename = c + 1;



    /* Set initial state */

    s->vars.state = 1;



    /* Open the backing file */

    ret = bdrv_file_open(&bs->file, filename, flags);

    if (ret < 0) {

        return ret;

    }



    return 0;

}

static int blkdebug_open(BlockDriverState *bs, const char *filename, int flags)

{

    BDRVBlkdebugState *s = bs->opaque;

    int ret;

    char *config, *c;



    

    if (strncmp(filename, "blkdebug:", strlen("blkdebug:"))) {

        return -EINVAL;

    }

    filename += strlen("blkdebug:");



    

    c = strchr(filename, ':');

    if (c == NULL) {

        return -EINVAL;

    }



    config = strdup(filename);

    config[c - filename] = '\0';

    ret = read_config(s, config);

    free(config);

    if (ret < 0) {

        return ret;

    }

    filename = c + 1;



    

    s->vars.state = 1;



    

    ret = bdrv_file_open(&bs->file, filename, flags);

    if (ret < 0) {

        return ret;

    }



    return 0;

}

static int FUNC_0(BlockDriverState *VAR_0, const char *VAR_1, int VAR_2)

{

    BDRVBlkdebugState *s = VAR_0->opaque;

    int VAR_3;

    char *VAR_4, *VAR_5;



    

    if (strncmp(VAR_1, "blkdebug:", strlen("blkdebug:"))) {

        return -EINVAL;

    }

    VAR_1 += strlen("blkdebug:");



    

    VAR_5 = strchr(VAR_1, ':');

    if (VAR_5 == NULL) {

        return -EINVAL;

    }



    VAR_4 = strdup(VAR_1);

    VAR_4[VAR_5 - VAR_1] = '\0';

    VAR_3 = read_config(s, VAR_4);

    free(VAR_4);

    if (VAR_3 < 0) {

        return VAR_3;

    }

    VAR_1 = VAR_5 + 1;



    

    s->vars.state = 1;



    

    VAR_3 = bdrv_file_open(&VAR_0->file, VAR_1, VAR_2);

    if (VAR_3 < 0) {

        return VAR_3;

    }



    return 0;

}

static int FUNC_0(BlockDriverState *VAR_0, const char *VAR_1, int VAR_2)
{ BDRVBlkdebugState *s = VAR_0->opaque; int VAR_3; char *VAR_4, *VAR_5; if (strncmp(VAR_1, "blkdebug:", strlen("blkdebug:"))) { return -EINVAL; } VAR_1 += strlen("blkdebug:"); VAR_5 = strchr(VAR_1, ':'); if (VAR_5 == NULL) { return -EINVAL; } VAR_4 = strdup(VAR_1); VAR_4[VAR_5 - VAR_1] = '\0'; VAR_3 = read_config(s, VAR_4); free(VAR_4); if (VAR_3 < 0) { return VAR_3; } VAR_1 = VAR_5 + 1; s->vars.state = 1; VAR_3 = bdrv_file_open(&VAR_0->file, VAR_1, VAR_2); if (VAR_3 < 0) { return VAR_3; } return 0; }