summaryrefslogtreecommitdiffstats
path: root/src/pnext.h
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2009-02-17 09:32:59 +0100
committerChristophe Grenier <grenier@cgsecurity.org>2009-02-17 09:32:59 +0100
commit76a8f20f27b33023fe403b071f37085e934f26e2 (patch)
tree0cf7ec69185e4d5c51b8d3ad67f0b1a35c99ce83 /src/pnext.h
parentee97a896a22fcf1ff0bd7afd0ab18bba4d83185c (diff)
PhotoRec: move get_next_header() and get_next_sector() to the new file pnext.h
Diffstat (limited to 'src/pnext.h')
-rw-r--r--src/pnext.h81
1 files changed, 81 insertions, 0 deletions
diff --git a/src/pnext.h b/src/pnext.h
new file mode 100644
index 0000000..1201c1d
--- /dev/null
+++ b/src/pnext.h
@@ -0,0 +1,81 @@
+/*
+
+ File: pnext.c
+
+ Copyright (C) 2009 Christophe GRENIER <grenier@cgsecurity.org>
+
+ This software is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write the Free Software Foundation, Inc., 51
+ Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+ */
+
+/* #define DEBUG_GET_NEXT_SECTOR */
+static
+#ifndef DEBUG_GET_NEXT_SECTOR
+inline
+#endif
+void get_next_header(alloc_data_t *list_search_space, alloc_data_t **current_search_space, uint64_t *offset)
+{
+#ifdef DEBUG_GET_NEXT_SECTOR
+ log_trace(" get_next_header %llu (%llu-%llu)\n",
+ (unsigned long long)((*offset)/512),
+ (unsigned long long)((*current_search_space)->start/512),
+ (unsigned long long)((*current_search_space)->end)/512);
+#endif
+ if((*current_search_space) != list_search_space)
+ *current_search_space=td_list_entry((*current_search_space)->list.next, alloc_data_t, list);
+ *offset=(*current_search_space)->start;
+}
+
+static
+#ifndef DEBUG_GET_NEXT_SECTOR
+inline
+#endif
+void get_next_sector(alloc_data_t *list_search_space, alloc_data_t **current_search_space, uint64_t *offset, const unsigned int blocksize)
+{
+#ifdef DEBUG_GET_NEXT_SECTOR
+ log_debug(" get_next_sector %llu (%llu-%llu)\n",
+ (unsigned long long)((*offset)/512),
+ (unsigned long long)((*current_search_space)->start/512),
+ (unsigned long long)((*current_search_space)->end)/512);
+#endif
+ if((*current_search_space) == list_search_space)
+ {
+ return ;
+ }
+#ifdef DEBUG_GET_NEXT_SECTOR
+ if(! ((*current_search_space)->start <= *offset && (*offset)<=(*current_search_space)->end))
+ {
+ log_critical("BUG: get_next_sector stop everything %llu (%llu-%llu)\n",
+ (unsigned long long)((*offset)/512),
+ (unsigned long long)((*current_search_space)->start/512),
+ (unsigned long long)((*current_search_space)->end/512));
+ log_flush();
+ bug();
+ log_close();
+ exit(1);
+ }
+#endif
+ if((*offset)+blocksize <= (*current_search_space)->end)
+ *offset+=blocksize;
+ else
+ get_next_header(list_search_space, current_search_space, offset);
+}
+
+#ifdef DEBUG_GET_NEXT_SECTOR
+void bug(void)
+{
+ log_critical("bug\n");
+}
+#endif