Page 1 of 1

dir_data->current_directory

Posted: 27 Nov 2019, 15:57
by mesajflaviu
I have tried to trace the value of dir_data->current_directory from dir_whole_partition_log_aux function. And I noticed that this variable could have file names too, not only directory names ... I have done something wrong here ?

Code: Select all

int dir_whole_partition_log_aux(disk_t* disk, const partition_t* partition, dir_data_t* dir_data, const unsigned long int inode)
{
...
....
	td_list_for_each(file_walker, &dir_list.list)
	{
		const file_info_t* current_file = td_list_entry_const(file_walker, const file_info_t, list);
		if (LINUX_S_ISDIR(current_file->st_mode) != 0 &&
			is_inode_valid(current_file, dir_nbr, inode_known) > 0 &&
			strlen(dir_data->current_directory) + 1 + strlen(current_file->name) < sizeof(dir_data->current_directory) - 1)
		{
			TRACE("%s\n", dir_data->current_directory);		// here I could have files or folders ?
			if (strcmp(dir_data->current_directory, "/"))
				strcat(dir_data->current_directory, "/");
			strcat(dir_data->current_directory, current_file->name);
			dir_whole_partition_log_aux(disk, partition, dir_data, current_file->st_ino);
			/* restore current_directory name */
			dir_data->current_directory[current_directory_namelength] = '\0';
		}
	}
...
...
}


Re: dir_data->current_directory

Posted: 28 Nov 2019, 06:51
by cgrenier
The variable is truncated to remove the filename part before exiting the function:

Code: Select all

/* restore current_directory name */
dir_data->current_directory[current_directory_namelength] = '\0';