<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=gb2312" http-equiv=Content-Type>
<META content="MSHTML 5.00.2920.0" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>If you are using RTEMS 4.5.0, there is a bug
in imfs readdir (file imfs_directory.c), about line 115</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>The code is</FONT></DIV>
<DIV><FONT face=Arial size=2> if( current_entry
>= first_entry ) {<BR> /*
Move the entry to the return buffer
*/<BR> tmp_dirent.d_ino = 1; //
IT DOESN'T WORK WITH
GETCWD<BR> tmp_dirent.d_off =
current_entry;<BR>
tmp_dirent.d_reclen = sizeof( struct dirent
);<BR> the_jnode = (IMFS_jnode_t
*) the_node;<BR>
tmp_dirent.d_namlen = strlen( the_jnode->name
);<BR> strcpy(
tmp_dirent.d_name, the_jnode->name
);<BR> memcpy(
<BR> buffer +
bytes_transferred,
<BR> (void
*)&tmp_dirent,
<BR> sizeof(
struct dirent ) <BR>
);<BR> iop->offset =
iop->offset + sizeof(struct
dirent);<BR> bytes_transferred =
bytes_transferred + sizeof( struct dirent );<BR>
}<BR>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)</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> if( current_entry
>= first_entry ) {<BR> /*
Move the entry to the return buffer
*/<BR> tmp_dirent.d_off =
current_entry;<BR>
tmp_dirent.d_reclen = sizeof( struct dirent
);<BR> the_jnode = (IMFS_jnode_t
*) the_node;<BR>
tmp_dirent.d_ino =
the_jnode->st_ino;<BR>
tmp_dirent.d_namlen = strlen( the_jnode->name
);<BR> strcpy(
tmp_dirent.d_name, the_jnode->name
);<BR> memcpy(
<BR> buffer +
bytes_transferred,
<BR> (void
*)&tmp_dirent,
<BR> sizeof(
struct dirent ) <BR>
);<BR> iop->offset =
iop->offset + sizeof(struct
dirent);<BR> bytes_transferred =
bytes_transferred + sizeof( struct dirent );<BR>
}<BR></FONT><FONT face=Arial size=2></DIV></FONT>
<BLOCKQUOTE
style="BORDER-LEFT: #000000 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px">
<DIV style="FONT: 10pt arial">----- Original Message ----- </DIV>
<DIV
style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><B>From:</B>
<A href="mailto:jtu@utstar.com" title=jtu@utstar.com>Tu Juan</A> </DIV>
<DIV style="FONT: 10pt arial"><B>To:</B> <A
href="mailto:rtems-users@oarcorp.com"
title=rtems-users@oarcorp.com>rtems-users@oarcorp.com</A> </DIV>
<DIV style="FONT: 10pt arial"><B>Sent:</B> Wednesday, September 05, 2001 5:27
PM</DIV>
<DIV style="FONT: 10pt arial"><B>Subject:</B> about getcwd</DIV>
<DIV><BR></DIV>
<DIV><FONT color=#000080 face=宋体 size=2>Anyone who can help me to explain
these problems in getcwd().</FONT></DIV>
<DIV> </DIV>
<DIV><FONT color=#000080 face=宋体 size=2>
/*<BR> * If it's a mount point, have to
stat each element because<BR> * the inode
number in the directory is for the entry in
the<BR> * parent directory, not the inode
number of the mounted file.<BR>
*/</FONT></DIV>
<DIV> </DIV>
<DIV><FONT color=#000080 face=宋体 size=2> save_errno = 0;<BR> if
(s.st_dev == dev)<FONT color=#ff0000>// When use this, it's not
work. </FONT><BR> {<BR> for
(;;)<BR> {<BR> if
(!(dp = _readdir (dir)))<BR>
goto notfound;<BR> if (<FONT
color=#ff0000>dp->d_ino </FONT>== ino) <FONT color=#ff0000>// <FONT
face=宋体 size=2>dp->d_ino is always be 1. It has been set in imfs_dir_read
(imfs_directory.c).</FONT><BR></FONT><FONT color=#ff0000>
</FONT> break;<BR>
}<BR> }<BR> else <FONT color=#ff0000>// This is
work.</FONT><BR> for (;;)<BR> {<BR>
if (!(dp = _readdir (dir)))<BR> goto
notfound;<BR> if (ISDOT
(dp))<BR>
continue;<BR> bcopy (dp->d_name, bup, strlen
(dp->d_name) + 1);</FONT></DIV>
<DIV> </DIV>
<DIV><FONT color=#000080 face=宋体 size=2> /* Save the
first error for later. */<BR> if (stat (up,
&s))<BR> {<BR>
if (!save_errno)<BR>
save_errno = errno;<BR>
errno = 0;<BR>
continue;<BR>
}<BR> if (s.st_dev == dev && s.st_ino ==
ino)<BR> break;<BR>
}</FONT></DIV>
<DIV> </DIV>
<DIV><FONT color=#000080 face=宋体 size=2>Thanks,</FONT></DIV>
<DIV> </DIV>
<DIV><FONT color=#000080 face=宋体 size=2>Tu
Juan</FONT></DIV></BLOCKQUOTE></BODY></HTML>