AnsweredAssumed Answered

MQX 3.6 MFS FindFirst/FindNext bug

Question asked by Mark Armbrust on Jul 13, 2010
Latest reply on Jul 20, 2010 by Petr Lukas

There is a bug in MQX3.6 MFS's IO_IOCTL_FIND_FIRST_FILE (MFS_Find_first_file) function.

 

If you use search attribute MFS_SEARCH_NORMAL it finds no files.  This worked OK in 3.3, but appears to have been broken in 3.4.

 

The problem is in the MFS_Attribute_match() function in mfs_parse.c not handling MFS_SEARCH_NORMAL.  Here is a patch that corrects the problem (and properly handles MFS_ATTR_SYSTEM_FILE).

 

If you use the shell "dir" command you will also want to patch sh_dir.c to change the default search attribute from "m*" to "m".  so that files with the archive bit set will also be displayed.  This broke with the 3.4 changes to mfs_parse.c.

 

--Mark

 

-----8<----------

*** mfs_parse.c    2010/07/13 18:01:07    1.1
--- mfs_parse.c    2010/07/13 19:41:09    1.2
***************
*** 620,642 ****
              }  
          }
          else
          {
              /* if checked file is hidden, and have not selected hidden in wanted mask,
               return FALSE otherwise check all others parameters    */
              if ((dattr & MFS_ATTR_HIDDEN_FILE) && !(wattr & MFS_ATTR_HIDDEN_FILE))
              {
                 match = FALSE;
              }
              else
              {
!                if ( dattr & wattr )
                 {
                     match = TRUE;
                 }
                 else
                 {
                     match = FALSE;
                 }
              }
          }  
      }  
--- 620,648 ----
              }  
          }
          else
          {
              /* if checked file is hidden, and have not selected hidden in wanted mask,
               return FALSE otherwise check all others parameters    */
              if ((dattr & MFS_ATTR_HIDDEN_FILE) && !(wattr & MFS_ATTR_HIDDEN_FILE))
              {
                 match = FALSE;
              }
+             /* same for system files */
+             else if ((dattr & MFS_ATTR_SYSTEM_FILE) && !(wattr & MFS_ATTR_SYSTEM_FILE))
+             {
+                match = FALSE;
+             }
              else
              {
!                /* MFS_SEARCH_NORMAL returns all non-hidden, non-system files */
!                if (wattr == MFS_SEARCH_NORMAL || (dattr & wattr) )
                 {
                     match = TRUE;
                 }
                 else
                 {
                     match = FALSE;
                 }
              }
          }  
      } 
-----8<----------

*** sh_dir.c    2010/07/13 18:36:48    1.1
--- sh_dir.c    2010/07/13 19:48:18    1.2
***************
*** 68,88 ****
 
     print_usage = Shell_check_help_request(argc, argv, &shorthelp );
 
     if (!print_usage)  {
        if (argc > 3)  {
           printf("Error, invalid number of parameters\n");
           return_code = SHELL_EXIT_ERROR;
           print_usage=TRUE;
        } else {
           path_ptr  ="*.*";
!          mode_ptr = "m*";
           if (argc >= 2)  {
              path_ptr = argv[1];
              if (argc== 3)  {
                 mode_ptr = argv[2];
              }
           }
           
           fs_ptr = Shell_get_current_filesystem(argv);
           /* check if filesystem is mounted */
           if (fs_ptr == NULL)  {
--- 68,88 ----
 
     print_usage = Shell_check_help_request(argc, argv, &shorthelp );
 
     if (!print_usage)  {
        if (argc > 3)  {
           printf("Error, invalid number of parameters\n");
           return_code = SHELL_EXIT_ERROR;
           print_usage=TRUE;
        } else {
           path_ptr  ="*.*";
!          mode_ptr = "m";
           if (argc >= 2)  {
              path_ptr = argv[1];
              if (argc== 3)  {
                 mode_ptr = argv[2];
              }
           }
           
           fs_ptr = Shell_get_current_filesystem(argv);
           /* check if filesystem is mounted */
           if (fs_ptr == NULL)  {
 -----8<----------

Outcomes