[rtems commit] dosfs: Start scan with a valid data cluster

Sebastian Huber sebh at rtems.org
Fri Feb 15 16:08:44 UTC 2013


Module:    rtems
Branch:    master
Commit:    cd85e841de54575be06ce034882b4d321cef3f81
Changeset: http://git.rtems.org/rtems/commit/?id=cd85e841de54575be06ce034882b4d321cef3f81

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Fri Feb 15 16:57:21 2013 +0100

dosfs: Start scan with a valid data cluster

Simpify the loop.  Set last cluster to an undefined value in case no
free cluster exists.

---

 cpukit/libfs/src/dosfs/fat_fat_operations.c |   42 ++++++++++----------------
 1 files changed, 16 insertions(+), 26 deletions(-)

diff --git a/cpukit/libfs/src/dosfs/fat_fat_operations.c b/cpukit/libfs/src/dosfs/fat_fat_operations.c
index e558cec..172c371 100644
--- a/cpukit/libfs/src/dosfs/fat_fat_operations.c
+++ b/cpukit/libfs/src/dosfs/fat_fat_operations.c
@@ -53,27 +53,24 @@ fat_scan_fat_for_free_clusters(
 {
     int            rc = RC_OK;
     uint32_t       cl4find = 2;
-    uint32_t       next_cln = 0;
-    uint32_t       save_cln = 0;
+    uint32_t       save_cln = FAT_UNDEFINED_VALUE;
     uint32_t       data_cls_val = fs_info->vol.data_cls + 2;
     uint32_t       i = 2;
-    ssize_t        bytes_written;
-
-    *cls_added = 0;
-
-    if (count == 0)
-        return rc;
 
-    if (fs_info->vol.next_cl != FAT_UNDEFINED_VALUE)
+    if (fs_info->vol.next_cl - 2 < fs_info->vol.data_cls)
         cl4find = fs_info->vol.next_cl;
 
+    *cls_added = 0;
+
     /*
      * fs_info->vol.data_cls is exactly the count of data clusters
      * starting at cluster 2, so the maximum valid cluster number is
      * (fs_info->vol.data_cls + 1)
      */
-    while (i < data_cls_val)
+    while (*cls_added != count && i < data_cls_val)
     {
+        uint32_t next_cln = 0;
+
         rc = fat_get_fat_cluster(fs_info, cl4find, &next_cln);
         if ( rc != RC_OK )
         {
@@ -120,7 +117,9 @@ fat_scan_fat_for_free_clusters(
 
             if (zero_fill)
             {
-                bytes_written = fat_cluster_set (fs_info, cl4find, 0, fs_info->vol.bpc, 0);
+                ssize_t bytes_written =
+                    fat_cluster_set(fs_info, cl4find, 0, fs_info->vol.bpc, 0);
+
                 if (fs_info->vol.bpc != bytes_written)
                 {
                     rc = -1;
@@ -130,17 +129,6 @@ fat_scan_fat_for_free_clusters(
 
             save_cln = cl4find;
             (*cls_added)++;
-
-            /* have we satisfied request ? */
-            if (*cls_added == count)
-            {
-                    fs_info->vol.next_cl = save_cln;
-                    if (fs_info->vol.free_cls != FAT_UNDEFINED_VALUE)
-                        fs_info->vol.free_cls -= (*cls_added);
-                *last_cl = save_cln;
-                fat_buf_release(fs_info);
-                return rc;
-            }
         }
         i++;
         cl4find++;
@@ -148,12 +136,14 @@ fat_scan_fat_for_free_clusters(
             cl4find = 2;
     }
 
-        fs_info->vol.next_cl = save_cln;
-        if (fs_info->vol.free_cls != FAT_UNDEFINED_VALUE)
-            fs_info->vol.free_cls -= (*cls_added);
-
     *last_cl = save_cln;
+    fs_info->vol.next_cl = save_cln;
+
+    if (fs_info->vol.free_cls != FAT_UNDEFINED_VALUE)
+        fs_info->vol.free_cls -= (*cls_added);
+
     fat_buf_release(fs_info);
+
     return RC_OK;
 
 cleanup:




More information about the vc mailing list