也是移植到ucos平台上的问题.
跟踪后发现是ntfs_filldir太花时间,其中主要是ntfs_attr_name_get/ntfs_attr_name_free花的时间比较多(malloc/free).
static int ntfs_filldir(ntfs_inode *dir_ni, s64 *pos, u8 ivcn_bits,
const INDEX_TYPE index_type, void *iu, INDEX_ENTRY *ie,
void *dirent, struct file_info* info)
{
FILE_NAME_ATTR *fn = &ie->key.file_name;
unsigned dt_type;
MFT_REF mref;
//tchar_t* filename;
ntfs_log_enter("Entering %s\n", __FUNCTION__);
//ntfs_log_trace("file name is %s\n", fn->file_name);
//<strong>filename = ntfs_attr_name_get(fn->file_name, fn->file_name_length);</strong>
//dump_fname(filename, fn->file_name_length * sizeof(tchar_t));
//
ntfs_log_trace(" %c%c%c%c%c %lld %s\n",
(fn->file_attributes & FILE_ATTR_I30_INDEX_PRESENT) ? 'D' : '-',
(fn->file_attributes & FILE_ATTR_READONLY) ? 'R' : '-',
(fn->file_attributes & FILE_ATTR_HIDDEN) ? 'H' : '-',
(fn->file_attributes & FILE_ATTR_SYSTEM) ? 'S' : '-',
(fn->file_attributes & FILE_ATTR_ARCHIVE) ? 'A' : '-',
fn->data_size, fn->file_name);
info->flag = (fn->file_attributes & FILE_ATTR_I30_INDEX_PRESENT) ? FILE_DIR : FILE_REGULAR; // 0 means regular file, 1 means dir
info->is_system_file = (fn->file_attributes & FILE_ATTR_SYSTEM) ? 1 : 0;
info->is_hidden_file = (fn->file_attributes & FILE_ATTR_HIDDEN) ? 1 : 0;
info->fattr = fn->file_attributes;
info->fsize = fn->data_size;
/* Advance the position even if going to skip the entry. */
if (index_type == INDEX_TYPE_ALLOCATION)
*pos = (u8*)ie - (u8*)iu + (sle64_to_cpu(
((INDEX_ALLOCATION *)iu)->index_block_vcn) << ivcn_bits) +
dir_ni->vol->mft_record_size;
else /* if (index_type == INDEX_TYPE_ROOT) */
*pos = (u8*)ie - (u8*)iu;
/* Skip root directory self reference entry. */
if (MREF_LE(ie->indexed_file) == FILE_root){
//<strong>ntfs_attr_name_free(&filename);</strong>
return 0;
}
if (ie->key.file_name.file_attributes & FILE_ATTR_I30_INDEX_PRESENT)
dt_type = NTFS_DT_DIR;
else if (fn->file_attributes & FILE_ATTR_SYSTEM)
dt_type = NTFS_DT_UNKNOWN;
else
dt_type = NTFS_DT_REG;
<strong>memcpy(dirent, fn->file_name, fn->file_name_length * sizeof(tchar_t));</strong>
*(((tchar_t*)dirent) + fn->file_name_length) = '\0';//do not forget the ending \0
info->name_len = fn->file_name_length;
/* return metadata files and hidden files if requested */
mref = le64_to_cpu(ie->indexed_file);
//<strong>ntfs_attr_name_free(&filename);</strong>
return 0;
}
实际上,不要重新去malloc/free,直接用fn->file_name copy 到dirent里面就可以的.