Fix dependencies in Kconfig
[yaffs2.git] / direct / yaffsfs.c
index 6206ed4..a096190 100644 (file)
@@ -24,7 +24,7 @@
 #endif
 
 
 #endif
 
 
-const char *yaffsfs_c_version="$Id: yaffsfs.c,v 1.20 2008-07-02 20:17:41 charles Exp $";
+const char *yaffsfs_c_version="$Id: yaffsfs.c,v 1.24 2008-11-11 01:47:46 charles Exp $";
 
 // configurationList is the list of devices that are supported
 static yaffsfs_DeviceConfiguration *yaffsfs_configurationList;
 
 // configurationList is the list of devices that are supported
 static yaffsfs_DeviceConfiguration *yaffsfs_configurationList;
@@ -169,6 +169,7 @@ static yaffs_Device *yaffsfs_FindDevice(const YCHAR *path, YCHAR **restOfPath)
        yaffs_Device *retval = NULL;
        int thisMatchLength;
        int longestMatch = -1;
        yaffs_Device *retval = NULL;
        int thisMatchLength;
        int longestMatch = -1;
+       int matching;
 
        // Check all configs, choose the one that:
        // 1) Actually matches a prefix (ie /a amd /abc will not match
 
        // Check all configs, choose the one that:
        // 1) Actually matches a prefix (ie /a amd /abc will not match
@@ -178,45 +179,45 @@ static yaffs_Device *yaffsfs_FindDevice(const YCHAR *path, YCHAR **restOfPath)
                leftOver = path;
                p = cfg->prefix;
                thisMatchLength = 0;
                leftOver = path;
                p = cfg->prefix;
                thisMatchLength = 0;
+               matching = 1;
 
 
 
 
-               // 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))))
+               while(matching && *p && *leftOver){
+                       // Skip over any /s
+                       while(yaffsfs_IsPathDivider(*p))
                              p++;
 
                              p++;
 
-                       // Only skip over multiple /'s
-                       while(yaffsfs_IsPathDivider(*leftOver) &&
-                             yaffsfs_IsPathDivider(*(leftOver+1)))
-                             leftOver++;
+                       // Skip over any /s
+                       while(yaffsfs_IsPathDivider(*leftOver))
+                             leftOver++;
+
+                       // Now match the text part
+                       while(matching &&
+                             *p && !yaffsfs_IsPathDivider(*p) &&
+                             *leftOver && !yaffsfs_IsPathDivider(*leftOver)){
+                               if(yaffsfs_Match(*p,*leftOver)){
+                                       p++;
+                                       leftOver++;
+                                       thisMatchLength++;
+                               } else {
+                                       matching = 0;
+                               }
+                       }
                }
 
                }
 
+               // Skip over any /s in leftOver
+               while(yaffsfs_IsPathDivider(*leftOver))
+                     leftOver++;
+               
 
 
-               if((!*p ) &&
-                  (!*leftOver || yaffsfs_IsPathDivider(*leftOver)) && // no more in this path name part
-                  (thisMatchLength > longestMatch))
+               if( matching && (thisMatchLength > longestMatch))
                {
                        // Matched prefix
                        *restOfPath = (YCHAR *)leftOver;
                        retval = cfg->dev;
                        longestMatch = thisMatchLength;
                }
                {
                        // Matched prefix
                        *restOfPath = (YCHAR *)leftOver;
                        retval = cfg->dev;
                        longestMatch = thisMatchLength;
                }
+
                cfg++;
        }
        return retval;
                cfg++;
        }
        return retval;
@@ -488,7 +489,7 @@ int yaffs_open(const YCHAR *path, int oflag, int mode)
                        // Check if the object is already in use
                        alreadyOpen = alreadyExclusive = 0;
 
                        // Check if the object is already in use
                        alreadyOpen = alreadyExclusive = 0;
 
-                       for(i = 0; i <= YAFFSFS_N_HANDLES; i++)
+                       for(i = 0; i < YAFFSFS_N_HANDLES; i++)
                        {
 
                                if(i != handle &&
                        {
 
                                if(i != handle &&
@@ -1283,7 +1284,7 @@ int yaffs_set_wince_times(int fd,
 
 static int yaffsfs_DoChMod(yaffs_Object *obj,mode_t mode)
 {
 
 static int yaffsfs_DoChMod(yaffs_Object *obj,mode_t mode)
 {
-       int result;
+       int result = -1;
 
        if(obj)
        {
 
        if(obj)
        {
@@ -1602,6 +1603,28 @@ loff_t yaffs_totalspace(const YCHAR *path)
        return retVal;
 }
 
        return retVal;
 }
 
+int yaffs_inodecount(const YCHAR *path)
+{
+       loff_t retVal= -1;
+       yaffs_Device *dev=NULL;
+       YCHAR *dummy;
+
+       yaffsfs_Lock();
+       dev = yaffsfs_FindDevice(path,&dummy);
+       if(dev  && dev->isMounted) {
+          int nObjects = dev->nObjectsCreated - dev->nFreeObjects;
+          if(nObjects > dev->nHardLinks)
+               retVal = nObjects - dev->nHardLinks;
+       }
+       
+       if(retVal < 0){
+               yaffsfs_SetError(-EINVAL);
+       }
+       
+       yaffsfs_Unlock();
+       return retVal;  
+}
+
 
 
 void yaffs_initialise(yaffsfs_DeviceConfiguration *cfgList)
 
 
 void yaffs_initialise(yaffsfs_DeviceConfiguration *cfgList)