From 3cef60408bd7e721ff582e07b79adf0ce1dde804 Mon Sep 17 00:00:00 2001 From: Ivan Baravy Date: Wed, 28 Dec 2022 15:06:15 +0000 Subject: [PATCH] Use 64bit time_t, add XFS bigtime test, allow atime and mtime testing --- TODO | 1 + img/makefile | 35 ++++++++++++++- makefile | 2 +- shell.c | 68 +++++++++++++++++++++--------- test/055_#xfs_#bigtime_all.ref.log | 50 ++++++++++++++++++++++ test/055_#xfs_#bigtime_all.t | 11 +++++ test/makefile | 2 +- umka.asm | 4 +- umka.h | 3 +- 9 files changed, 149 insertions(+), 27 deletions(-) create mode 100644 test/055_#xfs_#bigtime_all.ref.log create mode 100644 test/055_#xfs_#bigtime_all.t diff --git a/TODO b/TODO index 98ef5bc..3ec265e 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,5 @@ multithreaded: kofu one.t two.t +make mkfs.xfs use config file via -c option compare with reference XFS implementation stressing via ref impl diff --git a/img/makefile b/img/makefile index 243287d..b7cbacf 100644 --- a/img/makefile +++ b/img/makefile @@ -4,6 +4,7 @@ MKFILEPATTERN=../tools/mkfilepattern DIRTOTEST=python3 ../tools/dirtotest.py MOUNT_OPT=-t xfs TEMP_DIR:=$(shell mktemp -d) +XFS_MIN_PART_SIZE=300MiB all: s05k s4k unicode v5 kolibri.img fat32_test0.img coverage rmdir $(TEMP_DIR) @@ -14,7 +15,7 @@ s4k: xfs_v4_ftype0_s4k_b4k_n8k.img unicode: xfs_v4_unicode.img -v5: xfs_v5_ftype1_s05k_b2k_n8k.img xfs_v5_files_s05k_b4k_n8k.img +v5: xfs_v5_ftype1_s05k_b2k_n8k.img xfs_v5_files_s05k_b4k_n8k.img xfs_bigtime.img coverage: jfs.img xfs_borg_bit.img xfs_short_dir_i8.img @@ -36,8 +37,38 @@ jfs.img: parted --script $@ mktable gpt parted --script --align optimal $@ mkpart primary 1MiB 100% +xfs_bigtime.img: + fallocate -l $(XFS_MIN_PART_SIZE) $@ + mkfs.xfs -m bigtime=1 $@ + sudo mount $(MOUNT_OPT) $@ $(TEMP_DIR) + sudo chown $$USER $(TEMP_DIR) -R +# + mkdir $(TEMP_DIR)/dira + mkdir $(TEMP_DIR)/dirb + mkdir $(TEMP_DIR)/dirc + mkdir $(TEMP_DIR)/dird + mkdir $(TEMP_DIR)/dire + mkdir $(TEMP_DIR)/dirf + touch -a -t 200504031122.33 $(TEMP_DIR)/dira + touch -m -t 200504031122.44 $(TEMP_DIR)/dira + touch -a -t 199504031122.33 $(TEMP_DIR)/dirb + touch -m -t 203504031122.44 $(TEMP_DIR)/dirb + touch -a -t 197504031122.33 $(TEMP_DIR)/dirc + touch -m -t 207504031122.44 $(TEMP_DIR)/dirc + touch -a -t 192504031122.33 $(TEMP_DIR)/dird + touch -m -t 210504031122.44 $(TEMP_DIR)/dird + touch -a -t 190004031122.33 $(TEMP_DIR)/dire + touch -m -t 220504031122.44 $(TEMP_DIR)/dire + touch -a -t 180004031122.33 $(TEMP_DIR)/dirf + touch -m -t 220504031122.44 $(TEMP_DIR)/dirf +# + sudo umount $(TEMP_DIR) + fallocate -i -o 0 -l 1MiB $@ + parted --script --align optimal $@ mktable msdos + parted --script --align optimal $@ mkpart primary xfs 1MiB 100% + xfs_borg_bit.img: - fallocate -l 16MiB $@ + fallocate -l $(XFS_MIN_PART_SIZE) $@ mkfs.xfs -n version=ci $@ fallocate -i -o 0 -l 1MiB $@ parted --script $@ mktable gpt diff --git a/makefile b/makefile index 4350473..1a062cb 100644 --- a/makefile +++ b/makefile @@ -28,7 +28,7 @@ endif CFLAGS=$(WARNINGS) $(NOWARNINGS) -std=c11 -g -O0 -D_FILE_OFFSET_BITS=64 \ -DNDEBUG -masm=intel -D_POSIX_C_SOURCE=200809L -I$(HOST) -fno-pie -CFLAGS_32=$(CFLAGS) -m32 +CFLAGS_32=$(CFLAGS) -m32 -D__USE_TIME_BITS64 LDFLAGS=-no-pie LDFLAGS_32=$(LDFLAGS) -m32 diff --git a/shell.c b/shell.c index 5df1867..ada6f8e 100644 --- a/shell.c +++ b/shell.c @@ -2381,14 +2381,17 @@ cmd_ls80(struct shell_ctx *ctx, int argc, char **argv) { static void cmd_stat(struct shell_ctx *ctx, int argc, char **argv, f70or80_t f70or80) { - (void)ctx; const char *usage = \ - "usage: stat \n" - " file path/to/file\n"; - if (argc != 2) { + "usage: stat [-c] [-m] [-a]\n" + " file path/to/file\n" + " [-c] force show creation time\n" + " [-m] force show modification time\n" + " [-a] force show access time"; + if (argc < 2) { puts(usage); return; } + bool force_ctime = false, force_mtime = false, force_atime = false; f7080s5arg_t fX0 = {.sf = 5, .flags = 0}; f7080ret_t r; bdfe_t file; @@ -2413,25 +2416,48 @@ cmd_stat(struct shell_ctx *ctx, int argc, char **argv, f70or80_t f70or80) { printf("size: %llu\n", file.size); } -#if PRINT_DATE_TIME == 1 // TODO: runtime, argv flag + int opt; + optind = 2; // skip command and file + while ((opt = getopt(argc, argv, "cma")) != -1) { + switch (opt) { + case 'c': + force_ctime = true; + break; + case 'm': + force_mtime = true; + break; + case 'a': + force_atime = true; + break; + default: + puts(usage); + return; + } + } + time_t time; struct tm *t; - time = kos_time_to_epoch(&file.ctime); - t = localtime(&time); - printf("ctime: %4.4i.%2.2i.%2.2i %2.2i:%2.2i:%2.2i\n", - t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, - t->tm_hour, t->tm_min, t->tm_sec); - time = kos_time_to_epoch(&file.atime); - t = localtime(&time); - printf("atime: %4.4i.%2.2i.%2.2i %2.2i:%2.2i:%2.2i\n", - t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, - t->tm_hour, t->tm_min, t->tm_sec); - time = kos_time_to_epoch(&file.mtime); - t = localtime(&time); - printf("mtime: %4.4i.%2.2i.%2.2i %2.2i:%2.2i:%2.2i\n", - t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, - t->tm_hour, t->tm_min, t->tm_sec); -#endif + if (!ctx->reproducible || force_atime) { + time = kos_time_to_epoch(&file.atime); + t = localtime(&time); + printf("atime: %4.4i.%2.2i.%2.2i %2.2i:%2.2i:%2.2i\n", + t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, + t->tm_hour, t->tm_min, t->tm_sec); + } + if (!ctx->reproducible || force_mtime) { + time = kos_time_to_epoch(&file.mtime); + t = localtime(&time); + printf("mtime: %4.4i.%2.2i.%2.2i %2.2i:%2.2i:%2.2i\n", + t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, + t->tm_hour, t->tm_min, t->tm_sec); + } + if (!ctx->reproducible || force_ctime) { + time = kos_time_to_epoch(&file.ctime); + t = localtime(&time); + printf("ctime: %4.4i.%2.2i.%2.2i %2.2i:%2.2i:%2.2i\n", + t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, + t->tm_hour, t->tm_min, t->tm_sec); + } return; } diff --git a/test/055_#xfs_#bigtime_all.ref.log b/test/055_#xfs_#bigtime_all.ref.log new file mode 100644 index 0000000..c80721a --- /dev/null +++ b/test/055_#xfs_#bigtime_all.ref.log @@ -0,0 +1,50 @@ +/> umka_init +/> disk_add ../img/xfs_bigtime.img hd0 -c 0 +/hd0/1: xfs +/> ls70 /hd0/1/ +status = 6 end_of_file, count = 8 +total = 8 +----f . +----f .. +----f dira +----f dirb +----f dirc +----f dird +----f dire +----f dirf +/> ls70 /hd0/1/dira +status = 6 end_of_file, count = 2 +total = 2 +----f . +----f .. +/> stat70 /hd0/1/dira -am +status = 0 success +attr: ----f +atime: 2005.04.03 11:22:33 +mtime: 2005.04.03 11:22:44 +/> stat70 /hd0/1/dirb -am +status = 0 success +attr: ----f +atime: 2001.01.01 00:00:00 +mtime: 2035.04.03 11:22:44 +/> stat70 /hd0/1/dirc -am +status = 0 success +attr: ----f +atime: 2001.01.01 00:00:00 +mtime: 2075.04.03 11:22:44 +/> stat70 /hd0/1/dird -am +status = 0 success +attr: ----f +atime: 2001.01.01 00:00:00 +mtime: 2105.04.03 11:22:44 +/> stat70 /hd0/1/dire -am +status = 0 success +attr: ----f +atime: 2001.01.01 00:00:00 +mtime: 2137.02.07 06:28:15 +/> stat70 /hd0/1/dirf -am +status = 0 success +attr: ----f +atime: 2001.01.01 00:00:00 +mtime: 2137.02.07 06:28:15 +/> disk_del hd0 diff --git a/test/055_#xfs_#bigtime_all.t b/test/055_#xfs_#bigtime_all.t new file mode 100644 index 0000000..b2c1aa0 --- /dev/null +++ b/test/055_#xfs_#bigtime_all.t @@ -0,0 +1,11 @@ +umka_init +disk_add ../img/xfs_bigtime.img hd0 -c 0 +ls70 /hd0/1/ +ls70 /hd0/1/dira +stat70 /hd0/1/dira -am +stat70 /hd0/1/dirb -am +stat70 /hd0/1/dirc -am +stat70 /hd0/1/dird -am +stat70 /hd0/1/dire -am +stat70 /hd0/1/dirf -am +disk_del hd0 diff --git a/test/makefile b/test/makefile index 6a681b9..54656d7 100644 --- a/test/makefile +++ b/test/makefile @@ -57,7 +57,7 @@ acpi: $(acpi_tests) input: $(input_tests) %.out.log: %.t - $(UMKA_SHELL) -i $*.t -o $@ + $(UMKA_SHELL) -ri $*.t -o $@ ifeq ($(HOST),linux) @ cmp $*.out.log $*.ref.log @ if [ -f "$*.ref.png" ]; then cmp $*.out.png $*.ref.png; fi diff --git a/umka.asm b/umka.asm index 9a9c05e..5e713a2 100644 --- a/umka.asm +++ b/umka.asm @@ -472,7 +472,9 @@ endp proc kos_time_to_epoch c uses ebx esi edi ebp, _time mov esi, [_time] call fsCalculateTime - add eax, 978307200 ; epoch to 2001.01.01 + xor edx, edx + add eax, UNIXTIME_TO_KOS_OFFSET + adc edx, 0 ret endp diff --git a/umka.h b/umka.h index fb265ee..fdead64 100644 --- a/umka.h +++ b/umka.h @@ -14,6 +14,7 @@ #include #include #include +#include #define UMKA_PATH_MAX 4096 // TODO: Cleanup @@ -519,7 +520,7 @@ umka_init(void); void i40(void); -uint32_t +time_t kos_time_to_epoch(uint32_t *time); STDCALL disk_t *