public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] opendir with empty directory name?
@ 2008-03-18 16:33 Hong,Zhichao
  2008-03-18 16:37 ` Alex Garcia
  2008-03-18 18:36 ` Gary Thomas
  0 siblings, 2 replies; 7+ messages in thread
From: Hong,Zhichao @ 2008-03-18 16:33 UTC (permalink / raw)
  To: ecos-discuss

Hi, all,
 
I am wondering what is the behavior of opendir("") in eCos fileio
implementation?  I am reading some code written by others.  And the
comment says open the current directory then code is written as
opendir(""). 
And the code seems to work as documented.  But should not this actually
be opendir(".").  I search the POSIX and various compiler
implementation.  It does not seem any of them support this kind of empty
directory.  Is this an eCos bug or a feature?

Zhichao Hong,CSDP


--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [ECOS] opendir with empty directory name?
  2008-03-18 16:33 [ECOS] opendir with empty directory name? Hong,Zhichao
@ 2008-03-18 16:37 ` Alex Garcia
  2008-03-18 16:54   ` Hong,Zhichao
  2008-03-18 18:36 ` Gary Thomas
  1 sibling, 1 reply; 7+ messages in thread
From: Alex Garcia @ 2008-03-18 16:37 UTC (permalink / raw)
  To: Hong,Zhichao; +Cc: ecos-discuss

Hi,

The fatfs implementation of opendir uses init_dirsearch() to check the 
actual dir variable passed through the aforementioned.
Here's the function:

static void
init_dirsearch(fatfs_dirsearch_t *ds,
              fatfs_disk_t      *disk,
              fatfs_node_t      *dir,
              const char        *name)
{
   ds->disk = disk;
     if (NULL == dir)
       ds->dir = disk->root;
   else
       ds->dir = dir;
     ds->path    = name;
   ds->node    = ds->dir;
   ds->namelen = 0;
   ds->last    = false;
}

In my understanding of it the function would consider both "" & "." as 
referring to the current directory since "." always refers to it this 
way, so I would assume ... feature ^^.

More on this just to confirm you that the function I previously 
mentioned seem to be the one actually called by the opendir() 
implementation.
Take a look at "io/fileio/current/src/dir.cxx" for the actual opendir 
function declaration.

The call is handled on line 127 here:

    LOCK_FS( mte );
    ret = mte->fs->opendir( mte, dir, name, file );
    UNLOCK_FS( mte );

Someone may prove me wrong, anyway, my 2 cents.

Alex Garcia

PS: sorry for the double post, forgot to reply-to-all ...

Hong,Zhichao wrote:
> Hi, all,
>  
> I am wondering what is the behavior of opendir("") in eCos fileio
> implementation?  I am reading some code written by others.  And the
> comment says open the current directory then code is written as
> opendir(""). 
> And the code seems to work as documented.  But should not this actually
> be opendir(".").  I search the POSIX and various compiler
> implementation.  It does not seem any of them support this kind of empty
> directory.  Is this an eCos bug or a feature?
>
> Zhichao Hong,CSDP
>
>
>   

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: [ECOS] opendir with empty directory name?
  2008-03-18 16:37 ` Alex Garcia
@ 2008-03-18 16:54   ` Hong,Zhichao
  2008-03-18 17:06     ` Alex Garcia
  0 siblings, 1 reply; 7+ messages in thread
From: Hong,Zhichao @ 2008-03-18 16:54 UTC (permalink / raw)
  To: Alex Garcia; +Cc: ecos-discuss

Alex,

Thanks for your quick reply!  BTW, will this also apply to jffs2?

Zhichao Hong,CSDP 

-----Original Message-----
From: Alex Garcia [mailto:thekyz@gmail.com] 
Sent: Tuesday, March 18, 2008 11:32 AM
To: Hong,Zhichao
Cc: ecos-discuss@ecos.sourceware.org
Subject: Re: [ECOS] opendir with empty directory name?

Hi,

The fatfs implementation of opendir uses init_dirsearch() to check the
actual dir variable passed through the aforementioned.
Here's the function:

static void
init_dirsearch(fatfs_dirsearch_t *ds,
              fatfs_disk_t      *disk,
              fatfs_node_t      *dir,
              const char        *name)
{
   ds->disk = disk;
     if (NULL == dir)
       ds->dir = disk->root;
   else
       ds->dir = dir;
     ds->path    = name;
   ds->node    = ds->dir;
   ds->namelen = 0;
   ds->last    = false;
}

In my understanding of it the function would consider both "" & "." as
referring to the current directory since "." always refers to it this
way, so I would assume ... feature ^^.

More on this just to confirm you that the function I previously
mentioned seem to be the one actually called by the opendir()
implementation.
Take a look at "io/fileio/current/src/dir.cxx" for the actual opendir
function declaration.

The call is handled on line 127 here:

    LOCK_FS( mte );
    ret = mte->fs->opendir( mte, dir, name, file );
    UNLOCK_FS( mte );

Someone may prove me wrong, anyway, my 2 cents.

Alex Garcia

PS: sorry for the double post, forgot to reply-to-all ...

Hong,Zhichao wrote:
> Hi, all,
>  
> I am wondering what is the behavior of opendir("") in eCos fileio 
> implementation?  I am reading some code written by others.  And the 
> comment says open the current directory then code is written as 
> opendir("").
> And the code seems to work as documented.  But should not this 
> actually be opendir(".").  I search the POSIX and various compiler 
> implementation.  It does not seem any of them support this kind of 
> empty directory.  Is this an eCos bug or a feature?
>
> Zhichao Hong,CSDP
>
>
>   

--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [ECOS] opendir with empty directory name?
  2008-03-18 16:54   ` Hong,Zhichao
@ 2008-03-18 17:06     ` Alex Garcia
  0 siblings, 0 replies; 7+ messages in thread
From: Alex Garcia @ 2008-03-18 17:06 UTC (permalink / raw)
  To: Hong,Zhichao; +Cc: ecos-discuss

Well the fs implementation you use will always be called by the upper 
layer opendir() function as mentionned on that line:

ret = mte->fs->opendir( mte, dir, name, file );

The "actual" function is referred to it using a function pointer.
Anyway here is the opendir for the jffs2 implementation (few first lines):

static int jffs2_opendir(cyg_mtab_entry * mte, cyg_dir dir, const char 
*name,
             cyg_file * file)
{
    jffs2_dirsearch ds;
    int err;

    D2(printf("jffs2_opendir\n"));

    init_dirsearch(&ds, (struct _inode *) dir,
                       (const unsigned char *) name);


... which also calls init_dirsearch()
YET, it's not the same init_dirsearch() as in fatfs implementation 
(which i find pretty confusing). Here is the function:

    static void init_dirsearch(jffs2_dirsearch * ds,
                   struct _inode *dir, const unsigned char *name)
    {
        D2(printf("init_dirsearch name = %s\n", name));
        D2(printf("init_dirsearch dir = %x\n", dir));

        dir->i_count++;
        ds->dir = dir;
        ds->path = name;
        ds->node = dir;
        ds->name = name;
        ds->namelen = 0;
        ds->last = false;
    }

In this case I think "." would get you the result you wanted but I don't 
really know for "".
I think the macro S_ISDIR uses stat() to check if the directory exists 
(or is a directory at all) so it should work as intended at least.

Alex Garcia

Hong,Zhichao wrote:
> Alex,
>
> Thanks for your quick reply!  BTW, will this also apply to jffs2?
>
> Zhichao Hong,CSDP 
>
> -----Original Message-----
> From: Alex Garcia [mailto:thekyz@gmail.com] 
> Sent: Tuesday, March 18, 2008 11:32 AM
> To: Hong,Zhichao
> Cc: ecos-discuss@ecos.sourceware.org
> Subject: Re: [ECOS] opendir with empty directory name?
>
> Hi,
>
> The fatfs implementation of opendir uses init_dirsearch() to check the
> actual dir variable passed through the aforementioned.
> Here's the function:
>
> static void
> init_dirsearch(fatfs_dirsearch_t *ds,
>               fatfs_disk_t      *disk,
>               fatfs_node_t      *dir,
>               const char        *name)
> {
>    ds->disk = disk;
>      if (NULL == dir)
>        ds->dir = disk->root;
>    else
>        ds->dir = dir;
>      ds->path    = name;
>    ds->node    = ds->dir;
>    ds->namelen = 0;
>    ds->last    = false;
> }
>
> In my understanding of it the function would consider both "" & "." as
> referring to the current directory since "." always refers to it this
> way, so I would assume ... feature ^^.
>
> More on this just to confirm you that the function I previously
> mentioned seem to be the one actually called by the opendir()
> implementation.
> Take a look at "io/fileio/current/src/dir.cxx" for the actual opendir
> function declaration.
>
> The call is handled on line 127 here:
>
>     LOCK_FS( mte );
>     ret = mte->fs->opendir( mte, dir, name, file );
>     UNLOCK_FS( mte );
>
> Someone may prove me wrong, anyway, my 2 cents.
>
> Alex Garcia
>
> PS: sorry for the double post, forgot to reply-to-all ...
>
> Hong,Zhichao wrote:
>   
>> Hi, all,
>>  
>> I am wondering what is the behavior of opendir("") in eCos fileio 
>> implementation?  I am reading some code written by others.  And the 
>> comment says open the current directory then code is written as 
>> opendir("").
>> And the code seems to work as documented.  But should not this 
>> actually be opendir(".").  I search the POSIX and various compiler 
>> implementation.  It does not seem any of them support this kind of 
>> empty directory.  Is this an eCos bug or a feature?
>>
>> Zhichao Hong,CSDP
>>
>>
>>   
>>     

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [ECOS] opendir with empty directory name?
  2008-03-18 16:33 [ECOS] opendir with empty directory name? Hong,Zhichao
  2008-03-18 16:37 ` Alex Garcia
@ 2008-03-18 18:36 ` Gary Thomas
  2008-03-19  8:38   ` Nick Garnett
  2008-03-20  5:02   ` Hong,Zhichao
  1 sibling, 2 replies; 7+ messages in thread
From: Gary Thomas @ 2008-03-18 18:36 UTC (permalink / raw)
  To: Hong,Zhichao; +Cc: ecos-discuss

Hong,Zhichao wrote:
> Hi, all,
>  
> I am wondering what is the behavior of opendir("") in eCos fileio
> implementation?  I am reading some code written by others.  And the
> comment says open the current directory then code is written as
> opendir(""). 
> And the code seems to work as documented.  But should not this actually
> be opendir(".").  I search the POSIX and various compiler
> implementation.  It does not seem any of them support this kind of empty
> directory.  Is this an eCos bug or a feature?

Why not just use the POSIX standard path (".") and *not*
rely on [possibly] non-standard behaviour.

If you've seen other code that uses "" to mean the current
directory, I'd postulate that code is incorrect or at the
very least, non portable.  Was this eCos code?  in CVS or
elsewhere?

-- 
------------------------------------------------------------
Gary Thomas                 |  Consulting for the
MLB Associates              |    Embedded world
------------------------------------------------------------

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [ECOS] opendir with empty directory name?
  2008-03-18 18:36 ` Gary Thomas
@ 2008-03-19  8:38   ` Nick Garnett
  2008-03-20  5:02   ` Hong,Zhichao
  1 sibling, 0 replies; 7+ messages in thread
From: Nick Garnett @ 2008-03-19  8:38 UTC (permalink / raw)
  To: Gary Thomas; +Cc: Hong,Zhichao, ecos-discuss

Gary Thomas <gary@mlbassoc.com> writes:

> Hong,Zhichao wrote:
> > Hi, all,
> >  I am wondering what is the behavior of opendir("") in eCos fileio
> > implementation?  I am reading some code written by others.  And the
> > comment says open the current directory then code is written as
> > opendir(""). And the code seems to work as documented.  But should
> > not this actually
> > be opendir(".").  I search the POSIX and various compiler
> > implementation.  It does not seem any of them support this kind of empty
> > directory.  Is this an eCos bug or a feature?
> 
> Why not just use the POSIX standard path (".") and *not*
> rely on [possibly] non-standard behaviour.
> 
> If you've seen other code that uses "" to mean the current
> directory, I'd postulate that code is incorrect or at the
> very least, non portable.  Was this eCos code?  in CVS or
> elsewhere?

While opendir("") is probably non-standard, eCos allows it through by
default as a result of the way that filesystem prefixes are handled.

For example, if a filesystem is mounted on "/fatfs" then
opendir("/fatfs") will cause the filesystem itself to be passed an
empty string after the prefix is stripped off. It is not possible to
distinguish this case from calls to opendir("") in the current
directory -- it's all essentially the same thing.

A more obscure point is that not all filesystems that might be ported
to eCos necessarily implement the "." and ".." pseudo-entries. So it
is useful to have a way to refer to the current directory that doesn't
use them.

As Gary says, for full portability, stick to the POSIX standard naming
conventions.

-- 
Nick Garnett                                      eCos Kernel Architect
eCosCentric Limited    http://www.eCosCentric.com      The eCos experts
Barnwell House, Barnwell Drive, Cambridge, UK.     Tel: +44 1223 245571
Registered in England and Wales: Reg No 4422071.
**  Visit us at ESC Silicon Valley <http://www.embedded.com/esc/sv>  **
**  April 15-17 2008, Booth 3012, San Jose McEnery Convention Center **


-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: [ECOS] opendir with empty directory name?
  2008-03-18 18:36 ` Gary Thomas
  2008-03-19  8:38   ` Nick Garnett
@ 2008-03-20  5:02   ` Hong,Zhichao
  1 sibling, 0 replies; 7+ messages in thread
From: Hong,Zhichao @ 2008-03-20  5:02 UTC (permalink / raw)
  To: Gary Thomas; +Cc: ecos-discuss

This is the client code.  I agree with you that we should use "." for
the currdir to avoid this non portable behavior.

Zhichao Hong,CSDP 

-----Original Message-----
From: Gary Thomas [mailto:gary@mlbassoc.com] 
Sent: Tuesday, March 18, 2008 12:06 PM
To: Hong,Zhichao
Cc: ecos-discuss@ecos.sourceware.org
Subject: Re: [ECOS] opendir with empty directory name?

Hong,Zhichao wrote:
> Hi, all,
>  
> I am wondering what is the behavior of opendir("") in eCos fileio 
> implementation?  I am reading some code written by others.  And the 
> comment says open the current directory then code is written as 
> opendir("").
> And the code seems to work as documented.  But should not this 
> actually be opendir(".").  I search the POSIX and various compiler 
> implementation.  It does not seem any of them support this kind of 
> empty directory.  Is this an eCos bug or a feature?

Why not just use the POSIX standard path (".") and *not* rely on
[possibly] non-standard behaviour.

If you've seen other code that uses "" to mean the current directory,
I'd postulate that code is incorrect or at the very least, non portable.
Was this eCos code?  in CVS or elsewhere?

--
------------------------------------------------------------
Gary Thomas                 |  Consulting for the
MLB Associates              |    Embedded world
------------------------------------------------------------

--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2008-03-19 19:08 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-18 16:33 [ECOS] opendir with empty directory name? Hong,Zhichao
2008-03-18 16:37 ` Alex Garcia
2008-03-18 16:54   ` Hong,Zhichao
2008-03-18 17:06     ` Alex Garcia
2008-03-18 18:36 ` Gary Thomas
2008-03-19  8:38   ` Nick Garnett
2008-03-20  5:02   ` Hong,Zhichao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).