Index: trunk/kernel/devices/dev_ioc.c
===================================================================
--- trunk/kernel/devices/dev_ioc.c	(revision 605)
+++ trunk/kernel/devices/dev_ioc.c	(revision 614)
@@ -91,5 +91,5 @@
 // This static function is called by dev_ioc_read() & dev_ioc_write() functions.
 // It builds and registers the command in the calling thread descriptor.
-// Then, it registers the calling thead in IOCchdev waiting queue.
+// Then, it registers the calling thead in IOC chdev waiting queue.
 // Finally it blocks on the THREAD_BLOCKED_IO condition and deschedule.
 ////////////////////////////////////i/////////////////////////////////////////////
@@ -108,6 +108,6 @@
     if( chdev_dir.iob )
     {
-        if ( cmd_type == IOC_READ ) dev_mmc_inval( XPTR( local_cxy , buffer ) , count<<9 );
-        else                        dev_mmc_sync ( XPTR( local_cxy , buffer ) , count<<9 );
+        if (cmd_type == IOC_READ) dev_mmc_inval( XPTR( local_cxy , buffer ) , count<<9 );
+        else                      dev_mmc_sync ( XPTR( local_cxy , buffer ) , count<<9 );
     }
 
@@ -162,12 +162,4 @@
 
     return dev_ioc_access( IOC_READ , buffer , lba , count );
-
-#if DEBUG_DEV_IOC_RX
-cycle = (uint32_t)hal_get_cycles();
-if( DEBUG_DEV_IOC_RX < cycle )
-printk("\n[%s] thread[%x,%x] exit / lba  %x / buffer %x / cycle %d\n",
-__FUNCTION__ , this->process->pid, this->trdid, lba, buffer, cycle );
-#endif
-
 }
 
@@ -187,13 +179,67 @@
 
     return dev_ioc_access( IOC_WRITE , buffer , lba , count );
-
-#if DEBUG_DEV_IOC_TX
-cycle = (uint32_t)hal_get_cycles();
-if( DEBUG_DEV_IOC_TX < cycle )
-printk("\n[%s] thread[%x,%x] exit / lba  %x / buffer %x / cycle %d\n",
-__FUNCTION__ , this->process->pid, this->trdid, lba, buffer, cycle );
-#endif
-
 }
+
+
+
+
+
+//////////////////////////////////////////////////////////////////////////////////
+// This static function is called by dev_ioc_sync_read() & dev_ioc_sync_write().
+// It builds and registers the command in the calling thread descriptor, and
+// calls directly the blocking IOC driver command, that returns only when the
+// IO operation is completed.
+////////////////////////////////////i/////////////////////////////////////////////
+error_t dev_ioc_sync_access( uint32_t   cmd_type,
+                             uint8_t  * buffer,
+                             uint32_t   lba,
+                             uint32_t   count )
+{
+    // get pointer on calling thread
+    thread_t * this = CURRENT_THREAD;
+
+    // software L2/L3 cache coherence for memory buffer
+    if( chdev_dir.iob )
+    {
+        if (cmd_type == IOC_SYNC_READ) dev_mmc_inval( XPTR(local_cxy,buffer) , count<<9 );
+        else                           dev_mmc_sync ( XPTR(local_cxy,buffer) , count<<9 );
+    }
+
+    // get extended pointer on IOC[0] chdev
+    xptr_t  ioc_xp = chdev_dir.ioc[0];
+
+// check ioc_xp
+assert( (ioc_xp != XPTR_NULL) , "undefined IOC chdev descriptor" );
+
+    // register command in calling thread descriptor
+    this->ioc_cmd.dev_xp    = ioc_xp;
+    this->ioc_cmd.type      = cmd_type;
+    this->ioc_cmd.buf_xp    = XPTR( local_cxy , buffer );
+    this->ioc_cmd.lba       = lba;
+    this->ioc_cmd.count     = count;
+
+    // get driver command function
+    cxy_t       ioc_cxy = GET_CXY( ioc_xp );
+    chdev_t   * ioc_ptr = GET_PTR( ioc_xp );
+    dev_cmd_t * cmd = (dev_cmd_t *)hal_remote_lpt( XPTR( ioc_cxy , &ioc_ptr->cmd ) );
+
+    // get core local index for the core handling the IOC IRQ
+    thread_t * server = (thread_t *)hal_remote_lpt( XPTR( ioc_cxy , &ioc_ptr->server ) );
+    core_t   * core   = (core_t *)hal_remote_lpt( XPTR( ioc_cxy , &server->core ) );
+    lid_t      lid    = (lid_t)hal_remote_l32( XPTR( ioc_cxy , &core->lid ) );
+
+    // mask the IRQ
+    dev_pic_disable_irq( lid , ioc_xp );
+
+    // call driver function
+    cmd( XPTR( local_cxy , this ) );
+
+    // unmask the IRQ
+    dev_pic_enable_irq( lid , ioc_xp );
+
+    // return I/O operation status from calling thread descriptor
+    return this->ioc_cmd.error;
+
+}  // end ioc_sync_access()
 
 /////////////////////////////////////////////
@@ -202,9 +248,25 @@
                            uint32_t   count )
 {
-    // get pointer on calling thread
-    thread_t * this = CURRENT_THREAD;
 
 #if DEBUG_DEV_IOC_RX
-uint32_t cycle = (uint32_t)hal_get_cycles();
+thread_t * this  = CURRENT_THREAD;
+uint32_t   cycle = (uint32_t)hal_get_cycles();
+if( DEBUG_DEV_IOC_RX < cycle )
+printk("\n[%s] thread[%x,%x] : lba  %x / buffer %x / cycle %d\n",
+__FUNCTION__ , this->process->pid, this->trdid, lba, buffer, cycle );
+#endif
+
+    return dev_ioc_sync_access( IOC_SYNC_READ , buffer , lba , count );
+} 
+
+//////////////////////////////////////////////
+error_t dev_ioc_sync_write( uint8_t  * buffer,
+                            uint32_t   lba,
+                            uint32_t   count )
+{
+
+#if DEBUG_DEV_IOC_RX
+thread_t * this  = CURRENT_THREAD;
+uint32_t   cycle = (uint32_t)hal_get_cycles();
 if( DEBUG_DEV_IOC_RX < cycle )
 printk("\n[%s] thread[%x,%x] enters / lba  %x / buffer %x / cycle %d\n",
@@ -212,48 +274,5 @@
 #endif
 
-    // software L2/L3 cache coherence for memory buffer
-    if( chdev_dir.iob ) dev_mmc_inval( XPTR( local_cxy , buffer ) , count<<9 );
-
-    // get extended pointer on IOC[0] chdev
-    xptr_t  ioc_xp = chdev_dir.ioc[0];
-
-    assert( (ioc_xp != XPTR_NULL) , "undefined IOC chdev descriptor" );
-
-    // register command in calling thread descriptor
-    this->ioc_cmd.dev_xp    = ioc_xp;
-    this->ioc_cmd.type      = IOC_SYNC_READ;
-    this->ioc_cmd.buf_xp    = XPTR( local_cxy , buffer );
-    this->ioc_cmd.lba       = lba;
-    this->ioc_cmd.count     = count;
-
-    // get driver command function
-    cxy_t       ioc_cxy = GET_CXY( ioc_xp );
-    chdev_t   * ioc_ptr = (chdev_t *)GET_PTR( ioc_xp );
-    dev_cmd_t * cmd = (dev_cmd_t *)hal_remote_lpt( XPTR( ioc_cxy , &ioc_ptr->cmd ) );
-
-    // get core local index for the core handling the IOC IRQ
-    thread_t * server = (thread_t *)hal_remote_lpt( XPTR( ioc_cxy , &ioc_ptr->server ) );
-    core_t   * core   = (core_t *)hal_remote_lpt( XPTR( ioc_cxy , &server->core ) );
-    lid_t      lid    = (lid_t)hal_remote_l32( XPTR( ioc_cxy , &core->lid ) );
-
-    // mask the IRQ
-    dev_pic_disable_irq( lid , ioc_xp );
-
-    // call driver function
-    cmd( XPTR( local_cxy , this ) );
-
-    // unmask the IRQ
-    dev_pic_enable_irq( lid , ioc_xp );
-
-#if DEBUG_DEV_IOC_RX
-cycle = (uint32_t)hal_get_cycles();
-if( DEBUG_DEV_IOC_RX < cycle )
-printk("\n[%s] thread[%x,%x] exit / lba  %x / buffer %x / cycle %d\n",
-__FUNCTION__ , this->process->pid, this->trdid, lba, buffer, cycle );
-#endif
-
-    // return I/O operation status from calling thread descriptor
-    return this->ioc_cmd.error;
-
-}  // end ioc_sync_read()
-
+    return dev_ioc_sync_access( IOC_SYNC_WRITE , buffer , lba , count );
+} 
+
