int fw_cfg_add_file(FWCfgState *s,  const char *dir, const char *filename,

                    uint8_t *data, uint32_t len)

{

    const char *basename;

    int index;



    if (!s->files) {

        int dsize = sizeof(uint32_t) + sizeof(FWCfgFile) * FW_CFG_FILE_SLOTS;

        s->files = qemu_mallocz(dsize);

        fw_cfg_add_bytes(s, FW_CFG_FILE_DIR, (uint8_t*)s->files, dsize);

    }



    index = be32_to_cpu(s->files->count);

    if (index == FW_CFG_FILE_SLOTS) {

        fprintf(stderr, "fw_cfg: out of file slots\n");

        return 0;

    }



    fw_cfg_add_bytes(s, FW_CFG_FILE_FIRST + index, data, len);



    basename = strrchr(filename, '/');

    if (basename) {

        basename++;

    } else {

        basename = filename;

    }

    if (dir) {

        snprintf(s->files->f[index].name, sizeof(s->files->f[index].name),

                 "%s/%s", dir, basename);

    } else {

        snprintf(s->files->f[index].name, sizeof(s->files->f[index].name),

                 "%s", basename);

    }

    s->files->f[index].size   = cpu_to_be32(len);

    s->files->f[index].select = cpu_to_be16(FW_CFG_FILE_FIRST + index);

    FW_CFG_DPRINTF("%s: #%d: %s (%d bytes)\n", __FUNCTION__,

                   index, s->files->f[index].name, len);



    s->files->count = cpu_to_be32(index+1);

    return 1;

}

int fw_cfg_add_file(FWCfgState *s,  const char *dir, const char *filename,

                    uint8_t *data, uint32_t len)

{

    const char *basename;

    int index;



    if (!s->files) {

        int dsize = sizeof(uint32_t) + sizeof(FWCfgFile) * FW_CFG_FILE_SLOTS;

        s->files = qemu_mallocz(dsize);

        fw_cfg_add_bytes(s, FW_CFG_FILE_DIR, (uint8_t*)s->files, dsize);

    }



    index = be32_to_cpu(s->files->count);

    if (index == FW_CFG_FILE_SLOTS) {

        fprintf(stderr, "fw_cfg: out of file slots\n");

        return 0;

    }



    fw_cfg_add_bytes(s, FW_CFG_FILE_FIRST + index, data, len);



    basename = strrchr(filename, '/');

    if (basename) {

        basename++;

    } else {

        basename = filename;

    }

    if (dir) {

        snprintf(s->files->f[index].name, sizeof(s->files->f[index].name),

                 "%s/%s", dir, basename);

    } else {

        snprintf(s->files->f[index].name, sizeof(s->files->f[index].name),

                 "%s", basename);

    }

    s->files->f[index].size   = cpu_to_be32(len);

    s->files->f[index].select = cpu_to_be16(FW_CFG_FILE_FIRST + index);

    FW_CFG_DPRINTF("%s: #%d: %s (%d bytes)\n", __FUNCTION__,

                   index, s->files->f[index].name, len);



    s->files->count = cpu_to_be32(index+1);

    return 1;

}

int FUNC_0(FWCfgState *VAR_0,  const char *VAR_1, const char *VAR_2,

                    uint8_t *VAR_3, uint32_t VAR_4)

{

    const char *VAR_5;

    int VAR_6;



    if (!VAR_0->files) {

        int VAR_7 = sizeof(uint32_t) + sizeof(FWCfgFile) * FW_CFG_FILE_SLOTS;

        VAR_0->files = qemu_mallocz(VAR_7);

        fw_cfg_add_bytes(VAR_0, FW_CFG_FILE_DIR, (uint8_t*)VAR_0->files, VAR_7);

    }



    VAR_6 = be32_to_cpu(VAR_0->files->count);

    if (VAR_6 == FW_CFG_FILE_SLOTS) {

        fprintf(stderr, "fw_cfg: out of file slots\n");

        return 0;

    }



    fw_cfg_add_bytes(VAR_0, FW_CFG_FILE_FIRST + VAR_6, VAR_3, VAR_4);



    VAR_5 = strrchr(VAR_2, '/');

    if (VAR_5) {

        VAR_5++;

    } else {

        VAR_5 = VAR_2;

    }

    if (VAR_1) {

        snprintf(VAR_0->files->f[VAR_6].name, sizeof(VAR_0->files->f[VAR_6].name),

                 "%VAR_0/%VAR_0", VAR_1, VAR_5);

    } else {

        snprintf(VAR_0->files->f[VAR_6].name, sizeof(VAR_0->files->f[VAR_6].name),

                 "%VAR_0", VAR_5);

    }

    VAR_0->files->f[VAR_6].size   = cpu_to_be32(VAR_4);

    VAR_0->files->f[VAR_6].select = cpu_to_be16(FW_CFG_FILE_FIRST + VAR_6);

    FW_CFG_DPRINTF("%VAR_0: #%d: %VAR_0 (%d bytes)\n", __FUNCTION__,

                   VAR_6, VAR_0->files->f[VAR_6].name, VAR_4);



    VAR_0->files->count = cpu_to_be32(VAR_6+1);

    return 1;

}

int FUNC_0(FWCfgState *VAR_0,  const char *VAR_1, const char *VAR_2,
uint8_t *VAR_3, uint32_t VAR_4)
{ const char *VAR_5; int VAR_6; if (!VAR_0->files) { int VAR_7 = sizeof(uint32_t) + sizeof(FWCfgFile) * FW_CFG_FILE_SLOTS; VAR_0->files = qemu_mallocz(VAR_7); fw_cfg_add_bytes(VAR_0, FW_CFG_FILE_DIR, (uint8_t*)VAR_0->files, VAR_7); } VAR_6 = be32_to_cpu(VAR_0->files->count); if (VAR_6 == FW_CFG_FILE_SLOTS) { fprintf(stderr, "fw_cfg: out of file slots\n"); return 0; } fw_cfg_add_bytes(VAR_0, FW_CFG_FILE_FIRST + VAR_6, VAR_3, VAR_4); VAR_5 = strrchr(VAR_2, '/'); if (VAR_5) { VAR_5++; } else { VAR_5 = VAR_2; } if (VAR_1) { snprintf(VAR_0->files->f[VAR_6].name, sizeof(VAR_0->files->f[VAR_6].name),
"%VAR_0/%VAR_0", VAR_1, VAR_5); } else { snprintf(VAR_0->files->f[VAR_6].name, sizeof(VAR_0->files->f[VAR_6].name),
"%VAR_0", VAR_5); } VAR_0->files->f[VAR_6].size   = cpu_to_be32(VAR_4); VAR_0->files->f[VAR_6].select = cpu_to_be16(FW_CFG_FILE_FIRST + VAR_6); FW_CFG_DPRINTF("%VAR_0: #%d: %VAR_0 (%d bytes)\n", __FUNCTION__,
VAR_6, VAR_0->files->f[VAR_6].name, VAR_4); VAR_0->files->count = cpu_to_be32(VAR_6+1); return 1; }