| 98 | } |
| 99 | |
| 100 | int disk_image(disk_t *disk, const partition_t *partition, const char *image_dd) |
| 101 | { |
| 102 | int ind_stop=0; |
| 103 | uint64_t nbr_read_error=0; |
| 104 | uint64_t src_offset=partition->part_offset; |
| 105 | uint64_t src_offset_old; |
| 106 | uint64_t dst_offset=0; |
| 107 | const uint64_t src_offset_end=partition->part_offset+partition->part_size; |
| 108 | const uint64_t offset_inc=(src_offset_end-src_offset)/10000; |
| 109 | uint64_t src_offset_next=src_offset; |
| 110 | struct stat stat_buf; |
| 111 | unsigned char *buffer=(unsigned char *)MALLOC(READ_SIZE); |
| 112 | unsigned int readsize=READ_SIZE; |
| 113 | int disk_dst; |
| 114 | #ifdef HAVE_PWRITE |
| 115 | int use_pwrite=1; |
| 116 | #endif |
| 117 | #ifdef HAVE_NCURSES |
| 118 | WINDOW *window; |
| 119 | #endif |
| 120 | assert(disk->sector_size > 0); |
| 121 | assert(disk->sector_size <= READ_SIZE); |
| 122 | if((disk_dst=open(image_dd, O_CREAT|O_LARGEFILE|O_RDWR|O_BINARY, 0644)) < 0) |
| 123 | { |
| 124 | log_error("Can't create file %s.\n",image_dd); |
| 125 | display_message("Can't create file!\n"); |
| 126 | free(buffer); |
| 127 | return -1; |
| 128 | } |
| 129 | #if !defined(DISABLED_FOR_FRAMAC) |
| 130 | if(fstat(disk_dst, &stat_buf)==0) |
| 131 | { |
| 132 | int res=1; |
| 133 | #ifdef HAVE_NCURSES |
| 134 | if(stat_buf.st_size > 0) |
| 135 | res=ask_confirmation("Append to existing file ? (Y/N)"); |
| 136 | #endif |
| 137 | if(res>0) |
| 138 | { |
| 139 | dst_offset=stat_buf.st_size; |
| 140 | src_offset+=dst_offset; |
| 141 | } |
| 142 | } |
| 143 | #endif |
| 144 | src_offset_old=src_offset; |
| 145 | #ifdef HAVE_NCURSES |
| 146 | window=newwin(LINES, COLS, 0, 0); /* full screen */ |
| 147 | aff_copy(window); |
| 148 | wmove(window,5,0); |
| 149 | wprintw(window,"%s\n",disk->description_short(disk)); |
| 150 | wmove(window,6,0); |
| 151 | aff_part(window,AFF_PART_ORDER|AFF_PART_STATUS,disk,partition); |
| 152 | wmove(window,10,0); |
| 153 | waddstr(window, "Disk images are mainly used "); |
| 154 | wmove(window,11,0); |
| 155 | waddstr(window, "- for forensic purposes"); |
| 156 | wmove(window,12,0); |
| 157 | waddstr(window, "- or to deal with media with bad sectors"); |
no test coverage detected