+static yaffs_Device *yaffsfs_FindDevice(const YCHAR *path, YCHAR **restOfPath)
+{
+ yaffsfs_DeviceConfiguration *cfg = yaffsfs_configurationList;
+ const YCHAR *leftOver;
+ const YCHAR *p;
+ yaffs_Device *retval = NULL;
+ int thisMatchLength;
+ int longestMatch = -1;
+
+ // Check all configs, choose the one that:
+ // 1) Actually matches a prefix (ie /a amd /abc will not match
+ // 2) Matches the longest.
+ while(cfg && cfg->prefix && cfg->dev)
+ {
+ leftOver = path;
+ p = cfg->prefix;
+ thisMatchLength = 0;
+
+
+ // Strip off any leading /'s
+
+ while(yaffsfs_IsPathDivider(*p))
+ p++;
+
+ while(yaffsfs_IsPathDivider(*leftOver))
+ leftOver++;
+
+ while(*p && *leftOver &&
+ yaffsfs_Match(*p,*leftOver))
+ {
+ p++;
+ leftOver++;
+ thisMatchLength++;
+
+ // Skip over any multiple /'s to treat them as one or
+ // skip over a trailling / in the prefix, but not the matching string
+ while(yaffsfs_IsPathDivider(*p) &&
+ (yaffsfs_IsPathDivider(*(p+1)) || !(*(p+1))))
+ p++;
+
+ // Only skip over multiple /'s
+ while(yaffsfs_IsPathDivider(*leftOver) &&
+ yaffsfs_IsPathDivider(*(leftOver+1)))
+ leftOver++;
+ }
+
+ if((!*p ) &&
+ (!*leftOver || yaffsfs_IsPathDivider(*leftOver)) && // no more in this path name part
+ (thisMatchLength > longestMatch))
+ {
+ // Matched prefix
+ *restOfPath = (YCHAR *)leftOver;
+ retval = cfg->dev;
+ longestMatch = thisMatchLength;
+ }
+ cfg++;
+ }
+ return retval;
+}
+#if 0
+static yaffs_Device *yaffsfs_FindDevice(const YCHAR *path, YCHAR **restOfPath)