[RTEMS Project] #4674: readdir skips entries after unlink

RTEMS trac trac at rtems.org
Sun Mar 5 01:41:16 UTC 2023


#4674: readdir skips entries after unlink
-----------------------------+----------------------------
 Reporter:  Alexandre Oliva  |       Owner:  Needs Funding
     Type:  defect           |      Status:  assigned
 Priority:  normal           |   Milestone:  6.1
Component:  fs               |     Version:  6
 Severity:  normal           |  Resolution:
 Keywords:                   |  Blocked By:
 Blocking:                   |
-----------------------------+----------------------------

Comment (by z.ling111):

 Hi  i am working on #4674
     currently I'm not able to get it to produce the error
     my code looks like this
     Tested in on IMFS
    {{{
   #ifdef HAVE_CONFIG_H
     #include "config.h"
     #endif

     #include <dirent.h>
     #include <stdio.h>
     #include <sys/types.h>
     #include <fcntl.h>
     #include <dirent.h>
     #include <string.h>
     #include <unistd.h>
     #include <errno.h>
     #include <rtems/imfs.h>

     const char rtems_test_name[] = "FSREADDIR ";
     int test( void );

     int test( void )
     {
        char *many_files[] = {"a", "b","c"};


       printf( "\nchdir to the root directory\n" );
      int  status = chdir( "/" );
       printf( "chdir() status : %d\n\n", status );
     for (int i = 0; i<3; i++) {
         printf("Create %s\n", many_files[i]);
         int fd = open (many_files[i], O_CREAT, S_IRWXU);
         close (fd);
       }
         struct dirent* direntp;
          DIR* dirp;
         dirp = opendir( "/" );
         if( dirp != NULL ) {
             for(;;) {
                 direntp = readdir( dirp );
                 if( direntp == NULL ) break;

                 printf( "%s\n", direntp->d_name );
             }

             closedir( dirp );

         }

        status =  unlink("/b");
         printf( "removing the second directory  : %d\n\n", status );
        dirp = opendir( "/" );
         if( dirp != NULL ) {
             for(;;) {
                 direntp = readdir( dirp );
                 if( direntp == NULL ) break;

                 printf( "%s\n", direntp->d_name );
             }

             closedir( dirp );

         }

        return 0;

     }
  }}}


     Am i unlinking it correctly?

--
Ticket URL: <http://devel.rtems.org/ticket/4674#comment:5>
RTEMS Project <http://www.rtems.org/>
RTEMS Project


More information about the bugs mailing list