From: Timothy Manning Date: Thu, 3 Jun 2021 22:21:27 +0000 (+1200) Subject: Added endianness support for YTIME_T X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs2.git;a=commitdiff_plain;h=99c3936c718cd7bd83a9edbc4327768215872b73 Added endianness support for YTIME_T Added a inline function that handles swapping the Endianness for YTIME_T. Signed-off-by: Timothy Manning --- diff --git a/direct/test-framework/basic-tests/dtest.c b/direct/test-framework/basic-tests/dtest.c index bafd6f8..60d1749 100644 --- a/direct/test-framework/basic-tests/dtest.c +++ b/direct/test-framework/basic-tests/dtest.c @@ -18,9 +18,11 @@ #include #include + #include "yaffsfs.h" #include "yaffs_guts.h" /* Only for dumping device innards */ +#include "yaffs_endian.h" /*For testing the swap_u64 macro */ extern int yaffs_trace_mask; @@ -2711,6 +2713,50 @@ void basic_utime_test(const char *mountpt) } +void print_binary(u64 val){ + int count = 0; + for (int i= 63; i>=0; i --) { + if (count == 0){ + printf(" "); + } + if ((((u64)1) << i) & val) { + printf("1"); + } else { + printf("0"); + } + count = (count +1) % 8; + } +} + +void testing_swap_u64() { + int numberOfFailedTests = 0; + for (int i =0; i < 8; i ++) { + u64 startingNumber = (0xffLLu << (i*8)); + u64 expected = (0xffLLu << (64 - (i*8) -8)); + u64 converted = swap_u64(startingNumber); + if (converted != expected) { + numberOfFailedTests ++; + printf("numbers do not match.\n"); + printf("0xff\t\t\t"); + print_binary(0xff); + printf("\nStarting Number \t"); + print_binary(startingNumber); + printf("\nExpecting \t\t"); + print_binary(expected); + printf("\nConverted \t\t"); + print_binary(converted); + + printf("\n"); + } + } + if (numberOfFailedTests){ + printf("testing_swap failed %d tests\n", numberOfFailedTests); + } else { + printf("testing_swap_u64 passed all tests\n"); + } +} + + void size_utime_test(const char *mountpt) { char name[100]; @@ -3642,6 +3688,7 @@ int main(int argc, char *argv[]) //readdir_test("/nand"); basic_utime_test("/nand"); + testing_swap_u64(); size_utime_test("/nand"); //case_insensitive_test("/nand"); diff --git a/yaffs_endian.c b/yaffs_endian.c index 6103f4e..571a35f 100644 --- a/yaffs_endian.c +++ b/yaffs_endian.c @@ -42,9 +42,9 @@ void yaffs_do_endian_oh(struct yaffs_dev *dev, struct yaffs_obj_hdr *oh) oh->yst_uid = swap_u32(oh->yst_uid); oh->yst_gid = swap_u32(oh->yst_gid); - oh->yst_atime = swap_u32(oh->yst_atime); - oh->yst_mtime = swap_u32(oh->yst_mtime); - oh->yst_ctime = swap_u32(oh->yst_ctime); + oh->yst_atime = swap_ytime_t(oh->yst_atime); + oh->yst_mtime = swap_ytime_t(oh->yst_mtime); + oh->yst_ctime = swap_ytime_t(oh->yst_ctime); oh->file_size_low = swap_u32(oh->file_size_low); diff --git a/yaffs_endian.h b/yaffs_endian.h index 8c27189..0f1ef04 100644 --- a/yaffs_endian.h +++ b/yaffs_endian.h @@ -25,6 +25,26 @@ static inline u32 swap_u32(u32 val) ((val <<24) & 0xff000000); } +static inline u64 swap_u64(u64 val) +{ + return ((val >> 56) & 0x00000000000000ff) | + ((val >> 40) & 0x000000000000ff00) | + ((val >> 24) & 0x0000000000ff0000) | + ((val >> 8) & 0x00000000ff000000) | + ((val << 8) & 0x000000ff00000000) | + ((val << 24) & 0x0000ff0000000000) | + ((val << 40) & 0x00ff000000000000) | + ((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 + +//swap a signed 32 bit integer. #define swap_s32(val) \ (s32)(swap_u32((u32)(val)))