yaffs Improve hard link handling in yaffs direct
[yaffs2.git] / direct / yaffsfs.c
index 2b64bc6be9ee8390b2ed8280ec61d6d5d686352b..22948881b5081e1eb8b8da97674b952f6c852a2d 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 yaffs_Object *yaffsfs_FindObject(yaffs_Object *relativeDirectory, const YCHAR *path, int symDepth, int getEquiv);
 static void yaffsfs_RemoveObjectCallback(yaffs_Object *obj);
 
 unsigned int yaffs_wr_attempts;
@@ -60,30 +53,35 @@ typedef struct {
 } yaffsfs_Inode;
 
 typedef struct{
-       __u8    readOnly:1;
+       __u8    reading:1;
+       __u8    writing:1;
        __u8    append:1;
-       int     inodeId:13;     /* Index to corresponding yaffsfs_Inode */
-       int     useCount:16;    /* Use count for this handle */
+       __u8    shareRead:1;
+       __u8    shareWrite:1;
+       int     inodeId:12;     /* Index to corresponding yaffsfs_Inode */
+       int     useCount:10;    /* Use count for this handle */
        __u32 position;         /* current position in file */
 }yaffsfs_Handle;
 
 static yaffsfs_Inode yaffsfs_inode[YAFFSFS_N_HANDLES];
 static yaffsfs_Handle yaffsfs_handle[YAFFSFS_N_HANDLES];
+static int yaffsfs_handlesInitialised;
 
 /*
  * yaffsfs_InitHandle
  * Inilitalise handle management on start-up.
  */
 
-static int yaffsfs_InitHandles(void)
+static void yaffsfs_InitHandles(void)
 {
        int i;
+       if(yaffsfs_handlesInitialised)
+                return;
+
        memset(yaffsfs_inode,0,sizeof(yaffsfs_inode));
        memset(yaffsfs_handle,0,sizeof(yaffsfs_handle));
        for(i = 0; i < YAFFSFS_N_HANDLES; i++)
                yaffsfs_handle[i].inodeId = -1;
-
-       return 0;
 }
 
 yaffsfs_Handle *yaffsfs_GetHandlePointer(int h)
@@ -115,31 +113,46 @@ yaffs_Object *yaffsfs_GetHandleObject(int handle)
 }
 
 /*
- * yaffsfs_GetInodeIdForObject
- * Grab an inode entry when opening a new inode.
+ * yaffsfs_FindInodeIdForObject
+ * Find the inode entry for an object, if it exists.
  */
 
-static int yaffsfs_GetInodeIdForObject(yaffs_Object *obj)
+static int yaffsfs_FindInodeIdForObject(yaffs_Object *obj)
 {
        int i;
        int ret = -1;
-       yaffsfs_Inode *in = NULL;
        
        if(obj)
                obj = yaffs_GetEquivalentObject(obj);
 
-       /* Look for it. If we can't find it then make one */
+       /* Look for it in open inode table*/
        for(i = 0; i < YAFFSFS_N_HANDLES && ret < 0; i++){
                if(yaffsfs_inode[i].iObj == obj)
                        ret = i;
        }
+       return ret;
+}
+
+/*
+ * yaffsfs_GetInodeIdForObject
+ * Grab an inode entry when opening a new inode.
+ */
+static int yaffsfs_GetInodeIdForObject(yaffs_Object *obj)
+{
+       int i;
+       int ret;
+       yaffsfs_Inode *in = NULL;
+       
+       if(obj)
+               obj = yaffs_GetEquivalentObject(obj);
+
+        ret = yaffsfs_FindInodeIdForObject(obj);
 
        for(i = 0; i < YAFFSFS_N_HANDLES && ret < 0; i++){
                if(!yaffsfs_inode[i].iObj)
                        ret = i;
        }
-       
-       
+
        if(ret>=0){
                in = &yaffsfs_inode[ret];
                if(!in->iObj)
@@ -152,6 +165,17 @@ static int yaffsfs_GetInodeIdForObject(yaffs_Object *obj)
        return ret;
 }
 
+
+static int yaffsfs_CountHandles(yaffs_Object *obj)
+{
+       int i = yaffsfs_FindInodeIdForObject(obj);
+
+       if(i >= 0)
+               return yaffsfs_inode[i].count;
+       else
+               return 0;
+}
+
 static void yaffsfs_ReleaseInode(yaffsfs_Inode *in)
 {
        yaffs_Object *obj;
@@ -253,7 +277,7 @@ int yaffsfs_Match(YCHAR a, YCHAR b)
 
 int yaffsfs_IsPathDivider(YCHAR ch)
 {
-       YCHAR *str = YAFFS_PATH_DIVIDERS;
+       const YCHAR *str = YAFFS_PATH_DIVIDERS;
 
        while(*str){
                if(*str == ch)
@@ -264,6 +288,10 @@ int yaffsfs_IsPathDivider(YCHAR ch)
        return 0;
 }
 
+
+
+YLIST_HEAD(yaffsfs_deviceList);
+
 /*
  * yaffsfs_FindDevice
  * yaffsfs_FindRoot
@@ -273,10 +301,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 +315,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 +349,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;
 }
@@ -391,15 +428,18 @@ static yaffs_Object *yaffsfs_FindRoot(const YCHAR *path, YCHAR **restOfPath)
 static yaffs_Object *yaffsfs_FollowLink(yaffs_Object *obj,int symDepth)
 {
 
+       if(obj)
+               obj = yaffs_GetEquivalentObject(obj);
+
        while(obj && obj->variantType == YAFFS_OBJECT_TYPE_SYMLINK){
                YCHAR *alias = obj->variant.symLinkVariant.alias;
 
                if(yaffsfs_IsPathDivider(*alias))
                        /* Starts with a /, need to scan from root up */
-                       obj = yaffsfs_FindObject(NULL,alias,symDepth++);
+                       obj = yaffsfs_FindObject(NULL,alias,symDepth++,1);
                else
                        /* Relative to here, so use the parent of the symlink as a start */
-                       obj = yaffsfs_FindObject(obj->parent,alias,symDepth++);
+                       obj = yaffsfs_FindObject(obj->parent,alias,symDepth++,1);
        }
        return obj;
 }
@@ -463,8 +503,7 @@ static yaffs_Object *yaffsfs_DoFindDirectory(yaffs_Object *startDir,
                        else{
                                dir = yaffs_FindObjectByName(dir,str);
 
-                               while(dir && dir->variantType == YAFFS_OBJECT_TYPE_SYMLINK)
-                                       dir = yaffsfs_FollowLink(dir,symDepth);
+                               dir = yaffsfs_FollowLink(dir,symDepth);
 
 
                                if(dir && dir->variantType != YAFFS_OBJECT_TYPE_DIRECTORY)
@@ -485,17 +524,22 @@ static yaffs_Object *yaffsfs_FindDirectory(yaffs_Object *relativeDirectory,
 /*
  * yaffsfs_FindObject turns a path for an existing object into the object
  */
-static yaffs_Object *yaffsfs_FindObject(yaffs_Object *relativeDirectory, const YCHAR *path,int symDepth)
+static yaffs_Object *yaffsfs_FindObject(yaffs_Object *relativeDirectory, const YCHAR *path,int symDepth,int getEquiv)
 {
        yaffs_Object *dir;
+       yaffs_Object *obj;
        YCHAR *name;
 
        dir = yaffsfs_FindDirectory(relativeDirectory,path,&name,symDepth);
 
        if(dir && *name)
-               return yaffs_FindObjectByName(dir,name);
+               obj = yaffs_FindObjectByName(dir,name);
+       else
+               obj = dir;
+       if(getEquiv)
+               obj = yaffs_GetEquivalentObject(obj);
 
-       return dir;
+       return obj;
 }
 
 
@@ -527,16 +571,24 @@ int yaffs_dup(int fd)
 
 }
 
-int yaffs_open(const YCHAR *path, int oflag, int mode)
+int yaffs_open_sharing(const YCHAR *path, int oflag, int mode, int sharing)
 {
        yaffs_Object *obj = NULL;
        yaffs_Object *dir = NULL;
        YCHAR *name;
        int handle = -1;
-       yaffsfs_Handle *h = NULL;
+       yaffsfs_Handle *yh = NULL;
        int openDenied = 0;
        int symDepth = 0;
        int errorReported = 0;
+       __u8 shareRead = (sharing & YAFFS_SHARE_READ) ?  1 : 0;
+       __u8 shareWrite = (sharing & YAFFS_SHARE_WRITE) ? 1 : 0;
+       __u8 sharedReadAllowed;
+       __u8 sharedWriteAllowed;
+       __u8 alreadyReading;
+       __u8 alreadyWriting;
+       __u8 readRequested;
+       __u8 writeRequested;
 
        /* O_EXCL only has meaning if O_CREAT is specified */
        if(!(oflag & O_CREAT))
@@ -555,24 +607,28 @@ int yaffs_open(const YCHAR *path, int oflag, int mode)
 
        if(handle >= 0){
 
-               h = yaffsfs_GetHandlePointer(handle);
-
+               yh = yaffsfs_GetHandlePointer(handle);
 
                /* try to find the exisiting object */
-               obj = yaffsfs_FindObject(NULL,path,0);
-
-               if(obj && obj->variantType == YAFFS_OBJECT_TYPE_SYMLINK)
-                       obj = yaffsfs_FollowLink(obj,symDepth++);
+               obj = yaffsfs_FindObject(NULL,path,0,1);
 
-               if(obj)
-                       obj = yaffs_GetEquivalentObject(obj);
+               obj = yaffsfs_FollowLink(obj,symDepth++);
 
-               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
@@ -596,6 +652,43 @@ int yaffs_open(const YCHAR *path, int oflag, int mode)
                           !(obj->yst_mode & S_IWRITE))
                                openDenied = 1;
 
+                       /* Check sharing of an existing object. */
+                       {
+                               yaffsfs_Handle *hx;
+                               int i;
+                               sharedReadAllowed = 1;
+                               sharedWriteAllowed = 1;
+                               alreadyReading = 0;
+                               alreadyWriting = 0;
+                               for( i = 0; i < YAFFSFS_N_HANDLES; i++){
+                                       hx = &yaffsfs_handle[i];
+                                       if(hx->useCount > 0 &&
+                                               hx->inodeId >= 0 &&
+                                               yaffsfs_inode[hx->inodeId].iObj == obj){
+                                               if(!hx->shareRead)
+                                                       sharedReadAllowed = 0;
+                                               if(!hx->shareWrite)
+                                                       sharedWriteAllowed = 0;
+                                               if(hx->reading)
+                                                       alreadyReading = 1;
+                                               if(hx->writing)
+                                                       alreadyWriting = 0;
+                                       }
+                               }
+
+                               readRequested = (oflag & (O_RDWR | O_RDONLY)) ? 1 : 0;
+                               writeRequested = (oflag & (O_RDWR | O_WRONLY)) ? 1 : 0;
+
+                               if((!sharedReadAllowed && readRequested)|| 
+                                       (!shareRead  && alreadyReading) ||
+                                       (!sharedWriteAllowed && writeRequested) ||
+                                       (!shareWrite && alreadyWriting)){
+                                       openDenied = 1;
+                                       yaffsfs_SetError(-EBUSY);
+                                       errorReported=1;
+                               }
+                       }
+
                } else if((oflag & O_CREAT)) {
                        /* Let's see if we can create this file */
                        dir = yaffsfs_FindDirectory(NULL,path,&name,0);
@@ -620,15 +713,18 @@ int yaffs_open(const YCHAR *path, int oflag, int mode)
                                 */
                        }
                        
-                       h->inodeId = inodeId;
-                       h->readOnly = (oflag & (O_WRONLY | O_RDWR)) ? 0 : 1;
-                       h->append =  (oflag & O_APPEND) ? 1 : 0;
-                       h->position = 0;
+                       yh->inodeId = inodeId;
+                       yh->reading = (oflag & (O_RDONLY | O_RDWR)) ? 1 : 0;
+                       yh->writing = (oflag & (O_WRONLY | O_RDWR)) ? 1 : 0;
+                       yh->append =  (oflag & O_APPEND) ? 1 : 0;
+                       yh->position = 0;
+                       yh->shareRead = shareRead;
+                       yh->shareWrite = shareWrite;
 
                        /* Hook inode to object */
                         obj->myInode = (void*) &yaffsfs_inode[inodeId];
 
-                        if((oflag & O_TRUNC) && !h->readOnly)
+                        if((oflag & O_TRUNC) && yh->writing)
                                 yaffs_ResizeFile(obj,0);
                } else {
                        yaffsfs_PutHandle(handle);
@@ -645,6 +741,11 @@ int yaffs_open(const YCHAR *path, int oflag, int mode)
        return handle;
 }
 
+int yaffs_open(const YCHAR *path, int oflag, int mode)
+{
+       return yaffs_open_sharing(path, oflag, mode, YAFFS_SHARE_READ | YAFFS_SHARE_WRITE);
+}
+
 int yaffs_Dofsync(int fd,int datasync)
 {
        yaffsfs_Handle *h = NULL;
@@ -822,7 +923,7 @@ int yaffsfs_do_write(int fd, const void *vbuf, unsigned int nbyte, int isPwrite,
                /* bad handle */
                yaffsfs_SetError(-EBADF);
                totalWritten = -1;
-       } else if( h && obj && (h->readOnly || obj->myDev->readOnly)){
+       } else if( h && obj && (!h->writing || obj->myDev->readOnly)){
                yaffsfs_SetError(-EINVAL);
                totalWritten=-1;
        } else if( h && obj){
@@ -897,9 +998,7 @@ int yaffs_truncate(const YCHAR *path,off_t newSize)
 
        yaffsfs_Lock();
 
-       obj = yaffsfs_FindObject(NULL,path,0);
-       if(obj)
-               obj = yaffs_GetEquivalentObject(obj);
+       obj = yaffsfs_FindObject(NULL,path,0,1);
 
        if(!obj)
                yaffsfs_SetError(-ENOENT);
@@ -991,7 +1090,7 @@ int yaffsfs_DoUnlink(const YCHAR *path,int isDirectory)
 
        yaffsfs_Lock();
 
-       obj = yaffsfs_FindObject(NULL,path,0);
+       obj = yaffsfs_FindObject(NULL,path,0,0);
        dir = yaffsfs_FindDirectory(NULL,path,&name,0);
        if(!dir)
                yaffsfs_SetError(-ENOTDIR);
@@ -1042,7 +1141,7 @@ int yaffs_rename(const YCHAR *oldPath, const YCHAR *newPath)
 
        olddir = yaffsfs_FindDirectory(NULL,oldPath,&oldname,0);
        newdir = yaffsfs_FindDirectory(NULL,newPath,&newname,0);
-       obj = yaffsfs_FindObject(NULL,oldPath,0);
+       obj = yaffsfs_FindObject(NULL,oldPath,0,0);
 
        if(!olddir || !newdir || !obj) {
                /* bad file */
@@ -1087,11 +1186,10 @@ static int yaffsfs_DoStat(yaffs_Object *obj,struct yaffs_stat *buf)
 {
        int retVal = -1;
 
-       if(obj)
-               obj = yaffs_GetEquivalentObject(obj);
+       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 */
 
@@ -1133,7 +1231,8 @@ static int yaffsfs_DoStatOrLStat(const YCHAR *path, struct yaffs_stat *buf,int d
        int retVal = -1;
 
        yaffsfs_Lock();
-       obj = yaffsfs_FindObject(NULL,path,0);
+
+       obj = yaffsfs_FindObject(NULL,path,0,1);
 
        if(!doLStat && obj)
                obj = yaffsfs_FollowLink(obj,0);
@@ -1180,7 +1279,7 @@ int yaffs_fstat(int fd, struct yaffs_stat *buf)
        return retVal;
 }
 
-
+#ifndef CONFIG_YAFFS_WINCE
 /* xattrib functions */
 
 
@@ -1191,7 +1290,8 @@ static int yaffs_do_setxattr(const YCHAR *path, const char *name, const void *da
        int retVal = -1;
 
        yaffsfs_Lock();
-       obj = yaffsfs_FindObject(NULL,path,0);
+
+       obj = yaffsfs_FindObject(NULL,path,0,1);
 
        if(follow)
                obj = yaffsfs_FollowLink(obj,0);
@@ -1255,7 +1355,8 @@ static int yaffs_do_getxattr(const YCHAR *path, const char *name, void *data, in
        int retVal = -1;
 
        yaffsfs_Lock();
-       obj = yaffsfs_FindObject(NULL,path,0);
+
+       obj = yaffsfs_FindObject(NULL,path,0,1);
 
        if(follow)
                obj = yaffsfs_FollowLink(obj,0);
@@ -1318,7 +1419,8 @@ static int yaffs_do_listxattr(const YCHAR *path, char *data, int size, int follo
        int retVal = -1;
 
        yaffsfs_Lock();
-       obj = yaffsfs_FindObject(NULL,path,0);
+
+       obj = yaffsfs_FindObject(NULL,path,0,1);
 
        if(follow)
                obj = yaffsfs_FollowLink(obj,0);
@@ -1380,7 +1482,8 @@ static int yaffs_do_removexattr(const YCHAR *path, const char *name, int follow)
        int retVal = -1;
 
        yaffsfs_Lock();
-       obj = yaffsfs_FindObject(NULL,path,0);
+
+       obj = yaffsfs_FindObject(NULL,path,0,1);
 
        if(follow)
                obj = yaffsfs_FollowLink(obj,0);
@@ -1434,6 +1537,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)
@@ -1538,7 +1642,8 @@ int yaffs_access(const YCHAR *path, int amode)
        int retval = 0;
 
        yaffsfs_Lock();
-       obj = yaffsfs_FindObject(NULL,path,0);
+
+       obj = yaffsfs_FindObject(NULL,path,0,1);
 
        if(obj) {
                int access_ok = 1;
@@ -1574,7 +1679,8 @@ int yaffs_chmod(const YCHAR *path, mode_t mode)
        int retVal = -1;
 
        yaffsfs_Lock();
-       obj = yaffsfs_FindObject(NULL,path,0);
+
+       obj = yaffsfs_FindObject(NULL,path,0,1);
 
        if(!obj)
                yaffsfs_SetError(-ENOENT);
@@ -1621,7 +1727,10 @@ int yaffs_mkdir(const YCHAR *path, mode_t mode)
 
        yaffsfs_Lock();
        parent = yaffsfs_FindDirectory(NULL,path,&name,0);
-       if(parent && parent->myDev->readOnly){
+       if(parent && yaffs_strnlen(name,5) == 0){
+               /* Trying to make the root itself */
+               yaffsfs_SetError(-EEXIST);
+       } else if(parent && parent->myDev->readOnly){
                yaffsfs_SetError(-EINVAL);
        } else {
                if(parent)
@@ -1644,6 +1753,14 @@ int yaffs_mkdir(const YCHAR *path, mode_t mode)
        return retVal;
 }
 
+void * yaffs_getdev(const YCHAR *path)
+{
+       yaffs_Device *dev=NULL;
+       YCHAR *dummy;
+       dev = yaffsfs_FindDevice(path,&dummy);
+       return (void *)dev;
+}
+
 int yaffs_mount2(const YCHAR *path,int readOnly)
 {
        int retVal=-1;
@@ -1654,6 +1771,9 @@ int yaffs_mount2(const YCHAR *path,int readOnly)
        T(YAFFS_TRACE_ALWAYS,(TSTR("yaffs: Mounting %s" TENDSTR),path));
 
        yaffsfs_Lock();
+
+       yaffsfs_InitHandles();
+
        dev = yaffsfs_FindDevice(path,&dummy);
        if(dev){
                if(!dev->isMounted){
@@ -1695,7 +1815,7 @@ int yaffs_sync(const YCHAR *path)
                         
                         yaffs_FlushEntireDeviceCache(dev);
                         yaffs_CheckpointSave(dev);
-                        
+                        retVal = 0;
                         
                 } else
                         /* todo error - not mounted. */
@@ -1846,7 +1966,7 @@ int yaffs_inodecount(const YCHAR *path)
        yaffsfs_Lock();
        dev = yaffsfs_FindDevice(path,&dummy);
        if(dev  && dev->isMounted) {
-          int nObjects = dev->nObjectsCreated - dev->nFreeObjects;
+          int nObjects = dev->nObjects;
           if(nObjects > dev->nHardLinks)
                retVal = nObjects - dev->nHardLinks;
        }
@@ -1859,26 +1979,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;
+       if(!dev->devList.next)
+               YINIT_LIST_HEAD(&dev->devList);
 
-       yaffsfs_configurationList = cfgList;
-
-       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. */
@@ -1978,7 +2095,7 @@ yaffs_DIR *yaffs_opendir(const YCHAR *dirname)
 
        yaffsfs_Lock();
 
-       obj = yaffsfs_FindObject(NULL,dirname,0);
+       obj = yaffsfs_FindObject(NULL,dirname,0,1);
 
        if(obj && obj->variantType == YAFFS_OBJECT_TYPE_DIRECTORY){
 
@@ -2106,7 +2223,7 @@ int yaffs_readlink(const YCHAR *path, YCHAR *buf, int bufsiz)
 
        yaffsfs_Lock();
 
-       obj = yaffsfs_FindObject(NULL,path,0);
+       obj = yaffsfs_FindObject(NULL,path,0,1);
 
        if(!obj) {
                yaffsfs_SetError(-ENOENT);
@@ -2135,8 +2252,8 @@ int yaffs_link(const YCHAR *oldpath, const YCHAR *newpath)
 
        yaffsfs_Lock();
 
-       obj = yaffsfs_FindObject(NULL,oldpath,0);
-       target = yaffsfs_FindObject(NULL,newpath,0);
+       obj = yaffsfs_FindObject(NULL,oldpath,0,1);
+       target = yaffsfs_FindObject(NULL,newpath,0,0);
 
        if(!obj) {
                yaffsfs_SetError(-ENOENT);
@@ -2194,6 +2311,21 @@ int yaffs_mknod(const YCHAR *pathname, mode_t mode, dev_t dev)
        return -1;
 }
 
+
+
+/*
+ * yaffs_n_handles()
+ * Returns number of handles attached to the object
+ */
+int yaffs_n_handles(const YCHAR *path)
+{
+       yaffs_Object *obj;
+
+       obj = yaffsfs_FindObject(NULL,path,0,1);
+
+       return yaffsfs_CountHandles(obj);
+}
+
 int yaffs_DumpDevStruct(const YCHAR *path)
 {
 #if 0