This is the mail archive of the
ecos-patches@sourceware.org
mailing list for the eCos project.
fileio/cyg_mtab_lookup fix for relative paths spanning mounts
- From: Peter Korsgaard <jacmet at sunsite dot dk>
- To: ecos-patches at ecos dot sourceware dot org
- Date: Wed, 15 Feb 2006 16:58:08 +0100
- Subject: fileio/cyg_mtab_lookup fix for relative paths spanning mounts
Hi,
The current cyg_mtab_lookup implementation doesn't handle relative
paths crossing mount points - E.G. open("mnt/file", O_RDWR); where mnt
is the mount point of another fs. The following patch fixes that.
Index: packages/io/fileio/current/ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/io/fileio/current/ChangeLog,v
retrieving revision 1.61
diff -u -r1.61 ChangeLog
--- packages/io/fileio/current/ChangeLog 23 Oct 2005 20:45:11 -0000 1.61
+++ packages/io/fileio/current/ChangeLog 15 Feb 2006 15:49:28 -0000
@@ -1,3 +1,8 @@
+2006-02-15 Peter Korsgaard <jacmet@sunsite.dk>
+
+ * src/misc.cxx (cyg_mtab_lookup): Corrected implementation for
+ relative paths crossing mount points.
+
2005-10-20 Andrew Lunn <andrew.lunn@ascom.ch>
* src/select.cxx: Needs sys/time.h for struct timeval.
Index: packages/io/fileio/current/src/misc.cxx
===================================================================
RCS file: /cvs/ecos/ecos/packages/io/fileio/current/src/misc.cxx,v
retrieving revision 1.10
diff -u -r1.10 misc.cxx
--- packages/io/fileio/current/src/misc.cxx 22 Jan 2005 14:03:37 -0000 1.10
+++ packages/io/fileio/current/src/misc.cxx 15 Feb 2006 15:49:28 -0000
@@ -222,6 +222,16 @@
}
// -------------------------------------------------------------------------
+// Simple strlen implementation
+
+static int my_strlen(const char *c)
+{
+ int l = 0;
+ while (*c++) l++;
+ return l;
+}
+
+// -------------------------------------------------------------------------
// Search the mtab for the entry that matches the longest substring of
// **name.
@@ -230,30 +240,54 @@
cyg_mtab_entry *m, *best = NULL;
int best_len = 0;
- // Unrooted file names go straight to current dir
+ // Unrooted file names start from current dir
if( **name != '/' ) {
+ int cwd_len;
if (*mte == (cyg_mtab_entry *)NULL) {
// No known current directory
return -1;
}
- // Current directory is well known
- return 0;
- }
- // Otherwise search the mount table.
- for( m = &cyg_mtab[0]; m != &cyg_mtab_end; m++ )
+ best = *mte;
+ cwd_len = my_strlen((*mte)->name);
+
+ // current dir is not the correct mte if the relative path crosses
+ // mount points - search for best matching mount point
+ for( m = &cyg_mtab[0]; m != &cyg_mtab_end; m++ )
+ {
+ if( m->name != NULL && m->valid )
+ {
+ int len = matchlen(m->name, (*mte)->name);
+ // mount point under cwd?
+ if (len == cwd_len)
+ {
+ if (m->name[len] == '/')
+ len++;
+
+ len = matchlen(*name, &m->name[len]);
+ if (len > best_len)
+ best = m, best_len = len;
+ }
+ }
+ }
+ }
+ else
{
- if( m->name != NULL && m->valid )
+ // Otherwise search the mount table.
+ for( m = &cyg_mtab[0]; m != &cyg_mtab_end; m++ )
{
- int len = matchlen(*name,m->name);
- if( len > best_len )
- best = m, best_len = len;
+ if( m->name != NULL && m->valid )
+ {
+ int len = matchlen(*name,m->name);
+ if( len > best_len )
+ best = m, best_len = len;
+ }
}
+
+ // No match found, bad path name...
+ if( best_len == 0 ) return -1;
}
- // No match found, bad path name...
- if( best_len == 0 ) return -1;
-
*name += best_len;
if( **name == '/' )
(*name)++;
--
Bye, Peter Korsgaard