AnsweredAssumed Answered

MFS using FlashX on a TWRK60N512

Question asked by Myke Predko on Aug 30, 2012
Latest reply on Oct 25, 2013 by Martin Latal

Hey folks,


Hopefully this is an easy one - I am trying to set up a Flash Drive on a K60N512 running MQX 3.8.1 with specific libraries and then check to see what was created. 


Code follows:

void initMFS() {int_32                      errorCode;uint_32                     mfsStatus;uint_32                     space;MFS_SEARCH_DATA             searchData;MFS_SEARCH_PARAM            search;char_ptr                    filePath = "*.*";                   if (NULL == (pf_IntFlash = fopen("flashx:", NULL))) {  printf("Error open internal flash device!\n");     fflush(stdout);     _mqx_exit(0); } else if (MFS_NO_ERROR != (mfsStatus = _io_mfs_install(pf_IntFlash, "c:", (_file_size)0))) {  printf("MFS install failed!\n");  fflush(stdout);  _mqx_exit(0); } else {  pf_fd = fopen("c:", NULL);  if (MFS_NO_ERROR == (errorCode = ferror(pf_fd))) {   printf("Internal flash device initialized.\n");   fflush(stdout);  }  else if (MFS_NOT_A_DOS_DISK == errorCode) {   printf("Formating internal flash drive...\n");   fflush(stdout);   if (MFS_NO_ERROR == (errorCode = ioctl(pf_fd, IO_IOCTL_DEFAULT_FORMAT, NULL))) {    if (MFS_NO_ERROR != (errorCode = ioctl(pf_fd, IO_IOCTL_CREATE_SUBDIR, (uint_32_ptr)"\\subdir1"))) {     printf("Unable to create \"\\subdir1\" (0x%04X)\n", errorCode);     fflush(stdout);     _mqx_exit(0);    }    if (MFS_NO_ERROR != (errorCode = ioctl(pf_fd, IO_IOCTL_CREATE_SUBDIR, (uint_32_ptr)"\\subdir2"))) {     if (MFS_CANNOT_CREATE_DIRECTORY == errorCode) {      printf("MFS Cannot Create \"\\subdir2\"\n");      fflush(stdout);     }     printf("Unable to create \"\\subdir2\" (0x%04X)\n", errorCode);     fflush(stdout);    }        search.ATTRIBUTE = MFS_SEARCH_NORMAL;    search.WILDCARD = filePath;    search.SEARCH_DATA_PTR = &searchData;        errorCode = ioctl(pf_fd, IO_IOCTL_FIND_FIRST_FILE, (uint_32_ptr)&search);    while (MFS_NO_ERROR == errorCode) {     printf("%-12.12s %61u\n", searchData.NAME, searchData.FILE_SIZE);                    fflush(stdout);     errorCode = ioctl(pf_fd, IO_IOCTL_FIND_NEXT_FILE, (uint_32_ptr)&search);    }   }   else {    printf("IntFlash format error!(%X)\n", errorCode);    fflush(stdout);    _mqx_exit(0);   }  }  else {   printf("Error while opening c:\\ (%s)\n", MFS_Error_text((uint_32)(uint_32)errorCode));   fflush(stdout);   _mqx_exit(0);  }  space = ioctl(pf_fd, IO_IOCTL_FREE_SPACE, NULL);  printf("\n%i Bytes available in drive c:\n", space);  fflush(stdout);



Going through the steps:

1.  flashx open takes place without any problems.

2.  MFS Install executes without any problems

3.1.  If the first time through, disk not formatted recognized and format executes without any problems

3.2.  If a second time through, disk is recognized as being formatted

4.  First subdir create works without any problems

5.  Second and about 2/3rds of the subsequent subdir creates fail.  Note that they don't return with "MFS_CANNOT_CREATE_SUBDIRECTORY" which is strange.  The error code doesn't match what's listed in the MFS User Guide. 

6.  When I try to read through the file system to see the created folders, the find first file fails.  The error code does not match what's listed in the MFS User Guide

7.  When I loko at the total space available to the file system, it is greater than 440k, which makes sense for the device. 


Anybody have any ideas why the create subdirectory and file system reads fail?  I can't really find any example code for what I'm trying to do - if you can point me in the right direction, it would be greatly appreciated.