Mercurial > ecos
changeset 2129:8eb72dcf503a
* src/misc.cxx (cyg_mtab_lookup): Corrected implementation for
relative paths crossing mount points.
* tests/fileio1.c (cyg_user_start): Add a test for the above fix.
| author | asl |
|---|---|
| date | Thu, 16 Feb 2006 18:46:06 +0000 |
| parents | 06a1f8221912 |
| children | 9a0cafc8b9bf |
| files | packages/io/fileio/current/ChangeLog packages/io/fileio/current/src/misc.cxx packages/io/fileio/current/tests/fileio1.c |
| diffstat | 3 files changed, 65 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/packages/io/fileio/current/ChangeLog +++ b/packages/io/fileio/current/ChangeLog @@ -1,3 +1,9 @@ +2006-02-16 Peter Korsgaard <jacmet@sunsite.dk> + + * src/misc.cxx (cyg_mtab_lookup): Corrected implementation for + relative paths crossing mount points. + * tests/fileio1.c (cyg_user_start): Add a test for the above fix. + 2005-10-20 Andrew Lunn <andrew.lunn@ascom.ch> * src/select.cxx: Needs sys/time.h for struct timeval.
--- a/packages/io/fileio/current/src/misc.cxx +++ b/packages/io/fileio/current/src/misc.cxx @@ -222,6 +222,16 @@ static int matchlen( const char *s1, con } // ------------------------------------------------------------------------- +// 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,35 +240,64 @@ static int matchlen( const char *s1, con 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; + + 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; + } + } + } + + // did we find a better match? + if (best != *mte) + *dir = best->root; + } + else + { + // Otherwise search the mount table. + for( m = &cyg_mtab[0]; m != &cyg_mtab_end; m++ ) + { + 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; + + *dir = best->root; } - // Otherwise search the mount table. - for( m = &cyg_mtab[0]; m != &cyg_mtab_end; m++ ) - { - 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; - *name += best_len; if( **name == '/' ) (*name)++; *mte = best; - *dir = best->root; return 0; }
--- a/packages/io/fileio/current/tests/fileio1.c +++ b/packages/io/fileio/current/tests/fileio1.c @@ -422,6 +422,8 @@ int cyg_user_start(void) checkfile( "/ram/tinky"); checkfile( "/ram/laalaa"); comparefiles( "/ram/tinky", "/ram/laalaa" ); + comparefiles( "/ram/tinky", "ram/laalaa" ); + comparefiles( "ram/tinky", "/ram/laalaa" ); err = chdir( "/ram" ); if( err < 0 ) SHOW_RESULT( chdir, err );
