int fw_cfg_add_file(FWCfgState *s,  const char *filename, uint8_t *data,

                    uint32_t len)

{

    int i, index;



    if (!s->files) {

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

        s->files = g_malloc0(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);



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

            filename);

    for (i = 0; i < index; i++) {

        if (strcmp(s->files->f[index].name, s->files->f[i].name) == 0) {

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

            return 1;

        }

    }



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

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

    trace_fw_cfg_add_file(s, 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 *filename, uint8_t *data,

                    uint32_t len)

{

    int i, index;



    if (!s->files) {

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

        s->files = g_malloc0(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);



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

            filename);

    for (i = 0; i < index; i++) {

        if (strcmp(s->files->f[index].name, s->files->f[i].name) == 0) {

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

            return 1;

        }

    }



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

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

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



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

    return 1;

}

        return 0;     return 1;         return 0;         return 0;     return 1; int fw_cfg_add_file(FWCfgState *s,  const char *filename, uint8_t *data,                     uint32_t len)     if (index == FW_CFG_FILE_SLOTS) {         fprintf(stderr, "fw_cfg: out of file slots\n");         return 0;             return 1;     return 1;
int FUNC_0(FWCfgState *VAR_0,  const char *VAR_1, uint8_t *VAR_2,

                    uint32_t VAR_3)

{

    int VAR_4, VAR_5;



    if (!VAR_0->files) {

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

        VAR_0->files = g_malloc0(VAR_6);

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

    }



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

    if (VAR_5 == 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_5, VAR_2, VAR_3);



    pstrcpy(VAR_0->files->f[VAR_5].name, sizeof(VAR_0->files->f[VAR_5].name),

            VAR_1);

    for (VAR_4 = 0; VAR_4 < VAR_5; VAR_4++) {

        if (strcmp(VAR_0->files->f[VAR_5].name, VAR_0->files->f[VAR_4].name) == 0) {

            trace_fw_cfg_add_file_dupe(VAR_0, VAR_0->files->f[VAR_5].name);

            return 1;

        }

    }



    VAR_0->files->f[VAR_5].size   = cpu_to_be32(VAR_3);

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

    trace_fw_cfg_add_file(VAR_0, VAR_5, VAR_0->files->f[VAR_5].name, VAR_3);



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

    return 1;

}

int FUNC_0(FWCfgState *VAR_0,  const char *VAR_1, uint8_t *VAR_2,
uint32_t VAR_3)
{ int VAR_4, VAR_5; if (!VAR_0->files) { int VAR_6 = sizeof(uint32_t) + sizeof(FWCfgFile) * FW_CFG_FILE_SLOTS; VAR_0->files = g_malloc0(VAR_6); fw_cfg_add_bytes(VAR_0, FW_CFG_FILE_DIR, (uint8_t*)VAR_0->files, VAR_6); } VAR_5 = be32_to_cpu(VAR_0->files->count); if (VAR_5 == 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_5, VAR_2, VAR_3); pstrcpy(VAR_0->files->f[VAR_5].name, sizeof(VAR_0->files->f[VAR_5].name),
VAR_1); for (VAR_4 = 0; VAR_4 < VAR_5; VAR_4++) { if (strcmp(VAR_0->files->f[VAR_5].name, VAR_0->files->f[VAR_4].name) == 0) { trace_fw_cfg_add_file_dupe(VAR_0, VAR_0->files->f[VAR_5].name); return 1; } } VAR_0->files->f[VAR_5].size   = cpu_to_be32(VAR_3); VAR_0->files->f[VAR_5].select = cpu_to_be16(FW_CFG_FILE_FIRST + VAR_5); trace_fw_cfg_add_file(VAR_0, VAR_5, VAR_0->files->f[VAR_5].name, VAR_3); VAR_0->files->count = cpu_to_be32(VAR_5+1); return 1; }