示例#1
0
int intrf_no_disk_ncurses(const char *prog_name)
{
  aff_copy(stdscr);
  wmove(stdscr,4,0);
  wprintw(stdscr,"  %s is free software, and",prog_name);
  wmove(stdscr,5,0);
  wprintw(stdscr,"comes with ABSOLUTELY NO WARRANTY.");
  wmove(stdscr,7,0);
  wprintw(stdscr,"No harddisk found\n");
#if defined(__CYGWIN__) || defined(__MINGW32__)
  wmove(stdscr,8,0);
  wprintw(stdscr,"You need to be administrator to use %s.\n", prog_name);
  wmove(stdscr,9,0);
  wprintw(stdscr,"Under Win9x, use the DOS version instead.\n");
  wmove(stdscr,10,0);
  wprintw(stdscr,"Under Vista or later, select %s, right-click and\n", prog_name);
  wmove(stdscr,11,0);
  wprintw(stdscr,"choose \"Run as administrator\".\n");
#elif defined(DJGPP)
#else
#ifdef HAVE_GETEUID
  if(geteuid()!=0)
  {
    wmove(stdscr,8,0);
    wprintw(stdscr,"You need to be root to use %s.\n", prog_name);
#ifdef SUDO_BIN
    {
      static const struct MenuItem menuSudo[]=
      {
	{'S',"Sudo","Use the sudo command to restart as root"},
	{'Q',"Quit",""},
	{0,NULL,NULL}
      };
      unsigned int menu=0;
      int command;
      command = wmenuSelect_ext(stdscr,23, 20, 0, menuSudo, 8,
	  "SQ", MENU_VERT | MENU_VERT_WARN | MENU_BUTTON, &menu,NULL);
      if(command=='s' || command=='S')
	return 1;
      return 0;
    }
#endif
  }
#endif
#endif
  wmove(stdscr,22,0);
  wattrset(stdscr, A_REVERSE);
  waddstr(stdscr,"[ Quit ]");
  wattroff(stdscr, A_REVERSE);
  wrefresh(stdscr);
  while(wgetch(stdscr)==ERR);
  return 0;
}
示例#2
0
文件: tdisksel.c 项目: Tom9X/TestDisk
static int testdisk_disk_selection_ncurses(int verbose,int dump_ind, const list_disk_t *list_disk, const int saveheader, char **current_cmd)
{
  int command='Q';
  unsigned int menu=0;
  int offset=0;
  int pos_num=0;
  int use_sudo=0;
  const list_disk_t *element_disk;
  const list_disk_t *current_disk;
  static struct MenuItem menuMain[]=
  {
    { 'P', "Previous", ""},
    { 'N', "Next", "" },
    { 'O', "Proceed", ""},
    { 'S', "Sudo", "Use the sudo command to restart as root"},
    { 'Q', "Quit", "Quit program"},
    {  0,  NULL, NULL}
  };
  if(list_disk==NULL)
  {
    log_critical("No disk found\n");
    return intrf_no_disk_ncurses("TestDisk");
  }
  current_disk=list_disk;
  /* ncurses interface */
  while(1)
  {
    const char *options;
    int i;
#ifdef HAVE_NCURSES
    aff_copy(stdscr);
    wmove(stdscr,4,0);
    wprintw(stdscr,"  TestDisk is free software, and");
    wmove(stdscr,5,0);
    wprintw(stdscr,"comes with ABSOLUTELY NO WARRANTY.");
    wmove(stdscr,7,0);
    wprintw(stdscr,"Select a media (use Arrow keys, then press Enter):");
#endif
    for(i=0,element_disk=list_disk;
	element_disk!=NULL && i<offset+NBR_DISK_MAX;
	i++, element_disk=element_disk->next)
    {
      if(i<offset)
	continue;
      wmove(stdscr,8+i-offset,0);
      if(element_disk!=current_disk)
	wprintw(stdscr," %s\n",element_disk->disk->description_short(element_disk->disk));
      else
      {
	wattrset(stdscr, A_REVERSE);
	wprintw(stdscr,">%s\n",element_disk->disk->description_short(element_disk->disk));
	wattroff(stdscr, A_REVERSE);
      }
    }
    {
      int line=INTER_NOTE_Y;
      mvwaddstr(stdscr,line++,0,"Note: ");
#if defined(__CYGWIN__) || defined(__MINGW32__) || defined(DJGPP)
#else
#ifdef HAVE_GETEUID
      if(geteuid()!=0)
      {
        if(has_colors())
          wbkgdset(stdscr,' ' | A_BOLD | COLOR_PAIR(1));
        waddstr(stdscr,"Some disks won't appear unless you are root user.");
        if(has_colors())
          wbkgdset(stdscr,' ' | COLOR_PAIR(0));
        wmove(stdscr,line++,0);
#ifdef SUDO_BIN
	use_sudo=1;
#endif
      }
#endif
#endif
      waddstr(stdscr,"Disk capacity must be correctly detected for a successful recovery.");
      wmove(stdscr,line++,0);
      wprintw(stdscr,"If a disk listed above has incorrect size, check HD jumper settings, BIOS");
      wmove(stdscr,line,0);
      wprintw(stdscr,"detection, and install the latest OS patches and disk drivers."); 
    }
    if(use_sudo > 0)
    {
      if(i<=NBR_DISK_MAX && element_disk==NULL)
	options="OSQ";
      else
	options="PNOSQ";
    }
    else
    {
      if(i<=NBR_DISK_MAX && element_disk==NULL)
	options="OQ";
      else
	options="PNOQ";
    }
    command = wmenuSelect_ext(stdscr, INTER_NOTE_Y-1, INTER_DISK_Y, INTER_DISK_X, menuMain, 8,
	options, MENU_HORIZ | MENU_BUTTON | MENU_ACCEPT_OTHERS, &menu,NULL);
    switch(command)
    {
      case 'p':
      case 'P':
      case KEY_UP:
	if(current_disk->prev!=NULL)
	{
	  current_disk=current_disk->prev;
	  pos_num--;
	}
	break;
      case 'n':
      case 'N':
      case KEY_DOWN:
	if(current_disk->next!=NULL)
	{
	  current_disk=current_disk->next;
	  pos_num++;
	}
	break;
      case KEY_PPAGE:
	for(i=0;i<NBR_DISK_MAX-1 && current_disk->prev!=NULL;i++)
	{
	  current_disk=current_disk->prev;
	  pos_num--;
	}
	break;
      case KEY_NPAGE:
	for(i=0;i<NBR_DISK_MAX-1 && current_disk->next!=NULL;i++)
	{
	  current_disk=current_disk->next;
	  pos_num++;
	}
	break;
      case 'o':
      case 'O':
	{
	  disk_t *disk=current_disk->disk;
	  const int hpa_dco=is_hpa_or_dco(disk);
	  autodetect_arch(disk, NULL);
	  autoset_unit(disk);
	  if(interface_check_disk_capacity(disk)==0 &&
              interface_check_disk_access(disk, current_cmd)==0 &&
	      (hpa_dco==0 || interface_check_hidden_ncurses(disk, hpa_dco)==0) &&
	      interface_partition_type(disk, verbose, current_cmd)==0)
	  {
	    if(menu_disk(disk, verbose, dump_ind, saveheader, current_cmd))
	      return 0;
	  }
	}
	break;
      case 's':
      case 'S':
	return 1;
      case 'q':
      case 'Q':
	return 0;
    }
    if(pos_num<offset)
      offset=pos_num;
    if(pos_num>=offset+NBR_DISK_MAX)
      offset=pos_num-NBR_DISK_MAX+1;
  }
}
示例#3
0
int wmenuSelect(WINDOW *window, const int yinfo, const int y, const int x, const struct MenuItem *menuItems, const unsigned int itemLength, const char *available, const int menuType, const unsigned int menuDefault)
{
  unsigned int current=menuDefault;
  return wmenuSelect_ext(window, yinfo, y, x, menuItems, itemLength, available, menuType, &current, NULL);
}
示例#4
0
int screen_buffer_display_ext(WINDOW *window, const char *options_org, const struct MenuItem *menuItems, unsigned int *menu)
{
  int first_line_to_display=0;
  int current_line=0;
  int done=0;
  char options[20];
  const struct MenuItem menuDefault[]=
  {
    { 'P', "Previous",""},
    { 'N', "Next","" },
    { 'Q', "Quit","Quit this section"},
    { 0, NULL, NULL }
  };
  const unsigned int itemLength=8;
  /* FIXME itemLength */
  strncpy(options,"Q",sizeof(options));
  strncat(options,options_org,sizeof(options)-strlen(options));
  if(intr_buffer_screen[intr_nbr_line][0]!='\0')
    intr_nbr_line++;
  /* curses interface */
  do
  {
    int i;
    int key;
    wmove(window, INTER_ANALYSE_Y-1, INTER_ANALYSE_X+4);
    wclrtoeol(window);
    if(first_line_to_display>0)
      wprintw(window, "Previous");
    if(intr_nbr_line>INTER_MAX_LINES && has_colors())
    {
      for (i=first_line_to_display; i<intr_nbr_line && (i-first_line_to_display)<INTER_MAX_LINES; i++)
      {
	wmove(window,INTER_ANALYSE_Y+i-first_line_to_display,INTER_ANALYSE_X);
	wclrtoeol(window);
	if(i==current_line)
	{
	  wattrset(window, A_REVERSE);
	  wprintw(window, ">%-*s", COLS, intr_buffer_screen[i]);
	  wattroff(window, A_REVERSE);
	}
	else
	  wprintw(window, " %-*s", COLS, intr_buffer_screen[i]);
      }
    }
    else
    {
      for (i=first_line_to_display; i<intr_nbr_line && (i-first_line_to_display)<INTER_MAX_LINES; i++)
      {
	wmove(window,INTER_ANALYSE_Y+i-first_line_to_display,INTER_ANALYSE_X);
	wclrtoeol(window);
	wprintw(window, "%-*s", COLS, intr_buffer_screen[i]);
      }
    }
    wmove(window, INTER_ANALYSE_Y+INTER_MAX_LINES, INTER_ANALYSE_X+4);
    wclrtoeol(window);
    if(i<intr_nbr_line)
      wprintw(window, "Next");
    key=wmenuSelect_ext(window, INTER_ANALYSE_MENU_Y+1,
	INTER_ANALYSE_MENU_Y, INTER_ANALYSE_MENU_X,
	(menuItems!=NULL?menuItems:menuDefault), itemLength, options,
	MENU_HORIZ | MENU_BUTTON | MENU_ACCEPT_OTHERS, menu,NULL);
    switch (key)
    {
      case key_ESC:
      case 'q':
      case 'Q':
        done = TRUE;
        break;
      case 'p':
      case 'P':
      case KEY_UP:
        if(current_line>0)
          current_line--;
        break;
      case 'n':
      case 'N':
      case KEY_DOWN:
        if(current_line<intr_nbr_line-1)
          current_line++;
        break;
      case KEY_PPAGE:
        if(current_line>INTER_MAX_LINES-1)
          current_line-=INTER_MAX_LINES-1;
        else
          current_line=0;
        break;
      case KEY_NPAGE:
        if(current_line+INTER_MAX_LINES-1 < intr_nbr_line-1)
          current_line+=INTER_MAX_LINES-1;
        else
          current_line=intr_nbr_line-1;
        break;
      default:
        if(strchr(options,toupper(key))!=NULL)
          return toupper(key);
        break;
    }
    if(current_line<first_line_to_display)
      first_line_to_display=current_line;
    if(current_line>=first_line_to_display+INTER_MAX_LINES)
      first_line_to_display=current_line-INTER_MAX_LINES+1;
  } while(done!=TRUE);
  return 0;
}
示例#5
0
int repair_MFT(disk_t *disk_car, partition_t *partition, const int verbose, const unsigned int expert, char **current_cmd)
{
  struct ntfs_boot_sector *ntfs_header;
  unsigned char *buffer_mft;
  unsigned char *buffer_mftmirr;
  unsigned int cluster_size;
  unsigned int mft_record_size;
  unsigned int mftmirr_size_bytes;
  unsigned int use_MFT=0;
  /* 0: do nothing
   * 1: fix MFT mirror using MFT
   * 2: fix MFT using MFT mirror */
  uint64_t mft_pos;
  uint64_t mftmirr_pos;
  log_trace("repair_MFT\n");
  if(check_NTFS(disk_car, partition, verbose, 0)!=0)
  {
    display_message("Boot sector not valid, can't repair MFT.\n");
    return -1;
  }
  ntfs_header=(struct ntfs_boot_sector *)MALLOC(DEFAULT_SECTOR_SIZE);
  if(disk_car->pread(disk_car, ntfs_header, DEFAULT_SECTOR_SIZE, partition->part_offset) != DEFAULT_SECTOR_SIZE)
  {
    free(ntfs_header);
    display_message("Can't read NTFS boot sector.\n");
    return -1;
  }
  mft_pos=partition->part_offset+(uint64_t)(le16(ntfs_header->reserved)+le64(ntfs_header->mft_lcn)*ntfs_header->sectors_per_cluster)*ntfs_sector_size(ntfs_header);
  mftmirr_pos=partition->part_offset+(uint64_t)(le16(ntfs_header->reserved)+le64(ntfs_header->mftmirr_lcn)*ntfs_header->sectors_per_cluster)*ntfs_sector_size(ntfs_header);
  if(ntfs_header->clusters_per_mft_record>0)
    mft_record_size=ntfs_header->sectors_per_cluster*ntfs_header->clusters_per_mft_record;
  else
    mft_record_size=1<<(-ntfs_header->clusters_per_mft_record);

  cluster_size=ntfs_header->sectors_per_cluster;

  mftmirr_size_bytes = (cluster_size <= 4 * mft_record_size ? 4 * mft_record_size : cluster_size) * ntfs_sector_size(ntfs_header);
#ifdef DEBUG_REPAIR_MFT
  log_debug("mft_pos %lu\n",(unsigned long)(mft_pos/disk_car->sector_size));
  log_debug("mftmirr_pos %lu\n",(unsigned long)(mftmirr_pos/disk_car->sector_size));
  log_debug("cluster_size %u\n", cluster_size);
  log_debug("mft_record_size    %u\n", mft_record_size);
  log_debug("ntfs_sector_size   %u\n", ntfs_sector_size(ntfs_header));
  log_debug("mftmirr_size_bytes %u\n", mftmirr_size_bytes);
#endif
  if(mftmirr_size_bytes==0)
  {
    display_message("Invalid NTFS MFT size.\n");
    log_error("Invalid NTFS MFT size.\n");
    free(ntfs_header);
    return -1;
  }
  /* Check if MFT mirror is identical to the beginning of MFT */
  buffer_mft=(unsigned char *)MALLOC(mftmirr_size_bytes);
  if((unsigned)disk_car->pread(disk_car, buffer_mft, mftmirr_size_bytes, mft_pos) != mftmirr_size_bytes)
  {
    display_message("Can't read NTFS MFT.\n");
    log_error("Can't read NTFS MFT.\n");
    free(buffer_mft);
    free(ntfs_header);
    return -1;
  }
  buffer_mftmirr=(unsigned char *)MALLOC(mftmirr_size_bytes);
  if((unsigned)disk_car->pread(disk_car, buffer_mftmirr, mftmirr_size_bytes, mftmirr_pos) != mftmirr_size_bytes)
  {
    display_message("Can't read NTFS MFT mirror.\n");
    log_error("Can't read NTFS MFT mirror.\n");
    free(buffer_mftmirr);
    free(buffer_mft);
    free(ntfs_header);
    return -1;
  }
  if(memcmp(buffer_mft, buffer_mftmirr, mftmirr_size_bytes)==0)
  {
    log_info("MFT and MFT mirror match perfectly.\n");
    if(*current_cmd==NULL)
      display_message("MFT and MFT mirror match perfectly.\n");
    free(buffer_mftmirr);
    free(buffer_mft);
    free(ntfs_header);
    return 0;
  }
  if(partition->sb_offset!=0)
  {
    log_info("Please quit TestDisk and reboot your computer before trying to fix the MFT.\n");
    display_message("Please quit TestDisk and reboot your computer before trying to fix the MFT.\n");
    free(buffer_mftmirr);
    free(buffer_mft);
    free(ntfs_header);
    return -1;
  }
/*
  log_debug("MFT\n");
  dump_log(buffer_mft, mftmirr_size_bytes);
  log_debug("MFT mirror\n");
  dump_log(buffer_mftmirr, mftmirr_size_bytes);
  */
  /*
  The idea is to use the internal IO redirector built-in TestDisk
  to redirect read access to the MFT to the MFT backup instead (or
  vice-versa) when listing the NTFS files. If TestDisk can get
  a file listing, it also knows which MFT to use.
  */
  {
    int res1,res2;
    dir_data_t dir_data;
    /* Use MFT */
    io_redir_add_redir(disk_car, mftmirr_pos, mftmirr_size_bytes, 0, buffer_mft);
    res1=dir_partition_ntfs_init(disk_car,partition,&dir_data,verbose);
    if(res1==DIR_PART_ENOSYS)
    {
	display_message("Can't determine which MFT is correct, ntfslib is missing.\n");
	log_error("Can't determine which MFT is correct, ntfslib is missing.\n");
	free(buffer_mftmirr);
	free(buffer_mft);
	free(ntfs_header);
	io_redir_del_redir(disk_car,mftmirr_pos);
	return 0;
    }
    if(res1==DIR_PART_OK)
    {
      file_info_t dir_list;
      TD_INIT_LIST_HEAD(&dir_list.list);
      dir_data.get_dir(disk_car,partition,&dir_data,dir_data.current_inode, &dir_list);
      if(!td_list_empty(&dir_list.list))
      {
	log_info("NTFS listing using MFT:\n");
	dir_aff_log(&dir_data, &dir_list);
	if(delete_list_file(&dir_list)>2)
	  res1++;
      }
      dir_data.close(&dir_data);
    }
    io_redir_del_redir(disk_car,mftmirr_pos);
    /* Use MFT mirror */
    io_redir_add_redir(disk_car, mft_pos, mftmirr_size_bytes, 0, buffer_mftmirr);
    res2=dir_partition_ntfs_init(disk_car,partition,&dir_data,verbose);
    if(res2==DIR_PART_OK)
    {
      file_info_t dir_list;
      TD_INIT_LIST_HEAD(&dir_list.list);
      dir_data.get_dir(disk_car,partition,&dir_data,dir_data.current_inode, &dir_list);
      if(!td_list_empty(&dir_list.list))
      {
	log_info("NTFS listing using MFT mirror:\n");
	dir_aff_log(&dir_data, &dir_list);
	if(delete_list_file(&dir_list)>2)
	  res2++;
      }
      dir_data.close(&dir_data);
    }
    io_redir_del_redir(disk_car,mft_pos);
    /* */
    if(res1>res2 && res1>DIR_PART_OK)
    {
      /* Use MFT */
#ifdef HAVE_NCURSES
      if(ask_confirmation("Fix MFT mirror using MFT ? (Y/N)")!=0)
	use_MFT=1;
      else
#endif
	log_info("Don't fix MFT mirror.\n");
    }
    else if(res1<res2 && res2>DIR_PART_OK)
    {
      /* Use MFT mirror */
#ifdef HAVE_NCURSES
      if(ask_confirmation("Fix MFT using its mirror ? (Y/N) - DANGEROUS NON REVERSIBLE OPERATION\nUse it ONLY IF Windows failed to access this filesystem.")!=0)
	use_MFT=2;
      else
#endif
	log_info("Don't fix MFT.\n");
    }
    else
    { /* res1==res2 */
      if(res1>DIR_PART_OK && res2>DIR_PART_OK)
	log_error("Both MFT seems ok but they don't match, use chkdsk.\n");
      else
	log_error("MFT and MFT mirror are bad. Failed to repair them.\n");
      if(expert==0)
      {
	if(res1>DIR_PART_OK && res2>DIR_PART_OK)
	  display_message("Both MFT seems ok but they don't match, use chkdsk.\n");
	else
	  display_message("MFT and MFT mirror are bad. Failed to repair them.\n");
      }
      else
      {
#ifdef HAVE_NCURSES
	unsigned int menu=2;
	int real_key;
	int command;
	static const struct MenuItem menuMFT[]=
	{
	  {'B',"MFT",		"Fix MFT using MFT mirror"},
	  {'M',"MFT Mirror",	"Fix MFT mirror using MFT"},
	  {'Q',"Quit","Return to NTFS functions"},
	  {0,NULL,NULL}
	};
	aff_copy(stdscr);
	wmove(stdscr,4,0);
	wprintw(stdscr,"%s",disk_car->description(disk_car));
	mvwaddstr(stdscr,5,0,msg_PART_HEADER_LONG);
	wmove(stdscr,6,0);
	aff_part(stdscr,AFF_PART_ORDER|AFF_PART_STATUS,disk_car,partition);
	wmove(stdscr,8,0);
	if(res1>0 && res2>0)
	  wprintw(stdscr, "Both MFT seem ok but they don't match.\n");
	else
	  wprintw(stdscr, "MFT and MFT mirror are bad.\n");
	command=wmenuSelect_ext(stdscr, 23, INTER_MFT_Y, INTER_MFT_X, menuMFT, 10, "MBQ",
	    MENU_VERT | MENU_VERT_WARN | MENU_BUTTON, &menu, &real_key);
	switch(command)
	{
	  case 'b':
	  case 'B':
	    use_MFT=2;
	    break;
	  case 'm':
	  case 'M':
	    use_MFT=1;
	    break;
	  default:
	    use_MFT=0;
	    break;
	}
#endif
      }
    }
  }
  if(use_MFT==2)
  {
    if((unsigned)disk_car->pwrite(disk_car, buffer_mftmirr, mftmirr_size_bytes, mft_pos) != mftmirr_size_bytes)
    {
      display_message("Failed to fix MFT: write error.\n");
    }
    else
    {
      disk_car->sync(disk_car);
      display_message("MFT fixed.\n");
    }
  }
  else if(use_MFT==1)
  {
    if((unsigned)disk_car->pwrite(disk_car, buffer_mft, mftmirr_size_bytes, mftmirr_pos) != mftmirr_size_bytes)
    {
      display_message("Failed to fix MFT mirror: write error.\n");
    }
    else
    {
      disk_car->sync(disk_car);
      display_message("MFT mirror fixed.\n");
    }
  }
  free(buffer_mftmirr);
  free(buffer_mft);
  free(ntfs_header);
  return 0;
}
示例#6
0
static int photorec_disk_selection_ncurses(struct ph_param *params, struct ph_options *options, const list_disk_t *list_disk, alloc_data_t *list_search_space)
{
  int command;
  int real_key;
  unsigned int menu=0;
  int offset=0;
  int pos_num=0;
  int use_sudo=0;
  const list_disk_t *element_disk;
  const list_disk_t *current_disk=list_disk;
  static const struct MenuItem menuMain[]=
  {
    { 'P', "Previous",""},
    { 'N', "Next","" },
    { 'O',"Proceed",""},
    { 'S', "Sudo", "Use the sudo command to restart as root"},
    { 'Q',"Quit","Quit program"},
    { 0,NULL,NULL}
  };
  if(list_disk==NULL)
  {
    log_critical("No disk found\n");
    return intrf_no_disk_ncurses("PhotoRec");
  }
  /* ncurses interface */
  while(1)
  {
    const char *menu_options;
    int i;
    aff_copy(stdscr);
    wmove(stdscr,4,0);
    wprintw(stdscr,"  PhotoRec is free software, and");
    wmove(stdscr,5,0);
    wprintw(stdscr,"comes with ABSOLUTELY NO WARRANTY.");
    wmove(stdscr,7,0);
    wprintw(stdscr,"Select a media (use Arrow keys, then press Enter):");
#if defined(KEY_MOUSE) && defined(ENABLE_MOUSE)
    mousemask(ALL_MOUSE_EVENTS, NULL);
#endif
    for(i=0,element_disk=list_disk;
	element_disk!=NULL && i<offset+NBR_DISK_MAX;
	i++, element_disk=element_disk->next)
    {
      if(i<offset)
	continue;
      wmove(stdscr,8+i-offset,0);
      if(element_disk!=current_disk)
	wprintw(stdscr," %s\n",element_disk->disk->description_short(element_disk->disk));
      else
      {
	wattrset(stdscr, A_REVERSE);
	wprintw(stdscr,">%s\n",element_disk->disk->description_short(element_disk->disk));
	wattroff(stdscr, A_REVERSE);
      }
    }
    {
      mvwaddstr(stdscr, INTER_NOTE_Y,0,"Note: ");
#if defined(__CYGWIN__) || defined(__MINGW32__)
#else
#ifndef DJGPP
#ifdef HAVE_GETEUID
      if(geteuid()!=0)
      {
	if(has_colors())
	  wbkgdset(stdscr,' ' | A_BOLD | COLOR_PAIR(1));
	wprintw(stdscr,"Some disks won't appear unless you're root user.");
        if(has_colors())
          wbkgdset(stdscr,' ' | COLOR_PAIR(0));
#ifdef SUDO_BIN
	use_sudo=1;
#endif
      }
#endif
#endif
#endif
      wmove(stdscr, INTER_NOTE_Y+1, 0);
      wprintw(stdscr,"Disk capacity must be correctly detected for a successful recovery.");
      wmove(stdscr, INTER_NOTE_Y+2, 0);
      wprintw(stdscr,"If a disk listed above has incorrect size, check HD jumper settings, BIOS");
      wmove(stdscr, INTER_NOTE_Y+3, 0);
      wprintw(stdscr,"detection, and install the latest OS patches and disk drivers."); 
    }
    if(use_sudo > 0)
    {
      if(i<=NBR_DISK_MAX && element_disk==NULL)
	menu_options="OSQ";
      else
	menu_options="PNOSQ";
    }
    else
    {
      if(i<=NBR_DISK_MAX && element_disk==NULL)
	menu_options="OQ";
      else
	menu_options="PNOQ";
    }
    command = wmenuSelect_ext(stdscr, INTER_NOTE_Y-1, INTER_DISK_Y, INTER_DISK_X, menuMain, 8,
	menu_options, MENU_HORIZ | MENU_BUTTON | MENU_ACCEPT_OTHERS, &menu,&real_key);
#if defined(KEY_MOUSE) && defined(ENABLE_MOUSE)
    if(command == KEY_MOUSE)
    {
      MEVENT event;
      if(getmouse(&event) == OK)
      {	/* When the user clicks left mouse button */
	if((event.bstate & BUTTON1_CLICKED) || (event.bstate & BUTTON1_DOUBLE_CLICKED))
	{
	  if(event.y >=8 && event.y<8+NBR_DISK_MAX)
	  {
	    const int pos_num_old=pos_num;
	    /* Disk selection */
	    while(pos_num > event.y-(8-offset) && current_disk->prev!=NULL)
	    {
	      current_disk=current_disk->prev;
	      pos_num--;
	    }
	    while(pos_num < event.y-(8-offset) && current_disk->next!=NULL)
	    {
	      current_disk=current_disk->next;
	      pos_num++;
	    }
	    if(((event.bstate & BUTTON1_CLICKED) && pos_num==pos_num_old) ||
		(event.bstate & BUTTON1_DOUBLE_CLICKED))
	      command='O';
	  }
	  else
	    command = menu_to_command(INTER_NOTE_Y-1, INTER_DISK_Y, INTER_DISK_X, menuMain, 8,
		menu_options, MENU_HORIZ | MENU_BUTTON | MENU_ACCEPT_OTHERS, event.y, event.x);
	}
      }
    }
#endif
    switch(command)
    {
      case KEY_UP:
      case 'P':
	if(current_disk->prev!=NULL)
	{
	  current_disk=current_disk->prev;
	  pos_num--;
	}
	break;
      case KEY_DOWN:
      case 'N':
	if(current_disk->next!=NULL)
	{
	  current_disk=current_disk->next;
	  pos_num++;
	}
	break;
      case KEY_PPAGE:
	for(i=0;i<NBR_DISK_MAX-1 && current_disk->prev!=NULL;i++)
	{
	  current_disk=current_disk->prev;
	  pos_num--;
	}
	break;
      case KEY_NPAGE:
	for(i=0;i<NBR_DISK_MAX-1 && current_disk->next!=NULL;i++)
	{
	  current_disk=current_disk->next;
	  pos_num++;
	}
	break;
      case 'o':
      case 'O':
	{
	  disk_t *disk=current_disk->disk;
	  const int hpa_dco=is_hpa_or_dco(disk);
	  autodetect_arch(disk, &arch_none);
	  params->disk=disk;
	  if((hpa_dco==0 || interface_check_hidden_ncurses(disk, hpa_dco)==0) &&
	      (options->expert == 0 ||
	       change_arch_type_ncurses(disk, options->verbose)==0))
	    menu_photorec(params, options, list_search_space);
	}
	break;
      case 's':
      case 'S':
	return 1;
      case 'q':
      case 'Q':
	return 0;
    }
    if(pos_num<offset)
      offset=pos_num;
    if(pos_num>=offset+NBR_DISK_MAX)
      offset=pos_num-NBR_DISK_MAX+1;
  }
}
示例#7
0
unsigned int menu_choose_blocksize(unsigned int blocksize, const unsigned int sector_size, uint64_t *offset)
{
  int command;
  unsigned int menu=0;
  const char *optionsBlocksize="BS51248736";
  static const struct MenuItem menuBlocksize[]=
  {
	{'B',"1",""},
	{'S',"256",""},
	{'5',"512",""},
	{'1',"1024",""},
	{'2',"2048",""},
	{'4',"4096",""},
	{'8',"8192",""},
	{'7',"16384",""},
	{'3',"32768",""},
	{'6',"65536",""},
	{0,NULL,NULL}
  };
  switch(sector_size)
  {
    case 256: optionsBlocksize+=1; break;
    case 512: optionsBlocksize+=2; break;
    case 1024: optionsBlocksize+=3; break;
    case 2048: optionsBlocksize+=4; break;
    case 4096: optionsBlocksize+=5; break;
    case 8192: optionsBlocksize+=6; break;
    case 16384: optionsBlocksize+=7;break;
    case 32768: optionsBlocksize+=8; break;
    case 65536: optionsBlocksize+=9; break;
  }
  switch(blocksize)
  {
    case 1: menu=0; break;
    case 256: menu=1; break;
    case 512: menu=2; break;
    case 1024: menu=3; break;
    case 2048: menu=4; break;
    case 4096: menu=5; break;
    case 8192: menu=6; break;
    case 16384: menu=7; break;
    case 32768: menu=8; break;
    case 65536: menu=9; break;
  }
  aff_copy(stdscr);
  wmove(stdscr,INTER_PARTITION_Y-1,0);
  wprintw(stdscr,"Please select the block size, press Enter when done.");
  command = wmenuSelect_ext(stdscr, 23, INTER_PARTITION_Y, INTER_PARTITION_X, menuBlocksize, 7,
      optionsBlocksize, MENU_VERT| MENU_BUTTON|MENU_VERT_WARN, &menu,NULL);
  switch(command)
  {
    case 'B': blocksize=1; break;
    case 'S': blocksize=256; break;
    case '5': blocksize=512; break;
    case '1': blocksize=1024; break;
    case '2': blocksize=2048; break;
    case '4': blocksize=4096; break;
    case '8': blocksize=8192; break;
    case '7': blocksize=16384; break;
    case '3': blocksize=32768; break;
    case '6': blocksize=65536; break;
  }
  *offset=*offset % blocksize;
  if(*offset%sector_size!=0)
    *offset=0;
  if(sector_size < blocksize)
  {
    unsigned int quit=0;
    aff_copy(stdscr);
    wmove(stdscr,INTER_PARTITION_Y-2,0);
    wprintw(stdscr,"Please select the offset (0 - %u). Press Up/Down to increase/decrease it,",blocksize-sector_size);
    wmove(stdscr,INTER_PARTITION_Y-1,0);
    wprintw(stdscr,"Enter when done.");
    do
    {
      wmove(stdscr,INTER_PARTITION_Y,0);
      wclrtoeol(stdscr);
      wprintw(stdscr,"Offset %u",(unsigned int)(*offset));
      switch(wgetch(stdscr))
      {
	case KEY_ENTER:
#ifdef PADENTER
	case PADENTER:
#endif
	case '\n':
	case '\r':
	  quit=1;
	  break;
	case KEY_PPAGE:
	case KEY_UP:
	case KEY_RIGHT:
	case '+':
	  if(*offset + sector_size < blocksize)
	    *offset+=sector_size;
	  break;
	case KEY_NPAGE:
	case KEY_DOWN:
	case KEY_LEFT:
	case '-':
	  if(*offset >= sector_size)
	    *offset-=sector_size;
	  break;
      }
    } while(quit==0);
  }
  return blocksize;
}
示例#8
0
static int menu_disk_ncurses(disk_t *disk, const int verbose,int dump_ind, const int saveheader, char **current_cmd)
{
  int align=1;
  int ask_part_order=0;
  unsigned int expert=0;
  char options[16];
  static const struct MenuItem menuMain[]=
  {
	{'A',"Analyse","Analyse current partition structure and search for lost partitions"},
	{'T',"Advanced","Filesystem Utils"},
	{'G',"Geometry", "Change disk geometry" },
	{'O',"Options","Modify options"},
	{'C',"MBR Code","Write TestDisk MBR code to first sector"},
	{'D',"Delete","Delete all data in the partition table"},
	{'Q',"Quit","Return to disk selection"},
	{'E',"Editor","Basic disk editor"},
	{0,NULL,NULL}
  };
  unsigned int menu=(disk->arch == &arch_none ? 1 : 0);
  strcpy(options, "AGOPTQ");
  if(disk->arch->write_MBR_code!=NULL)
    strcat(options,"C");
  if(disk->arch->erase_list_part!=NULL)
    strcat(options,"D");
  while(1)
  {
    int real_key;
    int command;
    aff_copy(stdscr);
    wmove(stdscr,5,0);
    wprintw(stdscr, "%s\n", disk->description_short(disk));
    wmove(stdscr,6,0);
    if(disk->geom.heads_per_cylinder == 1 && disk->geom.sectors_per_head == 1)
      wprintw(stdscr, "     %llu sectors", (long long unsigned)(disk->disk_size / disk->sector_size));
    else
      wprintw(stdscr, "     CHS %lu %u %u",
	  disk->geom.cylinders, disk->geom.heads_per_cylinder, disk->geom.sectors_per_head);
    wprintw(stdscr, " - sector size=%u", disk->sector_size);
    wmove(stdscr,20,0);
    wprintw(stdscr,"Note: Correct disk geometry is required for a successful recovery. 'Analyse'");
    wmove(stdscr,21,0);
    wprintw(stdscr,"process may give some warnings if it thinks the logical geometry is mismatched.");
    command = wmenuSelect_ext(stdscr, 23, INTER_DISK_Y, INTER_DISK_X, menuMain, 10,
	options, MENU_VERT | MENU_VERT_WARN | MENU_BUTTON | MENU_ACCEPT_OTHERS, &menu,&real_key);
    /* e for editor will be added when the editor will be better */
    switch(command)
    {
      case 'a':
      case 'A':
	{
	  list_part_t *list_part;
	  list_part=interface_analyse(disk, verbose, saveheader, current_cmd);
	  interface_recovery(disk, list_part, verbose, dump_ind, align, ask_part_order, expert, current_cmd);
	  part_free_list(list_part);
	}
	break;
      case 'd':
      case 'D':
	write_clean_table(disk);
	break;
      case 'c':
      case 'C':
	write_MBR_code(disk);
	break;
      case 'g':
      case 'G':
	change_geometry_ncurses(disk);
	break;
      case 'o':
      case 'O':
	{
	  interface_options(&dump_ind, &align, &expert, current_cmd);
	}
	break;
      case 't':
      case 'T':
	interface_adv(disk, verbose, dump_ind, expert, current_cmd);
	break;
      case 'e':
      case 'E':
	interface_editor(disk);
	break;
      case 'q':
      case 'Q':
	return 0;
    }
  }
}
示例#9
0
文件: adv.c 项目: gonboy/TestDisk
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
    }
}