changeset 2945:bce3ef5fd9ab

* src/ramfs.c (add_direntry): Fix directory file name corruption with the SIMPLE allocation method: do not cache pointers returned from findbuffer_node(), but do a fresh lookup based on position. * src/ramfs.c (find_entry): Fixed wrong type for a local counter (namelen): s/char/int/.
author sergeig
date Mon, 29 Mar 2010 19:39:12 +0000
parents f5ae5af1e5f8
children 418d34334c77
files packages/fs/ram/current/ChangeLog packages/fs/ram/current/src/ramfs.c
diffstat 2 files changed, 33 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/packages/fs/ram/current/ChangeLog
+++ b/packages/fs/ram/current/ChangeLog
@@ -1,3 +1,15 @@
+2010-03-29  Oyvind Harboe  <oyvind.harboe@zylin.com>
+            Jonathan Larmour  <jifl@eCosCentric.com>
+
+	* src/ramfs.c (add_direntry): Fix directory file name corruption
+	with the SIMPLE allocation method: do not cache pointers returned
+	from findbuffer_node(), but do a fresh lookup based on position.
+
+2010-02-27  Sergei Gavrikov  <sergei.gavrikov@gmail.com>
+
+	* src/ramfs.c (find_entry): Fixed wrong type for a local counter
+	(namelen): s/char/int/.
+
 2009-04-28  John Dallaway  <john@dallaway.org.uk>
 
 	cdl/ramfs.cdl: Use CYGPKG_IO_FILEIO as the parent.
--- a/packages/fs/ram/current/src/ramfs.c
+++ b/packages/fs/ram/current/src/ramfs.c
@@ -1122,6 +1122,9 @@ static int add_direntry( ramfs_node *dir
                        )
 {
     off_t pos = 0;
+#ifdef CYGPKG_FS_RAM_SIMPLE
+    off_t prev_pos = 0;
+#endif
     ramfs_dirent *d = NULL, *dp = NULL;
     cyg_bool isfirst = true;
 
@@ -1154,6 +1157,20 @@ static int add_direntry( ramfs_node *dir
             break;
         }
 
+#ifdef CYGPKG_FS_RAM_SIMPLE
+        // Tricky! Here we have to look up the previous segment as
+        // reallocating could have moved it.
+        if( !isfirst ) {
+            cyg_uint8 *buf;
+            size_t size;
+            int err;
+            err = findbuffer_node( dir, prev_pos, &buf, &size, false );
+            if( err != ENOERR ) return err;
+
+            dp = (ramfs_dirent *) buf;
+        }
+#endif
+
         // d now points to a free dirent structure
 
         d->node         = node;
@@ -1167,6 +1184,9 @@ static int add_direntry( ramfs_node *dir
 
         name            += fraglen;
         namelen         -= fraglen;
+#ifdef CYGPKG_FS_RAM_SIMPLE
+        prev_pos        = pos;
+#endif
         pos             += sizeof(ramfs_dirent);
         dp              = d;
         isfirst         = false;
@@ -1339,7 +1359,7 @@ static int find_entry( ramfs_dirsearch *
     ramfs_node *dir = ds->dir;
     const char *name = ds->path;
     const char *n = name;
-    char namelen = 0;
+    int namelen = 0;
     ramfs_dirent *d;
     
     // check that we really have a directory