View | Details | Raw Unified
Collapse All | Expand All

(-) testdisk-6.8.org/src/dir.h (-1 / +1 lines)
 Lines 51-57    Link Here 
};
};
struct file_info {
struct file_info {
  struct list_head list;
  struct td_list_head list;
  char name[4096];
  char name[4096];
  struct stat stat;
  struct stat stat;
};
};
(-) testdisk-6.8.org/src/filegen.h (-1 / +1 lines)
 Lines 88-94    Link Here 
struct alloc_data_struct
struct alloc_data_struct
{
{
  struct list_head list;
  struct td_list_head list;
  uint64_t start;
  uint64_t start;
  uint64_t end;
  uint64_t end;
  file_stat_t *file_stat;
  file_stat_t *file_stat;
(-) testdisk-6.8.org/src/intrface.c (-9 / +9 lines)
 Lines 1080-1094    Link Here 
static list_part_t *interface_load(disk_t *disk_car,list_part_t *list_part, const int debug)
static list_part_t *interface_load(disk_t *disk_car,list_part_t *list_part, const int debug)
{
{
  struct list_head *backup_walker=NULL;
  struct td_list_head *backup_walker=NULL;
  backup_disk_t *backup_list=partition_load(disk_car,debug);
  backup_disk_t *backup_list=partition_load(disk_car,debug);
  {
  {
    log_info("interface_load\n");
    log_info("interface_load\n");
    list_for_each(backup_walker,&backup_list->list)
    td_list_for_each(backup_walker,&backup_list->list)
    {
    {
      list_part_t *element;
      list_part_t *element;
      backup_disk_t *backup;
      backup_disk_t *backup;
      backup=list_entry(backup_walker, backup_disk_t, list);
      backup=td_list_entry(backup_walker, backup_disk_t, list);
      log_info("%s %s",backup->description,ctime(&backup->my_time));
      log_info("%s %s",backup->description,ctime(&backup->my_time));
      for(element=backup->list_part;element!=NULL;element=element->next)
      for(element=backup->list_part;element!=NULL;element=element->next)
	log_partition(disk_car,element->part);
	log_partition(disk_car,element->part);
 Lines 1100-1106    Link Here 
    int backup_current_num=0;
    int backup_current_num=0;
    int rewrite=1;
    int rewrite=1;
    unsigned int menu=3;   /* default : quit */
    unsigned int menu=3;   /* default : quit */
    struct list_head *backup_current=backup_list->list.next;
    struct td_list_head *backup_current=backup_list->list.next;
    struct MenuItem menuLoadBackup[]=
    struct MenuItem menuLoadBackup[]=
    {
    {
      { 'P', "Previous",""},
      { 'P', "Previous",""},
 Lines 1134-1140    Link Here 
	for(i=0,backup_walker=backup_list->list.next;(backup_walker!=&backup_list->list) && (i<offset);backup_walker=backup_walker->next,i++);
	for(i=0,backup_walker=backup_list->list.next;(backup_walker!=&backup_list->list) && (i<offset);backup_walker=backup_walker->next,i++);
	for(i=offset;(backup_walker!=&backup_list->list) &&((i-offset)<INTER_STRUCTURE);i++,backup_walker=backup_walker->next)
	for(i=offset;(backup_walker!=&backup_list->list) &&((i-offset)<INTER_STRUCTURE);i++,backup_walker=backup_walker->next)
	{
	{
	  backup=list_entry(backup_walker, backup_disk_t, list);
	  backup=td_list_entry(backup_walker, backup_disk_t, list);
	  wmove(stdscr,8+i-offset,0);
	  wmove(stdscr,8+i-offset,0);
	  wclrtoeol(stdscr);	/* before addstr for BSD compatibility */
	  wclrtoeol(stdscr);	/* before addstr for BSD compatibility */
	  if(backup_walker==backup_current)
	  if(backup_walker==backup_current)
 Lines 1222-1228    Link Here 
    {
    {
      list_part_t *partition;
      list_part_t *partition;
      backup_disk_t *backup;
      backup_disk_t *backup;
      backup=list_entry(backup_current, backup_disk_t, list);
      backup=td_list_entry(backup_current, backup_disk_t, list);
      for(partition=backup->list_part;partition!=NULL;partition=partition->next)
      for(partition=backup->list_part;partition!=NULL;partition=partition->next)
      {
      {
	/* Check partition and load partition name */
	/* Check partition and load partition name */
 Lines 1232-1242    Link Here 
    }
    }
  }
  }
  { /* Cleanup */
  { /* Cleanup */
    struct list_head *backup_walker_next = NULL;
    struct td_list_head *backup_walker_next = NULL;
    list_for_each_safe(backup_walker,backup_walker_next,&backup_list->list)
    td_list_for_each_safe(backup_walker,backup_walker_next,&backup_list->list)
    {
    {
      backup_disk_t *backup;
      backup_disk_t *backup;
      backup=list_entry(backup_walker, backup_disk_t, list);
      backup=td_list_entry(backup_walker, backup_disk_t, list);
      delete_list_part(backup->list_part);
      delete_list_part(backup->list_part);
      free(backup);
      free(backup);
    }
    }
(-) testdisk-6.8.org/src/intrf.c (-13 / +13 lines)
 Lines 1548-1558    Link Here 
  do
  do
  {
  {
    DIR* dir;
    DIR* dir;
    struct list_head *dir_current;
    struct td_list_head *dir_current;
    int offset=0;
    int offset=0;
    int pos_num=0;
    int pos_num=0;
    static struct file_info dir_list = {
    static struct file_info dir_list = {
      .list = LIST_HEAD_INIT(dir_list.list),
      .list = TD_LIST_HEAD_INIT(dir_list.list),
      .name = {0}
      .name = {0}
    };
    };
    wmove(window,7,0);
    wmove(window,7,0);
 Lines 1576-1582    Link Here 
	new_drive->name[2]=PATH_SEP;
	new_drive->name[2]=PATH_SEP;
	new_drive->name[3]='\0';
	new_drive->name[3]='\0';
	new_drive->stat.st_mode=LINUX_S_IFDIR|LINUX_S_IRWXUGO;
	new_drive->stat.st_mode=LINUX_S_IFDIR|LINUX_S_IRWXUGO;
	list_add_tail(&new_drive->list,&dir_list.list);
	td_list_add_tail(&new_drive->list,&dir_list.list);
      }
      }
      dir=NULL;
      dir=NULL;
    }
    }
 Lines 1633-1639    Link Here 
	      }
	      }
#endif
#endif
	      strncpy(dir_info->name,dir_entrie->d_name,sizeof(dir_info->name));
	      strncpy(dir_info->name,dir_entrie->d_name,sizeof(dir_info->name));
	      list_add_tail(&dir_info->list,&dir_list.list);
	      td_list_add_tail(&dir_info->list,&dir_list.list);
	      dir_info=(struct file_info*)MALLOC(sizeof(*dir_info));
	      dir_info=(struct file_info*)MALLOC(sizeof(*dir_info));
	    }
	    }
	  }
	  }
 Lines 1665-1678    Link Here 
	wdoprintf(window,"To select another directory, use the arrow keys.");
	wdoprintf(window,"To select another directory, use the arrow keys.");
#endif
#endif
	{
	{
	  struct list_head *dir_walker = NULL;
	  struct td_list_head *dir_walker = NULL;
	  int i=0;
	  int i=0;
	  list_for_each(dir_walker,&dir_list.list)
	  td_list_for_each(dir_walker,&dir_list.list)
	  {
	  {
	    if(offset<=i)
	    if(offset<=i)
	    {
	    {
	      struct file_info *dir_info;
	      struct file_info *dir_info;
	      dir_info=list_entry(dir_walker, struct file_info, list);
	      dir_info=td_list_entry(dir_walker, struct file_info, list);
	      wmove(window,8+i-offset,0);
	      wmove(window,8+i-offset,0);
	      wclrtoeol(window);	/* before addstr for BSD compatibility */
	      wclrtoeol(window);	/* before addstr for BSD compatibility */
	      if(dir_walker==dir_current)
	      if(dir_walker==dir_current)
 Lines 1792-1798    Link Here 
	      if(dir_current!=&dir_list.list)
	      if(dir_current!=&dir_list.list)
	      {
	      {
		struct file_info *dir_info;
		struct file_info *dir_info;
		dir_info=list_entry(dir_current, struct file_info, list);
		dir_info=td_list_entry(dir_current, struct file_info, list);
		if(strcmp(dir_info->name,".")==0)
		if(strcmp(dir_info->name,".")==0)
		{
		{
		}
		}
 Lines 1819-1831    Link Here 
	} while(quit==0);
	} while(quit==0);
      } while(quit==1);
      } while(quit==1);
      {
      {
	struct list_head *dir_walker = NULL;
	struct td_list_head *dir_walker = NULL;
	struct list_head *dir_walker_next = NULL;
	struct td_list_head *dir_walker_next = NULL;
	list_for_each_safe(dir_walker,dir_walker_next,&dir_list.list)
	td_list_for_each_safe(dir_walker,dir_walker_next,&dir_list.list)
	{
	{
	  struct file_info *dir_info;
	  struct file_info *dir_info;
	  dir_info=list_entry(dir_walker, struct file_info, list);
	  dir_info=td_list_entry(dir_walker, struct file_info, list);
	  list_del(dir_walker);
	  td_list_del(dir_walker);
	  free(dir_info);
	  free(dir_info);
	}
	}
      }
      }
(-) testdisk-6.8.org/src/list.c (-3 / +3 lines)
 Lines 87-100    Link Here 
      if(file_size>=size)
      if(file_size>=size)
      {
      {
	element->end-=(file_size-size);
	element->end-=(file_size-size);
	list_delete(element->next);
	td_list_delete(element->next);
//	element->next=NULL;	already done by list_delete
//	element->next=NULL;	already done by td_list_delete
      }
      }
    }
    }
  }
  }
}
}
void list_delete(alloc_list_t *list)
void td_list_delete(alloc_list_t *list)
{
{
  alloc_list_t *next;
  alloc_list_t *next;
  if(list!=NULL && list->prev!=NULL)
  if(list!=NULL && list->prev!=NULL)
(-) testdisk-6.8.org/src/list.h (-91 / +91 lines)
 Lines 34-40    Link Here 
void list_append_block(alloc_list_t *list, const uint64_t offset, const uint64_t blocksize, const int data);
void list_append_block(alloc_list_t *list, const uint64_t offset, const uint64_t blocksize, const int data);
void list_truncate(alloc_list_t *list, uint64_t size);
void list_truncate(alloc_list_t *list, uint64_t size);
void list_delete(alloc_list_t *list);
void td_list_delete(alloc_list_t *list);
/*
/*
 Lines 56-71    Link Here 
 * using the generic single-entry routines.
 * using the generic single-entry routines.
 */
 */
struct list_head {
struct td_list_head {
	struct list_head *next, *prev;
	struct td_list_head *next, *prev;
};
};
#define LIST_HEAD_INIT(name) { &(name), &(name) }
#define TD_LIST_HEAD_INIT(name) { &(name), &(name) }
#define LIST_HEAD(name) \
#define TD_LIST_HEAD(name) \
	struct list_head name = LIST_HEAD_INIT(name)
	struct td_list_head name = TD_LIST_HEAD_INIT(name)
#define INIT_LIST_HEAD(ptr) do { \
#define INIT_TD_LIST_HEAD(ptr) do { \
	(ptr)->next = (ptr); (ptr)->prev = (ptr); \
	(ptr)->next = (ptr); (ptr)->prev = (ptr); \
} while (0)
} while (0)
 Lines 75-83    Link Here 
 * This is only for internal list manipulation where we know
 * This is only for internal list manipulation where we know
 * the prev/next entries already!
 * the prev/next entries already!
 */
 */
static inline void __list_add(struct list_head *new,
static inline void __td_list_add(struct td_list_head *new,
			      struct list_head *prev,
			      struct td_list_head *prev,
			      struct list_head *next)
			      struct td_list_head *next)
{
{
	next->prev = new;
	next->prev = new;
	new->next = next;
	new->next = next;
 Lines 86-114    Link Here 
}
}
/**
/**
 * list_add - add a new entry
 * td_list_add - add a new entry
 * @new: new entry to be added
 * @new: new entry to be added
 * @head: list head to add it after
 * @head: list head to add it after
 *
 *
 * Insert a new entry after the specified head.
 * Insert a new entry after the specified head.
 * This is good for implementing stacks.
 * This is good for implementing stacks.
 */
 */
static inline void list_add(struct list_head *new, struct list_head *head)
static inline void td_list_add(struct td_list_head *new, struct td_list_head *head)
{
{
	__list_add(new, head, head->next);
	__td_list_add(new, head, head->next);
}
}
/**
/**
 * list_add_tail - add a new entry
 * td_list_add_tail - add a new entry
 * @new: new entry to be added
 * @new: new entry to be added
 * @head: list head to add it before
 * @head: list head to add it before
 *
 *
 * Insert a new entry before the specified head.
 * Insert a new entry before the specified head.
 * This is useful for implementing queues.
 * This is useful for implementing queues.
 */
 */
static inline void list_add_tail(struct list_head *new, struct list_head *head)
static inline void td_list_add_tail(struct td_list_head *new, struct td_list_head *head)
{
{
	__list_add(new, head->prev, head);
	__td_list_add(new, head->prev, head);
}
}
/*
/*
 Lines 118-208    Link Here 
 * This is only for internal list manipulation where we know
 * This is only for internal list manipulation where we know
 * the prev/next entries already!
 * the prev/next entries already!
 */
 */
static inline void __list_del(struct list_head * prev, struct list_head * next)
static inline void __td_list_del(struct td_list_head * prev, struct td_list_head * next)
{
{
	next->prev = prev;
	next->prev = prev;
	prev->next = next;
	prev->next = next;
}
}
/**
/**
 * list_del - deletes entry from list.
 * td_list_del - deletes entry from list.
 * @entry: the element to delete from the list.
 * @entry: the element to delete from the list.
 * Note: list_empty on entry does not return true after this, the entry is
 * Note: td_list_empty on entry does not return true after this, the entry is
 * in an undefined state.
 * in an undefined state.
 */
 */
static inline void list_del(struct list_head *entry)
static inline void td_list_del(struct td_list_head *entry)
{
{
	__list_del(entry->prev, entry->next);
	__td_list_del(entry->prev, entry->next);
	entry->next = LIST_POISON1;
	entry->next = LIST_POISON1;
	entry->prev = LIST_POISON2;
	entry->prev = LIST_POISON2;
}
}
/**
/**
 * list_del_init - deletes entry from list and reinitialize it.
 * td_list_del_init - deletes entry from list and reinitialize it.
 * @entry: the element to delete from the list.
 * @entry: the element to delete from the list.
 */
 */
static inline void list_del_init(struct list_head *entry)
static inline void td_list_del_init(struct td_list_head *entry)
{
{
	__list_del(entry->prev, entry->next);
	__td_list_del(entry->prev, entry->next);
	INIT_LIST_HEAD(entry);
	INIT_TD_LIST_HEAD(entry);
}
}
/**
/**
 * list_move - delete from one list and add as another's head
 * td_list_move - delete from one list and add as another's head
 * @list: the entry to move
 * @list: the entry to move
 * @head: the head that will precede our entry
 * @head: the head that will precede our entry
 */
 */
static inline void list_move(struct list_head *list, struct list_head *head)
static inline void td_list_move(struct td_list_head *list, struct td_list_head *head)
{
{
        __list_del(list->prev, list->next);
        __td_list_del(list->prev, list->next);
        list_add(list, head);
        td_list_add(list, head);
}
}
/**
/**
 * list_move_tail - delete from one list and add as another's tail
 * td_list_move_tail - delete from one list and add as another's tail
 * @list: the entry to move
 * @list: the entry to move
 * @head: the head that will follow our entry
 * @head: the head that will follow our entry
 */
 */
static inline void list_move_tail(struct list_head *list,
static inline void td_list_move_tail(struct td_list_head *list,
				  struct list_head *head)
				  struct td_list_head *head)
{
{
        __list_del(list->prev, list->next);
        __td_list_del(list->prev, list->next);
        list_add_tail(list, head);
        td_list_add_tail(list, head);
}
}
/**
/**
 * list_empty - tests whether a list is empty
 * td_list_empty - tests whether a list is empty
 * @head: the list to test.
 * @head: the list to test.
 */
 */
static inline int list_empty(const struct list_head *head)
static inline int td_list_empty(const struct td_list_head *head)
{
{
	return head->next == head;
	return head->next == head;
}
}
/**
/**
 * list_empty_careful - tests whether a list is
 * td_list_empty_careful - tests whether a list is
 * empty _and_ checks that no other CPU might be
 * empty _and_ checks that no other CPU might be
 * in the process of still modifying either member
 * in the process of still modifying either member
 *
 *
 * NOTE: using list_empty_careful() without synchronization
 * NOTE: using td_list_empty_careful() without synchronization
 * can only be safe if the only activity that can happen
 * can only be safe if the only activity that can happen
 * to the list entry is list_del_init(). Eg. it cannot be used
 * to the list entry is td_list_del_init(). Eg. it cannot be used
 * if another CPU could re-list_add() it.
 * if another CPU could re-td_list_add() it.
 *
 *
 * @head: the list to test.
 * @head: the list to test.
 */
 */
static inline int list_empty_careful(const struct list_head *head)
static inline int td_list_empty_careful(const struct td_list_head *head)
{
{
	struct list_head *next = head->next;
	struct td_list_head *next = head->next;
	return (next == head) && (next == head->prev);
	return (next == head) && (next == head->prev);
}
}
static inline void __list_splice(struct list_head *list,
static inline void __td_list_splice(struct td_list_head *list,
				 struct list_head *head)
				 struct td_list_head *head)
{
{
	struct list_head *first = list->next;
	struct td_list_head *first = list->next;
	struct list_head *last = list->prev;
	struct td_list_head *last = list->prev;
	struct list_head *at = head->next;
	struct td_list_head *at = head->next;
	first->prev = head;
	first->prev = head;
	head->next = first;
	head->next = first;
 Lines 212-336    Link Here 
}
}
/**
/**
 * list_splice - join two lists
 * td_list_splice - join two lists
 * @list: the new list to add.
 * @list: the new list to add.
 * @head: the place to add it in the first list.
 * @head: the place to add it in the first list.
 */
 */
static inline void list_splice(struct list_head *list, struct list_head *head)
static inline void td_list_splice(struct td_list_head *list, struct td_list_head *head)
{
{
	if (!list_empty(list))
	if (!td_list_empty(list))
		__list_splice(list, head);
		__td_list_splice(list, head);
}
}
/**
/**
 * list_splice_init - join two lists and reinitialise the emptied list.
 * td_list_splice_init - join two lists and reinitialise the emptied list.
 * @list: the new list to add.
 * @list: the new list to add.
 * @head: the place to add it in the first list.
 * @head: the place to add it in the first list.
 *
 *
 * The list at @list is reinitialised
 * The list at @list is reinitialised
 */
 */
static inline void list_splice_init(struct list_head *list,
static inline void td_list_splice_init(struct td_list_head *list,
				    struct list_head *head)
				    struct td_list_head *head)
{
{
	if (!list_empty(list)) {
	if (!td_list_empty(list)) {
		__list_splice(list, head);
		__td_list_splice(list, head);
		INIT_LIST_HEAD(list);
		INIT_TD_LIST_HEAD(list);
	}
	}
}
}
/**
/**
 * list_entry - get the struct for this entry
 * td_list_entry - get the struct for this entry
 * @ptr:	the &struct list_head pointer.
 * @ptr:	the &struct td_list_head pointer.
 * @type:	the type of the struct this is embedded in.
 * @type:	the type of the struct this is embedded in.
 * @member:	the name of the list_struct within the struct.
 * @member:	the name of the list_struct within the struct.
 */
 */
#define list_entry(ptr, type, member) \
#define td_list_entry(ptr, type, member) \
	((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
	((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
/**
/**
 * __list_for_each	-	iterate over a list
 * __td_list_for_each	-	iterate over a list
 * @pos:	the &struct list_head to use as a loop counter.
 * @pos:	the &struct td_list_head to use as a loop counter.
 * @head:	the head for your list.
 * @head:	the head for your list.
 *
 *
 */
 */
#define list_for_each(pos, head) \
#define td_list_for_each(pos, head) \
	for (pos = (head)->next; pos != (head); pos = pos->next)
	for (pos = (head)->next; pos != (head); pos = pos->next)
/**
/**
 * list_for_each_prev	-	iterate over a list backwards
 * td_list_for_each_prev	-	iterate over a list backwards
 * @pos:	the &struct list_head to use as a loop counter.
 * @pos:	the &struct td_list_head to use as a loop counter.
 * @head:	the head for your list.
 * @head:	the head for your list.
 */
 */
#define list_for_each_prev(pos, head) \
#define td_list_for_each_prev(pos, head) \
	for (pos = (head)->prev; pos != (head); \
	for (pos = (head)->prev; pos != (head); \
        	pos = pos->prev)
        	pos = pos->prev)
/**
/**
 * list_for_each_safe	-	iterate over a list safe against removal of list entry
 * td_list_for_each_safe	-	iterate over a list safe against removal of list entry
 * @pos:	the &struct list_head to use as a loop counter.
 * @pos:	the &struct td_list_head to use as a loop counter.
 * @n:		another &struct list_head to use as temporary storage
 * @n:		another &struct td_list_head to use as temporary storage
 * @head:	the head for your list.
 * @head:	the head for your list.
 */
 */
#define list_for_each_safe(pos, n, head) \
#define td_list_for_each_safe(pos, n, head) \
	for (pos = (head)->next, n = pos->next; pos != (head); \
	for (pos = (head)->next, n = pos->next; pos != (head); \
		pos = n, n = pos->next)
		pos = n, n = pos->next)
/**
/**
 * list_for_each_entry	-	iterate over list of given type
 * td_list_for_each_entry	-	iterate over list of given type
 * @pos:	the type * to use as a loop counter.
 * @pos:	the type * to use as a loop counter.
 * @head:	the head for your list.
 * @head:	the head for your list.
 * @member:	the name of the list_struct within the struct.
 * @member:	the name of the list_struct within the struct.
 */
 */
#define list_for_each_entry(pos, head, member)				\
#define td_list_for_each_entry(pos, head, member)				\
	for (pos = list_entry((head)->next, typeof(*pos), member);	\
	for (pos = td_list_entry((head)->next, typeof(*pos), member);	\
	     &pos->member != (head); 	\
	     &pos->member != (head); 	\
	     pos = list_entry(pos->member.next, typeof(*pos), member))
	     pos = td_list_entry(pos->member.next, typeof(*pos), member))
/**
/**
 * list_for_each_entry_reverse - iterate backwards over list of given type.
 * td_list_for_each_entry_reverse - iterate backwards over list of given type.
 * @pos:	the type * to use as a loop counter.
 * @pos:	the type * to use as a loop counter.
 * @head:	the head for your list.
 * @head:	the head for your list.
 * @member:	the name of the list_struct within the struct.
 * @member:	the name of the list_struct within the struct.
 */
 */
#define list_for_each_entry_reverse(pos, head, member)			\
#define td_list_for_each_entry_reverse(pos, head, member)			\
	for (pos = list_entry((head)->prev, typeof(*pos), member);	\
	for (pos = td_list_entry((head)->prev, typeof(*pos), member);	\
	     &pos->member != (head); 	\
	     &pos->member != (head); 	\
	     pos = list_entry(pos->member.prev, typeof(*pos), member))
	     pos = td_list_entry(pos->member.prev, typeof(*pos), member))
/**
/**
 * list_prepare_entry - prepare a pos entry for use as a start point in
 * td_list_prepare_entry - prepare a pos entry for use as a start point in
 *			list_for_each_entry_continue
 *			td_list_for_each_entry_continue
 * @pos:	the type * to use as a start point
 * @pos:	the type * to use as a start point
 * @head:	the head of the list
 * @head:	the head of the list
 * @member:	the name of the list_struct within the struct.
 * @member:	the name of the list_struct within the struct.
 */
 */
#define list_prepare_entry(pos, head, member) \
#define td_list_prepare_entry(pos, head, member) \
	((pos) ? : list_entry(head, typeof(*pos), member))
	((pos) ? : td_list_entry(head, typeof(*pos), member))
/**
/**
 * list_for_each_entry_continue -	iterate over list of given type
 * td_list_for_each_entry_continue -	iterate over list of given type
 *			continuing after existing point
 *			continuing after existing point
 * @pos:	the type * to use as a loop counter.
 * @pos:	the type * to use as a loop counter.
 * @head:	the head for your list.
 * @head:	the head for your list.
 * @member:	the name of the list_struct within the struct.
 * @member:	the name of the list_struct within the struct.
 */
 */
#define list_for_each_entry_continue(pos, head, member) 		\
#define td_list_for_each_entry_continue(pos, head, member) 		\
	for (pos = list_entry(pos->member.next, typeof(*pos), member);	\
	for (pos = td_list_entry(pos->member.next, typeof(*pos), member);	\
	     &pos->member != (head);	\
	     &pos->member != (head);	\
	     pos = list_entry(pos->member.next, typeof(*pos), member))
	     pos = td_list_entry(pos->member.next, typeof(*pos), member))
/**
/**
 * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
 * td_list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
 * @pos:	the type * to use as a loop counter.
 * @pos:	the type * to use as a loop counter.
 * @n:		another type * to use as temporary storage
 * @n:		another type * to use as temporary storage
 * @head:	the head for your list.
 * @head:	the head for your list.
 * @member:	the name of the list_struct within the struct.
 * @member:	the name of the list_struct within the struct.
 */
 */
#define list_for_each_entry_safe(pos, n, head, member)			\
#define td_list_for_each_entry_safe(pos, n, head, member)			\
	for (pos = list_entry((head)->next, typeof(*pos), member),	\
	for (pos = td_list_entry((head)->next, typeof(*pos), member),	\
		n = list_entry(pos->member.next, typeof(*pos), member);	\
		n = td_list_entry(pos->member.next, typeof(*pos), member);	\
	     &pos->member != (head); 					\
	     &pos->member != (head); 					\
	     pos = n, n = list_entry(n->member.next, typeof(*n), member))
	     pos = n, n = td_list_entry(n->member.next, typeof(*n), member))
#endif
#endif
(-) testdisk-6.8.org/src/ntfs.c (-7 / +7 lines)
 Lines 233-239    Link Here 
    {
    {
      unsigned int attr_value_length=NTFS_GETU16(attr_record+0x10);
      unsigned int attr_value_length=NTFS_GETU16(attr_record+0x10);
      unsigned int attr_value_offset=NTFS_GETU16(attr_record+0x14);
      unsigned int attr_value_offset=NTFS_GETU16(attr_record+0x14);
      const char *attr_list_entry=attr_record+attr_value_offset;
      const char *attr_td_list_entry=attr_record+attr_value_offset;
      if(attr_value_offset%8!=0)
      if(attr_value_offset%8!=0)
      {
      {
#ifdef NTFS_DEBUG
#ifdef NTFS_DEBUG
 Lines 241-255    Link Here 
#endif
#endif
	return 2;
	return 2;
      }
      }
      if(attr_list_entry+26>=end)
      if(attr_td_list_entry+26>=end)
      {
      {
#ifdef NTFS_DEBUG
#ifdef NTFS_DEBUG
	log_debug("ntfs_get_attr attr_list_entry+26=%p, end=%p\n",attr_list_entry+26,end);
	log_debug("ntfs_get_attr attr_td_list_entry+26=%p, end=%p\n",attr_td_list_entry+26,end);
#endif
#endif
	return 2;
	return 2;
      }
      }
      /* We found the attribute type. Is the name correct, too? */
      /* We found the attribute type. Is the name correct, too? */
      if((attr_value_offset+attr_value_length>attr_len) || (attr_list_entry+attr_len >= end))
      if((attr_value_offset+attr_value_length>attr_len) || (attr_td_list_entry+attr_len >= end))
      {
      {
#ifdef NTFS_DEBUG
#ifdef NTFS_DEBUG
	// log_debug("ntfs_get_attr \n");
	// log_debug("ntfs_get_attr \n");
 Lines 262-268    Link Here 
	{
	{
	  case 0x30:	/* AT_FILE_NAME */
	  case 0x30:	/* AT_FILE_NAME */
	    {
	    {
	      const char *file_name_attr=attr_list_entry;
	      const char *file_name_attr=attr_td_list_entry;
	      unsigned int file_name_length;
	      unsigned int file_name_length;
	      const char *name_it;
	      const char *name_it;
	      if(file_name_attr+0x42>=end)
	      if(file_name_attr+0x42>=end)
 Lines 303-315    Link Here 
	      volume_name_length/=2;	/* Unicode */
	      volume_name_length/=2;	/* Unicode */
	      if(volume_name_length>sizeof(partition->name)-1)
	      if(volume_name_length>sizeof(partition->name)-1)
		volume_name_length=sizeof(partition->name)-1;
		volume_name_length=sizeof(partition->name)-1;
	      for(name_it=attr_list_entry;(volume_name_length>0) && (*name_it!='\0') && (name_it[1]=='\0'); name_it+=2,volume_name_length--)
	      for(name_it=attr_td_list_entry;(volume_name_length>0) && (*name_it!='\0') && (name_it[1]=='\0'); name_it+=2,volume_name_length--)
		*dest++=*name_it;
		*dest++=*name_it;
	      *dest++='\0'; /* 27 january 2003: Correct a bug found by Andreas du Plessis-Denz */
	      *dest++='\0'; /* 27 january 2003: Correct a bug found by Andreas du Plessis-Denz */
	    }
	    }
	    return 1;
	    return 1;
	  case 0x90:	/* AT_INDEX_ROOT */
	  case 0x90:	/* AT_INDEX_ROOT */
	    return NTFS_GETU32(attr_list_entry+8);	/* index_block_size */
	    return NTFS_GETU32(attr_td_list_entry+8);	/* index_block_size */
	}
	}
      }
      }
    }
    }
(-) testdisk-6.8.org/src/ntfs_dir.c (-5 / +5 lines)
 Lines 93-99    Link Here 
extern u64 ntfs_inode_lookup_by_name(ntfs_inode *dir_ni,
extern u64 ntfs_inode_lookup_by_name(ntfs_inode *dir_ni,
                const ntfschar *uname, const int uname_len);
                const ntfschar *uname, const int uname_len);
static time_t ntfs2utc (s64 ntfstime);
static time_t ntfs2utc (s64 ntfstime);
static int ntfs_list_entry(  struct ntfs_dir_struct *ls, const ntfschar *name, 
static int ntfs_td_list_entry(  struct ntfs_dir_struct *ls, const ntfschar *name, 
		const int name_len, const int name_type, const s64 pos,
		const int name_len, const int name_type, const s64 pos,
		const MFT_REF mref, const unsigned dt_type);
		const MFT_REF mref, const unsigned dt_type);
static file_data_t *ntfs_dir(disk_t *disk_car, const partition_t *partition, dir_data_t *dir_data, const unsigned long int cluster);
static file_data_t *ntfs_dir(disk_t *disk_car, const partition_t *partition, dir_data_t *dir_data, const unsigned long int cluster);
 Lines 138-147    Link Here 
}
}
/**
/**
 * ntfs_list_entry
 * ntfs_td_list_entry
 * FIXME: Should we print errors as we go along? (AIA)
 * FIXME: Should we print errors as we go along? (AIA)
 */
 */
static int ntfs_list_entry(  struct ntfs_dir_struct *ls, const ntfschar *name, 
static int ntfs_td_list_entry(  struct ntfs_dir_struct *ls, const ntfschar *name, 
		const int name_len, const int name_type, const s64 pos,
		const int name_len, const int name_type, const s64 pos,
		const MFT_REF mref, const unsigned dt_type)
		const MFT_REF mref, const unsigned dt_type)
{
{
 Lines 150-156    Link Here 
  filename = calloc (1, MAX_PATH);
  filename = calloc (1, MAX_PATH);
  if (!filename)
  if (!filename)
  {
  {
    log_critical("ntfs_list_entry calloc failed\n");
    log_critical("ntfs_td_list_entry calloc failed\n");
    return -1;
    return -1;
  }
  }
 Lines 292-298    Link Here 
   */
   */
  pos = 0;
  pos = 0;
  if (inode->mrec->flags & MFT_RECORD_IS_DIRECTORY) {
  if (inode->mrec->flags & MFT_RECORD_IS_DIRECTORY) {
    if(ntfs_readdir(inode, &pos, ls, (ntfs_filldir_t)ntfs_list_entry)<0)
    if(ntfs_readdir(inode, &pos, ls, (ntfs_filldir_t)ntfs_td_list_entry)<0)
    {
    {
      log_error("ntfs_readdir failed\n");
      log_error("ntfs_readdir failed\n");
    }
    }
(-) testdisk-6.8.org/src/photorec.c (-54 / +54 lines)
 Lines 223-236    Link Here 
static void list_free_add(const file_recovery_t *file_recovery, alloc_data_t *list_search_space)
static void list_free_add(const file_recovery_t *file_recovery, alloc_data_t *list_search_space)
{
{
  struct list_head *search_walker = NULL;
  struct td_list_head *search_walker = NULL;
#ifdef DEBUG_FREE
#ifdef DEBUG_FREE
  log_trace("list_free_add %lu\n",(long unsigned)(file_recovery->location.start/512));
  log_trace("list_free_add %lu\n",(long unsigned)(file_recovery->location.start/512));
#endif
#endif
  list_for_each(search_walker, &list_search_space->list)
  td_list_for_each(search_walker, &list_search_space->list)
  {
  {
    alloc_data_t *current_search_space;
    alloc_data_t *current_search_space;
    current_search_space=list_entry(search_walker, alloc_data_t, list);
    current_search_space=td_list_entry(search_walker, alloc_data_t, list);
    if(current_search_space->start < file_recovery->location.start && file_recovery->location.start < current_search_space->end)
    if(current_search_space->start < file_recovery->location.start && file_recovery->location.start < current_search_space->end)
    {
    {
      alloc_data_t *new_free_space;
      alloc_data_t *new_free_space;
 Lines 239-245    Link Here 
      new_free_space->end=current_search_space->end;
      new_free_space->end=current_search_space->end;
      new_free_space->file_stat=NULL;
      new_free_space->file_stat=NULL;
      current_search_space->end=file_recovery->location.start-1;
      current_search_space->end=file_recovery->location.start-1;
      list_add(&new_free_space->list, search_walker);
      td_list_add(&new_free_space->list, search_walker);
    }
    }
    if(current_search_space->start==file_recovery->location.start)
    if(current_search_space->start==file_recovery->location.start)
    {
    {
 Lines 252-273    Link Here 
static alloc_data_t *update_search_space(const 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)
static alloc_data_t *update_search_space(const 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 alloc_list_t *element;
  const alloc_list_t *element;
  struct list_head *search_walker = NULL;
  struct td_list_head *search_walker = NULL;
#ifdef DEBUG_UPDATE_SEARCH_SPACE
#ifdef DEBUG_UPDATE_SEARCH_SPACE
  log_trace("update_search_space\n");
  log_trace("update_search_space\n");
  list_for_each(search_walker, &list_search_space->list)
  td_list_for_each(search_walker, &list_search_space->list)
  {
  {
    alloc_data_t *cur_free_space;
    alloc_data_t *cur_free_space;
    cur_free_space=list_entry(search_walker, alloc_data_t, list);
    cur_free_space=td_list_entry(search_walker, alloc_data_t, list);
    log_trace(" %llu-%llu",(long long unsigned)(cur_free_space->start/512),
    log_trace(" %llu-%llu",(long long unsigned)(cur_free_space->start/512),
	(long long unsigned)(cur_free_space->end/512));
	(long long unsigned)(cur_free_space->end/512));
  }
  }
  log_trace("\n");
  log_trace("\n");
#endif
#endif
  list_for_each(search_walker, &list_search_space->list)
  td_list_for_each(search_walker, &list_search_space->list)
  {
  {
    alloc_data_t *current_search_space;
    alloc_data_t *current_search_space;
    current_search_space=list_entry(search_walker, alloc_data_t, list);
    current_search_space=td_list_entry(search_walker, alloc_data_t, list);
    if(current_search_space->start <= file_recovery->location.start &&
    if(current_search_space->start <= file_recovery->location.start &&
	file_recovery->location.start <= current_search_space->end)
	file_recovery->location.start <= current_search_space->end)
    {
    {
 Lines 291-297    Link Here 
static alloc_data_t *update_search_space_aux(alloc_data_t *list_search_space, uint64_t start, uint64_t end, alloc_data_t **new_current_search_space, uint64_t *offset)
static alloc_data_t *update_search_space_aux(alloc_data_t *list_search_space, uint64_t start, uint64_t end, alloc_data_t **new_current_search_space, uint64_t *offset)
{
{
  struct list_head *search_walker = NULL;
  struct td_list_head *search_walker = NULL;
#ifdef DEBUG_UPDATE_SEARCH_SPACE
#ifdef DEBUG_UPDATE_SEARCH_SPACE
    log_trace("update_search_space_aux offset=%llu remove [%llu-%llu]\n",
    log_trace("update_search_space_aux offset=%llu remove [%llu-%llu]\n",
	(long long unsigned)((*offset)/512),
	(long long unsigned)((*offset)/512),
 Lines 300-309    Link Here 
#endif
#endif
  if(start >= end)
  if(start >= end)
    return list_search_space;
    return list_search_space;
  list_for_each(search_walker, &list_search_space->list)
  td_list_for_each(search_walker, &list_search_space->list)
  {
  {
    alloc_data_t *current_search_space;
    alloc_data_t *current_search_space;
    current_search_space=list_entry(search_walker, alloc_data_t, list);
    current_search_space=td_list_entry(search_walker, alloc_data_t, list);
#ifdef DEBUG_UPDATE_SEARCH_SPACE
#ifdef DEBUG_UPDATE_SEARCH_SPACE
    log_trace("update_search_space_aux offset=%llu remove [%llu-%llu] in [%llu-%llu]\n",
    log_trace("update_search_space_aux offset=%llu remove [%llu-%llu] in [%llu-%llu]\n",
	(long long unsigned)((*offset)/512),
	(long long unsigned)((*offset)/512),
 Lines 328-341    Link Here 
      /* current_search_space->start==start current_search_space->end<=end */
      /* current_search_space->start==start current_search_space->end<=end */
      start=current_search_space->end+1;
      start=current_search_space->end+1;
      if(list_search_space==current_search_space)
      if(list_search_space==current_search_space)
	list_search_space=list_entry(current_search_space->list.next, alloc_data_t, list);
	list_search_space=td_list_entry(current_search_space->list.next, alloc_data_t, list);
      if(offset!=NULL && new_current_search_space!=NULL &&
      if(offset!=NULL && new_current_search_space!=NULL &&
	  current_search_space->start<=*offset && *offset<=current_search_space->end)
	  current_search_space->start<=*offset && *offset<=current_search_space->end)
      {
      {
	*new_current_search_space=list_entry(current_search_space->list.next, alloc_data_t, list);
	*new_current_search_space=td_list_entry(current_search_space->list.next, alloc_data_t, list);
	*offset=(*new_current_search_space)->start;
	*offset=(*new_current_search_space)->start;
      }
      }
      list_del(search_walker);
      td_list_del(search_walker);
      free(current_search_space);
      free(current_search_space);
      return update_search_space_aux(list_search_space, start,end, new_current_search_space, offset);
      return update_search_space_aux(list_search_space, start,end, new_current_search_space, offset);
    }
    }
 Lines 349-355    Link Here 
	if(offset!=NULL && new_current_search_space!=NULL &&
	if(offset!=NULL && new_current_search_space!=NULL &&
	  start<=*offset && *offset<=current_search_space->end)
	  start<=*offset && *offset<=current_search_space->end)
	{
	{
	  *new_current_search_space=list_entry(current_search_space->list.next, alloc_data_t, list);
	  *new_current_search_space=td_list_entry(current_search_space->list.next, alloc_data_t, list);
	  *offset=(*new_current_search_space)->start;
	  *offset=(*new_current_search_space)->start;
	}
	}
	current_search_space->end=start-1;
	current_search_space->end=start-1;
 Lines 358-371    Link Here 
      /* start<=current_search_space->start current_search_space->end==end */
      /* start<=current_search_space->start current_search_space->end==end */
      end=current_search_space->start-1;
      end=current_search_space->start-1;
      if(list_search_space==current_search_space)
      if(list_search_space==current_search_space)
	list_search_space=list_entry(current_search_space->list.next, alloc_data_t, list);
	list_search_space=td_list_entry(current_search_space->list.next, alloc_data_t, list);
      if(offset!=NULL && new_current_search_space!=NULL &&
      if(offset!=NULL && new_current_search_space!=NULL &&
	  current_search_space->start<=*offset && *offset<=current_search_space->end)
	  current_search_space->start<=*offset && *offset<=current_search_space->end)
      {
      {
	*new_current_search_space=list_entry(current_search_space->list.next, alloc_data_t, list);
	*new_current_search_space=td_list_entry(current_search_space->list.next, alloc_data_t, list);
	*offset=(*new_current_search_space)->start;
	*offset=(*new_current_search_space)->start;
      }
      }
      list_del(search_walker);
      td_list_del(search_walker);
      free(current_search_space);
      free(current_search_space);
      return update_search_space_aux(list_search_space, start,end, new_current_search_space, offset);
      return update_search_space_aux(list_search_space, start,end, new_current_search_space, offset);
    }
    }
 Lines 388-394    Link Here 
      new_free_space->end=current_search_space->end;
      new_free_space->end=current_search_space->end;
      new_free_space->file_stat=NULL;
      new_free_space->file_stat=NULL;
      current_search_space->end=start-1;
      current_search_space->end=start-1;
      list_add(&new_free_space->list,search_walker);
      td_list_add(&new_free_space->list,search_walker);
      if(offset!=NULL && new_current_search_space!=NULL &&
      if(offset!=NULL && new_current_search_space!=NULL &&
	  new_free_space->start<=*offset && *offset<=new_free_space->end)
	  new_free_space->start<=*offset && *offset<=new_free_space->end)
      {
      {
 Lines 418-430    Link Here 
void free_list_search_space(alloc_data_t *list_search_space)
void free_list_search_space(alloc_data_t *list_search_space)
{
{
  struct list_head *search_walker = NULL;
  struct td_list_head *search_walker = NULL;
  struct list_head *search_walker_next = NULL;
  struct td_list_head *search_walker_next = NULL;
  list_for_each_safe(search_walker,search_walker_next,&list_search_space->list)
  td_list_for_each_safe(search_walker,search_walker_next,&list_search_space->list)
  {
  {
    alloc_data_t *current_search_space;
    alloc_data_t *current_search_space;
    current_search_space=list_entry(search_walker, alloc_data_t, list);
    current_search_space=td_list_entry(search_walker, alloc_data_t, list);
    list_del(search_walker);
    td_list_del(search_walker);
    free(current_search_space);
    free(current_search_space);
  }
  }
}
}
 Lines 514-520    Link Here 
static void get_prev_header(alloc_data_t *list_search_space, alloc_data_t **current_search_space, uint64_t *offset)
static void get_prev_header(alloc_data_t *list_search_space, alloc_data_t **current_search_space, uint64_t *offset)
{
{
  if((*current_search_space) != list_search_space)
  if((*current_search_space) != list_search_space)
    *current_search_space=list_entry((*current_search_space)->list.prev, alloc_data_t, list);
    *current_search_space=td_list_entry((*current_search_space)->list.prev, alloc_data_t, list);
  *offset=(*current_search_space)->start;
  *offset=(*current_search_space)->start;
}
}
#endif
#endif
 Lines 525-531    Link Here 
  alloc_data_t *file_space=*current_search_space;
  alloc_data_t *file_space=*current_search_space;
  for(nbr=0;nbr<5;nbr++)
  for(nbr=0;nbr<5;nbr++)
  {
  {
    file_space=list_entry(file_space->list.prev, alloc_data_t, list);
    file_space=td_list_entry(file_space->list.prev, alloc_data_t, list);
    if(file_space==list_search_space)
    if(file_space==list_search_space)
      return -1;
      return -1;
    if(file_space->file_stat!=NULL)
    if(file_space->file_stat!=NULL)
 Lines 540-547    Link Here 
void forget(alloc_data_t *list_search_space, alloc_data_t *current_search_space)
void forget(alloc_data_t *list_search_space, alloc_data_t *current_search_space)
{
{
  struct list_head *search_walker = NULL;
  struct td_list_head *search_walker = NULL;
  struct list_head *prev= NULL;
  struct td_list_head *prev= NULL;
  int nbr=0;
  int nbr=0;
  if(current_search_space==list_search_space)
  if(current_search_space==list_search_space)
    return ;
    return ;
 Lines 553-560    Link Here 
    if(nbr>10000)
    if(nbr>10000)
    {
    {
      alloc_data_t *tmp;
      alloc_data_t *tmp;
      tmp=list_entry(search_walker, alloc_data_t, list);
      tmp=td_list_entry(search_walker, alloc_data_t, list);
      list_del(&tmp->list);
      td_list_del(&tmp->list);
      free(tmp);
      free(tmp);
    }
    }
    else
    else
 Lines 564-577    Link Here 
void list_cluster_free(list_cluster_t *list_cluster)
void list_cluster_free(list_cluster_t *list_cluster)
{
{
  struct list_head *dir_walker = NULL;
  struct td_list_head *dir_walker = NULL;
  struct list_head *dir_walker_next = NULL;
  struct td_list_head *dir_walker_next = NULL;
  list_for_each_safe(dir_walker,dir_walker_next,&list_cluster->list)
  td_list_for_each_safe(dir_walker,dir_walker_next,&list_cluster->list)
  {
  {
    list_cluster_t *info;
    list_cluster_t *info;
    info=list_entry(dir_walker, list_cluster_t, list);
    info=td_list_entry(dir_walker, list_cluster_t, list);
    delete_list_file(info->dir_list);
    delete_list_file(info->dir_list);
    list_del(dir_walker);
    td_list_del(dir_walker);
    free(info);
    free(info);
  }
  }
}
}
 Lines 589-604    Link Here 
void update_stats(file_stat_t *file_stats, alloc_data_t *list_search_space)
void update_stats(file_stat_t *file_stats, alloc_data_t *list_search_space)
{
{
  struct list_head *search_walker = NULL;
  struct td_list_head *search_walker = NULL;
  int i;
  int i;
  /* Reset */
  /* Reset */
  for(i=0;file_stats[i].file_hint!=NULL;i++)
  for(i=0;file_stats[i].file_hint!=NULL;i++)
    file_stats[i].not_recovered=0;
    file_stats[i].not_recovered=0;
  /* Update */
  /* Update */
  list_for_each(search_walker, &list_search_space->list)
  td_list_for_each(search_walker, &list_search_space->list)
  {
  {
    alloc_data_t *current_search_space;
    alloc_data_t *current_search_space;
    current_search_space=list_entry(search_walker, alloc_data_t, list);
    current_search_space=td_list_entry(search_walker, alloc_data_t, list);
    if(current_search_space->file_stat!=NULL)
    if(current_search_space->file_stat!=NULL)
    {
    {
      current_search_space->file_stat->not_recovered++;
      current_search_space->file_stat->not_recovered++;
 Lines 705-717    Link Here 
  unsigned int nbr_max=0;
  unsigned int nbr_max=0;
  for(cluster_size=default_blocksize;cluster_size<=128*512;cluster_size*=2)
  for(cluster_size=default_blocksize;cluster_size<=128*512;cluster_size*=2)
  {
  {
    struct list_head *dir_walker = NULL;
    struct td_list_head *dir_walker = NULL;
    cluster_offset_t cluster_offset[1000];
    cluster_offset_t cluster_offset[1000];
    unsigned int nbr_sol=0;
    unsigned int nbr_sol=0;
    list_for_each(dir_walker,&list_cluster->list)
    td_list_for_each(dir_walker,&list_cluster->list)
    {
    {
      list_cluster_t *info;
      list_cluster_t *info;
      info=list_entry(dir_walker, list_cluster_t, list);
      info=td_list_entry(dir_walker, list_cluster_t, list);
      if(info->cluster>=2 && (info->cluster-2)*cluster_size<info->offset)
      if(info->cluster>=2 && (info->cluster-2)*cluster_size<info->offset)
      {
      {
	unsigned int sol_cur;
	unsigned int sol_cur;
 Lines 753-767    Link Here 
  int blocksize_ok=0;
  int blocksize_ok=0;
  unsigned int blocksize;
  unsigned int blocksize;
  *offset=0;
  *offset=0;
  if(list_empty(&list_file->list))
  if(td_list_empty(&list_file->list))
    return default_blocksize;
    return default_blocksize;
  for(blocksize=128*512;blocksize>=default_blocksize && blocksize_ok==0;blocksize=blocksize>>1)
  for(blocksize=128*512;blocksize>=default_blocksize && blocksize_ok==0;blocksize=blocksize>>1)
  {
  {
    struct list_head *search_walker = NULL;
    struct td_list_head *search_walker = NULL;
    blocksize_ok=1;
    blocksize_ok=1;
    {
    {
      alloc_data_t *tmp;
      alloc_data_t *tmp;
      tmp=list_entry(list_file->list.next, alloc_data_t, list);
      tmp=td_list_entry(list_file->list.next, alloc_data_t, list);
      *offset=tmp->start%blocksize;
      *offset=tmp->start%blocksize;
    }
    }
    for(search_walker=list_file->list.next;
    for(search_walker=list_file->list.next;
 Lines 769-775    Link Here 
      search_walker=search_walker->next)
      search_walker=search_walker->next)
    {
    {
      alloc_data_t *current_file;
      alloc_data_t *current_file;
      current_file=list_entry(search_walker, alloc_data_t, list);
      current_file=td_list_entry(search_walker, alloc_data_t, list);
      if(current_file->start%blocksize!=*offset)
      if(current_file->start%blocksize!=*offset)
	blocksize_ok=0;
	blocksize_ok=0;
    }
    }
 Lines 780-797    Link Here 
alloc_data_t * update_blocksize(unsigned int blocksize, alloc_data_t *list_search_space, const uint64_t offset)
alloc_data_t * update_blocksize(unsigned int blocksize, alloc_data_t *list_search_space, const uint64_t offset)
{
{
  struct list_head *search_walker = NULL;
  struct td_list_head *search_walker = NULL;
  struct list_head *search_walker_next = NULL;
  struct td_list_head *search_walker_next = NULL;
  list_for_each_safe(search_walker,search_walker_next,&list_search_space->list)
  td_list_for_each_safe(search_walker,search_walker_next,&list_search_space->list)
  {
  {
    alloc_data_t *current_search_space;
    alloc_data_t *current_search_space;
    current_search_space=list_entry(search_walker, alloc_data_t, list);
    current_search_space=td_list_entry(search_walker, alloc_data_t, list);
    current_search_space->start=(current_search_space->start-offset%blocksize+blocksize-1)/blocksize*blocksize+offset%blocksize;
    current_search_space->start=(current_search_space->start-offset%blocksize+blocksize-1)/blocksize*blocksize+offset%blocksize;
    if(current_search_space->start>current_search_space->end)
    if(current_search_space->start>current_search_space->end)
    {
    {
      list_del(search_walker);
      td_list_del(search_walker);
      if(list_search_space==current_search_space)
      if(list_search_space==current_search_space)
	list_search_space=list_entry(search_walker_next, alloc_data_t, list);
	list_search_space=td_list_entry(search_walker_next, alloc_data_t, list);
      free(current_search_space);
      free(current_search_space);
    }
    }
  }
  }
 Lines 1240-1253    Link Here 
      list_free_add(file_recovery, list_search_space);
      list_free_add(file_recovery, list_search_space);
      if((*current_search_space)!=list_search_space &&
      if((*current_search_space)!=list_search_space &&
	  !((*current_search_space)->start <= *offset && *offset <= (*current_search_space)->end))
	  !((*current_search_space)->start <= *offset && *offset <= (*current_search_space)->end))
	*current_search_space=list_entry((*current_search_space)->list.next, alloc_data_t, list);
	*current_search_space=td_list_entry((*current_search_space)->list.next, alloc_data_t, list);
    }
    }
    else if(status!=STATUS_EXT2_ON_SAVE_EVERYTHING && status!=STATUS_EXT2_OFF_SAVE_EVERYTHING && status!=STATUS_FIND_OFFSET)
    else if(status!=STATUS_EXT2_ON_SAVE_EVERYTHING && status!=STATUS_EXT2_OFF_SAVE_EVERYTHING && status!=STATUS_FIND_OFFSET)
    {
    {
      list_search_space=update_search_space(file_recovery,list_search_space,current_search_space,offset,blocksize);
      list_search_space=update_search_space(file_recovery,list_search_space,current_search_space,offset,blocksize);
      file_recovered=1;
      file_recovered=1;
    }
    }
    list_delete(file_recovery->location.next);
    td_list_delete(file_recovery->location.next);
    file_recovery->location.next=NULL;
    file_recovery->location.next=NULL;
  }
  }
  if(file_recovery->file_size==0 && file_recovery->offset_error!=0)
  if(file_recovery->file_size==0 && file_recovery->offset_error!=0)
(-) testdisk-6.8.org/src/photorec.h (-1 / +1 lines)
 Lines 9-15    Link Here 
typedef struct list_cluster_struct list_cluster_t;
typedef struct list_cluster_struct list_cluster_t;
struct list_cluster_struct
struct list_cluster_struct
{
{
  struct list_head list;
  struct td_list_head list;
  uint64_t offset;
  uint64_t offset;
  uint32_t cluster;
  uint32_t cluster;
  file_data_t *dir_list;
  file_data_t *dir_list;
(-) testdisk-6.8.org/src/phrecn.c (-30 / +30 lines)
 Lines 365-372    Link Here 
static int photorec_bf(disk_t *disk_car, partition_t *partition, const int debug, const int paranoid, const char *recup_dir, const int interface, file_stat_t *file_stats, unsigned int *file_nbr, unsigned int *blocksize, alloc_data_t *list_search_space, const time_t real_start_time, unsigned int *dir_num, const photorec_status_t status, const unsigned int pass, const unsigned int expert, const unsigned int lowmem)
static int photorec_bf(disk_t *disk_car, partition_t *partition, const int debug, const int paranoid, const char *recup_dir, const int interface, file_stat_t *file_stats, unsigned int *file_nbr, unsigned int *blocksize, alloc_data_t *list_search_space, const time_t real_start_time, unsigned int *dir_num, const photorec_status_t status, const unsigned int pass, const unsigned int expert, const unsigned int lowmem)
{
{
  struct list_head *search_walker = NULL;
  struct td_list_head *search_walker = NULL;
  struct list_head *n= NULL;
  struct td_list_head *n= NULL;
  unsigned char *buffer_start;
  unsigned char *buffer_start;
  unsigned int read_size;
  unsigned int read_size;
  unsigned int buffer_size;
  unsigned int buffer_size;
 Lines 385-391    Link Here 
    uint64_t offset;
    uint64_t offset;
    int need_to_check_file;
    int need_to_check_file;
    file_recovery_t file_recovery;
    file_recovery_t file_recovery;
    current_search_space=list_entry(search_walker, alloc_data_t, list);
    current_search_space=td_list_entry(search_walker, alloc_data_t, list);
    offset=current_search_space->start;
    offset=current_search_space->start;
    buffer_olddata=buffer_start;
    buffer_olddata=buffer_start;
    buffer=buffer_olddata+(*blocksize);
    buffer=buffer_olddata+(*blocksize);
 Lines 394-405    Link Here 
    disk_car->read(disk_car,READ_SIZE, buffer, offset);
    disk_car->read(disk_car,READ_SIZE, buffer, offset);
#ifdef DEBUG_BF
#ifdef DEBUG_BF
    {
    {
      struct list_head *tmp= NULL;
      struct td_list_head *tmp= NULL;
      log_debug("Explore ");
      log_debug("Explore ");
      list_for_each(tmp, &list_search_space->list)
      td_list_for_each(tmp, &list_search_space->list)
      {
      {
	alloc_data_t *cur_free_space;
	alloc_data_t *cur_free_space;
	cur_free_space=list_entry(tmp, alloc_data_t, list);
	cur_free_space=td_list_entry(tmp, alloc_data_t, list);
	log_debug(" %lu-%lu",(long unsigned)(cur_free_space->start/disk_car->sector_size),
	log_debug(" %lu-%lu",(long unsigned)(cur_free_space->start/disk_car->sector_size),
	    (long unsigned)(cur_free_space->end/disk_car->sector_size));
	    (long unsigned)(cur_free_space->end/disk_car->sector_size));
	if(cur_free_space==current_search_space)
	if(cur_free_space==current_search_space)
 Lines 538-544    Link Here 
    {
    {
      if(file_finish(&file_recovery,recup_dir,paranoid,file_nbr, *blocksize, list_search_space, &current_search_space, &offset, dir_num,status,disk_car->sector_size,disk_car)<0)
      if(file_finish(&file_recovery,recup_dir,paranoid,file_nbr, *blocksize, list_search_space, &current_search_space, &offset, dir_num,status,disk_car->sector_size,disk_car)<0)
      { /* BF */
      { /* BF */
	current_search_space=list_entry(search_walker, alloc_data_t, list);
	current_search_space=td_list_entry(search_walker, alloc_data_t, list);
	ind_stop=photorec_bf_aux(disk_car, partition, paranoid, recup_dir, interface, file_stats, file_nbr, &file_recovery, *blocksize, list_search_space, current_search_space, real_start_time, dir_num, status, pass2);
	ind_stop=photorec_bf_aux(disk_car, partition, paranoid, recup_dir, interface, file_stats, file_nbr, &file_recovery, *blocksize, list_search_space, current_search_space, real_start_time, dir_num, status, pass2);
	pass2++;
	pass2++;
      }
      }
 Lines 619-629    Link Here 
	  extrablock_offset=element->end/blocksize*blocksize;
	  extrablock_offset=element->end/blocksize*blocksize;
      }
      }
      /* Get the corresponding search_place */
      /* Get the corresponding search_place */
      extractblock_search_space=list_entry(list_search_space->list.next, alloc_data_t, list);
      extractblock_search_space=td_list_entry(list_search_space->list.next, alloc_data_t, list);
      while(extractblock_search_space != list_search_space &&
      while(extractblock_search_space != list_search_space &&
	  !(extractblock_search_space->start <= extrablock_offset &&
	  !(extractblock_search_space->start <= extrablock_offset &&
	    extrablock_offset <= extractblock_search_space->end))
	    extrablock_offset <= extractblock_search_space->end))
	extractblock_search_space=list_entry(extractblock_search_space->list.next, alloc_data_t, list);
	extractblock_search_space=td_list_entry(extractblock_search_space->list.next, alloc_data_t, list);
      /* Update extractblock_search_space & extrablock_offset */
      /* Update extractblock_search_space & extrablock_offset */
      get_next_sector(list_search_space, &extractblock_search_space, &extrablock_offset, blocksize);
      get_next_sector(list_search_space, &extractblock_search_space, &extrablock_offset, blocksize);
      /* */
      /* */
 Lines 730-739    Link Here 
  alloc_data_t *current_search_space;
  alloc_data_t *current_search_space;
  file_recovery_t file_recovery;
  file_recovery_t file_recovery;
  static alloc_data_t list_file={
  static alloc_data_t list_file={
    .list = LIST_HEAD_INIT(list_file.list)
    .list = TD_LIST_HEAD_INIT(list_file.list)
  };
  };
  static list_cluster_t list_cluster= {
  static list_cluster_t list_cluster= {
    .list = LIST_HEAD_INIT(list_cluster.list)
    .list = TD_LIST_HEAD_INIT(list_cluster.list)
  };
  };
#define READ_SIZE 256*512
#define READ_SIZE 256*512
  read_size=((*blocksize)>8192?(*blocksize):8192);
  read_size=((*blocksize)>8192?(*blocksize):8192);
 Lines 747-764    Link Here 
  memset(buffer_olddata,0,(*blocksize));
  memset(buffer_olddata,0,(*blocksize));
  if(debug>1)
  if(debug>1)
  {
  {
    struct list_head *search_walker = NULL;
    struct td_list_head *search_walker = NULL;
    log_debug("Explore ");
    log_debug("Explore ");
    list_for_each(search_walker, &list_search_space->list)
    td_list_for_each(search_walker, &list_search_space->list)
    {
    {
      alloc_data_t *cur_free_space;
      alloc_data_t *cur_free_space;
      cur_free_space=list_entry(search_walker, alloc_data_t, list);
      cur_free_space=td_list_entry(search_walker, alloc_data_t, list);
      log_debug(" %lu-%lu",(long unsigned)(cur_free_space->start/disk_car->sector_size),
      log_debug(" %lu-%lu",(long unsigned)(cur_free_space->start/disk_car->sector_size),
	  (long unsigned)(cur_free_space->end/disk_car->sector_size));
	  (long unsigned)(cur_free_space->end/disk_car->sector_size));
    }
    }
    log_debug("\n");
    log_debug("\n");
  }
  }
  current_search_space=list_entry(list_search_space->list.next, alloc_data_t, list);
  current_search_space=td_list_entry(list_search_space->list.next, alloc_data_t, list);
  if(current_search_space!=list_search_space)
  if(current_search_space!=list_search_space)
    offset=current_search_space->start;
    offset=current_search_space->start;
  disk_car->read(disk_car,READ_SIZE, buffer, offset);
  disk_car->read(disk_car,READ_SIZE, buffer, offset);
 Lines 832-838    Link Here 
	      new_file_alloc=(alloc_data_t*)MALLOC(sizeof(*new_file_alloc));
	      new_file_alloc=(alloc_data_t*)MALLOC(sizeof(*new_file_alloc));
	      new_file_alloc->start=file_recovery.location.start;
	      new_file_alloc->start=file_recovery.location.start;
	      new_file_alloc->end=0;
	      new_file_alloc->end=0;
	      list_add_tail(&new_file_alloc->list,&list_file.list);
	      td_list_add_tail(&new_file_alloc->list,&list_file.list);
	      (*file_nbr)++;
	      (*file_nbr)++;
	    }
	    }
	    if(file_recovery.file_stat->file_hint==&file_hint_dir)
	    if(file_recovery.file_stat->file_hint==&file_hint_dir)
 Lines 1080-1086    Link Here 
  aff_buffer(BUFFER_RESET,"Q");
  aff_buffer(BUFFER_RESET,"Q");
  log_info("\nAnalyse\n");
  log_info("\nAnalyse\n");
  log_partition(disk_car,partition);
  log_partition(disk_car,partition);
  if(blocksize==0 || list_empty(&list_search_space->list))
  if(blocksize==0 || td_list_empty(&list_search_space->list))
  {
  {
    blocksize=disk_car->sector_size;
    blocksize=disk_car->sector_size;
    blocksize_is_known=0;
    blocksize_is_known=0;
 Lines 1088-1097    Link Here 
  else
  else
    blocksize_is_known=1;
    blocksize_is_known=1;
  if(list_empty(&list_search_space->list))
  if(td_list_empty(&list_search_space->list))
  {
  {
    alloc_data_t *tmp=init_search_space(partition,disk_car);
    alloc_data_t *tmp=init_search_space(partition,disk_car);
    list_add_tail(&tmp->list, &list_search_space->list);
    td_list_add_tail(&tmp->list, &list_search_space->list);
    if(mode_ext2==0 && carve_free_space_only>0)
    if(mode_ext2==0 && carve_free_space_only>0)
    {
    {
      blocksize=remove_used_space(disk_car, partition, list_search_space);
      blocksize=remove_used_space(disk_car, partition, list_search_space);
 Lines 1103-1113    Link Here 
  }
  }
  else
  else
  { /* Correct the values */
  { /* Correct the values */
    struct list_head *search_walker = NULL;
    struct td_list_head *search_walker = NULL;
    list_for_each(search_walker, &list_search_space->list)
    td_list_for_each(search_walker, &list_search_space->list)
    {
    {
      alloc_data_t *current_search_space;
      alloc_data_t *current_search_space;
      current_search_space=list_entry(search_walker, alloc_data_t, list);
      current_search_space=td_list_entry(search_walker, alloc_data_t, list);
      current_search_space->start=current_search_space->start*disk_car->sector_size;
      current_search_space->start=current_search_space->start*disk_car->sector_size;
      current_search_space->end=current_search_space->end*disk_car->sector_size+disk_car->sector_size-1;
      current_search_space->end=current_search_space->end*disk_car->sector_size+disk_car->sector_size-1;
    }
    }
 Lines 1266-1280    Link Here 
    }
    }
  }
  }
  {
  {
    struct list_head *search_walker = NULL;
    struct td_list_head *search_walker = NULL;
    struct list_head *search_walker_next = NULL;
    struct td_list_head *search_walker_next = NULL;
    unsigned long int nbr_headers=0;
    unsigned long int nbr_headers=0;
    uint64_t sectors_with_unknown_data=0;
    uint64_t sectors_with_unknown_data=0;
    /* Free memory */
    /* Free memory */
    list_for_each_safe(search_walker,search_walker_next,&list_search_space->list)
    td_list_for_each_safe(search_walker,search_walker_next,&list_search_space->list)
    {
    {
      alloc_data_t *current_search_space;
      alloc_data_t *current_search_space;
      current_search_space=list_entry(search_walker, alloc_data_t, list);
      current_search_space=td_list_entry(search_walker, alloc_data_t, list);
      if(current_search_space->file_stat!=NULL)
      if(current_search_space->file_stat!=NULL)
      {
      {
	nbr_headers++;
	nbr_headers++;
 Lines 1290-1296    Link Here 
	      current_search_space->file_stat->file_hint->extension:""):
	      current_search_space->file_stat->file_hint->extension:""):
	     "(null)"));
	     "(null)"));
      }
      }
      list_del(search_walker);
      td_list_del(search_walker);
      free(current_search_space);
      free(current_search_space);
    }
    }
    log_info("%llu sectors contains unknown data, %lu invalid files found %s.\n",
    log_info("%llu sectors contains unknown data, %lu invalid files found %s.\n",
 Lines 1533-1544    Link Here 
  };
  };
  char *current_cmd=cmd_run;
  char *current_cmd=cmd_run;
  alloc_data_t list_search_space={
  alloc_data_t list_search_space={
    .list = LIST_HEAD_INIT(list_search_space.list)
    .list = TD_LIST_HEAD_INIT(list_search_space.list)
  };
  };
  if(cmd_device==NULL)
  if(cmd_device==NULL)
  {
  {
    session_load(&cmd_device, &current_cmd,&list_search_space);
    session_load(&cmd_device, &current_cmd,&list_search_space);
    if(cmd_device!=NULL && current_cmd!=NULL && !list_empty(&list_search_space.list) && ask_confirmation("Continue previous session ? (Y/N)")!=0)
    if(cmd_device!=NULL && current_cmd!=NULL && !td_list_empty(&list_search_space.list) && ask_confirmation("Continue previous session ? (Y/N)")!=0)
    {
    {
      /* yes */
      /* yes */
    }
    }
 Lines 2041-2047    Link Here 
      (unsigned long long)((*current_search_space)->end)/512);
      (unsigned long long)((*current_search_space)->end)/512);
#endif
#endif
  if((*current_search_space) != list_search_space)
  if((*current_search_space) != list_search_space)
    *current_search_space=list_entry((*current_search_space)->list.next, alloc_data_t, list);
    *current_search_space=td_list_entry((*current_search_space)->list.next, alloc_data_t, list);
  *offset=(*current_search_space)->start;
  *offset=(*current_search_space)->start;
}
}
(-) testdisk-6.8.org/src/savehdr.c (-2 / +2 lines)
 Lines 137-143    Link Here 
	log_debug("new disk: %s\n",pos);
	log_debug("new disk: %s\n",pos);
      }
      }
      if(new_backup!=NULL)
      if(new_backup!=NULL)
	list_add_tail(&new_backup->list,&list_backup->list);
	td_list_add_tail(&new_backup->list,&list_backup->list);
      new_backup=(backup_disk_t*)MALLOC(sizeof(*new_backup));
      new_backup=(backup_disk_t*)MALLOC(sizeof(*new_backup));
      new_backup->description[0]='\0';
      new_backup->description[0]='\0';
      new_backup->list_part=NULL;
      new_backup->list_part=NULL;
 Lines 196-202    Link Here 
    }
    }
  }
  }
  if(new_backup!=NULL)
  if(new_backup!=NULL)
    list_add_tail(&new_backup->list,&list_backup->list);
    td_list_add_tail(&new_backup->list,&list_backup->list);
  fclose(f_backup);
  fclose(f_backup);
  free(buffer);
  free(buffer);
  return list_backup;
  return list_backup;
(-) testdisk-6.8.org/src/savehdr.h (-1 / +1 lines)
 Lines 23-29    Link Here 
typedef struct backup_disk backup_disk_t;
typedef struct backup_disk backup_disk_t;
struct backup_disk
struct backup_disk
{
{
  struct list_head list;
  struct td_list_head list;
  time_t my_time;
  time_t my_time;
  char description[128];
  char description[128];
  list_part_t *list_part;
  list_part_t *list_part;
(-) testdisk-6.8.org/src/sessionp.c (-4 / +4 lines)
 Lines 142-148    Link Here 
	  new_free_space->start=start;
	  new_free_space->start=start;
	  new_free_space->end=end;
	  new_free_space->end=end;
	  new_free_space->file_stat=NULL;
	  new_free_space->file_stat=NULL;
	  list_add_tail(&new_free_space->list, &list_free_space->list);
	  td_list_add_tail(&new_free_space->list, &list_free_space->list);
#ifdef DEBUG
#ifdef DEBUG
	  log_trace(">%lu-%lu<\n",start,end);
	  log_trace(">%lu-%lu<\n",start,end);
#endif
#endif
 Lines 161-167    Link Here 
int session_save(alloc_data_t *list_free_space, disk_t *disk_car, const partition_t *partition, const file_enable_t *files_enable, const unsigned int blocksize, const int debug)
int session_save(alloc_data_t *list_free_space, disk_t *disk_car, const partition_t *partition, const file_enable_t *files_enable, const unsigned int blocksize, const int debug)
{
{
  struct list_head *free_walker = NULL;
  struct td_list_head *free_walker = NULL;
  FILE *f_session;
  FILE *f_session;
  unsigned int i;
  unsigned int i;
  if(debug>1)
  if(debug>1)
 Lines 183-192    Link Here 
    }
    }
  }
  }
  fprintf(f_session,"search,inter\n");
  fprintf(f_session,"search,inter\n");
  list_for_each(free_walker, &list_free_space->list)
  td_list_for_each(free_walker, &list_free_space->list)
  {
  {
    alloc_data_t *current_free_space;
    alloc_data_t *current_free_space;
    current_free_space=list_entry(free_walker, alloc_data_t, list);
    current_free_space=td_list_entry(free_walker, alloc_data_t, list);
    fprintf(f_session,"%lu-%lu\n",(long unsigned)(current_free_space->start/disk_car->sector_size),
    fprintf(f_session,"%lu-%lu\n",(long unsigned)(current_free_space->start/disk_car->sector_size),
	(long unsigned)(current_free_space->end/disk_car->sector_size));
	(long unsigned)(current_free_space->end/disk_car->sector_size));
  }
  }