176 points · by sohkamyung · 3y ago · 227 comments
Practically, though, it's a shit show. My "favorite" is the inability to delete a file that is open by another process. Combine this with Windows Defender that scans every file that your application creates, and now you have no reliable way of deleting or moving your files.
As someone who works on a C/C++ build toolchain and has to deal with Windows design decisions every day, I can tell you without any hesitation there is nothing coherent or beautiful about it. I don't think even Microsoft believes this.
I usually put it as "Deep inside windows is a really beautiful OS just screaming to be let out from under all that junk on top."
The NT kernel isn't that bad, different from unix for sure but still good. It then just keeps getting progressively worse as you go upwards in the stack from there.
If you really want to close it and know you could break another process but don't care(Which you should), you can use NtQueryFileInformation to get the process ID's that have the file opened, then use OpenProcess with the PID, then use NtQueryProcessInformation to get the open handles. Call DuplicateHandle on each of the handles. Then use NtQueryObject on each of them to get the name of the file, then close it.
There is no such problem. On all the unix-likes, the kernel handles that perfectly naturally.
Think of deleting a file as requesting the file deletion from the kernel rather than directly doing it like in assembly with no os.
When you delete a file, the only thing that happens for sure immediately is no other process can see it in the filesystem, so no new access can be made. To all processes that didn't already have an open file handle, it is effectively deleted and no longer exists.
The contents are not necessarily touched yet, and the filesysyem has not yet necessarily released the occupied inodes and blocks for any other use yet, they are all still tracked as the original file, but now invisible that nothing else except the kernel can see or access.
It stays like that as long as any process anywhere has an open file handle to that file.
Any process with a handle can continue using that handle as normal. If it was opened for write, it can continue to write, seek, read, etc, whatever modes the handle was created with.
The kernel even keeps on coordinating between multiple processes accessing the same now-invisible file. The open file handles aren't just pacifiers, it's still a real file.
But no new file handles can be opened. One by one as processes close file handles, they can no longer open new ones, until the last user has released the last handle.
Only at that point the kernel frees the inodes and blocks in the filesystem making the disk blocks available for new files.
No other processes break, and it's all perfectly graceful and not a problem at all.
For NT not to have that is like some 70's trs-80 stuff.
And holy cow that stuff you just described about querying all other processes...holy cow, not an advertisement for a great, desirable, slick system. "37 easy steps!" It's almost like you were writing a joke to say something is reasonable and then proceed to describe an absolutely laughable process.
This isn't how things work on Linux. It keeps the file "alive" as long as there is at least one process using it. Any processes which do not have the file open already will not be able to see it but those that do can keep using it. The file will be deleted when all processes release the file.
Because of this Linux "feature" I experienced data loss - I zipped a file and deleted it, but the process which created it was still writing to it. But all the data that it wrote now ended up in the void since the file didn't exist anymore. And there was no error/warning that the process was writing to a non-linked file, so I discovered the data loss much later.
So, you experienced data loss because you deleted a file you didn't mean to.
...and?
Someone with more knowledge please correct me if I got the above wrong.
That being said, the issue with Windows is that it prevents me from deleting a file if it's open in a text editor or any program, which should not be the default in my opinion. A directory gets locked simply because you have explorer open in that path, or a terminal cd'd into that path, which is annoying and counter productive most of the time.
And I understand people will argue for it because it does have some utility, but not near enough to pay for the all the damage it's done to people's time.
otoh if you have never encountered Unix, you might be surprised that it's even possible to delete a file currently open by another process.
This doesn't happen for years now due to "opportunistic locks" -- when you open a file being used by an app which support oplocks (i.e.: usually antiviruses), they get a blocking notification and can release the file. They can hold the notification (and stall the requesting application) until they're done, close their handle, and the other app's open succeeds.
But you dont care, obv you dont use it.
If yes - that sounds insane!
If no - it doesn't really help, then, does it? The complaint was that an application developer cannot create a file and then just move/remove it when they please.
I'm neither a Windows user nor Windows dev, so I might be missing something.
[EDIT] It may have been a ZFS export operation, not exactly an unmount? I can't recall for sure. Point is, Linux made you go find and kill the relevant processes yourself, while FreeBSD made it trivial to override that and do what you needed to do with no further fuss.
Most of the discussion around it has linkrotted. https://lwn.net/Articles/192632/ has some mentions.
Some filesystems implement a less-comprehensive variant that's `umount(2)` with `MNT_FORCE` -- but generally that's only network/FUSE-style ones:
MNT_FORCE (since Linux 2.1.116)
Ask the filesystem to abort pending requests before attempting the
unmount. This may allow the unmount to complete without waiting
for an inaccessible server, but could cause data loss. If, after
aborting requests, some processes still have active references to
the filesystem, the unmount will still fail. As at Linux 4.12,
MNT_FORCE is supported only on the following filesystems: 9p (since
Linux 2.6.16), ceph (since Linux 2.6.34), cifs (since Linux
2.6.12), fuse (since Linux 2.6.16), lustre (since Linux 3.11), and
NFS (since Linux 2.1.116).> someone who works on a C/C++ build toolchain
Pick one. No seriously, tradeoffs have to be made, and I don't think "people who work on build automation" are the intended main use case for Windows Home Edition.
What does the alternative look like?
Lets say a process has a file open. Lets say it is a really big one, like 200GB. Ok, so our disk is nearly out of space, better delete this 200GB file, problem solved right?
Only not. Because now even though the file looks deleted, the process still has it open and that space is still allocated to it.
So either you're hiding reality from the user, or you're preventing them from deleting a file that is in use. Windows went one way and UNIX went another.
There's two problems here, the process and the file, it seems you need to deal with both situations on both styles of OS. You could truncate the file (there's also a `truncate` command I have never used):
cat /dev/null > somefile
and let the process continue writing, or you could just `rm` the file, then either kill the process (or the other way round), or if you've got mysterious disk space usage issues you think are due to still open but deleted files you can:
lsof | grep deleted
I'm an ex (mostly) sysadmin and so this stuff is easy, but is obviously out of reach for "normal" users. Personally as someone who still uses Unix-like machines (Mac, servers) and Windows (games, chkdsk) and I greatly prefer the Linux/Unix way and find the Windows way frustrating.
Not naively intuitive, but for this you can write an empty file to the large open file with shell redirection.
cat /dev/null > /path/to/big/file
and that will free up the space on disk immediately. Not great, but more or less nicely handles the somewhat common runaway log file case.I get how this corner case sucks, but to me it seems so much better than the endless parade of reboots and application restarts necessitated by file locking in the Windows world.
Edit: I liked vms fine, I don't think this is inheritance from that, or even dos. I knew how to debug in dos, using debug.com even. I think it has something to do with the lack of expectations for a user to be able to debug a problem. Osx has abit of this, but sitting on a bsd saves it to some extent.
To wit, Windows has plenty of debugging functionality. Historically not as extensive as Unix, but it was there.
However, 0% of that was exposed in any sane way, because Microsoft...? Actually, I have no idea why it wasn't. For the price of 2 senior engineers and a willingness to actually release tools, Microsoft could have drastically improved the situation.
Instead they just (eventually) bought sysinternals. :(
The ability to run different "operating systems" was neat. The graphics stack was all in user space.
The biggest hope was a selling WindowsNT with Alpha CPUs to the Defense department if memory serves. (Which is why the POSIX parts were added) That never happened.
NT4 was not made to be the best OS for games.
After that Microsoft has cut a lot of neat parts out and bastardized the clean separation between the kernels and user space in order to make the OS faster.
I wish they had branched it "Windows Home" and "Windows Workstation"
It would be a lot of work I guess. They do have Windows Service but I think that it has undergone the same changes.
It was called Windows Me.
Also, the selling point of the Professional editions was and continues to be use in Active Directory and business environments, not developer workstations.
Is that the same wanker that got in a hissy fit over distros including xscreensaver ?
Well, yeah. I sympathize with @bagder here trying to be cross-platform but Windows is just Different than POSIX, and if you try to write everything for Linux then "compatibility shim" your way to Windows support, you're gonna have a Bad Time
[0]https://daniel.haxx.se/blog/wp-content/uploads/2022/11/curl-...
How many of them are supported in mainline Curl, aren't POSIX and aren't dead operating systems?
What is a dead operating system anyway, and how is that relevant to the point that Windows is the hardest OS to maintain support for?
* See for instance the config-*.h files in https://github.com/curl/curl/tree/1c567f797bce0befce109bceac...
Mac OS 9
DR DOS
OS/2
VMS
Windows CE
z/OS
MorphOS
Atari FreeMiNT
OS/400
[...]
Actually probably a fourth (EDIT: after looking more closely, make that ~half) or so of the list are not in any way UNIX.
I see Windows, Windows CE, XBox and even MS-DOS on that list.
Edit: And there are at least 4 Windows flavours in the list!
There are probably more there. I recognize about half of those names only.
Are you really saying that it's normal to be harder to port some software into Windows than into z/OS?
Another comment here mentions NT being full of all sorts of quirks. Such sentiments ignore all sorts of quirks with Linux. For some reason, they're ignored or forgot about because people like digging into the internals of esoteric design choices of Unix tools and the Linux OS.
I find myself fairly OS agnostic having spent about equal times on macOS and Windows and a little less on Linux other than as a programming target. In my experience, Windows is the best these days to work on because I get both Linux and Windows on one machine and OS. macOS and Linux all by itself are too much of a compromise as a Linux and as a desktop OS, respectively, for me.
I am currently working on a cross-platform windowing tool with GLFW. Linux and macOS are by far the problem children because of strange limitations in Cocoa/macOS and because Linux has no "built-in" windowing solution.
> If it's written for linux it can be made to work well with BSD and Mac.
Maybe that's true in a theoretical sense, but it has not been my practical experience with macOS. Too many times have I found I needed a plethora of workarounds on macOS only for the same thing to work flawlessly on Ubuntu.
A lot of issues disappeared when better abstractions were found on top of POSIX.
That's a weird and derogatory way to talk about people who appreciate having a standard which makes it easier to write cross-platform software.
EDIT: To expand on this comment and make it more productive. You're right. If the goal is to have first-class support for both Windows and POSIX-like platforms, the right approach is to have an understanding of what your software needs to do, what the POSIX APIs make easy, and what the Windows APIs make easy, and build abstractions which make sense based on that. But man, do I appreciate that if first-class Windows support isn't top priority, I can support essentially every other widely used platform in the world (including macOS) by just writing against the POSIX API, and I can even get okay-ish Windows support by using a POSIX compatibility layer on Windows. So my point isn't, "People who want to have first-class Windows support but do so through POSIX compatibility shims are doing it right".
When I say "POSIX fanbois" I mean "fanboys" (people that are unreasonably attached to this standard and try to use it everywhere without being level-headed about its usefulness). That probably doesn't include the people who actually wrote the standard, which are all (in my experience) pretty reasonable and realistic about the limitations of things they've created.
If anything, it's even more problematic, because Windows is "wierd" and people go out of their way to create special approaches to handle it. For macOS, too many developers think it's "just posix, ya know, like Linux" and then walk into horrible compatibility edge cases.
> everything from path separators, stupid shells, charsets, to not excepting non-sockets in select, no std libc, ownershipd of memory passed to DLLs, ...
Not having a standard-compliant libc seems really annoying. Also, curl is an IO heavy library. Not having select work as it does on other platforms or not having libc work as expected is going to be really annoying.
There are several standard-compliant libc implementations (and C implementations in general) available on Windows, pick any one that you fancy. And why should an OS even ship a default runtime for some random programming language anyhow? Just because it was written in that programming language so it gets a preferential treatment? That's breaking the abstraction layering.
And at runtime, libcurl could find itself using a different libc from the application, so a buffer malloc’d in libc can’t be passed to free() by the app.
That sounds like a problem that could be solved by not doing that and picking one.
Yes, it's something anybody who has been seriously programming for Windows has been aware since forever. Which is why libraries and plugins generally expose FreeX() for every X they allocate and return.
That's a general issue with C plugins/libraries. You cannot even assume that objects are allocated with malloc() because the library might use its own memory allocator, object pool, etc.
Emphasis on library, curl is not just a command line tool. Calling a library compiled with one version of libc (actually msvcrXX.dll) from a program or library compiled with a different version of libc (for instance, msvcr71.dll vs msvcr81.dll) means things like file descriptors (not just FILE structs, but also numeric file descriptors) aren't shared between them.
That would probably require killing CMD, which would be a big compatibility break. I suspect it could be turned into a shim layer for corporates who need to keep running BAT files.
Not accepting non-sockets in select() .. the native API (WaitForMultipleObjects) is much more flexible, but it doesn't look like select().
libc: require the user to install vcrt like everyone else. Microsoft have actually kind of fixed this with the "universal" runtime: https://learn.microsoft.com/en-us/cpp/windows/universal-crt-... but only recently.
If you're a Windows-first developer, you're probably used to these things, but to non-Windows developers, Windows is strange and annoying.
I tried to port one of our server applications to Windows. I eventually gave up because our service would remove files that were still open. To me, it's crazy that Windows doesn't allow you to do that. This also means you can't use a tool like SSH or SCP. If you accidentally kill the local SCP process while the file is transferring, you need to remotely connect to the destination and kill the remote SCP process to allow that file to be modified again.
Except the APIs you need to use to avoid the 260-character MAX_PATH limit (without depending on both an obscure group policy setting and a setting on the application manifest, and keep in mind that curl is also a library so it cannot control the application manifest). AFAIK, the "\\?\" trick to extend the limit to 32767 characters requires both absolute paths and the use of a backslash (\) as the path separator.
In fact, maybe the fact that a Windows port of libcurl can exist at all means that the Windows BSD socket implementation is useful enough to allow these sort of things.
In its last years it got a POSIX compatibility layer. Before that it was hard to even use C strings — which I presume was considered a feature by the Symbian API designers, but unfortunately they made their design choices in the mid-1990s using a subset of C++ that didn’t age well at all.
(and it happens to have a libcurl port)
Also it is not true. A sibling comment mentions Nintendo Switch OS.
I've worked on a medium sized open-source project (~500kLOC) that was supported on Windows, Linux and MacOS, so I'm not unfamilar with cross-platform support. For us, MacOS was by far the weirdest of the bunch.
One of the complaints was the path separators. We solved that by just consistently using / everywhere internal. Any supplied paths would get converted right away. Not really an issue to write home about IMHO.
It's an HTTP client. Here's 1 of 7 HTTP RFCs https://www.rfc-editor.org/rfc/rfc7230
There are bigger specs like for wifi where it's thousands of pages, but I don't think you can classify a client that implements even half of the HTTP specs as basic.
> curl supports about 26 protocols. We say "about" because it depends on how you count and what you consider to be distinctly different protocols.
Yeah that's what I mean, on the face of it there's not all that much platform specific code should be required for that.
Sure handling all the edge cases of HTTP and whatnot isn't trivial, but almost all of that should be platform neutral so not relevant for this discussion.
Now granted I know HTTP/2 and HTTP/3 are different beasts. But that's why I said it would have been nice with some concrete examples. It's always interesting to learn about issues and pitfalls you've never considered, or similar.
I discovered things about the Windows driver, installer, and networking subsystems and APIs that are best described by pinhead from Hellraiser: “I have such sights to show you.”
No other OS comes close. Definitely not the fruit company one or even commercial Unix (yes Solaris and AIX still live). Most Linux package management is a tire fire but the OS is pretty nice.
I blame backward compatibility coupled with what seems to have been a series of fits of overengineering that now must be carried along as boat anchors.
You must remember, Windows was at its core made for the PC! Which meant random manufacturers get to shove it on their PC and random devs get to write code on it and it was closed source. This meant a lot of apis and the burden of supporting them long term. It was made in the era whe se purchased software in CDs.
The more I learn the internals of windows (it's a hybrid kernel but I mean the stuff close to the kernel not userspace) the more I am finding our a lot of fascinating design decisions that others can learn from. But even in user space, COM and WMI alone would be amazing to have on
nix (I think KDE sort of tries for COM).But from curl's perspective I can see why he'd be frustrated but I truly wonder what the problems are. If you use openssl and basically the same libs as on *nix, could it be the build systems and runtimes (Visual C++?)?
I miss those times.
Frankly, I'd count Windows 95 as really being in the CD era, floppy software was getting rare than (although apparently there's a even a 39 disc floppy version of Windows 98 if you're a real masochist), but a couple of years earlier CD-ROMs were still quite niche, although a high end workstation does seem a likely candidate to have one.
- What does Windows get right?
- What's it get miserably wrong?
- Is the trouble that all the other OS's are more POSIX-like and this is the odd one out?
C# has an excellent system for native interop ("P/Invoke") if you need to write a program that calls a couple of native functions that aren't available as nuget packages.
> disable taskbar tab grouping programmatically
.. fiddling with windows settings, on the other hand, is kind of a nightmare. Either you identify the registry key or you have to go hunting in an endless maze of APIs.
There are many ways to program Windows.
If you want C or C++, you can use Win32[0] and COM[1]. Of course, the C and C++ standard libraries are also available, within ucrt.dll[2]. Not to mention additional libraries/frameworks like Direct3D, OpenGL, DirectSound, etc.
For .NET, there's several options:
- Windows Forms[3]
- Windows Presentation Foundation (WPF)[4]
- WinUI 3[5] (most recent, but lacking some features)
Windows' command-line shell of choice is PowerShell[6], written in C#. There are two flavours, Windows PowerShell 5.1 (Windows-only, uses .NET Framework 4.8), and PowerShell Core (cross-platform, uses .NET 6+).> For example, let's say 'I want to disable taskbar tab grouping programmatically', how would I know where to look?
There are registry keys and GPO policies[7] (you can use any of the above C/C++/C# APIs to read/write from the registry, but your program will need the appropriate permissions)> However, Windows really is best configured with the GUI (Settings app -> Personalisation -> Taskbar).
[0]: https://learn.microsoft.com/en-us/windows/win32/
[1]: https://learn.microsoft.com/en-us/windows/win32/com/componen...
[2]: https://learn.microsoft.com/en-us/cpp/porting/upgrade-your-c...
[3]: https://learn.microsoft.com/en-us/dotnet/desktop/winforms/ov...
[4]: https://learn.microsoft.com/en-us/dotnet/desktop/wpf/overvie...
[5]: https://microsoft.github.io/microsoft-ui-xaml/
[6]: https://learn.microsoft.com/en-us/powershell/
[7]: https://social.technet.microsoft.com/Forums/en-US/f08bc6bb-a...
A "modern" Windows app can use WinRT, which is a reasonably clean OOP API, from multiple languages including C++. The API is based around coroutines and async/await for concurrency and you can do a lot without ever touching Win32, e.g. there are HTTP clients, file APIs etc all of which are not Win32 and also don't require .NET. Under the hood it's all COM based stuff but you aren't really exposed to that.
Example of what it looks like:
https://github.com/microsoft/Windows-appsample-photo-editor/...
But yes, it's a registry key. It will be a bit hard to make explorer.exe reread that registry key without restarting it, though, since it probably reads the key on startup and caches it.
My biggest gripe with Mastodon is just how bad their thread support is. With Twitter, it's easily noticeable which reply belongs to which chain, Mastodon just flattens everything.
edit I found a way. You can use the JS api, like:
https://mastodon.social/@bagder/109432034039353503
becomes,
https://mastodon.social/api/v1/statuses/109432034039353503
which returns the post in json form. Readable without execution.
https://twitter.com/autinerd https://twitter.com/ocdtrekkie
I don't get it
Opening a socket and issuing a GET call is somehow too difficult on Windows?
Will you entertain the possibility that CURL's architecture is to blame?
It does a lot more than that, because the Internet isn't actually that simple. You should look at the first paragraph of https://curl.se rather than have me rehash it here.
When the codebase depends on POSIX and platform-specific quirks everywhere, putting the blame on the operating system when it's time to port things is hilarious.
I don't see posts like this from the people who had to port Portal 2 to run natively on Linux, as an example. If Portal 2 (a codebase you can safely assume is 1000x more complex) made it fine without the drama, there's no reason CURL can't follow suit (unless the architecture is botched).
Porting a codebase to a specific target is way easier compare to porting it to multi version of the same target, especially the older ones.