summaryrefslogtreecommitdiffstats
path: root/src/psearch.h
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2013-05-16 18:09:15 +0200
committerChristophe Grenier <grenier@cgsecurity.org>2013-05-16 18:09:15 +0200
commit1471f47a5c5b9d69863ec496bd7a57a9b0081d89 (patch)
treef1a551a2d0ba7f5fa3a40f2a599213327b8b8f91 /src/psearch.h
parent478478bbccac2e9ac1197035e832b884ace801b3 (diff)
move ind_block(), file_recovery_cpy() and file_add_data() to psearch.h and photorec_aux() to psearchn.c
Diffstat (limited to 'src/psearch.h')
-rw-r--r--src/psearch.h60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/psearch.h b/src/psearch.h
new file mode 100644
index 0000000..1f6c860
--- /dev/null
+++ b/src/psearch.h
@@ -0,0 +1,60 @@
+static inline alloc_data_t *file_add_data(alloc_data_t *data, const uint64_t offset, const unsigned int content)
+{
+ if(!(data->start <= offset && offset <= data->end))
+ {
+ log_critical("file_add_data: bug\n");
+ return data;
+ }
+ if(data->start==offset)
+ {
+ data->data=content;
+ return data;
+ }
+ if(data->data==content)
+ return data;
+ {
+ alloc_data_t *datanext=(alloc_data_t*)MALLOC(sizeof(*datanext));
+ memcpy(datanext, data, sizeof(*datanext));
+ data->end=offset-1;
+ datanext->start=offset;
+ datanext->file_stat=NULL;
+ datanext->data=content;
+ td_list_add(&datanext->list, &data->list);
+ return datanext;
+ }
+}
+
+static inline void file_recovery_cpy(file_recovery_t *dst, file_recovery_t *src)
+{
+ memcpy(dst, src, sizeof(*dst));
+ dst->location.list.prev=&dst->location.list;
+ dst->location.list.next=&dst->location.list;
+}
+
+/* Check if the block looks like an indirect/double-indirect block */
+static inline int ind_block(const unsigned char *buffer, const unsigned int blocksize)
+{
+ const uint32_t *p32=(const uint32_t *)buffer;
+ unsigned int i;
+ unsigned int diff=1; /* IND: Indirect block */
+ if(le32(p32[0])==0)
+ return 0;
+ if(le32(p32[1])==le32(p32[0])+blocksize/4+1)
+ diff=blocksize/4+1; /* DIND: Double Indirect block */
+ for(i=0;i<blocksize/4-1 && le32(p32[i+1])!=0;i++)
+ {
+ if(le32(p32[i+1])!=le32(p32[i])+diff)
+ {
+ return 0;
+ }
+ }
+ i++;
+ for(;i<blocksize/4 && le32(p32[i])==0;i++);
+ if(i<blocksize/4)
+ {
+ return 0;
+ }
+ return 1; /* Ok: ind_block points to non-fragmented block */
+}
+
+