static dir_partition_t dir_partition_init(disk_t *disk, const partition_t *partition, const int verbose, dir_data_t *dir_data) { dir_partition_t res=DIR_PART_ENOSYS; if(is_part_fat(partition)) res=dir_partition_fat_init(disk, partition, dir_data, verbose); else if(is_part_ntfs(partition)) { res=dir_partition_ntfs_init(disk, partition, dir_data, verbose); if(res!=DIR_PART_OK) res=dir_partition_exfat_init(disk, partition, dir_data, verbose); } else if(is_part_linux(partition)) { res=dir_partition_ext2_init(disk, partition, dir_data, verbose); if(res!=DIR_PART_OK) res=dir_partition_reiser_init(disk, partition, dir_data, verbose); } if(res==DIR_PART_OK) return DIR_PART_OK; switch(partition->upart_type) { case UP_FAT12: case UP_FAT16: case UP_FAT32: return dir_partition_fat_init(disk, partition, dir_data, verbose); case UP_EXT4: case UP_EXT3: case UP_EXT2: return dir_partition_ext2_init(disk, partition, dir_data, verbose); case UP_RFS: case UP_RFS2: case UP_RFS3: return dir_partition_reiser_init(disk, partition, dir_data, verbose); case UP_NTFS: return dir_partition_ntfs_init(disk, partition, dir_data, verbose); case UP_EXFAT: return dir_partition_exfat_init(disk, partition, dir_data, verbose); default: return res; } }
static int is_exfat(const partition_t *partition) { return (is_part_ntfs(partition) || partition->upart_type==UP_EXFAT); }
int dir_partition(disk_t *disk_car, const partition_t *partition, const int verbose, char **current_cmd) { dir_data_t dir_data; #ifdef HAVE_NCURSES WINDOW *window; #endif int res=-3; fflush(stderr); dir_data.local_dir=NULL; if(is_part_fat(partition)) res=dir_partition_fat_init(disk_car,partition,&dir_data,verbose); else if(is_part_ntfs(partition)) { res=dir_partition_ntfs_init(disk_car,partition,&dir_data,verbose); if(res!=0) res=dir_partition_exfat_init(disk_car, partition, &dir_data, verbose); } else if(is_part_linux(partition)) { res=dir_partition_ext2_init(disk_car,partition,&dir_data,verbose); if(res!=0) res=dir_partition_reiser_init(disk_car,partition,&dir_data,verbose); } if(res!=0) { switch(partition->upart_type) { case UP_FAT12: case UP_FAT16: case UP_FAT32: res=dir_partition_fat_init(disk_car,partition,&dir_data,verbose); break; case UP_EXT4: case UP_EXT3: case UP_EXT2: res=dir_partition_ext2_init(disk_car,partition,&dir_data,verbose); break; case UP_RFS: case UP_RFS2: case UP_RFS3: res=dir_partition_reiser_init(disk_car,partition,&dir_data,verbose); break; case UP_NTFS: res=dir_partition_ntfs_init(disk_car,partition,&dir_data,verbose); break; case UP_EXFAT: res=dir_partition_exfat_init(disk_car, partition, &dir_data, verbose); break; default: return res; } } #ifdef HAVE_NCURSES window=newwin(LINES, COLS, 0, 0); /* full screen */ dir_data.display=window; aff_copy(window); #else dir_data.display=NULL; #endif log_info("\n"); switch(res) { case -2: screen_buffer_reset(); #ifdef HAVE_NCURSES aff_copy(window); wmove(window,4,0); aff_part(window,AFF_PART_ORDER|AFF_PART_STATUS,disk_car,partition); #endif log_partition(disk_car,partition); screen_buffer_add("Support for this filesystem hasn't been enable during compilation.\n"); screen_buffer_to_log(); if(*current_cmd==NULL) { #ifdef HAVE_NCURSES screen_buffer_display(window,"",NULL); #endif } break; case -1: screen_buffer_reset(); #ifdef HAVE_NCURSES aff_copy(window); wmove(window,4,0); aff_part(window,AFF_PART_ORDER|AFF_PART_STATUS,disk_car,partition); #endif log_partition(disk_car,partition); screen_buffer_add("Can't open filesystem. Filesystem seems damaged.\n"); screen_buffer_to_log(); if(*current_cmd==NULL) { #ifdef HAVE_NCURSES screen_buffer_display(window,"",NULL); #endif } break; default: { int recursive=0; if(*current_cmd!=NULL) { int do_continue; do { do_continue=0; while(*current_cmd[0]==',') (*current_cmd)++; if(strncmp(*current_cmd,"recursive",9)==0) { (*current_cmd)+=9; recursive=1; do_continue=1; } else if(strncmp(*current_cmd,"fullpathname",12)==0) { (*current_cmd)+=12; dir_data.param|=FLAG_LIST_PATHNAME; do_continue=1; } } while(do_continue==1); } if(recursive>0) dir_whole_partition_log(disk_car,partition,&dir_data,dir_data.current_inode); else { #ifdef HAVE_NCURSES dir_partition_aff(disk_car, partition, &dir_data, dir_data.current_inode, current_cmd); #else { file_data_t *dir_list; dir_list=dir_data.get_dir(disk_car, partition, &dir_data, dir_data.current_inode); dir_aff_log(&dir_data, dir_list); delete_list_file(dir_list); } #endif } dir_data.close(&dir_data); } break; } #ifdef HAVE_NCURSES delwin(window); (void) clearok(stdscr, TRUE); #ifdef HAVE_TOUCHWIN touchwin(stdscr); #endif wrefresh(stdscr); #endif fflush(stderr); free(dir_data.local_dir); return res; }
void interface_adv(disk_t *disk_car, const int verbose,const int dump_ind, const unsigned int expert, char**current_cmd) { #ifdef HAVE_NCURSES int offset=0; int current_element_num=0; int old_LINES=LINES; #endif int rewrite=1; unsigned int menu=0; list_part_t *element; list_part_t *list_part; list_part_t *current_element; log_info("\nInterface Advanced\n"); list_part=disk_car->arch->read_part(disk_car,verbose,0); current_element=list_part; log_all_partitions(disk_car, list_part); while(1) { const char *options; static struct MenuItem menuAdv[]= { {'t',"Type","Change type, this setting will not be saved on disk"}, {'b',"Boot","Boot sector recovery"}, {'s',"Superblock",NULL}, {'l',"List", "List and copy files"}, {'u',"Undelete", "File undelete"}, {'c',"Image Creation", "Create an image"}, // {'a',"Add", "Add temporary partition (Expert only)"}, {'q',"Quit","Return to main menu"}, {0,NULL,NULL} }; int command; #ifdef HAVE_NCURSES int i; if(old_LINES!=LINES) { old_LINES=LINES; rewrite=1; } if(rewrite!=0) { aff_copy(stdscr); wmove(stdscr,4,0); wprintw(stdscr,"%s",disk_car->description(disk_car)); if(list_part!=NULL) mvwaddstr(stdscr,6,0,msg_PART_HEADER_LONG); rewrite=0; } for(i=0,element=list_part; element!=NULL && i<offset+INTER_ADV; element=element->next,i++) { if(i<offset) continue; wmove(stdscr,7+i-offset,0); wclrtoeol(stdscr); /* before addstr for BSD compatibility */ if(element==current_element) { wattrset(stdscr, A_REVERSE); waddstr(stdscr, ">"); aff_part(stdscr,AFF_PART_ORDER|AFF_PART_STATUS,disk_car,element->part); wattroff(stdscr, A_REVERSE); } else { waddstr(stdscr, " "); aff_part(stdscr,AFF_PART_ORDER|AFF_PART_STATUS,disk_car,element->part); } } wmove(stdscr,7+INTER_ADV,5); wclrtoeol(stdscr); if(element!=NULL) wprintw(stdscr, "Next"); #endif if(current_element==NULL) { options="q"; #ifdef HAVE_NCURSES wmove(stdscr,7,0); wattrset(stdscr, A_REVERSE); wprintw(stdscr,"No partition available."); wattroff(stdscr, A_REVERSE); #endif } else { const partition_t *partition=current_element->part; if(menu==0 && (disk_car->arch!=&arch_none || partition->upart_type!=UP_UNK)) menu=1; if(is_part_fat(partition)) { options="tubcq"; menu=(partition->upart_type==UP_UNK?1:4); } else if(is_part_ntfs(partition)) options="tlubcq"; else if(is_part_linux(partition)) { if(partition->upart_type==UP_EXT2) options="tuscq"; else options="tlscq"; menuAdv[2].desc="Locate ext2/ext3/ext4 backup superblock"; } else if(is_part_hfs(partition) || is_part_hfsp(partition)) { options="tscq"; menuAdv[2].desc="Locate HFS/HFS+ backup volume header"; } else if(is_fat(partition)) options="tubcq"; else if(is_ntfs(partition)) options="tlubcq"; else if(is_exfat(partition)) options="tlubcq"; else if(is_linux(partition)) { if(partition->upart_type==UP_EXT2) options="tluscq"; else options="tlscq"; menuAdv[2].desc="Locate ext2/ext3/ext4 backup superblock"; } else if(is_hfs(partition) || is_hfsp(partition)) { options="tscq"; menuAdv[2].desc="Locate HFS/HFS+ backup volume header"; } else options="tcq"; } if(*current_cmd!=NULL) { int keep_asking; command='q'; do { keep_asking=0; while(*current_cmd[0]==',') (*current_cmd)++; if(strncmp(*current_cmd,"type",4)==0) { (*current_cmd)+=4; command='t'; } else if(strncmp(*current_cmd,"addpart",7)==0) { (*current_cmd)+=7; command='a'; } else if(strncmp(*current_cmd,"boot",4)==0) { (*current_cmd)+=4; command='b'; } else if(strncmp(*current_cmd,"copy",4)==0) { (*current_cmd)+=4; command='c'; } else if(strncmp(*current_cmd,"list",4)==0) { (*current_cmd)+=4; command='l'; } else if(strncmp(*current_cmd,"undelete",8)==0) { (*current_cmd)+=8; command='u'; } else if(strncmp(*current_cmd,"superblock",10)==0) { (*current_cmd)+=10; command='s'; } else if(isdigit(*current_cmd[0])) { const unsigned int order= atoi(*current_cmd); while(*current_cmd[0]!=',' && *current_cmd[0]!='\0') (*current_cmd)++; for(element=list_part; element!=NULL && element->part->order!=order; element=element->next); if(element!=NULL) { current_element=element; keep_asking=1; } } } while(keep_asking>0); } else { #ifdef HAVE_NCURSES command = wmenuSelect_ext(stdscr, INTER_ADV_Y+1, INTER_ADV_Y, INTER_ADV_X, menuAdv, 8, options, MENU_HORIZ | MENU_BUTTON | MENU_ACCEPT_OTHERS, &menu, NULL); #else command = 'q'; #endif } switch(command) { case 'q': case 'Q': part_free_list(list_part); return; #ifdef HAVE_NCURSES case 'a': case 'A': if(disk_car->arch!=&arch_none) { if(*current_cmd!=NULL) list_part=add_partition_cli(disk_car, list_part, current_cmd); else list_part=add_partition_ncurses(disk_car, list_part); current_element=list_part; rewrite=1; } break; #endif } #ifdef HAVE_NCURSES if(current_element!=NULL) { switch(command) { case 'p': case 'P': case KEY_UP: if(current_element->prev!=NULL) { current_element=current_element->prev; current_element_num--; } break; case 'n': case 'N': case KEY_DOWN: if(current_element->next!=NULL) { current_element=current_element->next; current_element_num++; } break; case KEY_PPAGE: for(i=0; i<INTER_ADV-1 && current_element->prev!=NULL; i++) { current_element=current_element->prev; current_element_num--; } break; case KEY_NPAGE: for(i=0; i<INTER_ADV-1 && current_element->next!=NULL; i++) { current_element=current_element->next; current_element_num++; } break; case 'b': case 'B': { partition_t *partition=current_element->part; if(is_part_fat32(partition)) { fat32_boot_sector(disk_car, partition, verbose, dump_ind, expert,current_cmd); rewrite=1; } else if(is_part_fat12(partition) || is_part_fat16(partition)) { fat1x_boot_sector(disk_car, partition, verbose, dump_ind,expert,current_cmd); rewrite=1; } else if(is_part_ntfs(partition)) { if(partition->upart_type==UP_EXFAT) exFAT_boot_sector(disk_car, partition, verbose, current_cmd); else ntfs_boot_sector(disk_car, partition, verbose, expert, current_cmd); rewrite=1; } else if(partition->upart_type==UP_FAT32) { fat32_boot_sector(disk_car, partition, verbose, dump_ind, expert,current_cmd); rewrite=1; } else if(partition->upart_type==UP_FAT12 || partition->upart_type==UP_FAT16) { fat1x_boot_sector(disk_car, partition, verbose, dump_ind,expert,current_cmd); rewrite=1; } else if(partition->upart_type==UP_NTFS) { ntfs_boot_sector(disk_car, partition, verbose, expert, current_cmd); rewrite=1; } else if(partition->upart_type==UP_EXFAT) { exFAT_boot_sector(disk_car, partition, verbose, current_cmd); rewrite=1; } } break; case 'c': case 'C': { char *dst_path; #ifdef HAVE_NCURSES if(*current_cmd!=NULL) dst_path=get_default_location(); else { char msg[256]; snprintf(msg, sizeof(msg), "Please select where to store the file image.dd (%u MB), an image of the partition", (unsigned int)(current_element->part->part_size/1000/1000)); dst_path=ask_location(msg, "", NULL); } #else dst_path=get_default_location(); #endif if(dst_path!=NULL) { char *filename=(char *)MALLOC(strlen(dst_path) + 1 + strlen(DEFAULT_IMAGE_NAME) + 1); strcpy(filename, dst_path); strcat(filename, "/"); strcat(filename, DEFAULT_IMAGE_NAME); disk_image(disk_car, current_element->part, filename); free(filename); free(dst_path); } } rewrite=1; break; case 'u': case 'U': { partition_t *partition=current_element->part; if(partition->sb_offset!=0 && partition->sb_size>0) { io_redir_add_redir(disk_car, partition->part_offset+partition->sborg_offset, partition->sb_size, partition->part_offset+partition->sb_offset, NULL); if(partition->upart_type==UP_NTFS || (is_part_ntfs(partition) && partition->upart_type!=UP_EXFAT)) ntfs_undelete_part(disk_car, partition, verbose, current_cmd); else dir_partition(disk_car, partition, 0, current_cmd); io_redir_del_redir(disk_car, partition->part_offset+partition->sborg_offset); } else { if(partition->upart_type==UP_NTFS || (is_part_ntfs(partition) && partition->upart_type!=UP_EXFAT)) ntfs_undelete_part(disk_car, partition, verbose, current_cmd); else dir_partition(disk_car, partition, 0, current_cmd); } } rewrite=1; break; case 'l': case 'L': { partition_t *partition=current_element->part; if(partition->sb_offset!=0 && partition->sb_size>0) { io_redir_add_redir(disk_car, partition->part_offset+partition->sborg_offset, partition->sb_size, partition->part_offset+partition->sb_offset, NULL); dir_partition(disk_car,partition,verbose, current_cmd); io_redir_del_redir(disk_car, partition->part_offset+partition->sborg_offset); } else dir_partition(disk_car,partition,verbose, current_cmd); } rewrite=1; break; case 's': case 'S': { if(is_linux(current_element->part)) { list_part_t *list_sb=search_superblock(disk_car,current_element->part,verbose,dump_ind,1); interface_superblock(disk_car,list_sb,current_cmd); part_free_list(list_sb); } if(is_hfs(current_element->part) || is_hfsp(current_element->part)) { HFS_HFSP_boot_sector(disk_car, current_element->part, verbose, current_cmd); } rewrite=1; } break; case 't': case 'T': if(*current_cmd!=NULL) change_part_type_cli(disk_car, current_element->part, current_cmd); else change_part_type_ncurses(disk_car, current_element->part); rewrite=1; break; } if(current_element_num<offset) offset=current_element_num; if(current_element_num>=offset+INTER_ADV) offset=current_element_num-INTER_ADV+1; } #endif } }