MCPcopy Create free account
hub / github.com/cgsecurity/testdisk / ext2_remove_used_space

Function ext2_remove_used_space

src/ext2p.c:57–121  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

55#include "log_part.h"
56
57unsigned int ext2_remove_used_space(disk_t *disk, const partition_t *partition, alloc_data_t *list_search_space)
58{
59 dir_data_t dir_data;
60 switch(dir_partition_ext2_init(disk, partition, &dir_data, 0))
61 {
62 case DIR_PART_ENOIMP:
63 case DIR_PART_ENOSYS:
64 return 0;
65 case DIR_PART_EIO:
66 log_partition(disk, partition);
67 log_error("Can't open filesystem. Filesystem seems damaged.\n");
68 return 0;
69 case DIR_PART_OK:
70 break;
71 }
72 {
73 struct ext2_dir_struct *ls=(struct ext2_dir_struct *)dir_data.private_dir_data;
74 uint64_t start_free=0;
75 uint64_t end_free=0;
76 unsigned long int block;
77 unsigned long int start,end;
78 const unsigned int blocksize=ls->current_fs->blocksize;
79 ext2fs_block_bitmap bitmap;
80 if(ext2fs_read_block_bitmap(ls->current_fs))
81 {
82 log_error("ext2fs_read_block_bitmap failed\n");
83 return 0;
84 }
85 bitmap=ls->current_fs->block_map;
86 if(bitmap==NULL)
87 return 0;
88#ifdef HAVE_EXT2FS_GET_GENERIC_BITMAP_START
89 start=ext2fs_get_generic_bitmap_start(bitmap);
90 end=ext2fs_get_generic_bitmap_end(bitmap);
91#else
92 start=bitmap->start;
93 end=bitmap->end;
94#endif
95 log_trace("ext2_remove_used_space %lu-%lu\n", start, end);
96 for(block=start;block<=end;block++)
97 {
98#ifdef HAVE_EXT2FS_GET_GENERIC_BITMAP_START
99 if(ext2fs_test_generic_bitmap(bitmap,block)!=0)
100#else
101 if(ext2fs_test_bit(block - bitmap->start, bitmap->bitmap)!=0)
102#endif
103 {
104 /* Not free */
105 if(end_free+1==partition->part_offset+(uint64_t)block*blocksize)
106 end_free+=blocksize;
107 else
108 {
109 if(start_free != end_free)
110 del_search_space(list_search_space, start_free, end_free);
111 start_free=partition->part_offset+(uint64_t)block*blocksize;
112 end_free=start_free+(uint64_t)blocksize-1;
113 }
114 }

Callers 1

remove_used_spaceFunction · 0.85

Calls 3

dir_partition_ext2_initFunction · 0.85
log_partitionFunction · 0.85
del_search_spaceFunction · 0.85

Tested by

no test coverage detected