/* Find a directory entry based on filename or start cluster number If the directory entry is not found, the new position for writing a directory entry will be returned  */
static dir_entry* find_directory_entry(fat_itr *itr, char *filename)
/* Find a directory entry based on filename or start cluster number If the directory entry is not found, the new position for writing a directory entry will be returned  */
static dir_entry* find_directory_entry(fat_itr *itr, char *filename)
{
	int match = 0;
	while (fat_itr_next(itr)) {
		if (!strcasecmp(filename, itr->name))
			match = 1;
		else if (itr->name != itr->s_name &&
			 !strcasecmp(filename, itr->s_name))
			match = 1;
		if (!match)
			continue;
		if (itr->dent->name[0] == '\0')
			return NULL;
		else
			return itr->dent;
	}
	if (!itr->dent &&
	    (!itr->is_root || itr->fsdata->fatsize == 32) &&
	    new_dir_table(itr))
		itr->dent = NULL;
	return NULL;
}