about getcwd

Tu Juan jtu at utstar.com
Sat Sep 8 01:21:32 UTC 2001


Yes,that's the problem.
Thank you very much.:)
I will try it.

----- Original Message -----
From: Camilo Alejandro Arboleda
To: Tu Juan ; rtems-users at oarcorp.com
Sent: Friday, September 07, 2001 3:03 PM
Subject: Re: about getcwd


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 );

cpy( 
            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: Wednesda
y, 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




More information about the users mailing list