void display_message(const char*msg) { static const struct MenuItem menuGeometry[]= { { 'Q', "Ok", "" }, { 0, NULL, NULL } }; WINDOW *window=newwin(LINES, COLS, 0, 0); /* full screen */ log_info("%s",msg); aff_copy(window); mvwaddstr(window,5,0,msg); wmenuSimple(window,menuGeometry, 0); delwin(window); (void) clearok(stdscr, TRUE); #ifdef HAVE_TOUCHWIN touchwin(stdscr); #endif }
static void interface_editor_location(const disk_t *disk, uint64_t *lba) { const struct MenuItem menuGeometry[]= { { 'c', "Cylinders", "Change cylinder" }, { 'h', "Heads", "Change head" }, { 's', "Sectors", "Change sector" }, { 'l', "Logical Sectors", "Change logical sector" }, { 'd', "Done", "Done with changing" }, { 0, NULL, NULL } }; int default_option=4; while (1) { CHS_t location; char def[128]; char response[128]; unsigned long int tmp_val; int command; wmove(stdscr,5,0); wclrtoeol(stdscr); wprintw(stdscr,"%lu ", (unsigned long)(*lba/disk->sector_size)); aff_LBA2CHS(disk, *lba / disk->sector_size); offset2CHS(disk, *lba, &location); wmove(stdscr,INTER_GEOM_Y, INTER_GEOM_X); wclrtoeol(stdscr); wrefresh(stdscr); command=wmenuSimple(stdscr, menuGeometry, default_option); switch (command) { case 'c': case 'C': sprintf(def, "%lu", location.cylinder); mvwaddstr(stdscr,INTER_GEOM_Y, INTER_GEOM_X, "Enter the number of cylinders: "); if (get_string(stdscr, response, sizeof(response), def) > 0) { tmp_val = atol(response); if (tmp_val < disk->geom.cylinders) { location.cylinder = tmp_val; *lba=CHS2offset(disk,&location); } else wprintw(stdscr,"Illegal cylinders value"); } default_option=1; break; case 'h': case 'H': sprintf(def, "%u", location.head); mvwaddstr(stdscr,INTER_GEOM_Y, INTER_GEOM_X, "Enter the number of heads: "); if (get_string(stdscr, response, sizeof(response), def) > 0) { tmp_val = atoi(response); if (tmp_val < disk->geom.heads_per_cylinder) { location.head = tmp_val; *lba=CHS2offset(disk,&location); } else wprintw(stdscr,"Illegal heads value"); } default_option=2; break; case 's': case 'S': sprintf(def, "%u", location.sector); mvwaddstr(stdscr,INTER_GEOM_Y, INTER_GEOM_X, "Enter the number of sectors per track: "); if (get_string(stdscr, response, sizeof(response), def) > 0) { tmp_val = atoi(response); if (tmp_val > 0 && tmp_val <= disk->geom.sectors_per_head ) { location.sector = tmp_val; *lba=CHS2offset(disk,&location); } else wprintw(stdscr,"Illegal sectors value"); } default_option=3; break; case 'l': case 'L': { sprintf(def, "%lu", (unsigned long)(*lba / disk->sector_size)); mvwaddstr(stdscr,INTER_GEOM_Y, INTER_GEOM_X, "Enter the logical sector offset: "); if (get_string(stdscr, response, sizeof(response), def) > 0) { uint64_t l_sector; l_sector= strtoul(response, NULL, 10); l_sector*=disk->sector_size; if (l_sector <= disk->disk_size) { *lba=l_sector; } else wprintw(stdscr,"Illegal logical sector value"); } default_option=4; } break; case key_ESC: case 'd': case 'D': return; } } }
list_part_t *add_partition_gpt_ncurses(disk_t *disk_car,list_part_t *list_part, char **current_cmd) { int position=0; int done = FALSE; partition_t *new_partition=partition_new(&arch_gpt); new_partition->part_offset=disk_car->sector_size; new_partition->part_size=disk_car->disk_size-disk_car->sector_size; while (done==FALSE) { int command; static struct MenuItem menuGeometry[]= { { 's', "Sector", "Change starting sector" }, { 'S', "Sector", "Change ending sector" }, { 'T' ,"Type", "Change partition type"}, { 'd', "Done", "" }, { 0, NULL, NULL } }; aff_copy(stdscr); wmove(stdscr,4,0); wprintw(stdscr,"%s",disk_car->description(disk_car)); wmove(stdscr,10, 0); wclrtoeol(stdscr); aff_part(stdscr, AFF_PART_BASE, disk_car, new_partition); wmove(stdscr,INTER_GEOM_Y, INTER_GEOM_X); wclrtoeol(stdscr); wrefresh(stdscr); command=wmenuSimple(stdscr,menuGeometry, position); switch (command) { case 's': { uint64_t part_offset; part_offset=new_partition->part_offset; wmove(stdscr, INTER_GEOM_Y, INTER_GEOM_X); new_partition->part_offset=(uint64_t)ask_number( new_partition->part_offset/disk_car->sector_size, 1, (disk_car->disk_size-1)/disk_car->sector_size, "Enter the starting sector ") * (uint64_t)disk_car->sector_size; new_partition->part_size=new_partition->part_size + part_offset - new_partition->part_offset; position=1; } break; case 'S': wmove(stdscr, INTER_GEOM_Y, INTER_GEOM_X); new_partition->part_size=(uint64_t)ask_number( (new_partition->part_offset+new_partition->part_size-1)/disk_car->sector_size, new_partition->part_offset/disk_car->sector_size, (disk_car->disk_size-1)/disk_car->sector_size, "Enter the ending sector ") * (uint64_t)disk_car->sector_size + disk_car->sector_size - new_partition->part_offset; position=2; break; case 'T': case 't': change_part_type(disk_car,new_partition, current_cmd); position=3; break; case key_ESC: case 'd': case 'D': case 'q': case 'Q': done = TRUE; break; } } if(new_partition->part_size>0 && guid_cmp(new_partition->part_type_gpt, GPT_ENT_TYPE_UNUSED)!=0) { int insert_error=0; list_part_t *new_list_part=insert_new_partition(list_part, new_partition, 0, &insert_error); if(insert_error>0) { free(new_partition); return new_list_part; } new_partition->status=STATUS_PRIM; if(arch_gpt.test_structure(list_part)!=0) new_partition->status=STATUS_DELETED; return new_list_part; } free(new_partition); return list_part; }