yaffs Changes to direct tests
[yaffs2.git] / direct / yaffsfs.c
index c09513277c270eb2b70c46bb38c23fd6f51cc6c2..191c34f6bd1b6f79209c5642a4df244e1b79a85a 100644 (file)
 #define YAFFSFS_RW_SHIFT (13)
 #define YAFFSFS_RW_SIZE  (1<<YAFFSFS_RW_SHIFT)
 
-
-const char *yaffsfs_c_version="$Id: yaffsfs.c,v 1.35 2010-02-25 22:38:03 charles Exp $";
-
-/* configurationList is the list of devices that are supported */
-static yaffsfs_DeviceConfiguration *yaffsfs_configurationList;
-
-
 /* Some forward references */
 static yaffs_Object *yaffsfs_FindObject(yaffs_Object *relativeDirectory, const YCHAR *path, int symDepth);
 static void yaffsfs_RemoveObjectCallback(yaffs_Object *obj);
@@ -264,6 +257,10 @@ int yaffsfs_IsPathDivider(YCHAR ch)
        return 0;
 }
 
+
+
+YLIST_HEAD(yaffsfs_deviceList);
+
 /*
  * yaffsfs_FindDevice
  * yaffsfs_FindRoot
@@ -273,10 +270,11 @@ int yaffsfs_IsPathDivider(YCHAR ch)
  */
 static yaffs_Device *yaffsfs_FindDevice(const YCHAR *path, YCHAR **restOfPath)
 {
-       yaffsfs_DeviceConfiguration *cfg = yaffsfs_configurationList;
+       struct ylist_head *cfg;
        const YCHAR *leftOver;
        const YCHAR *p;
        yaffs_Device *retval = NULL;
+       yaffs_Device *dev = NULL;
        int thisMatchLength;
        int longestMatch = -1;
        int matching;
@@ -286,9 +284,10 @@ static yaffs_Device *yaffsfs_FindDevice(const YCHAR *path, YCHAR **restOfPath)
         * 1) Actually matches a prefix (ie /a amd /abc will not match
         * 2) Matches the longest.
         */
-       while(cfg && cfg->prefix && cfg->dev){
+       ylist_for_each(cfg, &yaffsfs_deviceList){
+               dev = ylist_entry(cfg, yaffs_Device, devList);
                leftOver = path;
-               p = cfg->prefix;
+               p = dev->param.name;
                thisMatchLength = 0;
                matching = 1;
 
@@ -319,16 +318,23 @@ static yaffs_Device *yaffsfs_FindDevice(const YCHAR *path, YCHAR **restOfPath)
                /* Skip over any /s in leftOver */
                while(yaffsfs_IsPathDivider(*leftOver))
                      leftOver++;
-               
 
-               if( matching && (thisMatchLength > longestMatch)){
-                       /* Matched prefix */
+               // Skip over any /s in p
+               while(yaffsfs_IsPathDivider(*p))
+                     p++;
+
+               // p should now be at the end of the string (ie. fully matched)
+               if(*p)
+                       matching = 0;
+
+               if( matching && (thisMatchLength > longestMatch))
+               {
+                       // Matched prefix
                        *restOfPath = (YCHAR *)leftOver;
-                       retval = cfg->dev;
+                       retval = dev;
                        longestMatch = thisMatchLength;
                }
 
-               cfg++;
        }
        return retval;
 }
@@ -567,12 +573,21 @@ int yaffs_open(const YCHAR *path, int oflag, int mode)
                if(obj)
                        obj = yaffs_GetEquivalentObject(obj);
 
-               if(obj && obj->variantType != YAFFS_OBJECT_TYPE_FILE)
+               if(obj &&
+                       obj->variantType != YAFFS_OBJECT_TYPE_FILE &&
+                       obj->variantType != YAFFS_OBJECT_TYPE_DIRECTORY)
                        obj = NULL;
 
                if(obj){
 
-                       /* The file already exists */
+                       /* The file already exists or it might be a directory */
+
+                       /* If it is a directory then we can't open it as a file */
+                       if(obj->variantType == YAFFS_OBJECT_TYPE_DIRECTORY){
+                               openDenied = 1;
+                               yaffsfs_SetError(-EISDIR);
+                               errorReported = 1;
+                       }
 
                        /* Open should fail if O_CREAT and O_EXCL are specified since
                         * the file exists
@@ -826,10 +841,10 @@ int yaffsfs_do_write(int fd, const void *vbuf, unsigned int nbyte, int isPwrite,
                yaffsfs_SetError(-EINVAL);
                totalWritten=-1;
        } else if( h && obj){
-               if(isPwrite)
-                       startPos = offset;
                if(h->append)
                        startPos = yaffs_GetObjectFileLength(obj);
+               else if(isPwrite)
+                       startPos = offset;
                else
                        startPos = h->position;
 
@@ -1091,7 +1106,7 @@ static int yaffsfs_DoStat(yaffs_Object *obj,struct yaffs_stat *buf)
                obj = yaffs_GetEquivalentObject(obj);
 
        if(obj && buf){
-               buf->st_dev = (int)obj->myDev->context;
+               buf->st_dev = (int)obj->myDev->osContext;
                buf->st_ino = obj->objectId;
                buf->st_mode = obj->yst_mode & ~S_IFMT; /* clear out file type bits */
 
@@ -1180,7 +1195,7 @@ int yaffs_fstat(int fd, struct yaffs_stat *buf)
        return retVal;
 }
 
-
+#ifndef CONFIG_YAFFS_WINCE
 /* xattrib functions */
 
 
@@ -1434,6 +1449,7 @@ int yaffs_fremovexattr(int fd, const char *name)
 
        return retVal;
 }
+#endif
 
 #ifdef CONFIG_YAFFS_WINCE
 int yaffs_get_wince_times(int fd, unsigned *wctime, unsigned *watime, unsigned *wmtime)
@@ -1859,26 +1875,23 @@ int yaffs_inodecount(const YCHAR *path)
 }
 
 
-
-void yaffs_initialise(yaffsfs_DeviceConfiguration *cfgList)
+void yaffs_AddDevice(yaffs_Device *dev)
 {
+       dev->isMounted = 0;
+       dev->param.removeObjectCallback = yaffsfs_RemoveObjectCallback;
 
-       yaffsfs_DeviceConfiguration *cfg;
-
-       yaffsfs_configurationList = cfgList;
+       if(!dev->devList.next)
+               YINIT_LIST_HEAD(&dev->devList);
 
-       yaffsfs_InitHandles();
-
-       cfg = yaffsfs_configurationList;
+       ylist_add(&dev->devList,&yaffsfs_deviceList);
+}
 
-       while(cfg && cfg->prefix && cfg->dev){
-               cfg->dev->isMounted = 0;
-               cfg->dev->param.removeObjectCallback = yaffsfs_RemoveObjectCallback;
-               cfg++;
-       }
+void yaffs_RemoveDevice(yaffs_Device *dev)
+{
+       ylist_del_init(&dev->devList);
+}
 
 
-}
 
 
 /* Directory search stuff. */