This is the mail archive of the ecos-discuss@sourceware.org mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: opendir with empty directory name?


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]