[rtems commit] dosfs: Write meta-data only if it changed

Sebastian Huber sebh at rtems.org
Thu Oct 23 08:33:54 UTC 2014


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Thu Oct 23 08:21:26 2014 +0200

dosfs: Write meta-data only if it changed

---

 cpukit/libfs/src/dosfs/fat_file.c   |   22 ++++++++++------------
 cpukit/libfs/src/dosfs/fat_file.h   |   31 ++++++++++++++++++++++++++++---
 cpukit/libfs/src/dosfs/msdos_file.c |    4 ++--
 3 files changed, 40 insertions(+), 17 deletions(-)

diff --git a/cpukit/libfs/src/dosfs/fat_file.c b/cpukit/libfs/src/dosfs/fat_file.c
index 1f20926..af71ee2 100644
--- a/cpukit/libfs/src/dosfs/fat_file.c
+++ b/cpukit/libfs/src/dosfs/fat_file.c
@@ -174,20 +174,17 @@ fat_file_update(fat_fs_info_t *fs_info, fat_file_fd_t *fat_fd)
      * if fat-file descriptor is not marked as "removed", synchronize
      * size, first cluster number, write time and date fields of the file
      */
-    if (!FAT_FILE_IS_REMOVED(fat_fd))
+    if (!FAT_FILE_IS_REMOVED(fat_fd) && FAT_FILE_HAS_META_DATA_CHANGED(fat_fd))
     {
         int rc;
 
-        if (fat_fd->fat_file_type == FAT_FILE)
-        {
-            rc = fat_file_write_first_cluster_num(fs_info, fat_fd);
-            if (rc != RC_OK)
-                ret_rc = rc;
+        rc = fat_file_write_first_cluster_num(fs_info, fat_fd);
+        if (rc != RC_OK)
+            ret_rc = rc;
 
-            rc = fat_file_write_file_size(fs_info, fat_fd);
-            if (rc != RC_OK)
-                ret_rc = rc;
-        }
+        rc = fat_file_write_file_size(fs_info, fat_fd);
+        if (rc != RC_OK)
+            ret_rc = rc;
 
         rc = fat_file_write_time_and_date(fs_info, fat_fd);
         if (rc != RC_OK)
@@ -677,8 +674,9 @@ fat_file_extend(
         /* add new chain to the end of existing */
         if ( fat_fd->fat_file_size == 0 )
         {
-            fat_fd->map.disk_cln = fat_fd->cln = chain;
+            fat_fd->map.disk_cln = chain;
             fat_fd->map.file_cln = 0;
+            fat_file_set_first_cluster_num(fat_fd, chain);
         }
         else
         {
@@ -721,7 +719,7 @@ fat_file_extend(
     }
 
     *a_length = new_length;
-    fat_fd->fat_file_size = new_length;
+    fat_file_set_file_size(fat_fd, new_length);
 
     return RC_OK;
 }
diff --git a/cpukit/libfs/src/dosfs/fat_file.h b/cpukit/libfs/src/dosfs/fat_file.h
index b162d8a..1a75cf7 100644
--- a/cpukit/libfs/src/dosfs/fat_file.h
+++ b/cpukit/libfs/src/dosfs/fat_file.h
@@ -93,10 +93,19 @@ typedef struct fat_file_fd_s
 
 } fat_file_fd_t;
 
-#define FAT_FILE_REMOVED  0x01
+#define FAT_FILE_REMOVED 0x01
 
-#define FAT_FILE_IS_REMOVED(p)\
-    (((p)->flags & FAT_FILE_REMOVED) ? 1 : 0)
+#define FAT_FILE_META_DATA_CHANGED 0x02
+
+static inline bool FAT_FILE_IS_REMOVED(const fat_file_fd_t *fat_fd)
+{
+     return (fat_fd->flags & FAT_FILE_REMOVED) != 0;
+}
+
+static inline bool FAT_FILE_HAS_META_DATA_CHANGED(const fat_file_fd_t *fat_fd)
+{
+     return (fat_fd->flags & FAT_FILE_META_DATA_CHANGED) != 0;
+}
 
 /* ioctl macros */
 #define F_CLU_NUM  0x01
@@ -140,20 +149,36 @@ fat_construct_key(
               ((pos->ofs >> 5) & (FAT_DIRENTRIES_PER_SEC512 - 1)) );
 }
 
+static inline void
+fat_file_set_first_cluster_num(fat_file_fd_t *fat_fd, uint32_t cln)
+{
+    fat_fd->cln = cln;
+    fat_fd->flags |= FAT_FILE_META_DATA_CHANGED;
+}
+
+static inline void fat_file_set_file_size(fat_file_fd_t *fat_fd, uint32_t s)
+{
+    fat_fd->fat_file_size = s;
+    fat_fd->flags |= FAT_FILE_META_DATA_CHANGED;
+}
+
 static inline void fat_file_set_ctime(fat_file_fd_t *fat_fd, time_t t)
 {
     fat_fd->ctime = t;
+    fat_fd->flags |= FAT_FILE_META_DATA_CHANGED;
 }
 
 static inline void fat_file_set_mtime(fat_file_fd_t *fat_fd, time_t t)
 {
     fat_fd->mtime = t;
+    fat_fd->flags |= FAT_FILE_META_DATA_CHANGED;
 }
 
 static inline void fat_file_set_ctime_mtime(fat_file_fd_t *fat_fd, time_t t)
 {
     fat_fd->ctime = t;
     fat_fd->mtime = t;
+    fat_fd->flags |= FAT_FILE_META_DATA_CHANGED;
 }
 
 /* Prototypes for "fat-file" operations */
diff --git a/cpukit/libfs/src/dosfs/msdos_file.c b/cpukit/libfs/src/dosfs/msdos_file.c
index b678d84..7a09272 100644
--- a/cpukit/libfs/src/dosfs/msdos_file.c
+++ b/cpukit/libfs/src/dosfs/msdos_file.c
@@ -108,7 +108,7 @@ msdos_file_write(rtems_libio_t *iop,const void *buffer, size_t count)
      */
     iop->offset += ret;
     if (iop->offset > fat_fd->fat_file_size)
-        fat_fd->fat_file_size = iop->offset;
+        fat_file_set_file_size(fat_fd, (uint32_t) iop->offset);
 
     if (ret > 0)
         fat_file_set_ctime_mtime(fat_fd, time(NULL));
@@ -202,7 +202,7 @@ msdos_file_ftruncate(rtems_libio_t *iop, off_t length)
 
     if (rc == RC_OK)
     {
-        fat_fd->fat_file_size = length;
+        fat_file_set_file_size(fat_fd, length);
         fat_file_set_ctime_mtime(fat_fd, time(NULL));
     }
 



More information about the vc mailing list