I'm running MFS and USB host MSD stack to read files from a USB drive. The drive is mounted fine and in the shell prompt I can enter dir and get a directory listing. All the other MFS shell commands seem to work normally as well. But I also have some code that attempts to get the first file from the directory but it returns -1. The code is essentially the same as the example given in the MFS user guide (rev2.2, page 32), so I'm not sure what's wrong. I also don't recognize that error code (-1). I would expected an error to be positive and in the 0x3000 range.
_mqx_int error_code;
MFS_SEARCH_DATA search_data;
MFS_SEARCH_PARAM search;
char filepath[] = “*.*”;
search.ATTRIBUTE = MFS_SEARCH_ANY;
search.WILDCARD = filepath;
search.SEARCH_DATA_PTR = &search_data;
error_code = ioctl(mfs_fd_ptr, IO_IOCTL_FIND_FIRST_FILE,(uint_32_ptr) &search);
while (error_code == MFS_NO_ERROR) {
printf ("%-12.12s\n", search_data.NAME);
error_code = ioctl(mfs_fd_ptr, IO_IOCTL_FIND_NEXT_FILE, (uint_32_ptr) &search_data);
} else {
printf ("error code %d\n", error_code);
}
Output:
error code -1
Any advice on what might be the problem, or what I could try to fix it?
Thank you
Hi Angelo,
I wrote this code some months ago. I believe it is still working. Please, try it and share your results:
/******************************************************/
int_32 test_find(int_32 argc, char_ptr argv[] )
{
_mqx_int error_code = MFS_NO_ERROR;
MFS_SEARCH_DATA search_data;
MFS_SEARCH_PARAM search;
char filepath [6]= "a:\\*.*";
MQX_FILE_PTR fs_ptr = NULL;
fs_ptr = _io_get_fs_by_name("a:");
search.ATTRIBUTE = MFS_SEARCH_ANY;
search.WILDCARD = (char_ptr)&filepath;
search.SEARCH_DATA_PTR = &search_data;
error_code = ioctl(fs_ptr, IO_IOCTL_FIND_FIRST_FILE, (uint_32_ptr) &search);
while (error_code == MFS_NO_ERROR)
{
printf ("%-12.12s %6lu %02lu-%02lu-%04lu %02lu:%02lu:%02lu\n",
search_data.NAME,
search_data.FILE_SIZE,
(uint_32)(search_data.DATE & MFS_MASK_MONTH) >>MFS_SHIFT_MONTH,
(uint_32)(search_data.DATE & MFS_MASK_DAY) >>MFS_SHIFT_DAY,
(uint_32)((search_data.DATE & MFS_MASK_YEAR) >>MFS_SHIFT_YEAR) + 1980,
(uint_32)(search_data.TIME & MFS_MASK_HOURS) >>MFS_SHIFT_HOURS,
(uint_32)(search_data.TIME & MFS_MASK_MINUTES) >>MFS_SHIFT_MINUTES,
(uint_32)(search_data.TIME & MFS_MASK_SECONDS) << 1);
error_code = ioctl(fs_ptr, IO_IOCTL_FIND_NEXT_FILE,(uint_32_ptr) &search_data);
}
return error_code;
}
/******************************************************/
Regards,
Garabo
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
We are facing the same problem. Any advice on what might be the problem.
Thanks,
Maddy