about getcwd

Camilo Alejandro Arboleda camilo.arboleda at ascom.com.co
Fri Sep 7 22:03:59 UTC 2001


If you are using RTEMS 4.5.0, there is a bug in imfs readdir (file imfs_directory.c), about line 115

The code  is
      if( current_entry >= first_entry ) {
         /* Move the entry to the return buffer */
         tmp_dirent.d_ino = 1; // IT DOESN'T WORK WITH GETCWD
         tmp_dirent.d_off = current_entry;
         tmp_dirent.d_reclen = sizeof( struct dirent );
         the_jnode = (IMFS_jnode_t *) the_node;
         tmp_dirent.d_namlen = strlen( the_jnode->name );
         strcpy( tmp_dirent.d_name, the_jnode->name );
         memcpy( 
            buffer + bytes_transferred, 
            (void *)&tmp_dirent, 
            sizeof( struct dirent ) 
         );
         iop->offset = iop->offset + sizeof(struct dirent);
         bytes_transferred = bytes_transferred + sizeof( struct dirent );
      }
The problem is that d_ino has not a valid value, so getcwd cannot realize what the current directory is. The next code works (it appears that way in more recent snapshots)

      if( current_entry >= first_entry ) {
         /* Move the entry to the return buffer */
         tmp_dirent.d_off = current_entry;
         tmp_dirent.d_reclen = sizeof( struct dirent );
         the_jnode = (IMFS_jnode_t *) the_node;
         tmp_dirent.d_ino = the_jnode->st_ino;
         tmp_dirent.d_namlen = strlen( the_jnode->name );
         strcpy( tmp_dirent.d_name, the_jnode->name );
         memcpy( 
            buffer + bytes_transferred, 
            (void *)&tmp_dirent, 
            sizeof( struct dirent ) 
         );
         iop->offset = iop->offset + sizeof(struct dirent);
         bytes_transferred = bytes_transferred + sizeof( struct dirent );
      }

  ----- Original Message ----- 
  From: Tu Juan 
  To: rtems-users at oarcorp.com 
  Sent: Wednesday, September 05, 2001 5:27 PM
  Subject: about getcwd


  Anyone who can help me to explain these problems in getcwd().

        /*
         * If it's a mount point, have to stat each element because
         * the inode number in the directory is for the entry in the
         * parent directory, not the inode number of the mounted file.
         */

   save_errno = 0;
   if (s.st_dev == dev)// When use this, it's not work. 
   {
     for (;;)
       {
         if (!(dp = _readdir (dir)))
            goto notfound;
         if (dp->d_ino == ino) // dp->d_ino is always be 1. It has been set in imfs_dir_read (imfs_directory.c).
            break;
       }
   }
   else // This is work.
   for (;;)
     {
       if (!(dp = _readdir (dir)))
         goto notfound;
       if (ISDOT (dp))
         continue;
       bcopy (dp->d_name, bup, strlen (dp->d_name) + 1);

       /* Save the first error for later. */
       if (stat (up, &s))
         {
            if (!save_errno)
              save_errno = errno;
            errno = 0;
            continue;
         }
       if (s.st_dev == dev && s.st_ino == ino)
         break;
     }

  Thanks,

  Tu Juan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/users/attachments/20010907/d746b7be/attachment-0001.html>


More information about the users mailing list