Writing a Simple Windows Driver in Rust
16 comments
·February 8, 2025mastax
mastax
Huh my Documents folder is weirdly empty, where did-
> Shortcut to Documents (OneDrive - Personal)
Oh good, now all that garbage is being synced across machines. Lovely.
rkagerer
I just completely ignore the My Documents toxic waste dump, and use a different place (with a shorter path) for files I actually care about. I might have created directory junctions to redirect one or two programs that hardcode their data location.
pjmlp
Just like a UNIX file system ends up filled with .dotfiles garbage I didn't ask about to have around.
And better know where they come from, as there is no clean way to safely remove them.
p_ing
Just get a registry! Problem solved ;)
Apps are terrible at this on Windows. Sometimes it's in %USERPROFILE%, sometimes in one of the three %appdata% folders, then My Docs, other times in %ProgramData%, and even worse, %PUBLIC%.
There's a registry for a reason, but even Microsoft doesn't use it for x-platform apps.
pjmlp
Like GNOME?
There are rules when to use what, but usually folks rather code away instead of reading documentation.
nicce
> Just like a UNIX file system ends up filled with .dotfiles garbage I didn't ask about to have around.
Which one is better - a configuration file in some place or default configuration buried inside binary blob?
ddulaney
Default configuration IMO.
I actually really like the way git does it, where it reads each of these in order, last one wins.
- Default configuration compiled in
- Global configuration
- Per-user configuration
- Per-project configuration
You can opt-in to however much configuration complexity you need. Just cloning the occasional thing? Don't bother configuring, the global defaults are probably good enough. Simple commits and pushes? Make a user-level dotfile in your $XDG_CONFIG_HOME to set some basic info. Complex per-project aliases? If you want that, go ahead and opt in.
Contrast that with programs that just dump their whole default config into my home dir on first run. Just filling up with nonsense, often no way to tell what I changed or didn’t.
pjmlp
Hardly makes a difference when the outcome is the same.
Also no one edits text files by hand, we use tools for that, tools that manipulate what is anyway a stream of bytes, whose meaning is given by whatever tool is used to manipulate such stream of bytes.
the8472
symlink + mark it as hidden?
7bit
> - %CSIDL_MYDOCUMENTS%\Call of Duty -> %userprofile%\Saved Games\Call of Duty
That is a fight not worth fighting. Even Microsoft does not give a care in the world when deciding on storage locations and they put files directly in your %USERPROFILE% folder. Often also naming them like Linux/Unix dotfiles. I have opened tickets, pointing them to Microsoft documentation clearly stating that this is not how it should be, but they just don't care.
Still, it is infuriating seeing so much willful ignorance, when choosing the correct location is a decision just as quick as choosing the wrong location.
antithesis-nl
> I have made my peace with the fact that a windows system is just going to be filled with garbage
Or, you know, create a "%USERPROFILE%\Desktop\Actual Documents" folder and set that as the default open/save location in the applications you care about?
The pollution of the "My Documents" folder is unfortunate, yet nothing new, and not exactly limited to Windows (I mean, even on supposedly-perfect MacOS, I have to tolerate various game save crap under 'Documents', not to mention various 'helpful' vendor detritus), and not something that you would want to write a device driver for.
(That being said, hello Rust people, welcome to the Windows kernel! Personally, I've been enjoying the freedom to write C# drivers for years, with a minimal C++ wrapper, and I'm looking forward to the fruits of your creativity!)
lostmsu
He could also replace the folders with hidden junctions or symlinks.
ilrwbwrkhv
Great article and even more impressive design of the blog. Just clean straight forward easy on the eyes and loads instantly.
the__alchemist
Interesting! This looks very different from embedded drivers, which I've done a lot of in rust. Those are mostly reg reads, writes, bit shifting, DMA, and data sheet references.
null
I had an idea to write a filesystem filter driver which would let you configure path remapping rules of sorts, depending on the application. Things like:
- %userprofile%\.vscode -> %appdata%\vscode
- %CSIDL_MYDOCUMENTS%\Call of Duty -> %userprofile%\Saved Games\Call of Duty
Because my documents and home directories filling up with a bunch of garbage which has a designated place on the filesystem filled me with impotent rage. I scaffolded out a project to write a filter driver in rust, read through the minifilter documentation, realized how much work it was going to be, and gave up.
I have made my peace with the fact that a windows system is just going to be filled with garbage.