Merge remote-tracking branch 'origin/64_and_32_bit_time_tests'
authorTimothy Manning <codedraftsman@gmail.com>
Thu, 5 Aug 2021 01:12:48 +0000 (13:12 +1200)
committerTimothy Manning <codedraftsman@gmail.com>
Thu, 5 Aug 2021 01:12:48 +0000 (13:12 +1200)
16 files changed:
direct/test-framework/tests/launch_tests.sh
direct/test-framework/yaffs_osglue.c
direct/yaffs_attribs.c
direct/ydirectenv.h
direct/yportenv.h
rtems/Makefile.rtems
rtems/RTEMS_NOTES
rtems/rtems_yaffs.c
rtems/rtems_yaffs_os_glue.c
yaffs_attribs.c
yaffs_endian.h
yaffs_guts.c
yaffs_guts.h
yaffs_tagsmarshall.c
yportenv_multi.h
yportenv_single.h

index b2041d3f1b62767aaa98d075b9b00503afe4bd8c..9b7c38d26820f287185a99fb3f02a6773ab2be32 100755 (executable)
@@ -11,8 +11,10 @@ LAUNCHDIR=`pwd`
 RUNDIR=`pwd`/tmp
 mkdir $RUNDIR
 
+# Check if RUNDIR is mounted, if not, mount as tmpfs
+# because we don't want to hammer the disk.
 if [ -z "$(mount | grep $RUNDIR)" ]; then
-sudo mount -t tmpfs -osize=2G none $RUNDIR
+sudo mount -t tmpfs -osize=7G none $RUNDIR
 sudo chmod a+wr $RUNDIR
 fi
 
@@ -30,3 +32,4 @@ xterm  -e "$LAUNCHDIR/manage_m18_test.sh  2 $iterations"&
 xterm  -e "$LAUNCHDIR/manage_nand_test.sh  0 $iterations"&
 xterm  -e "$LAUNCHDIR/manage_nand_test.sh  1 $iterations"&
 xterm  -e "$LAUNCHDIR/manage_nand_test.sh  2 $iterations"&
+xterm  -e "$LAUNCHDIR/manage_nand_test.sh  3 $iterations"&
index 2cc18bbdcb6bdec25eafef419df5caac894ed42a..94ca24dfd225a73bde9924f6c51a73672ed1c89b 100644 (file)
@@ -106,7 +106,13 @@ static void *bg_gc_func(void *dummy)
 
                while ((dev = yaffs_next_dev()) != NULL) {
                        result = yaffs_do_background_gc_reldev(dev, urgent);
-                       if (result > 0)
+
+                       /* result is 1 if more than half the free space is
+                        * erased.
+                        * If less than half the free space is erased then it is
+                        * worth doing another background_gc operation sooner.
+                        */
+                       if (result == 0)
                                next_urgent = 1;
                }
 
index 5486bdd142b9512ab1cabe65b14cec0f5d772c30..e798a88b3c3f96281ae54df9e6d80a7f6283e88f 100644 (file)
@@ -15,6 +15,7 @@
 
 void yaffs_load_attribs(struct yaffs_obj *obj, struct yaffs_obj_hdr *oh)
 {
+
 #ifdef CONFIG_YAFFS_WINCE
        obj->win_atime[0] = oh->win_atime[0];
        obj->win_ctime[0] = oh->win_ctime[0];
@@ -25,9 +26,11 @@ void yaffs_load_attribs(struct yaffs_obj *obj, struct yaffs_obj_hdr *oh)
 #else
        obj->yst_uid = oh->yst_uid;
        obj->yst_gid = oh->yst_gid;
-       obj->yst_atime = oh->yst_atime;
-       obj->yst_mtime = oh->yst_mtime;
-       obj->yst_ctime = oh->yst_ctime;
+
+        obj->yst_ctime = yaffs_oh_ctime_fetch(oh);
+        obj->yst_mtime = yaffs_oh_mtime_fetch(oh);
+        obj->yst_atime = yaffs_oh_atime_fetch(oh);
+
        obj->yst_rdev = oh->yst_rdev;
 #endif
 }
@@ -45,9 +48,11 @@ void yaffs_load_attribs_oh(struct yaffs_obj_hdr *oh, struct yaffs_obj *obj)
 #else
        oh->yst_uid = obj->yst_uid;
        oh->yst_gid = obj->yst_gid;
-       oh->yst_atime = obj->yst_atime;
-       oh->yst_mtime = obj->yst_mtime;
-       oh->yst_ctime = obj->yst_ctime;
+
+        yaffs_oh_ctime_load(obj, oh);
+        yaffs_oh_mtime_load(obj, oh);
+        yaffs_oh_atime_load(obj, oh);
+
        oh->yst_rdev = obj->yst_rdev;
 #endif
 }
@@ -81,8 +86,8 @@ void yaffs_load_current_time(struct yaffs_obj *obj, int do_a, int do_c)
 
        obj->yst_mtime = Y_CURRENT_TIME;
        if (do_a)
-               obj->yst_atime = obj->yst_atime;
+               obj->yst_atime = obj->yst_mtime;
        if (do_c)
-               obj->yst_ctime = obj->yst_atime;
+               obj->yst_ctime = obj->yst_mtime;
 #endif
 }
index 08fc04d3812a9cb1276479a046d943f32d3820a3..ae2e23cbbfd04e903d47c70fd823130d05a0b4bc 100644 (file)
@@ -29,7 +29,7 @@ void yaffs_bug_fn(const char *file_name, int line_no);
 
 #define BUG() do { yaffs_bug_fn(__FILE__, __LINE__); } while (0)
 
-#ifdef YAFFS_USE_32_BIT_TIME_T
+#ifdef CONFIG_YAFFS_USE_32_BIT_TIME_T
        #define YTIME_T u32
 #else
        #define YTIME_T u64
index ee27f73cee0c7011057c456102985d4f0ec92088..5a79f93583b963d715b0dee9a0b533363c1511e1 100644 (file)
@@ -30,6 +30,7 @@
 #define CONFIG_YAFFS_PROVIDE_DEFS 1
 #define CONFIG_YAFFSFS_PROVIDE_VALUES 1
 #define CONFIG_YAFFS_DEFINES_TYPES 1
+#define CONFIG_YAFFS_USE_32_BIT_TIME_T 1
 #define NO_Y_INLINE 1
 #define loff_t off_t
 
index 4803a9fb21b5319b3e071f0c5691276f5025784b..0741179a7dd2ee36524218d511da71a792cfa903 100644 (file)
@@ -24,6 +24,7 @@ CFLAGS += $(DEPFLAGS) $(GCCFLAGS)
 # Files to be made into local symlinks
 YCORE_SYMLINKS = \
        yaffs_ecc.c \
+       yaffs_cache.c \
        yaffs_endian.c \
        yaffs_guts.c \
        yaffs_packedtags1.c \
@@ -39,6 +40,7 @@ YCORE_SYMLINKS = \
        yaffs_verify.c \
        yaffs_summary.c \
        yaffs_tagsmarshall.c\
+       yaffs_cache.h \
        yaffs_ecc.h \
        yaffs_guts.h \
        yaffs_packedtags1.h \
@@ -93,6 +95,7 @@ LIB = $(BUILDDIR)/libyaffs2.a
 LIB_PIECES = yaffs_ecc \
        yaffs_endian \
        yaffs_guts \
+       yaffs_cache \
        yaffs_packedtags1 \
        yaffs_tagscompat \
        yaffs_tagsmarshall\
index 0366b0533879592ee5bedf194b881fbfe2c9762d..5e89b1394d56037b6d3965c74ecc69717fb74176 100644 (file)
@@ -28,38 +28,23 @@ $make -f Makefile.rtems install
 Building test application
 
 
-$ cd rtems-y-test/
+$ cd rtems-y-test/basic-test
+$ make
 
-
-
-Running 
-
-$  sparc-rtems5-sis hello_world_c/o-optimize/hello.exe
+$ sparc-rtems5-sis o-optimize/yaffs-rtems-test.exe 
 
  SIS - SPARC/RISCV instruction simulator 2.20,  copyright Jiri Gaisler 2019
  Bug-reports to jiri@gaisler.se
 
  ERC32 emulation enabled
 
- Loaded hello_world_c/o-optimize/hello.exe, entry 0x02000000
+ Loaded o-optimize/yaffs-rtems-test.exe, entry 0x02000000
 sis> go
 resuming at 0x02000000
-
-
-*** HELLO WORLD TEST ***
-Hello World 123
-*** END OF HELLO WORLD TEST ***
-
-*** FATAL ***
-fatal source: 5 (RTEMS_FATAL_SOURCE_EXIT)
-fatal code: 0 (0x00000000)
-RTEMS version: 5.0.0.e22554535796fc29a7ed7c5e2338128e324a621d-modified
-RTEMS tools: 7.5.0 20191114 (RTEMS 5, RSB 5 (599c4d7c87fa), Newlib d14714c69)
-executing thread ID: 0x08a010001
-executing thread name: UI1 
-cpu 0 in error mode (tt = 0x101)
-   125619  0200c0e0:  91d02000   ta  0x0
-sis> 
+Starting
+Created simulated flash device 0x2d203c8
+yaffs: 0 blocks to be sorted...
+....
 
 
 Running with GDB
index 461132074baf6d004212c98b4b99de591a5b3158..bb6edf1467871feed61567b09a14c24d2118816c 100644 (file)
@@ -281,9 +281,9 @@ static int ryfs_utime(
        obj = yaffs_get_equivalent_obj(obj);
        if (obj != NULL) {
                obj->dirty = 1;
-               obj->yst_atime = (u32) actime;
-               obj->yst_mtime = (u32) modtime;
-               obj->yst_ctime = (u32) time(NULL);
+               obj->yst_atime = actime;
+               obj->yst_mtime = modtime;
+               obj->yst_ctime = time(NULL);
        } else {
                errno = EIO;
                rv = -1;
@@ -680,7 +680,7 @@ static int ryfs_symlink(const rtems_filesystem_location_info_t *parent_loc,
        mode = S_IFLNK |
                ((S_IRWXU | S_IRWXG | S_IRWXO) & ~rtems_filesystem_umask);
 
-       created_link = yaffs_create_symlink(parent_dir, name, mode, 
+       created_link = yaffs_create_symlink(parent_dir, name, mode,
                                                geteuid(), getegid(), target);
 
        if (created_link != NULL) {
index 467d8b18f8b8bc6e814a9c15025450debcc63329..8999dff29bb9b73f6dd2db858e76c634efb6675b 100644 (file)
@@ -39,7 +39,7 @@ void yaffsfs_free(void *ptr)
        free(ptr);
 }
 
-u32 yaffsfs_CurrentTime(void)
+YTIME_T yaffsfs_CurrentTime(void)
 {
        return time(NULL);
 }
index a9ced27250aa0f86f4c079b8d5227b861dc61eba..c441185a68dcb07a45b1bb2b829ffda8afe3ac12 100644 (file)
@@ -29,9 +29,11 @@ void yaffs_load_attribs(struct yaffs_obj *obj, struct yaffs_obj_hdr *oh)
 {
        obj->yst_uid = oh->yst_uid;
        obj->yst_gid = oh->yst_gid;
-       obj->yst_atime = oh->yst_atime;
-       obj->yst_mtime = oh->yst_mtime;
-       obj->yst_ctime = oh->yst_ctime;
+
+       obj->yst_ctime = yaffs_oh_ctime_fetch(oh);
+       obj->yst_mtime = yaffs_oh_mtime_fetch(oh);
+       obj->yst_atime = yaffs_oh_atime_fetch(oh);
+
        obj->yst_rdev = oh->yst_rdev;
 }
 
@@ -39,9 +41,11 @@ void yaffs_load_attribs_oh(struct yaffs_obj_hdr *oh, struct yaffs_obj *obj)
 {
        oh->yst_uid = obj->yst_uid;
        oh->yst_gid = obj->yst_gid;
-       oh->yst_atime = obj->yst_atime;
-       oh->yst_mtime = obj->yst_mtime;
-       oh->yst_ctime = obj->yst_ctime;
+
+       yaffs_oh_ctime_load(obj, oh);
+       yaffs_oh_mtime_load(obj, oh);
+       yaffs_oh_atime_load(obj, oh);
+
        oh->yst_rdev = obj->yst_rdev;
 
 }
@@ -105,7 +109,6 @@ int yaffs_set_attribs(struct yaffs_obj *obj, struct iattr *attr)
        yaffs_update_oh(obj, NULL, 1, 0, 0, NULL);
 
        return YAFFS_OK;
-
 }
 
 int yaffs_get_attribs(struct yaffs_obj *obj, struct iattr *attr)
index 0f1ef0491e73e29d334aadde52fab103f679048d..09bcb29c4aa2379a00d7f93b7406a57baf8f2877 100644 (file)
@@ -37,12 +37,14 @@ static inline u64 swap_u64(u64 val)
               ((val << 56) & 0xff00000000000000);
 }
 
-//YTIME_T can be a 32 or 64 bit number.
-#if YAFFS_USE_32_BIT_TIME_T
-       #define swap_ytime_t( val ) swap_u32(val)
-#else
-       #define swap_ytime_t( val ) swap_u64(val)
-#endif
+static inline YTIME_T swap_ytime_t(YTIME_T val)
+{
+
+       if (sizeof(YTIME_T) == sizeof(u64))
+               return swap_u64(val);
+       else
+               return swap_u32(val);
+}
 
 //swap a signed 32 bit integer.
 #define swap_s32(val) \
index 4621dfa2117b33fc78abb105c389246074551b9c..41ceb5b526caca8d3a644ca1ae01eeeb55b2b52a 100644 (file)
@@ -3019,8 +3019,10 @@ static void yaffs_check_obj_details_loaded(struct yaffs_obj *in)
 
        result = yaffs_rd_chunk_tags_nand(dev, in->hdr_chunk, buf, &tags);
 
-       if (result == YAFFS_FAIL)
+       if (result == YAFFS_FAIL) {
+               yaffs_release_temp_buffer(dev, buf);
                return;
+       }
 
        oh = (struct yaffs_obj_hdr *)buf;
 
@@ -3203,7 +3205,6 @@ int yaffs_update_oh(struct yaffs_obj *in, const YCHAR *name, int force,
                bi->has_shrink_hdr = 1;
        }
 
-
        return new_chunk_id;
 }
 
@@ -4888,6 +4889,80 @@ int yaffs_get_n_free_chunks(struct yaffs_dev *dev)
        return n_free;
 }
 
+/*
+ * Marshalling functions to get the appropriate time values saved
+ * and restored to/from obj headers.
+ *
+ * Note that the WinCE time fields are used to store the 32-bit values.
+ */
+
+static void yaffs_oh_time_load(u32 *yst_time, u32 *win_time, YTIME_T timeval)
+{
+       u32 upper;
+       u32 lower;
+
+       lower = timeval & 0xffffffff;
+       if (sizeof(YTIME_T) > sizeof(u32))
+               upper = (timeval >> 32) & 0xffffffff;
+       else
+               upper = 0;
+
+       *yst_time = lower;
+       win_time[0] = lower;
+       win_time[1] = upper;
+}
+
+static YTIME_T yaffs_oh_time_fetch(const u32 *yst_time, const u32 *win_time)
+{
+       u32 upper;
+       u32 lower;
+
+       if (win_time[1] == 0xffffffff) {
+               upper = 0;
+               lower = *yst_time;
+       } else {
+               upper = win_time[1];
+               lower = win_time[0];
+       }
+       if (sizeof(YTIME_T) > sizeof(u32)) {
+               u64 ret;
+               ret = (((u64)upper) << 32) | lower;
+               return (YTIME_T) ret;
+
+       } else
+               return (YTIME_T) lower;
+}
+
+YTIME_T yaffs_oh_ctime_fetch(struct yaffs_obj_hdr *oh)
+{
+       return yaffs_oh_time_fetch(&oh->yst_ctime, oh->win_ctime);
+}
+
+YTIME_T yaffs_oh_mtime_fetch(struct yaffs_obj_hdr *oh)
+{
+       return yaffs_oh_time_fetch(&oh->yst_mtime, oh->win_mtime);
+}
+
+YTIME_T yaffs_oh_atime_fetch(struct yaffs_obj_hdr *oh)
+{
+       return yaffs_oh_time_fetch(&oh->yst_atime, oh->win_atime);
+}
+
+void yaffs_oh_ctime_load(struct yaffs_obj *obj, struct yaffs_obj_hdr *oh)
+{
+       yaffs_oh_time_load(&oh->yst_ctime, oh->win_ctime, obj->yst_ctime);
+}
+
+void yaffs_oh_mtime_load(struct yaffs_obj *obj, struct yaffs_obj_hdr *oh)
+{
+       yaffs_oh_time_load(&oh->yst_mtime, oh->win_mtime, obj->yst_mtime);
+}
+
+void yaffs_oh_atime_load(struct yaffs_obj *obj, struct yaffs_obj_hdr *oh)
+{
+       yaffs_oh_time_load(&oh->yst_atime, oh->win_atime, obj->yst_atime);
+}
+
 
 /*
  * Marshalling functions to get loff_t file sizes into and out of
index 22381f9c9fc695fd5741e5c9104cdc8448b0a4cf..74ded0be526f1f44c91ce90a6d54cc52bb338cf0 100644 (file)
@@ -354,6 +354,12 @@ struct yaffs_obj_hdr {
 
        u32 yst_rdev;   /* stuff for block and char devices (major/min) */
 
+       /*
+        * WinCE times are no longer just used to store WinCE times.
+        * They are also used to store 64-bit times.
+        * We actually store and read the times in both places and use
+        * the best we can.
+        */
        u32 win_ctime[2];
        u32 win_atime[2];
        u32 win_mtime[2];
@@ -1063,6 +1069,18 @@ void yaffs_count_blocks_by_state(struct yaffs_dev *dev, int bs[10]);
 int yaffs_find_chunk_in_file(struct yaffs_obj *in, int inode_chunk,
                                    struct yaffs_ext_tags *tags);
 
+/*
+ *Time marshalling functions
+ */
+
+YTIME_T yaffs_oh_ctime_fetch(struct yaffs_obj_hdr *oh);
+YTIME_T yaffs_oh_mtime_fetch(struct yaffs_obj_hdr *oh);
+YTIME_T yaffs_oh_atime_fetch(struct yaffs_obj_hdr *oh);
+
+void yaffs_oh_ctime_load(struct yaffs_obj *obj, struct yaffs_obj_hdr *oh);
+void yaffs_oh_mtime_load(struct yaffs_obj *obj, struct yaffs_obj_hdr *oh);
+void yaffs_oh_atime_load(struct yaffs_obj *obj, struct yaffs_obj_hdr *oh);
+
 /*
  * Define LOFF_T_32_BIT if a 32-bit LOFF_T is being used.
  * Not serious if you get this wrong - you might just get some warnings.
index d568208e91bd53ece6b685707ecca481c693c183..397715dbc9eb00f27a79afbd3a5910352e2768bc 100644 (file)
@@ -100,8 +100,12 @@ static int yaffs_tags_marshall_read(struct yaffs_dev *dev,
                BUG();
 
 
-       if (retval == YAFFS_FAIL)
+       if (retval == YAFFS_FAIL) {
+               if (local_data)
+                       yaffs_release_temp_buffer(dev, data);
+
                return YAFFS_FAIL;
+       }
 
        if (dev->param.inband_tags) {
                if (tags) {
index 68c239c0743513a6076bfec3df48a77edb886eec..fa5601b82bba915f6806841dc9a555f0620bf30d 100644 (file)
@@ -53,6 +53,8 @@
 #define YUCHAR unsigned char
 #define _Y(x)     x
 
+#define YTIME_T u64
+
 #define YAFFS_LOSTNFOUND_NAME          "lost+found"
 #define YAFFS_LOSTNFOUND_PREFIX                "obj"
 
index 436feae3c179c0496823aa4a10567e1c758d85f4..b915433521d6bfff5aba3ed2f04e25a16c955f11 100644 (file)
@@ -34,6 +34,8 @@
 #define YCHAR char
 #define YUCHAR unsigned char
 #define _Y(x)     x
+#define YTIME_T u64
+
 
 #define YAFFS_LOSTNFOUND_NAME          "lost+found"
 #define YAFFS_LOSTNFOUND_PREFIX                "obj"