Index: trunk/kernel/fs/fatfs.h
===================================================================
--- trunk/kernel/fs/fatfs.h	(revision 625)
+++ trunk/kernel/fs/fatfs.h	(revision 626)
@@ -173,13 +173,17 @@
 /*****************************************************************************************
  * This structure defines a FATFS specific context (extension to VFS context).
- * This extension is replicated in all clusters.
- *
- * WARNING : Almost all fields are constant values, but the <free_cluster_hint> and
- * <free_clusters> are shared variables. All kernel instances use the variables
- * in cluster 0, using the <free_lock> remote busy_lock for exclusive access.
+ * This fatfs context is replicated in all clusters.
+ *
+ * WARNING : Almost all fields are constant values, but the <free_cluster_hint>, 
+ * <free_clusters> and <free_lock> are shared variables. Moreover, the <fs_info_buffer>,
+ * only allocated in cluster 0, contains a copy of the FS_INFO sector. It is used by all
+ * kernel instances to synchronously update the free clusters info on IOC device.
+ * For these four variables, all kernel instances must use the values in cluster 0, 
+ * and take the <free_lock> stored in this cluster for exclusive access to FAT.
  ****************************************************************************************/
 
 typedef struct fatfs_ctx_s
 {
+    /* read-only constants replicated in all clusters                                   */
     uint32_t            fat_sectors_count;     /*! number of sectors in FAT region      */
     uint32_t            bytes_per_sector;      /*! number of bytes per sector           */
@@ -190,7 +194,10 @@
     uint32_t            root_dir_cluster;      /*! cluster index for  root directory    */
     xptr_t              fat_mapper_xp;         /*! extended pointer on FAT mapper       */
+
+    /* shared variables (only the copy in FAT cluster must be used)                     */
     uint32_t            free_cluster_hint;     /*! cluster[hint+1] is the first free    */
     uint32_t            free_clusters;         /*! free clusters number                 */
-    remote_queuelock_t  free_lock;             /*! exclusive access to hint & number    */
+    remote_queuelock_t  free_lock;             /*! exclusive access to FAT              */
+    uint8_t           * fs_info_buffer;        /*! local pointer on FS_INFO buffer      */
 }
 fatfs_ctx_t;
@@ -224,19 +231,22 @@
 
 /*****************************************************************************************
- * This function display the content of the local FATFS context.
- *****************************************************************************************
- * @ ctx  : local pointer on the context. 
- ****************************************************************************************/
-void fatfs_ctx_display( fatfs_ctx_t * ctx );
-
-/*****************************************************************************************
- * This function displays the content of a part of the File Allocation Table.
- * It loads the requested page fom device to mapper if required.
- *****************************************************************************************
- * @ page_id   : page index in FAT mapper (one page is 4 Kbytes).
- * @ nentries  : number of entries (one entry is 4 bytes).
+ * This function display the content of the FATFS context copy in cluster identified
+ * by the <cxy> argument.
+ * This function can be called by a thread running in any cluster.
+ *****************************************************************************************
+ * @ cxy       :  target cluster identifier.
+ ****************************************************************************************/
+void fatfs_display_ctx( cxy_t cxy );
+
+/*****************************************************************************************
+ * This function access the FAT mapper to display one page of the File Allocation Table.
+ * It loads the requested page fom IOC device to FAT mapper if required.
+ * This function can be called by a thread running in any cluster.
+ *****************************************************************************************
+ * @ page_id     : page index in FAT mapper (one page is 4 Kbytes).
+ * @ nb_entries  : number of entries (one entry is 4 bytes).
  ****************************************************************************************/
 void fatfs_display_fat( uint32_t  page_id,
-                        uint32_t  nentries );
+                        uint32_t  nb_entries );
 
 
@@ -254,6 +264,7 @@
 
 /*****************************************************************************************
- * This function access the boot device, and initialises the local FATFS context
- * from informations contained in the boot record. 
+ * This function access the boot device, and initialises the local FATFS context,
+ * from informations contained in the boot record. This initialisation includes the
+ * creation of the FAT mapper in cluster 0.
  *****************************************************************************************
  * @ vfs_ctx   : local pointer on VFS context for FATFS.
@@ -271,8 +282,8 @@
  * This function implements the generic vfs_fs_add_dentry() function for the FATFS.
  *****************************************************************************************
- * This function updates a directory identified by the <inode> argument
+ * This function updates a directory mapper identified by the <inode> argument
  * to add a new directory entry identified by the <dentry> argument.
- * All modified pages in directory mapper are synchronously updated on IOC device.
- * It must be called by a thread running in the cluster containing the inode.
+ * All modified pages in the directory mapper are synchronously updated on IOC device.
+ * It must be called by a thread running in the cluster containing the directory inode.
  *
  * Implementation note : this function works in two steps:
@@ -313,11 +324,11 @@
  * This function implements the generic vfs_fs_new_dentry() function for the FATFS.
  *****************************************************************************************
- * It initializes a new inode/dentry couple in Inode Tree, attached to the directory
- * identified by the <parent_inode> argument. The directory entry is identified
- * by the <name> argument. The child inode descriptor, identified by the <child_inode_xp>
- * argument, and the associated dentry descriptor must have been previously allocated.
- * It scan the parent mapper to find the <name> argument.
- * It set the "type", "size", and "extend" fields in the child inode descriptor.
- * It set the " extend" field in the dentry descriptor.
+ * It scan a parent directory mapper, identified by the <parent_inode> argument to find
+ * a directory entry identified by the <name> argument.  In case of success, it 
+ * initializes the inode/dentry couple, identified by the  <child_inode_xp> argument
+ * in the Inode Tree. The child inode descriptor, and the associated dentry descriptor
+ * must have been previously allocated by the caller.
+ * - It set the "type", "size", and "extend" fields in the child inode descriptor.
+ * - It set the " extend" field in the dentry descriptor.
  * It must be called by a thread running in the cluster containing the parent inode.
  *****************************************************************************************
@@ -325,5 +336,5 @@
  * @ name            : child name.
  * @ child_inode_xp  : extended pointer on remote child inode (file or directory).
- * @ return 0 if success / return ENOENT if child not found.
+ * @ return 0 if success / return -1 if child not found.
  ****************************************************************************************/
 error_t fatfs_new_dentry( struct vfs_inode_s * parent_inode,
@@ -392,5 +403,5 @@
  *****************************************************************************************
  * @ inode   : local pointer on inode.
- * @ return 0 if success / return EIO if failure during device access. 
+ * @ return 0 if success / return -1 if failure during IOC device access. 
  ****************************************************************************************/
 error_t fatfs_sync_inode( struct vfs_inode_s * inode );
@@ -399,5 +410,5 @@
  * This function implements the generic vfs_fs_sync_fat() function for the FATFS.
  *****************************************************************************************
- * It updates the FATFS on the IOC device for the FAT itself.
+ * It updates the FAT on the IOC device for the FAT itself.
  * It scan all clusters registered in the FAT mapper, and copies from mapper to device 
  * each page marked as dirty.
@@ -408,5 +419,5 @@
  *  variables defining the smallest/largest dirty page index in FAT mapper... 
  *****************************************************************************************
- * @ return 0 if success / return EIO if failure during device access.
+ * @ return 0 if success / return -1 if failure during IOC device access.
  ****************************************************************************************/
 error_t fatfs_sync_fat( void );
@@ -415,9 +426,12 @@
  * This function implements the generic vfs_fs_sync_fsinfo() function for the FATFS.
  *****************************************************************************************
- * It updates the FS_INFO sector on the IOC device. 
- * It copies the <free_cluster_hint> and <free_clusters> variables from
- * the FATFS context in cluster 0 to the FS_INFO sector on device. 
- *****************************************************************************************
- * @ return 0 if success / return EIO if failure during device access.
+ * It checks the current values of the "free_clusters" and "free_cluster_hint" variables
+ * in the FS_INFO sector on IOC, versus the values stored in the fatfs context.
+ * As these values are synchronously updated on IOC device at each modification, 
+ * it does nothing if the values are equal. It updates the FS_INFO sector on IOC device,
+ * and displays a warning message on TXT0 if they are not equal.
+ * This function can be called by any thread running in any cluster. 
+ *****************************************************************************************
+ * @ return 0 if success / return -1 if failure during IOC device access.
  ****************************************************************************************/
 error_t fatfs_sync_free_info( void );
@@ -430,7 +444,7 @@
  * It can be called by a thread running in any cluster, as it uses remote access
  * primitives when the FAT mapper is remote. It takes the queuelock stored in the FATFS
- * context (located in the same cluster as the FAT mapper itself), to get exclusive
- * access to the FAT. It uses the <free_cluster_hint> and <free_clusters> variables 
- * stored in this FATFS context.
+ * context located in the same cluster as the FAT mapper itself, to get exclusive
+ * access to the FAT. It uses and updates the <free_cluster_hint> and <free_clusters>
+ * variables stored in this FATFS context.
  * - it updates the <free_cluster_hint> and <free_clusters> variables in FATFS context.
  * - it updates the FAT mapper (handling miss from IOC device if required). 
@@ -445,5 +459,5 @@
 /*****************************************************************************************
  * This function implements the generic vfs_fs_release_inode() function for the FATFS.
- *****************************************************************************************
+  *****************************************************************************************
  * It releases all clusters allocated to a file/directory identified by the <inode_xp>
  * argument. All released clusters are marked FREE_CLUSTER in the FAT mapper. 
@@ -466,6 +480,6 @@
  * The pointer on the mapper and the page index in file are found in the page descriptor.
  * It is used for both a regular file/directory mapper, and the FAT mapper.
- * For the FAT mapper, it access the FATFS to get the location on IOC device.
- * For a regular file, it access the FAT mapper to get the cluster index on IOC device.
+ * - For the FAT mapper, it updates the FAT region on IOC device.
+ * - For a regular file, it access the FAT mapper to get the cluster index on IOC device.
  * It can be called by any thread running in any cluster.
  *
