summaryrefslogtreecommitdiffstats
path: root/src/dir.c
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2013-05-05 21:52:54 +0200
committerChristophe Grenier <grenier@cgsecurity.org>2013-05-05 21:52:54 +0200
commit3f03c0e6aafef241a795e62f2edb159b1de4b038 (patch)
treec04b806dd3d93d89dc2dfbeea1e2cd070252253b /src/dir.c
parentb9458447e8cbce92cbb8bb082ae447cc5a9d9341 (diff)
Migrate from file_data to file_info structure
Diffstat (limited to 'src/dir.c')
-rw-r--r--src/dir.c52
1 files changed, 23 insertions, 29 deletions
diff --git a/src/dir.c b/src/dir.c
index a4b9630..aa0c78b 100644
--- a/src/dir.c
+++ b/src/dir.c
@@ -149,16 +149,17 @@ void mode_string (const unsigned int mode, char *str)
#endif
}
-int dir_aff_log(const dir_data_t *dir_data, const file_data_t*dir_list)
+int dir_aff_log(const dir_data_t *dir_data, const file_info_t *dir_list)
{
int test_date=0;
- const file_data_t *current_file;
+ struct td_list_head *file_walker = NULL;
if(dir_data!=NULL)
{
log_info("Directory %s\n",dir_data->current_directory);
}
- for(current_file=dir_list;current_file!=NULL;current_file=current_file->next)
+ td_list_for_each(file_walker, &dir_list->list)
{
+ const file_info_t *current_file=td_list_entry(file_walker, file_info_t, list);
char datestr[80];
char str[11];
if(current_file->td_mtime)
@@ -247,52 +248,45 @@ int log_list_file(const disk_t *disk, const partition_t *partition, const dir_da
return test_date;
}
-unsigned int delete_list_file(file_data_t *file_list)
-{
- int nbr=0;
- file_data_t *current_file=file_list;
- while(current_file!=NULL)
- {
- file_data_t *next=current_file->next;
- free(current_file);
- current_file=next;
- nbr++;
- }
- return nbr;
-}
-
-void delete_list_file_info(struct td_list_head *list)
+unsigned int delete_list_file(file_info_t *file_info)
{
+ unsigned int nbr=0;
struct td_list_head *file_walker = NULL;
struct td_list_head *file_walker_next = NULL;
- td_list_for_each_safe(file_walker,file_walker_next, list)
+ td_list_for_each_safe(file_walker,file_walker_next, &file_info->list)
{
- file_info_t *file_info;
- file_info=td_list_entry(file_walker, file_info_t, list);
- free(file_info->name);
+ file_info_t *tmp;
+ tmp=td_list_entry(file_walker, file_info_t, list);
+ free(tmp->name);
td_list_del(file_walker);
- free(file_info);
+ free(tmp);
+ nbr++;
}
+ return nbr;
}
static int dir_whole_partition_log_aux(disk_t *disk, const partition_t *partition, dir_data_t *dir_data, const unsigned long int inode)
{
- file_data_t *dir_list;
- file_data_t *current_file;
+ struct td_list_head *file_walker = NULL;
#define MAX_DIR_NBR 256
static unsigned int dir_nbr=0;
static unsigned long int inode_known[MAX_DIR_NBR];
const unsigned int current_directory_namelength=strlen(dir_data->current_directory);
+ static file_info_t dir_list = {
+ .list = TD_LIST_HEAD_INIT(dir_list.list),
+ .name = NULL
+ };
if(dir_nbr==MAX_DIR_NBR)
return 1; /* subdirectories depth is too high => Back */
if(dir_data->verbose>0)
log_info("\ndir_partition inode=%lu\n",inode);
- dir_list=dir_data->get_dir(disk, partition, dir_data, inode);
- dir_aff_log(dir_data, dir_list);
+ dir_data->get_dir(disk, partition, dir_data, inode, &dir_list);
+ dir_aff_log(dir_data, &dir_list);
/* Not perfect for FAT32 root cluster */
inode_known[dir_nbr++]=inode;
- for(current_file=dir_list;current_file!=NULL;current_file=current_file->next)
+ td_list_for_each(file_walker, &dir_list.list)
{
+ const file_info_t *current_file=td_list_entry(file_walker, file_info_t, list);
if(LINUX_S_ISDIR(current_file->st_mode)!=0)
{
const unsigned long int new_inode=current_file->st_ino;
@@ -319,7 +313,7 @@ static int dir_whole_partition_log_aux(disk_t *disk, const partition_t *partitio
}
}
}
- delete_list_file(dir_list);
+ delete_list_file(&dir_list);
dir_nbr--;
return 0;
}