Help: IMFS and opendir/readdir.

Joel Sherrill joel.sherrill at OARcorp.com
Wed Nov 15 18:09:10 UTC 2000


Jake Janovetz wrote:
> 
> This problem has recently been found and is currently being investigated
> by Joel and Jennifer at OAR.  They estimated a couple days to patch
> this, but they're pretty busy...

Jennifer seems close.  She is fixing a side-effect of the fix. :)

The problem is that at a mount point there are two nodes.  One
is in the root filesystem and the other is the root of mounted 
filesystem.  WHen you do the opendir(), you are getting the
node information for the mount point not the root of the mounted
filesystem.  I have attached a simple test program illustrating this.

I still find it amazing how multiple people trip across the 
same thing at the same time regardless of how long it has been there. :)

--joel

>     Jake
> 
> On Wed, Nov 15, 2000 at 07:41:08PM +0300, Sergei Organov wrote:
> > Hello,
> >
> > I'm using rtems-ss-20000929 snapshot.
> >
> > I've mounted my own file-system on the '/log' directory. However, when FTPD
> > executes opendir("/log")/readdir() in response to 'ls /log' command issued in
> > FTP client, my routines aren't called at all. FTP then shows empty directory.
> >
> > My routines are called when I issue 'get /log/something' and downloading works
> > great, so my file-system is indeed mounted.
> >
> > I guess something is wrong with 'imfs_dir_open' and/or 'imfs_dir_read'
> > routines because they just output IMFS directory contents without checking if
> > another file-system is mounted on the directory. Am I right?
> >
> > Please help!
> >
> > BTW, 'ls /dev' output is also empty, while 'cd /dev' and then 'ls' gives the
> > list of registered devices. But this seems to be unrelated bug.
> >
> > BR,
> > Sergei Organov.
> >

-- 
Joel Sherrill, Ph.D.             Director of Research & Development
joel at OARcorp.com                 On-Line Applications Research
Ask me about RTEMS: a free RTOS  Huntsville AL 35805
   Support Available             (256) 722-9985
-------------- next part --------------
/*
 *  Simple test program -- demonstrate bug in IMFS not allowing
 *  readdir() to operate properly on root of mounted filesystem.
 */

#include <bsp.h>
#include <stdio.h>

#include <dirent.h>
#include <assert.h>
#include <imfs.h>

#if defined(__rtems__)
#define d_type d_reclen
#endif

void printdir( const char *name )
{
  DIR *directory;
  struct dirent *d;
  int rc;

  printf("Listing of directory %s\n", name );
  directory = opendir(name);
  assert( directory );

  printf( "    %-20s %8s %8s %8s %4s\n",
     "     name", "inode", " offset", "reclen", " type" );
  d = readdir(directory);
  while (d) {
    printf( "    %-20s %8d %8d %6d   0x%04x\n",
       d->d_name, (int)d->d_ino, (int)d->d_off, d->d_reclen, d->d_type );
    d = readdir(directory);
  }
  rc = closedir(directory);
  assert( !rc );
  printf("End of %s\n", name );
}             

rtems_task Init(
  rtems_task_argument ignored
)
{
  rtems_filesystem_mount_table_entry_t *entry;
  int rc;

  puts( "\n\n*** MOUNT DEMO ***" );

  puts("Mounting secondary IMFS (at /imfs)...");
  rc = mkdir("/imfs", S_IRWXU | S_IRWXG | S_IRWXO);
  assert( !rc  );
  rc = mkdir("/imfs/should_be_hidden", S_IRWXU | S_IRWXG | S_IRWXO);
  assert( !rc  );

  rc = mount(&entry, &IMFS_ops, RTEMS_FILESYSTEM_READ_ONLY, NULL, "/imfs");
  assert( !rc  );

  rc = mkdir("/imfs/testdir", S_IRWXU | S_IRWXG | S_IRWXO);
  assert( !rc  );

  rc = mkdir("/imfs/testdir/testsubdir", S_IRWXU | S_IRWXG | S_IRWXO);
  assert( !rc  );

  printdir( "/imfs" );
  printdir( "/imfs/" );
  printdir( "/imfs/." );
  printdir( "/imfs/testdir" );
  printdir( "/imfs/testdir/.." );

  printf( "*** END OF MOUNT DEMO ***\n" );
  exit( 0 );
}

/* configuration information */

#define CONFIGURE_TEST_NEEDS_CONSOLE_DRIVER
#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 10
#define CONFIGURE_MAXIMUM_TASKS 1

#define CONFIGURE_INIT

#include <confdefs.h>

/* end of file */


More information about the users mailing list