dosemu2 / fdpp

FreeDOS plus-plus, 64bit DOS
GNU General Public License v3.0
198 stars 18 forks source link

Windows' WinFile is setting the time in the future #222

Closed robert-j closed 1 year ago

robert-j commented 1 year ago

Describe the bug

Either WinFile or Windows itself is setting the time in the future (about 2 - 5 years. The amount is random).

To Reproduce

A regression?

Yes. It started to happen a few days ago.

Boot.log

date-bug.log.zip

The file is actually xz-compressed.

stsp commented 1 year ago

A few days ago there were only fdpp updates, so could you please check if it is fdpp-specific?

andrewbird commented 1 year ago

can't create local /var/run/user/0/dosemu2 directory

It's probably unconnected to your problem but that is very strange! What distro/hardware are you running on, or is it WSL?

robert-j commented 1 year ago

@andrewbird: Ubuntu 22.04 LTS virtual machine running in VirtualBox with nested virtualization enabled. Additionally I'm running dosemu with '-s' (sudo) to be able to expose ETH devices to dosemu.

andrewbird commented 1 year ago

I guess that 0 in the path is down to using -s.

stsp commented 1 year ago

Yes, -s should now be fixed. Of course you are aware about slirp and tap, both allowing to avoid -s?

As for windows, the log has things like LFN: using WIN date/time - never seen such. :) Andrew, do you know what these do?

robert-j commented 1 year ago

@stsp: I need a real ethernet interface for my stuff, and the bridge approach has stopped working after updating from 20.4 to 22.4 LTS. Attaching a tap device to a bridge returns EPERM, even as root.

Yes, w/out '-s' the warning goes away. I didn't pay attention and didn't file a bug. Thanks!

stsp commented 1 year ago

man tunctl will hint you about the -u option. And you can use the pre-set tap under dosemu.

robert-j commented 1 year ago

It seems that I'd need some help to debug this w/out fdpp. With MS-DOS 6.22 I get "KERNEL: unsupported DPMI server" from WIN and I have no idea which kind of EMM386 do I have to load (if any?).

andrewbird commented 1 year ago

@stsp something seems to be using int21/714e findfirst and it surprises me that WFW would do this. However I notice that there are no tests to cover these so I've no idea if those calls work with the 64bit time format http://www.ctyme.com/intr/rb-3203.htm.

robert-j commented 1 year ago

It might be 4DOS, which is my default shell. AFAIK it has some LFN support.

Edit: for the records: it's unrelated to 4DOS. With FreeCom same date/time issue.

stsp commented 1 year ago

I installed windows and its barely working. Multiple regressions again. :( Will need to bisect.

andrewbird commented 1 year ago

So I'm wondering now whether the file dates are changing, or just that we are returning bad data that 4DOS displays. Can you try switching to FreeCOM (which also has LFN support, but uses DOS date/time) and see what the timestamps are?

andrewbird commented 1 year ago

@robert-j you anticipated my question, it seems!

andrewbird commented 1 year ago

So run me through the procedure to create a bad timestamp on a file.

robert-j commented 1 year ago

okay, I've manged to configure & run MS-DOS 6.22: the error disappeared, so it's how @stsp predicted: a fdpp issue.

stsp commented 1 year ago

What was the problem? It doesn't work well with ms-dos 6.22 for me too now.

robert-j commented 1 year ago

It's fdpp related.

With MS-DOS 6.22 I can start the same pre-configured Windows, which I usually run under fdpp, then open WinFile and terminate Windows: date/time is still correct, error does not occur.

stsp commented 1 year ago

But what was the problem about a DPMI server?

robert-j commented 1 year ago

Ah, this one: Well, I didn't configure the boot floppy correctly and one of the dosemu drivers was not loaded. This was my bad.

stsp commented 1 year ago

OK, I bisected the windows problem and opened dosemu2/dosemu2#2007 Hope Andrew can deal with the files in a mean time. :)

andrewbird commented 1 year ago

I think the lfn file time is a red herring, I didn't read the full thread until now. The issue appears to be that the system time changes.

robert-j commented 1 year ago

@andrewbird: the file times are correct, probably because they are solely controlled by dosemu.

dir > foo dir foo

shows the current date/time of the system. It's probably only the int 21 getdate function, which is returning bad values.

Edit: not probably. 100% INT21 AH=2A is returning garbage. Edit2: when I'm correcting the date with AH=2B then it remains correct until I start Windows+WinFile again.

stsp commented 1 year ago

Edit2: when I'm correcting the date with AH=2B then it remains correct until I start Windows+WinFile again.

Please see what changes on a native FS are seen from these actions.

andrewbird commented 1 year ago

@stsp I think this might be a packing issue with struct dosdate it seems it's used to set registers! https://github.com/dosemu2/fdpp/blob/926b7c1a64369258e0641cfba1db0242a641965c/kernel/inthndlr.c#L705-L707

stsp commented 1 year ago
struct dosdate
{
  unsigned short year;
  unsigned char monthday, month;
};

I don't see the packing problems here (members are sorted by size), and sizeof() gives 4.

andrewbird commented 1 year ago

Sizes look okay here, but I wondered if the version of clang used would affect things?

stsp commented 1 year ago

No because sizes are sorted properly: "short" goes before smaller "char". You may want to read about alignment and padding rules, they are not essentially trivial. :)

andrewbird commented 1 year ago

You may want to read about alignment and padding rules, they are not essentially trivial. :)

Yes I've been a bit lazy on that front. I have it boiled down to just two options: I don't care about alignment and padding as the struct is internal, so let the compiler do whatever, and I do care because the struct has to be portable, so pack it.

stsp commented 1 year ago

That approach doesn't work if you use -Wpacking option. It will warn on redundant packing, which, on clang-16, is not redundant at all! So what clang-16 does, contradicts itself. Of course, after I reported that, they decided to break also -Wpacking option, instead of fixing things up. Because the "bug" is not following gcc these days, rather than what actually breaks things. :(

stsp commented 1 year ago

There are more problems to that approach. Namely, whatever is packed, is treated by gcc as misaligned! Even when its actually not. So fdpp won't even compile if you pack too much. And unfortunately clang devs almost threaten me with porting that bug from gcc too. :(

stsp commented 1 year ago

So overall you can't pack w/o actually reading about alignment and padding rules. If you do, you will either get a punishment from -Wpacking, or, in case it is gcc - will drown in its bugs, but your code won't work.

robert-j commented 1 year ago

Is there a DPMI layer on top of the real mode INT 21 handler in dosemu? I'm asking because INT 21 2A/2B need a real mode to protected mode translation. Maybe is that place the culprit.

Edit: scratch this, the APIs are solely register-based.

stsp commented 1 year ago

Is there a DPMI layer on top of the real mode INT 21 handler in dosemu?

Yes.

I'm asking because INT 21 2A/2B need a real mode to protected mode translation.

Not above the one mandated by dpmi specs, where the register values are propagated to PM as-is.

robert-j commented 1 year ago

I've tried this:

ERROR: fdpp: abort at /build/fdpp-xbqHwh/fdpp-1.6-1352/fdpp/farptr.hpp:571

This is 100% reproducible.

Observations:

Another observation: When I check INT 21 AH=2A in Windows using a Windows protected mode app, then the date is correct before invoking WinFile, wrong during WinFile and wrong after WinFile terminates.

stsp commented 1 year ago

Please attach the log of the crash.

robert-j commented 1 year ago

bug-222.log.xz.zip, actually an xz file.

I've redacted everything containing /drive_c/ for privacy reasons.

stsp commented 1 year ago

Please don't use -s when doing this log. Also you need to install the dbgsym package for fdpp and dosemu2. See this comment on how to: https://github.com/dosemu2/dosemu2/issues/1987#issuecomment-1501099547

You need to grep the resulting log for "No debugging symbols found" and "Could not attach to process." strings. Once they are not there, the log should be good.

robert-j commented 1 year ago

bug-222-2.log.xz.zip, actually an xz file.

It looks like it contains the backtraces you want.

stsp commented 1 year ago

Hmm, it seems fdpp compiler got confused with this statement at fatfs.c:408: j = sp->sftt_count, sftp = sp->sftt_table. Its too difficult for him. :) Could you please try this change:

diff --git a/kernel/fatfs.c b/kernel/fatfs.c
index 79498de..5ddec1e 100644
--- a/kernel/fatfs.c
+++ b/kernel/fatfs.c
@@ -405,7 +405,8 @@ STATIC int merge_file_changes(f_node_ptr fnp, int collect)
   i = 0;
   for (sp = sfthead; sp != (sfttbl FAR *) - 1; sp = sp->sftt_next)
   {
-    for(j = sp->sftt_count, sftp = sp->sftt_table; --j >= 0; sftp++, i++)
+    sftp = sp->sftt_table;
+    for(j = sp->sftt_count; --j >= 0; sftp++, i++)
     {
       if (i != fnp->f_sft_idx && sftp->sft_count != 0
           && fnp->f_dpb == sftp->sft_dcb

That would reduce the complexity and our dumb compiler will probably understand.

robert-j commented 1 year ago

How do I configure dosemu2 to use my custom fdpp from /usr/local?

stsp commented 1 year ago

Just remove fdpp and dosemu2 packages with apt-get, and in an absence of an alternative, dosemu2 will find it in /usr/local.

robert-j commented 1 year ago

It's now crashing in sftp = sp->sftt_table;

stsp commented 1 year ago

Could you please provide a ready to reproduce hd image?

robert-j commented 1 year ago

Not an hd image but a "drive_c" together with the FD image file on which it crashes when I try to write on it after Windows terminates. Is this okay?

stsp commented 1 year ago

If fd image alone is enough (I have win3.1 here too), then that alone.

robert-j commented 1 year ago

The image could be a new, empty one. I've just created a new one and it seems that the bug is not related to my image at all.

My .dosemurc is just this:

$_cpu_vm = "kvm"
$_floppy_a = "dos622.img"
$_attrs_support = (off)

dos622.img is the empty (but formatted) image.

stsp commented 1 year ago

So what needs to be done? Is copying of some file to floppy in winfile is enough?

robert-j commented 1 year ago

I've sent you an e-mail with the subject "FDPP Bug 222".

No, it's much easier:

Then:

cd a:
dir > test

Translation (as it's a German Windows): WinFile is called "Datei-Manager" and can be found in the "Hauptgruppe" ;)

stsp commented 1 year ago

OK, it appeared to have nothing to do with the compilation process. Its a genuine freedos bug.

robert-j commented 1 year ago

@stsp, thank you!

The actual issue (date in the future) of this bug entry isn't fixed, though. You can reproduce the same way as the SFT bug:

The SFT issue arose while we were arguing about the date bug.