microsoft / microsoft/WSL

sparse file creation for drvfs mounts

Open
#10,902 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature
Dominant language
C++
Stars
33.7k
Forks
1.8k
Avg merge
3d 17h
Merged PRs (30d)
116

Description

Is your feature request related to a problem? Please describe.
Occasionally, I need to perform some form of Linux filesystem maintenance (eg. for my Raspberry Pi). I use truncate --size $sizeinGB rpi.ext4 to create a sparse file, loopback attach it, create the ext4 filesystem and mount it.
Whilst of course, this works well within the WSL's root mount, being just a large, supposedly sparse file, I attempted working just via a /mnt/c path. In a sense so that I don't "stretch out" the backing vhdx file unnecessarily.
Of course, files created like this are not sparse. I haven't tried, but I suspect I can use fsutil to reclaim the pre-allocated space, and make the files sparse.

Describe the solution you'd like
I'd like a drvfs mount option that can specify to attempt sparse file creation (I understand that not all Windows drive mounts support this), by default for that mount.

Describe alternatives you've considered
I can use sshfs to mount via a configured Cygwin sshd instance that's colocated. If I use the right Cygwin mount options for a path available via this sshfs mount, I can achieve sparse file creation, even if there are tradeoffs with sshfs (for example, running du against the network mount doesn't reflect the actual sparseness of the file. it gives what would be the apparent size).

Additional context
Coincidentally for me, the Cygwin project is making improvements around sparse handling for a recent release. There is discussion on this thread that may be relevant for an analogous implementation in WSL:

https://cygwin.com/pipermail/cygwin/2023-December/254916.html

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the linked Cygwin discussion about sparse handling and then investigate how drvfs mount options are defined and applied. The proposed change is a mount option that attempts sparse file creation for supported Windows drives. Done means supported mounts create sparse files without changing behavior for mounts that cannot provide sparse storage.

Written by the indexing model from the issue text.

Assessment

Domain
operating-systems
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.