Index: trunk/kernel/kern/process.h
===================================================================
--- trunk/kernel/kern/process.h	(revision 657)
+++ trunk/kernel/kern/process.h	(revision 662)
@@ -70,18 +70,19 @@
 /*********************************************************************************************
  * This structure defines an array of extended pointers on the open file descriptors
- * for a given process. We use an extended pointer because the open file descriptors
- * are always stored in the same cluster as the inode associated to the file.
- * A free entry in this array contains the XPTR_NULL value.
+ * for a given process. The file descriptors are always stored in the same cluster 
+ * as the inode associated to the file. A free entry in this array contains XPTR_NULL.
  * The array size is defined by the CONFIG_PROCESS_FILE_MAX_NR parameter.
  *
- * NOTE: - Only the fd_array[] in the reference process contains a complete list of open
+ * NOTE: - Only the fd_array[] in the reference process contains the complete list of open
  *         files, and is protected by the lock against concurrent access.
- *       - the fd_array[] in a process copy is simply a cache containing a subset of the
- *         open files to speed the fdid to xptr translation, but the "lock" and "current
+ *       - the fd_array[] in a process copy is not used.
+ *         open files to speed the fdid to xptr translation, but the "lock" and "max"
  *         fields are not significant for these copies.
- *       - the modifications made by the process_fd_remove() function are done in the
- *         reference cluster in all process_copies.
- *       - The modifications made by the process_fd_register() function are done in the
- *         reference cluster, and in the cluster containing the calling thread.
+ *       - The modifications made by the process_fd_register() function are only done
+ *         in the owner cluster.
+ *       - The modifications made by the process_fd_remove() function are done in the
+ *         owner cluster, and in all process_copies.
+ *       - In case of miss on the local fd_array, the process_fd_get_xptr() access the
+ *         owner cluster fd_array, and update the fd_array local copy.
  ********************************************************************************************/
 
@@ -89,5 +90,5 @@
 {
 	remote_queuelock_t lock;                              /*! lock protecting fd_array      */
-    uint32_t           current;                           /*! current number of open files  */
+    uint32_t           max;                               /*! max non-free slot index       */
 	xptr_t             array[CONFIG_PROCESS_FILE_MAX_NR]; /*! open file descriptors         */
 }
@@ -278,5 +279,5 @@
 /*********************************************************************************************
  * This function releases all memory allocated for a process descriptor in the local cluster,
- * including memory allocated for embedded substructures (fd_array, vmm, etc).
+ * including memory allocated for embedded sub-structures (fd_array, vmm, etc).
  * The local th_tbl[] array must be empty.
  *********************************************************************************************
@@ -428,25 +429,35 @@
 
 
-/********************   File Management Operations   ****************************************/
+/********************     fd_array  operations       ****************************************/
+
+
+/*********************************************************************************************
+ * This function returns a printable string for a file descriptor type.
+ * These file types are defined in the <vfs.h> file.
+ *********************************************************************************************
+ * @ type     : [in] file type.
+ ********************************************************************************************/
+char * process_fd_type_str( uint32_t type );
 
 /*********************************************************************************************
  * This function initializes all entries of the local fd_array as empty.
  *********************************************************************************************
- * @ process  : pointer on the local process descriptor.
+ * @ process  : [in] pointer on the local process descriptor.
  ********************************************************************************************/
 void process_fd_init( process_t * process );
 
 /*********************************************************************************************
- * This function allocates a free slot in the fd_array of the reference process descriptor
- * identified by the <process_xp> argument, register the <file_xp> argument in the
- * allocated slot, and return the slot index in the <fdid> buffer.
- * Note: we must use the reference process descriptor, because the reference fd_array is
- * contained in the reference cluster.  It can be called by any thread in any cluster.
- * It takes the lock protecting the reference fd_array against concurrent accesses.
+ * This function allocates a free slot in the owner cluster process fd_array identified
+ * by the <process_xp> argument, register the <file_xp> argument in the allocated slot,
+ * and return the slot index in the <fdid> buffer.
+ * It can be called by any thread in any cluster.
+ * It takes the lock protecting the fd_array against concurrent accesses.
+ * Note: we must use the owner process descriptor, because this fd_array must
+ * contain all files open by a given process.
  *********************************************************************************************
  * @ process_xp : [in]  extended pointer on client reference process.
  * @ file_xp    : [in]  extended pointer on the file descriptor to be registered.
- * @ fdid       : [out] buffer for fd_array slot index.
- * @ return 0 if success / return EMFILE if array full.
+ * @ fdid       : [out] buffer for allocated fd_array slot index.
+ * @ return 0 if success / return -1 if array full.
  ********************************************************************************************/
 error_t process_fd_register( xptr_t      process_xp,
@@ -455,13 +466,14 @@
 
 /*********************************************************************************************
- * This function uses as many remote accesses as required, to reset an entry in fd_array[],
+ * This function uses as many remote accesses as required, to reset one fd_array[] entry,
  * identified by the <fdid> argument, in all clusters containing a copy of the 
  * process descriptor, identified by the <process_xp> argument. 
+ * It can be called by any thread in any cluster.
+ * It takes the lock protecting the fd_array against concurrent accesses.
  * Note: we must use the owner process descriptor, because only this owner cluster contains
- * the list of process copies. It can be called by any thread in any cluster.
- * It takes the lock protecting the reference fd_array against concurrent accesses.
- *********************************************************************************************
- * @ process  : [in] pointer on the local process descriptor.
- * @ fdid     : [in] file descriptor index in the fd_array.
+ * the complete list of process copies.
+ *********************************************************************************************
+ * @ process_xp  : [in] extended pointer on the owner process descriptor.
+ * @ fdid        : [in] file descriptor index in the fd_array.
  ********************************************************************************************/
 void process_fd_remove( xptr_t     process_xp,
@@ -469,18 +481,44 @@
 
 /*********************************************************************************************
- * This function returns an extended pointer on a file descriptor identified by its index
- * in fd_array. It can be called by any thread running in any cluster.
+ * This function scan the fd_array to close all files (or sockets) registered in the process
+ * fd_array identified by the <process_xp> argument. It call the sys_close() function for 
+ * each registered entry, to release all allocated memory, and reset this entry in all
+ * process descriptors copies.
+ * It takes the lock protecting the fd_array against concurrent accesses.
+ * Note: we must use the owner process descriptor, because only this owner cluster contains
+ * the complete list of process copies.
+ *********************************************************************************************
+ * @ process_xp  : [in] extended pointer on the owner process descriptor.
+ ********************************************************************************************/
+void process_fd_clean_all( xptr_t process_xp );
+
+/*********************************************************************************************
+ * This function returns an extended pointer on a file descriptor identified by its <fdid>
+ * index in fd_array of the local process, identified by the <process> argument.
+ * It can be called by any thread running in any cluster.
  * It accesses first the local process descriptor. In case of local miss, it takes
  * the lock protecting the reference fd_array, and access the reference process descriptor.
- * It updates the local fd_array when the file descriptor exists in reference cluster.
- * It takes the lock protecting the reference fd_array against concurrent accesses.
- * The file descriptor refcount is not incremented.
- *********************************************************************************************
- * @ process  : pointer on the local process descriptor.
+ * It updates the local fd_array when the file descriptor exists in owner cluster. 
+ * It release the lock protecting the reference fd_array.
+ *********************************************************************************************
+ * @ process  : local pointer on local process descriptor.
  * @ fdid     : file descriptor index in the fd_array.
  * @ return extended pointer on file descriptor if success / return XPTR_NULL if not found.
  ********************************************************************************************/
-xptr_t process_fd_get_xptr( process_t * process,
-                            uint32_t    fdid );
+xptr_t process_fd_get_xptr_from_local( process_t * process,
+                                       uint32_t    fdid );
+
+/*********************************************************************************************
+ * This function returns an extended pointer on a file descriptor identified by its <fdid>
+ * index in the fd_array of the owner process, identified by the <process_xp> argument,
+ * accessing directly the fd_array in owner cluster. It can be called by any thread running
+ * in any cluster, but the local fd_array copy is not updated.
+ *********************************************************************************************
+ * @ process_xp  : extended pointer on the owner process descriptor.
+ * @ fdid        : file descriptor index in the fd_array.
+ * @ return extended pointer on file descriptor if success / return XPTR_NULL if not found.
+ ********************************************************************************************/
+xptr_t process_fd_get_xptr_from_owner( xptr_t      process_xp,
+                                       uint32_t    fdid );
 
 /*********************************************************************************************
@@ -508,5 +546,12 @@
 bool_t process_fd_array_full( void );
 
-
+/*********************************************************************************************
+ * This debug function diplays on the kernel terminal TXT0 detailed informations on the
+ * set of file descriptors registered in the fd_array of a process descriptor identified
+ * by the <process_xp> argument. 
+ *********************************************************************************************
+ * @ process_xp    : [in] extended pointer on process descriptor.
+ ********************************************************************************************/
+void process_fd_display( xptr_t process_xp );
 
 /********************   Thread Related Operations   *****************************************/
