static int read_graphics_fb_mode(int fb)
{
    int size=0;
    int fp_modes=0;
    char fb_modes[1024];
    char temp_name[256];

    sprintf(temp_name, "/sys/class/graphics/fb%d/modes", fb);
    fp_modes = open(temp_name,O_RDONLY, 0);
    if(fp_modes < 0) {
        LOGI("Error %d! Cannot open %s", fp_modes, temp_name);
        goto set_graphics_fb_mode_error;
    }

    memset(fb_modes, 0, sizeof(fb_modes));
    size = read(fp_modes, fb_modes, sizeof(fb_modes));
    if(size <= 0)
    {
        LOGI("Error! Cannot read %s", temp_name);
        goto set_graphics_fb_mode_error;
    }

    close(fp_modes); fp_modes = 0;

    if(size == sizeof(fb_modes)) fb_modes[size -1] = 0;

    get_available_mode(fb, fb_modes);

    return 0;

set_graphics_fb_mode_error:

    if(fp_modes > 0) close(fp_modes);

    return -1;
}
static int read_graphics_fb_mode(int fb)
{
    int size=0;
    int fp_modes=0;
    char fb_modes[1024];
    char temp_name[256];

    if (g_config_len == 0) {
        char conf_modes[1024];
        //int size;
        memset(conf_modes, 0, sizeof(conf_modes));
        memset(&g_config_mode[0], 0, sizeof(g_config_mode));
        int fd = open("/system/etc/display_mode_fb0.conf", O_RDONLY, 0);
        if(fd < 0) {
            LOGE("Warning: /system/etc/display_mode_fb0.conf not defined");
        }
        else {
            size = read(fd, conf_modes, sizeof(conf_modes));
            if(size > 0) {
                char* m_start = conf_modes;
                int m_len = 0;
                char *pmode = conf_modes;
                while(*pmode != '\0') {
                    if (*pmode == '\n') {
                        m_len = pmode - m_start + 1;
                        strncpy(g_config_mode[g_config_len].mode, m_start, m_len);
                        g_config_len ++;
                        m_start = pmode + 1;
                    }
                    pmode ++;
                }//while
            }
            close(fd);
        }//else
    }

    sprintf(temp_name, "/sys/class/graphics/fb%d/modes", fb);
    fp_modes = open(temp_name,O_RDONLY, 0);
    if(fp_modes < 0) {
        LOGI("Error %d! Cannot open %s", fp_modes, temp_name);
        goto set_graphics_fb_mode_error;
    }

    memset(fb_modes, 0, sizeof(fb_modes));
    size = read(fp_modes, fb_modes, sizeof(fb_modes));
    if(size <= 0)
    {
        LOGI("Error! Cannot read %s", temp_name);
        goto set_graphics_fb_mode_error;
    }

    close(fp_modes); fp_modes = 0;

    if(size == sizeof(fb_modes)) fb_modes[size -1] = 0;

    get_available_mode(fb, fb_modes);

    read_mode_finished = 1;
    return 0;

set_graphics_fb_mode_error:

    if(fp_modes > 0) close(fp_modes);

    return -1;
}