From 1ebec0597a033cba1b18b32466bbd6b7dcfdcecb Mon Sep 17 00:00:00 2001 From: Charles Manning Date: Wed, 20 May 2015 10:21:52 +1200 Subject: [PATCH] Fix directory look up. Thanks to Trent Lillehaugen for new algorithm: Let's say I have two yaffs partitions: "/" and "/foo". If I call, yaffs_mkdir("/foobar", 0), yaffsfs_FindDevice will match the path with the "/foo" partition. I would expect it to match "/" instead. It will also match "/fo/o/bar" with "/foo", again I think it should match with "/". Signed-off-by: Charles Manning --- direct/yaffsfs.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/direct/yaffsfs.c b/direct/yaffsfs.c index 69cf0a4..dedd76c 100644 --- a/direct/yaffsfs.c +++ b/direct/yaffsfs.c @@ -515,17 +515,17 @@ static struct yaffs_dev *yaffsfs_FindDevice(const YCHAR *path, thisMatchLength = 0; matching = 1; + if(!p) continue; - while (matching && *p && *leftOver) { - /* Skip over any /s */ - while (yaffsfs_IsPathDivider(*p)) - p++; + /* Skip over any leading /s */ + while (yaffsfs_IsPathDivider(*p)) + p++; + while (yaffsfs_IsPathDivider(*leftOver)) + leftOver++; - /* Skip over any /s */ - while (yaffsfs_IsPathDivider(*leftOver)) - leftOver++; + while (matching && *p && *leftOver) { /* Now match the text part */ while (matching && @@ -539,6 +539,16 @@ static struct yaffs_dev *yaffsfs_FindDevice(const YCHAR *path, matching = 0; } } + + if ((*p && !yaffsfs_IsPathDivider(*p)) || + (*leftOver && !yaffsfs_IsPathDivider(*leftOver))) + matching = 0; + else { + while (yaffsfs_IsPathDivider(*p)) + p++; + while (yaffsfs_IsPathDivider(*leftOver)) + leftOver++; + } } /* Skip over any /s in leftOver */ @@ -559,7 +569,6 @@ static struct yaffs_dev *yaffsfs_FindDevice(const YCHAR *path, retval = dev; longestMatch = thisMatchLength; } - } return retval; } -- 2.30.2