1 /*
2 
3     File: photorec.h
4 
5     Copyright (C) 1998-2008 Christophe GRENIER <grenier@cgsecurity.org>
6 
7     This software is free software; you can redistribute it and/or modify
8     it under the terms of the GNU General Public License as published by
9     the Free Software Foundation; either version 2 of the License, or
10     (at your option) any later version.
11 
12     This program is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.
16 
17     You should have received a copy of the GNU General Public License along
18     with this program; if not, write the Free Software Foundation, Inc., 51
19     Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 
21  */
22 
23 #ifndef _TESTDISK_PHOTOREC_H
24 #define _TESTDISK_PHOTOREC_H
25 #define MAX_FILES_PER_DIR	500
26 #define DEFAULT_RECUP_DIR "recup_dir"
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 enum photorec_status { STATUS_FIND_OFFSET, STATUS_UNFORMAT, STATUS_EXT2_ON, STATUS_EXT2_ON_BF, STATUS_EXT2_OFF, STATUS_EXT2_OFF_BF, STATUS_EXT2_ON_SAVE_EVERYTHING, STATUS_EXT2_OFF_SAVE_EVERYTHING, STATUS_QUIT };
32 typedef enum photorec_status photorec_status_t;
33 
34 typedef enum { PSTATUS_OK=0, PSTATUS_STOP=1, PSTATUS_EACCES=2, PSTATUS_ENOSPC=3} pstatus_t;
35 typedef enum { PFSTATUS_BAD=0, PFSTATUS_OK=1, PFSTATUS_OK_TRUNCATED=2} pfstatus_t;
36 
37 struct ph_options
38 {
39   int paranoid;
40   int keep_corrupted_file;
41   unsigned int mode_ext2;
42   unsigned int expert;
43   unsigned int lowmem;
44   int verbose;
45   file_enable_t *list_file_format;
46 };
47 
48 struct ph_param
49 {
50   char *cmd_device;
51   char *cmd_run;
52   disk_t *disk;
53   partition_t *partition;
54   unsigned int carve_free_space_only;
55   unsigned int blocksize;
56   unsigned int pass;
57   photorec_status_t status;
58   time_t real_start_time;
59   char *recup_dir;
60   /* */
61   unsigned int dir_num;
62   unsigned int file_nbr;
63   file_stat_t *file_stats;
64   uint64_t offset;
65 };
66 
67 void get_prev_location_smart(alloc_data_t *list_search_space, alloc_data_t **current_search_space, uint64_t *offset, const uint64_t prev_location);
68 int get_prev_file_header(alloc_data_t *list_search_space, alloc_data_t **current_search_space, uint64_t *offset);
69 int file_finish_bf(file_recovery_t *file_recovery, struct ph_param *params,
70     alloc_data_t *list_search_space);
71 void file_recovery_aborted(file_recovery_t *file_recovery, struct ph_param *params, alloc_data_t *list_search_space);
72 pfstatus_t file_finish2(file_recovery_t *file_recovery, struct ph_param *params, const int paranoid, alloc_data_t *list_search_space);
73 void write_stats_log(const file_stat_t *file_stats);
74 void update_stats(file_stat_t *file_stats, alloc_data_t *list_search_space);
75 partition_t *new_whole_disk(const disk_t *disk_car);
76 unsigned int find_blocksize(alloc_data_t *list_file, const unsigned int default_blocksize, uint64_t *offset);
77 void update_blocksize(const unsigned int blocksize, alloc_data_t *list_search_space, const uint64_t offset);
78 void forget(alloc_data_t *list_search_space, alloc_data_t *current_search_space);
79 void init_search_space(alloc_data_t *list_search_space, const disk_t *disk_car, const partition_t *partition);
80 unsigned int remove_used_space(disk_t *disk_car, const partition_t *partition, alloc_data_t *list_search_space);
81 void free_list_search_space(alloc_data_t *list_search_space);
82 int sorfile_stat_ts(const void *p1, const void *p2);
83 unsigned int photorec_mkdir(const char *recup_dir, const unsigned int initial_dir_num);
84 void info_list_search_space(const alloc_data_t *list_search_space, const alloc_data_t *current_search_space, const unsigned int sector_size, const int keep_corrupted_file, const int verbose);
85 void free_search_space(alloc_data_t *list_search_space);
86 void set_filename(file_recovery_t *file_recovery, struct ph_param *params);
87 uint64_t set_search_start(struct ph_param *params, alloc_data_t **new_current_search_space, alloc_data_t *list_search_space);
88 void params_reset(struct ph_param *params, const struct ph_options *options);
89 const char *status_to_name(const photorec_status_t status);
90 void status_inc(struct ph_param *params, const struct ph_options *options);
91 list_part_t *init_list_part(disk_t *disk, const struct ph_options *options);
92 void file_block_log(const file_recovery_t *file_recovery, const unsigned int sector_size);
93 void file_block_free(alloc_list_t *list_allocation);
94 void file_block_append(file_recovery_t *file_recovery, alloc_data_t *list_search_space, alloc_data_t **new_current_search_space, uint64_t *offset, const unsigned int blocksize, const unsigned int data);
95 void file_block_truncate_and_move(file_recovery_t *file_recovery, alloc_data_t *list_search_space, const unsigned int blocksize,  alloc_data_t **new_current_search_space, uint64_t *offset, unsigned char *buffer);
96 #ifdef __cplusplus
97 } /* closing brace for extern "C" */
98 #endif
99 #endif
100