yaffs Add function to get number of open handles
authorCharles Manning <cdhmanning@gmail.com>
Fri, 17 Sep 2010 02:28:14 +0000 (14:28 +1200)
committerCharles Manning <cdhmanning@gmail.com>
Fri, 17 Sep 2010 02:28:14 +0000 (14:28 +1200)
This is not a POSIX function.

Useful for checking if the object is in use.

Signed-off-by: Charles Manning <cdhmanning@gmail.com>
direct/python/yaffsfs.py
direct/yaffsfs.c
direct/yaffsfs.h

index 7a51d3654acb941a360e4b73452b86d74a28355d..5ef7c76120a38e4ae00e549a8d1c1f03b735e01c 100644 (file)
@@ -230,6 +230,11 @@ yaffs_inodecount = ylib.yaffs_inodecount
 yaffs_inodecount.argtypes = [c_char_p]
 yaffs_inodecount.restype = c_int
 
 yaffs_inodecount.argtypes = [c_char_p]
 yaffs_inodecount.restype = c_int
 
+#int yaffs_n_handles(const YCHAR *path)
+yaffs_n_handles = ylib.yaffs_n_handles
+yaffs_n_handles.argtypes = [c_char_p]
+yaffs_n_handles.restype = c_int
+
 #int yaffs_StartUp(void)
 yaffs_StartUp = ylib.yaffs_StartUp
 yaffs_StartUp.argtypes = []
 #int yaffs_StartUp(void)
 yaffs_StartUp = ylib.yaffs_StartUp
 yaffs_StartUp.argtypes = []
index db51171405c6c881a8cd0d91b0e84a2c1fa4e8b1..b709d93fed1edf91332a66f756b3db6bae7ef813 100644 (file)
@@ -110,31 +110,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;
 {
        int i;
        int ret = -1;
-       yaffsfs_Inode *in = NULL;
        
        if(obj)
                obj = yaffs_GetEquivalentObject(obj);
 
        
        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;
        }
        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;
        }
 
        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)
        if(ret>=0){
                in = &yaffsfs_inode[ret];
                if(!in->iObj)
@@ -147,6 +162,17 @@ static int yaffsfs_GetInodeIdForObject(yaffs_Object *obj)
        return ret;
 }
 
        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;
 static void yaffsfs_ReleaseInode(yaffsfs_Inode *in)
 {
        yaffs_Object *obj;
@@ -2223,6 +2249,23 @@ int yaffs_mknod(const YCHAR *pathname, mode_t mode, dev_t dev)
        return -1;
 }
 
        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);
+       if(obj)
+               obj = yaffs_GetEquivalentObject(obj);
+
+       return yaffsfs_CountHandles(obj);
+}
+
 int yaffs_DumpDevStruct(const YCHAR *path)
 {
 #if 0
 int yaffs_DumpDevStruct(const YCHAR *path)
 {
 #if 0
index 7c36dabdd7a7cf5a2bc0b89dc0781ca721fa3b74..425e0f185ad1494562ba59be0804552df4b8933d 100644 (file)
@@ -158,6 +158,7 @@ loff_t yaffs_totalspace(const YCHAR *path);
 
 int yaffs_inodecount(const YCHAR *path);
 
 
 int yaffs_inodecount(const YCHAR *path);
 
+int yaffs_n_handles(const YCHAR *path);
 
 struct yaffs_DeviceStruct;
 void yaffs_AddDevice(struct yaffs_DeviceStruct *dev);
 
 struct yaffs_DeviceStruct;
 void yaffs_AddDevice(struct yaffs_DeviceStruct *dev);