multirom_themes_info *multirom_ui_init_themes(void) { multirom_themes_info *i = mzalloc(sizeof(multirom_themes_info)); i->data = mzalloc(sizeof(multirom_theme_data)); i->data->selected_tab = -1; #define ADD_THEME(RES) \ extern struct multirom_theme theme_info_ ## RES; \ list_add(&theme_info_ ## RES, &i->themes); #ifdef MULTIROM_THEME_800x1280 ADD_THEME(800x1280); #endif #ifdef MULTIROM_THEME_1280x800 ADD_THEME(1280x800); #endif #ifdef MULTIROM_THEME_1200x1920 ADD_THEME(1200x1920); #endif #ifdef MULTIROM_THEME_1920x1200 ADD_THEME(1920x1200); #endif return i; }
static void init_header(multirom_theme_data *t) { button **tab_btns = t->tab_btns; fb_text **tab_texts = t->tab_texts; const int TAB_BTN_WIDTH = fb_width*0.21; int i; int x = fb_width - (TAB_BTN_WIDTH*TAB_COUNT); static const char *str[] = { "Internal", "External", "Misc", "MultiROM" }; char buff[64]; fb_add_rect_lvl(100, 0, 0, fb_width, HEADER_HEIGHT, C_HIGHLIGHT_BG); ncard_set_top_offset(HEADER_HEIGHT); int maxW = 0; for(i = 0; i < TAB_COUNT; ++i) { fb_text_proto *p = fb_text_create(0, 0, C_HIGHLIGHT_TEXT, SIZE_BIG, str[i]); p->level = 110; tab_texts[i] = fb_text_finalize(p); maxW = imax(maxW, tab_texts[i]->w); } maxW += (30*DPI_MUL); x = fb_width/2 - (maxW*TAB_COUNT)/2; snprintf(buff, sizeof(buff), ":/miri_%dx%d.png", (int)MIRI_W, (int)MIRI_W); fb_img *logo = fb_add_png_img_lvl(110, 10*DPI_MUL, HEADER_HEIGHT/2 - MIRI_W/2, MIRI_W, MIRI_W, buff); if(logo) { pong_btn = mzalloc(sizeof(button)); pong_btn->x = logo->x; pong_btn->y = logo->y; pong_btn->w = logo->w; pong_btn->h = logo->h; pong_btn->clicked = &multirom_ui_start_pong; button_init_ui(pong_btn, NULL, 0); } for(i = 0; i < TAB_COUNT; ++i) { center_text(tab_texts[i], x, 0, maxW, HEADER_HEIGHT); tab_btns[i] = mzalloc(sizeof(button)); tab_btns[i]->x = x; tab_btns[i]->y = 0; tab_btns[i]->w = maxW; tab_btns[i]->h = HEADER_HEIGHT; tab_btns[i]->action = i; tab_btns[i]->clicked = &multirom_ui_switch; tab_btns[i]->level_off = 100; button_init_ui(tab_btns[i], "", 0); keyaction_add(tab_btns[i], button_keyaction_call, tab_btns[i]); x += maxW; } t->selected_tab_rect = fb_add_rect_lvl(110, tab_btns[0]->x, HEADER_HEIGHT-SELECTED_RECT_H, maxW, SELECTED_RECT_H, C_HIGHLIGHT_TEXT); t->tabs = tabview_create(0, HEADER_HEIGHT, fb_width, fb_height-HEADER_HEIGHT); }
multirom_themes_info *multirom_ui_init_themes(void) { multirom_themes_info *i = mzalloc(sizeof(multirom_themes_info)); i->data = mzalloc(sizeof(multirom_theme_data)); #define ADD_THEME(RES) \ extern struct multirom_theme theme_info_ ## RES; \ list_add(&i->themes, &theme_info_ ## RES); // universal themes which scale according to DPI_MUL ADD_THEME(landscape); ADD_THEME(portrait); return i; }
void cacheino(struct ufs1_dinode *dp, ufs1_ino_t inumber) { struct inoinfo *inp; struct inoinfo **inpp; int blks; blks = howmany(dp->di_size, sblock.fs_bsize); if (blks > NDADDR) blks = NDADDR + NIADDR; inp = mzalloc(&inoinfo_zone, sizeof(*inp) + (blks - 1) * sizeof(ufs_daddr_t)); if (inp == NULL) errx(EEXIT, "cannot increase directory list"); inpp = &inphead[DIRHASH(inumber)]; inp->i_nexthash = *inpp; *inpp = inp; inp->i_parent = inumber == ROOTINO ? ROOTINO : (ufs1_ino_t)0; inp->i_dotdot = (ufs1_ino_t)0; inp->i_number = inumber; inp->i_isize = dp->di_size; inp->i_numblks = blks * sizeof(ufs_daddr_t); memmove(&inp->i_blks[0], &dp->di_db[0], (size_t)inp->i_numblks); if (inplast == listmax) { listmax += 100; inpsort = (struct inoinfo **)realloc((char *)inpsort, (unsigned)listmax * sizeof(struct inoinfo *)); if (inpsort == NULL) errx(EEXIT, "cannot increase directory list"); } inpsort[inplast++] = inp; }
static void init_header(multirom_theme_data *t) { button **tab_btns = t->tab_btns; fb_text **tab_texts = t->tab_texts; const int TAB_BTN_WIDTH = fb_width*0.21; int i, x; static const char *str[] = { "INTERNAL", "EXTERNAL", "MISC" }; char buff[64]; fb_add_rect_lvl(100, 0, 0, fb_width, HEADER_HEIGHT, C_HIGHLIGHT_BG); fb_add_rect(0, HEADER_HEIGHT, fb_width, (3*DPI_MUL), C_BTN_FAKE_SHADOW); ncard_set_top_offset(HEADER_HEIGHT); int maxW = 0; for(i = 0; i < TAB_COUNT; ++i) { fb_text_proto *p = fb_text_create(0, 0, C_HIGHLIGHT_TEXT, SIZE_NORMAL, str[i]); p->level = 110; p->style = STYLE_MEDIUM; tab_texts[i] = fb_text_finalize(p); maxW = imax(maxW, tab_texts[i]->w); } maxW += (30*DPI_MUL); x = fb_width/2 - (maxW*TAB_COUNT)/2; snprintf(buff, sizeof(buff), ":/miri_%dx%d.png", (int)MIRI_W, (int)MIRI_W); fb_add_png_img_lvl(110, 10*DPI_MUL, HEADER_HEIGHT/2 - MIRI_W/2, MIRI_W, MIRI_W, buff); for(i = 0; i < TAB_COUNT; ++i) { center_text(tab_texts[i], x, 0, maxW, HEADER_HEIGHT); tab_btns[i] = mzalloc(sizeof(button)); tab_btns[i]->x = x; tab_btns[i]->y = 0; tab_btns[i]->w = maxW; tab_btns[i]->h = HEADER_HEIGHT; tab_btns[i]->clicked_data = malloc(sizeof(int)); *((int*)tab_btns[i]->clicked_data) = i; tab_btns[i]->clicked = &multirom_ui_switch_btn; tab_btns[i]->level_off = 100; button_init_ui(tab_btns[i], "", 0); keyaction_add(tab_btns[i], button_keyaction_call, tab_btns[i]); x += maxW; if(i < TAB_COUNT-1) t->selected_rect[i] = fb_add_rect_lvl(120, 0, 0, 0, 0, (0x4C << 24) | (C_HIGHLIGHT_BG & 0x00FFFFFF)); } t->selected_tab_rect = fb_add_rect_lvl(110, tab_btns[0]->x, HEADER_HEIGHT-SELECTED_RECT_H + (3*DPI_MUL), maxW, SELECTED_RECT_H, C_HIGHLIGHT_TEXT); t->tabs = tabview_create(0, HEADER_HEIGHT, fb_width, fb_height-HEADER_HEIGHT); header_set_tab_selector_pos(t, 0.f); }
static void add_touch_handler_priv(touch_callback callback, void *data) { touch_handler *handler = mzalloc(sizeof(touch_handler)); handler->data = data; handler->callback = callback; handler_list_it *new_it = mzalloc(sizeof(handler_list_it)); new_it->handler = handler; pthread_mutex_lock(&touch_mutex); handler_list_it *it = mt_handlers; if(mt_handlers) it->prev = new_it; new_it->next = it; mt_handlers = new_it; pthread_mutex_unlock(&touch_mutex); }
void input_push_context(void) { handlers_ctx *ctx = mzalloc(sizeof(handlers_ctx)); pthread_mutex_lock(&touch_mutex); ctx->handlers = mt_handlers; mt_handlers = NULL; pthread_mutex_unlock(&touch_mutex); list_add(&inactive_ctx, ctx); }
void *multirom_ui_tab_rom_init(int tab_type) { tab_data_roms *t = mzalloc(sizeof(tab_data_roms)); themes_info->data->tab_data = t; t->list = mzalloc(sizeof(listview)); t->list->item_draw = &rom_item_draw; t->list->item_hide = &rom_item_hide; t->list->item_height = &rom_item_height; t->list->item_destroy = &rom_item_destroy; t->list->item_selected = &multirom_ui_tab_rom_selected; t->list->item_confirmed = &multirom_ui_tab_rom_confirmed; t->boot_btn = mzalloc(sizeof(button)); list_add(t->boot_btn, &t->buttons); cur_theme->tab_rom_init(themes_info->data, t, tab_type); listview_init_ui(t->list); if(tab_type == TAB_INTERNAL) multirom_ui_fill_rom_list(t->list, MASK_INTERNAL); listview_update_ui(t->list); int has_roms = (int)(t->list->items == NULL); multirom_ui_tab_rom_set_empty((void*)t, has_roms); t->boot_btn->clicked = &multirom_ui_tab_rom_boot_btn; button_init_ui(t->boot_btn, "Boot", SIZE_BIG); button_enable(t->boot_btn, !has_roms); if(tab_type == TAB_USB) { multirom_set_usb_refresh_handler(&multirom_ui_refresh_usb_handler); multirom_set_usb_refresh_thread(mrom_status, 1); } return t; }
static void touch_handler_thread_dispatcher(int force_async, handler_call h_c, touch_callback callback, void *data) { if(force_async || pthread_self() == input_thread) { struct handler_thread_data *d = mzalloc(sizeof(struct handler_thread_data)); d->handler = h_c; d->callback = callback; d->data = data; pthread_t handler_thread; pthread_create(&handler_thread, NULL, touch_handler_thread_work, d); } else h_c(callback, data); }
progdots *progdots_create(int x, int y) { progdots *p = mzalloc(sizeof(progdots)); p->x = x; p->y = y; p->switch_timer = SWITCH_SPEED; int i; for(i = 0; i < PROGDOTS_CNT; ++i) { p->dots[i] = fb_add_rect(x, y, PROGDOTS_H, PROGDOTS_H, (i == 0 ? CLR_PRIMARY : WHITE)); x += PROGDOTS_H + (PROGDOTS_W - (PROGDOTS_CNT*PROGDOTS_H))/(PROGDOTS_CNT-1); } workers_add(progdots_animate, p); fb_draw(); return p; }
static void init_header(multirom_theme_data *t) { button **tab_btns = t->tab_btns; fb_text **tab_texts = t->tab_texts; int i, text_x, text_y; int x = fb_width - (TAB_BTN_WIDTH*TAB_COUNT); static const char *str[] = { "Internal", "USB", "Misc", "MultiROM" }; text_x = center_x(0, x, SIZE_EXTRA, str[3]); fb_add_text(text_x, 5, WHITE, SIZE_EXTRA, str[3]); pong_btn = mzalloc(sizeof(button)); pong_btn->w = x; pong_btn->h = HEADER_HEIGHT; pong_btn->clicked = &multirom_ui_start_pong; button_init_ui(pong_btn, NULL, 0); for(i = 0; i < TAB_COUNT; ++i) { text_x = center_x(x, TAB_BTN_WIDTH, SIZE_NORMAL, str[i]); text_y = center_y(0, HEADER_HEIGHT, SIZE_NORMAL); tab_texts[i] = fb_add_text(text_x, text_y, WHITE, SIZE_NORMAL, str[i]); fb_add_rect(x, 0, 2, HEADER_HEIGHT, WHITE); tab_btns[i] = malloc(sizeof(button)); memset(tab_btns[i], 0, sizeof(button)); tab_btns[i]->x = x; tab_btns[i]->w = TAB_BTN_WIDTH; tab_btns[i]->h = HEADER_HEIGHT; tab_btns[i]->action = i; tab_btns[i]->clicked = &multirom_ui_switch; button_init_ui(tab_btns[i], NULL, 0); x += TAB_BTN_WIDTH; } fb_add_rect(0, HEADER_HEIGHT, fb_width, 2, WHITE); }
static int impl_open(struct framebuffer *fb) { struct fb_qcom_overlay_data *data = mzalloc(sizeof(struct fb_qcom_overlay_data)); data->overlay_id = MSMFB_NEW_REQUEST; if (alloc_ion_mem(data, fb->fi.line_length * fb->vi.yres) < 0) goto fail; if(allocate_overlay(data, fb->fd, fb->vi.xres, fb->vi.yres) < 0) { free_ion_mem(data); goto fail; } fb->impl_data = data; return 0; fail: free(data); return -1; }
static void tab_misc_init(multirom_theme_data *t, tab_data_misc *d, int color_scheme) { int i; int x = fb_width/2 - (MISCBTN_W + 30*DPI_MUL); int y = HEADER_HEIGHT + ((fb_height - HEADER_HEIGHT)/2 - 2*(MISCBTN_H + 30*DPI_MUL)); fb_rect *shadow; y += MISCBTN_H + 30*DPI_MUL; button *b = mzalloc(sizeof(button)); b->x = x; b->y = y; b->w = MISCBTN_W; b->h = MISCBTN_H; b->clicked = &multirom_ui_tab_misc_copy_log; shadow = fb_add_rect_lvl(LEVEL_RECT, b->x + BTN_SHADOW_OFF, b->y + BTN_SHADOW_OFF, b->w, b->h, C_BTN_FAKE_SHADOW); button_init_ui(b, "COPY LOG TO /SDCARD", SIZE_NORMAL); list_add(&d->buttons, b); list_add(&d->ui_elements, shadow); tabview_add_item(t->tabs, TAB_MISC, b->text); tabview_add_item(t->tabs, TAB_MISC, b->rect); tabview_add_item(t->tabs, TAB_MISC, b); const int max_colors = colors_count(); x += (MISCBTN_W/2 - (max_colors*(CLRBTN_TOTAL+CLRBTN_MARGIN))/2); y += MISCBTN_H+30*DPI_MUL + (MISCBTN_H/2 - CLRBTN_TOTAL/2); fb_rect *r; for(i = 0; i < max_colors; ++i) { const struct mrom_color_theme *th = colors_get(i); r = fb_add_rect(x, y, CLRBTN_TOTAL, CLRBTN_TOTAL, i == color_scheme ? 0xFFFFCC00 : WHITE); list_add(&d->ui_elements, r); r = fb_add_rect(x+CLRBTN_B/2, y+CLRBTN_B/2, CLRBTN_W, CLRBTN_W, th->highlight_bg); list_add(&d->ui_elements, r); b = mzalloc(sizeof(button)); b->x = x; b->y = y; b->w = CLRBTN_TOTAL; b->h = CLRBTN_TOTAL; b->clicked_data = malloc(sizeof(int)); *((int*)b->clicked_data) = i; b->clicked = &multirom_ui_tab_misc_change_clr; button_init_ui(b, NULL, 0); list_add(&d->buttons, b); tabview_add_item(t->tabs, TAB_MISC, b); x += CLRBTN_TOTAL + CLRBTN_MARGIN; } x = fb_width/2 - (MISCBTN_W + 30*DPI_MUL) + MISCBTN_W + 30*DPI_MUL; y = HEADER_HEIGHT + ((fb_height - HEADER_HEIGHT)/2 - 2*(MISCBTN_H + 30*DPI_MUL)); static const char *texts[] = { "REBOOT", // 0 "REBOOT TO RECOVERY", // 1 "REBOOT TO BOOTLOADER", // 2 "SHUTDOWN", // 3 NULL }; static const int exit_codes[] = { UI_EXIT_REBOOT, UI_EXIT_REBOOT_RECOVERY, UI_EXIT_REBOOT_BOOTLOADER, UI_EXIT_SHUTDOWN }; for(i = 0; texts[i]; ++i) { b = mzalloc(sizeof(button)); b->x = x; b->y = y; b->w = MISCBTN_W; b->h = MISCBTN_H; b->clicked_data = malloc(sizeof(int)); *((int*)b->clicked_data) = exit_codes[i]; b->clicked = &multirom_ui_reboot_btn; shadow = fb_add_rect_lvl(LEVEL_RECT, b->x + BTN_SHADOW_OFF, b->y + BTN_SHADOW_OFF, b->w, b->h, C_BTN_FAKE_SHADOW); button_init_ui(b, texts[i], SIZE_NORMAL); list_add(&d->buttons, b); list_add(&d->ui_elements, shadow); tabview_add_item(t->tabs, TAB_MISC, b->text); tabview_add_item(t->tabs, TAB_MISC, b->rect); tabview_add_item(t->tabs, TAB_MISC, b); y += MISCBTN_H+30*DPI_MUL; } fb_text *text = fb_add_text(5*DPI_MUL, 0, C_TEXT_SECONDARY, SIZE_SMALL, "MultiROM v%d"VERSION_DEV_FIX" with trampoline v%d.", VERSION_MULTIROM, multirom_get_trampoline_ver()); text->y = fb_height - text->h; list_add(&d->ui_elements, text); text = fb_add_text(0, 0, C_TEXT_SECONDARY, SIZE_SMALL, "Battery: %d%%", multirom_get_battery()); text->x = fb_width - text->w - 5*DPI_MUL; text->y = fb_height - text->h; list_add(&d->ui_elements, text); for(i = 0; d->buttons[i]; ++i) keyaction_add(d->buttons[i], button_keyaction_call, d->buttons[i]); tabview_add_items(t->tabs, TAB_MISC, d->ui_elements); }
static void tab_misc_init(multirom_theme_data *t, tab_data_misc *d, int color_scheme) { int x = fb_width/2 - MISCBTN_W/2; int y = 270*DPI_MUL; button *b = mzalloc(sizeof(button)); b->x = x; b->y = y; b->w = MISCBTN_W; b->h = MISCBTN_H; b->clicked = &multirom_ui_tab_misc_copy_log; button_init_ui(b, "Copy log to /sdcard", SIZE_BIG); list_add(&d->buttons, b); tabview_add_item(t->tabs, TAB_MISC, b->text); tabview_add_item(t->tabs, TAB_MISC, b->rect); tabview_add_item(t->tabs, TAB_MISC, b); y += MISCBTN_H+70*DPI_MUL; static const char *texts[] = { "Reboot", // 0 "Reboot to recovery", // 1 "Reboot to bootloader", // 2 "Shutdown", // 3 NULL }; static const int exit_codes[] = { UI_EXIT_REBOOT, UI_EXIT_REBOOT_RECOVERY, UI_EXIT_REBOOT_BOOTLOADER, UI_EXIT_SHUTDOWN }; int i; for(i = 0; texts[i]; ++i) { b = mzalloc(sizeof(button)); b->x = x; b->y = y; b->w = MISCBTN_W; b->h = MISCBTN_H; b->action = exit_codes[i]; b->clicked = &multirom_ui_reboot_btn; button_init_ui(b, texts[i], SIZE_BIG); list_add(&d->buttons, b); tabview_add_item(t->tabs, TAB_MISC, b->text); tabview_add_item(t->tabs, TAB_MISC, b->rect); tabview_add_item(t->tabs, TAB_MISC, b); y += MISCBTN_H+20*DPI_MUL; if(i == 2) y += 50*DPI_MUL; } fb_text *text = fb_add_text(5*DPI_MUL, 0, C_TEXT_SECONDARY, SIZE_SMALL, "MultiROM v%d"VERSION_DEV_FIX" with trampoline v%d.", VERSION_MULTIROM, multirom_get_trampoline_ver()); text->y = fb_height - text->h; list_add(&d->ui_elements, text); text = fb_add_text(0, 0, C_TEXT_SECONDARY, SIZE_SMALL, "Battery: %d%%", multirom_get_battery()); text->x = fb_width - text->w - 5*DPI_MUL; text->y = fb_height - text->h; list_add(&d->ui_elements, text); const int max_colors = multirom_ui_get_color_theme_count(); x = fb_width/2 - (max_colors*(CLRBTN_TOTAL+CLRBTN_MARGIN))/2; fb_rect *r; for(i = 0; i < max_colors; ++i) { const struct multirom_color_theme *th = multirom_ui_get_color_theme(i); r = fb_add_rect(x, CLRBTN_Y, CLRBTN_TOTAL, CLRBTN_TOTAL, i == color_scheme ? 0xFFFFCC00 : WHITE); list_add(&d->ui_elements, r); r = fb_add_rect(x+CLRBTN_B/2, CLRBTN_Y+CLRBTN_B/2, CLRBTN_W, CLRBTN_W, th->highlight_bg); list_add(&d->ui_elements, r); b = mzalloc(sizeof(button)); b->x = x; b->y = CLRBTN_Y; b->w = CLRBTN_TOTAL; b->h = CLRBTN_TOTAL; b->action = i; b->clicked = &multirom_ui_tab_misc_change_clr; button_init_ui(b, NULL, 0); list_add(&d->buttons, b); tabview_add_item(t->tabs, TAB_MISC, b); x += CLRBTN_TOTAL + CLRBTN_MARGIN; } for(i = 0; d->buttons[i]; ++i) keyaction_add(d->buttons[i], button_keyaction_call, d->buttons[i]); tabview_add_items(t->tabs, TAB_MISC, d->ui_elements); }
void *multirom_ui_tab_misc_init(void) { tab_data_misc *t = mzalloc(sizeof(tab_data_misc)); cur_theme->tab_misc_init(themes_info->data, t, mrom_status->colors); return t; }
map *map_create(void) { map *m = mzalloc(sizeof(map)); return m; }
static void tab_misc_init(multirom_theme_data *t, tab_data_misc *d, int color_scheme) { int x = HEADER_WIDTH + ((fb_width - HEADER_WIDTH)/2 - MISCBTN_W/2); int y = 10; button *b = mzalloc(sizeof(button)); b->x = x; b->y = y; b->w = MISCBTN_W; b->h = MISCBTN_H; b->clicked = &multirom_ui_tab_misc_copy_log; button_init_ui(b, "Copy log to /sdcard", SIZE_BIG); list_add(b, &d->buttons); y += MISCBTN_H+50; static const char *texts[] = { "Reboot", // 0 "Reboot to recovery", // 1 "Reboot to bootloader", // 2 "Shutdown", // 3 NULL }; static const int exit_codes[] = { UI_EXIT_REBOOT, UI_EXIT_REBOOT_RECOVERY, UI_EXIT_REBOOT_BOOTLOADER, UI_EXIT_SHUTDOWN }; int i; for(i = 0; texts[i]; ++i) { b = mzalloc(sizeof(button)); b->x = x; b->y = y; b->w = MISCBTN_W; b->h = MISCBTN_H; b->action = exit_codes[i]; b->clicked = &multirom_ui_reboot_btn; button_init_ui(b, texts[i], SIZE_BIG); list_add(b, &d->buttons); y += MISCBTN_H+20; if(i == 2) y += 30; } fb_text *text = fb_add_text(HEADER_WIDTH+5, fb_height-16, WHITE, SIZE_SMALL, "MultiROM v%d"VERSION_DEV_FIX" with trampoline v%d.", VERSION_MULTIROM, multirom_get_trampoline_ver()); list_add(text, &d->ui_elements); char bat_text[16]; sprintf(bat_text, "Battery: %d%%", multirom_get_battery()); text = fb_add_text_long(fb_width-strlen(bat_text)*8, fb_height-16, WHITE, SIZE_SMALL, bat_text); list_add(text, &d->ui_elements); x = HEADER_WIDTH + ((fb_width - HEADER_WIDTH)/2 - (CLRS_MAX*CLRBTN_TOTAL)/2); uint32_t p, s; fb_rect *r; for(i = 0; i < CLRS_MAX; ++i) { multirom_ui_setup_colors(i, &p, &s); if(i == color_scheme) { r = fb_add_rect(x, CLRBTN_Y, CLRBTN_TOTAL, CLRBTN_TOTAL, WHITE); list_add(r, &d->ui_elements); } r = fb_add_rect(x+CLRBTN_B/2, CLRBTN_Y+CLRBTN_B/2, CLRBTN_W, CLRBTN_W, p); list_add(r, &d->ui_elements); b = mzalloc(sizeof(button)); b->x = x; b->y = CLRBTN_Y; b->w = CLRBTN_TOTAL; b->h = CLRBTN_TOTAL; b->action = i; b->clicked = &multirom_ui_tab_misc_change_clr; button_init_ui(b, NULL, 0); list_add(b, &d->buttons); x += CLRBTN_TOTAL; } }
struct fstab *fstab_load(const char *path) { FILE *f = fopen(path, "r"); if(!f) { ERROR("Failed to open fstab %s\n", path); return NULL; } struct fstab *t = mzalloc(sizeof(struct fstab)); t->version = -1; const char *delim = " \t"; char *saveptr = NULL; char *p; char line[1024]; int len; struct fstab_part *part = NULL; while((p = fgets(line, sizeof(line), f))) { len = strlen(line); if(line[len-1] == '\n') line[len-1] = 0; while(isspace(*p)) ++p; if(*p == '#' || *p == 0) continue; part = mzalloc(sizeof(struct fstab_part)); if(!(p = strtok_r(line, delim, &saveptr))) { ERROR("Error first token\n"); goto fail; } if(t->version == -1) { if(strstr(p, "/dev/") == p) t->version = 2; else t->version = 1; } if(t->version == 2) part->device = readlink_recursive(p); else part->path = strdup (p); if(!(p = strtok_r(NULL, delim, &saveptr))) { ERROR("Error second token\n"); goto fail; } if(t->version == 2) part->path = strdup(p); else part->type = strdup(p); if(!(p = strtok_r(NULL, delim, &saveptr))) { ERROR("Error third token\n"); goto fail; } if(t->version == 2) part->type = strdup(p); else part->device = readlink_recursive(p); if((p = strtok_r(NULL, delim, &saveptr))) fstab_parse_options(p, part); if((p = strtok_r(NULL, delim, &saveptr))) part->options2 = strdup(p); // Check device if(!part->device) { if (strcmp(part->path, "/data") == 0 || strcmp(part->path, "/system") == 0 || strcmp(part->path, "/boot") == 0 || strcmp(part->path, "/cache") == 0) { ERROR("fstab: device for part %s does not exist!\n", part->path); } fstab_destroy_part(part); part = NULL; continue; } list_add(part, &t->parts); ++t->count; part = NULL; } fclose(f); return t; fail: fclose(f); free(part); fstab_destroy(t); return NULL; }