Index: trunk/kernel/mm/mapper.h
===================================================================
--- trunk/kernel/mm/mapper.h	(revision 513)
+++ trunk/kernel/mm/mapper.h	(revision 606)
@@ -1,4 +1,4 @@
 /*
- * mapper.h - Map memory, file or device in process virtual address space.
+ * mapper.h - Kernel cache for FS files or directories definition.
  *
  * Authors   Mohamed Lamine Karaoui (2015)
@@ -72,6 +72,6 @@
 	struct vfs_inode_s * inode;	      /*! owner inode                                     */
     uint32_t             type;        /*! file system type                                */
-	grdxt_t	             radix;	      /*! pages cache implemented as a radix tree         */
-	rwlock_t             lock;        /*! several readers / only one writer               */
+	grdxt_t	             rt; 	      /*! embedded pages cache descriptor (radix tree)    */
+	remote_rwlock_t      lock;        /*! several readers / only one writer               */
 	uint32_t	         refcount;    /*! several vsegs can refer the same file           */
 	xlist_entry_t        vsegs_root;  /*! root of list of vsegs refering this mapper      */
@@ -109,23 +109,43 @@
 
 /*******************************************************************************************
- * This function releases all physical pages allocated for the mapper.
- * It synchronizes all dirty pages (i.e. update the file on disk) if required.
- * The mapper descriptor and the radix tree themselves are released.
+ * This function releases all physical memory allocated for a mapper.
+ * Both the mapper descriptor and the radix tree are released.
+ * It does NOT synchronize dirty pages. Use the vfs_sync_inode() function if required.
  * It must be executed by a thread running in the cluster containing the mapper.
  *******************************************************************************************
  * @ mapper	 : target mapper.
- * @ return 0 if success / return EIO if a dirty page cannot be updated on device.
- ******************************************************************************************/
-error_t mapper_destroy( mapper_t * mapper );
-
-/*******************************************************************************************
- * This function move data between a mapper and a - possibly distributed - user buffer.
- * It must be called by a thread running in the cluster containing the mapper.
- * It is called by the vfs_user_move() function to implement sys_read() and sys_write().
+ ******************************************************************************************/
+void mapper_destroy( mapper_t * mapper );
+
+/*******************************************************************************************
+ * This function load from device a missing page identified by the <page_id> argument
+ * into the mapper identified by the <mapper> local pointer.
+ * It allocates a physical page from the local cluster, initialise by accessing device,
+ * and register the page in the mapper radix tree.
+ * It must be executed by a thread running in the cluster containing the mapper.
+ * WARNING : the calling function mapper_remote_get_page() is supposed to take and release
+ * the lock protecting the mapper in WRITE_MODE.
+ *******************************************************************************************
+ * @ mapper	 : [in]  target mapper.
+ * @ page_id : [in]  missing page index in file.
+ * @ page_xp : [out] buffer for extended pointer on missing page descriptor.
+ * @ return 0 if success / return -1 if a dirty page cannot be updated on device.
+ ******************************************************************************************/
+error_t mapper_handle_miss( mapper_t * mapper,
+                            uint32_t   page_id,
+                            xptr_t   * page_xp );
+
+/*******************************************************************************************
+ * This function move data between a local mapper, and a distributed user buffer.
+ * It must be called by a thread running in cluster containing the mapper.
+ * It is called by the vfs_user_move() to implement sys_read() and sys_write() syscalls.
  * If required, the data transfer is split in "fragments", where one fragment contains 
  * contiguous bytes in the same mapper page.
  * It uses "hal_uspace" accesses to move a fragment to/from the user buffer.
  * In case of write, the dirty bit is set for all pages written in the mapper.
- * The offset in the file descriptor is not modified by this function.
+ * The mapper being an extendable cache, it is automatically extended when required
+ * for both read and write accesses. 
+ * The "offset" field in the file descriptor, and the "size" field in inode descriptor
+ * are not modified by this function.
  *******************************************************************************************
  * @ mapper       : local pointer on mapper.
@@ -134,5 +154,5 @@
  * @ u_buf        : user space pointer on user buffer.
  * @ size         : number of bytes to move.
- * returns O if success / returns EINVAL if error.
+ * returns O if success / returns -1 if error.
  ******************************************************************************************/
 error_t mapper_move_user( mapper_t * mapper,
@@ -142,21 +162,20 @@
                           uint32_t   size );
 
-/*******************************************************************************************
- * This function move data between a mapper and a remote kernel buffer.
- * It must be called by a thread running in the cluster containing the mapper.
+/********************************************************************************************
+ * This function move data between a remote mapper and a remote kernel buffer. 
+ * It can be called by a thread running any cluster. 
  * If required, the data transfer is split in "fragments", where one fragment contains 
  * contiguous bytes in the same mapper page.
  * It uses a "remote_memcpy" to move a fragment to/from the kernel buffer.
  * In case of write, the dirty bit is set for all pages written in the mapper.
- * The offset in the file descriptor is not modified by this function.
- *******************************************************************************************
- * @ mapper       : local pointer on mapper.
+ *******************************************************************************************
+ * @ mapper_xp    : extended pointer on mapper.
  * @ to_buffer    : mapper -> buffer if true / buffer -> mapper if false.
  * @ file_offset  : first byte to move in file.
  * @ buffer_xp    : extended pointer on kernel buffer.
  * @ size         : number of bytes to move.
- * returns O if success / returns EINVAL if error.
- ******************************************************************************************/
-error_t mapper_move_kernel( mapper_t * mapper,
+ * returns O if success / returns -1 if error.
+ ******************************************************************************************/
+error_t mapper_move_kernel( xptr_t     mapper_xp,
                             bool_t     to_buffer,
                             uint32_t   file_offset,
@@ -164,32 +183,63 @@
                             uint32_t   size );
 
-
-/*******************************************************************************************
- * This function removes a physical page from the mapper, update the FS if the page
- * is dirty, and releases the page to PPM. It is called by the mapper_destroy() function.
- * It must be executed by a thread running in the cluster containing the mapper.
- * It takes both the page lock and the mapper lock in WRITE_MODE to release the page.
+/*******************************************************************************************
+ * This function removes a physical page from the mapper, and releases
+ * the page to the local PPM. It is called by the mapper_destroy() function.
+ * It must be executed by a thread running in the cluster containing the mapper.
+ * It takes the mapper lock in WRITE_MODE to update the mapper.
  *******************************************************************************************
  * @ mapper	: local pointer on the mapper.
  * @ page	: pointer on page to remove.
- * @ return 0 if success / return EIO if a dirty page cannot be copied to FS.
- ******************************************************************************************/
-error_t mapper_release_page( mapper_t      * mapper,
-                             struct page_s * page );
-
-/*******************************************************************************************
- * This function searches a physical page descriptor from its index in mapper.
- * It must be executed by a thread running in the cluster containing the mapper.
+ ******************************************************************************************/
+void mapper_release_page( mapper_t      * mapper,
+                          struct page_s * page );
+
+/*******************************************************************************************
+ * This function returns an extended pointer on a mapper page, identified by <page_id>,
+ * index in the file. The - possibly remote - mapper is identified by the <mapper_xp>
+ * argument.  It can be executed by a thread running in any cluster, as it uses remote
+ * access primitives to scan the mapper.
+ * In case of miss, this function takes the mapper lock in WRITE_MODE, and call the 
+ * mapper_handle_miss() to load the missing page from device to mapper, using an RPC 
+ * when the mapper is remote.
+ *******************************************************************************************
+ * @ mapper_xp	: extended pointer on the mapper.
+ * @ page_id	: page index in file
+ * @ returns extended pointer on page base if success / return XPTR_NULL if error.
+ ******************************************************************************************/
+xptr_t mapper_remote_get_page( xptr_t    mapper_xp,
+                               uint32_t  page_id );
+
+/*******************************************************************************************
+ * This function allows to read a single word in a mapper seen as and array of uint32_t.
+ * It has bee designed to support remote access tho the FAT mapper of the FATFS. 
+ * It can be called by any thread running in any cluster.
  * In case of miss, it takes the mapper lock in WRITE_MODE, load the missing
- * page from device to the mapper, and release the mapper lock.
- *******************************************************************************************
- * @ mapper	: local pointer on the mapper.
- * @ index	: page index in file
- * @ returns pointer on page descriptor if success / return NULL if error.
- ******************************************************************************************/
-struct page_s * mapper_get_page( mapper_t * mapper,
-                                 uint32_t   index );
-
- 
+ * page from device to mapper, and release the mapper lock.
+ *******************************************************************************************
+ * @ mapper_xp	: [in]  extended pointer on the mapper.
+ * @ index	    : [in]  32 bits word index in file.
+ * @ p_value    : [out] local pointer on destination buffer.
+ * @ returns 0 if success / return -1 if error.
+ ******************************************************************************************/
+error_t mapper_remote_get_32( xptr_t     mapper_xp,
+                              uint32_t   word_id,
+                              uint32_t * p_value );
+
+/*******************************************************************************************
+ * This function allows to write a single word to a mapper seen as and array of uint32_t.
+ * It has bee designed to support remote access tho the FAT mapper of the FATFS. 
+ * It can be called by any thread running in any cluster.
+ * In case of miss, it takes the mapper lock in WRITE_MODE, load the missing
+ * page from device to mapper, and release the mapper lock.
+ *******************************************************************************************
+ * @ mapper_xp	: [in]  extended pointer on the mapper.
+ * @ index	    : [in]  32 bits word index in file.
+ * @ p_value    : [in]  value to be written.
+ * @ returns 0 if success / return -1 if error.
+ ******************************************************************************************/
+error_t mapper_remote_set_32( xptr_t     mapper_xp,
+                              uint32_t   word_id,
+                              uint32_t   value );
 
 #endif /* _MAPPER_H_ */
