maharmstone / btrfs

WinBtrfs - an open-source btrfs driver for Windows
GNU Lesser General Public License v3.0
5.52k stars 220 forks source link

Unmounting aka removing #651

Open inoperable opened 2 months ago

inoperable commented 2 months ago

Dear Mike, first, thanks for this great your work and effort you put int this. Thanks for making Windows suck-less 👍

I stumbled upon a peculiar obstacle (probably just dont know how):

How do I sync and then umount a filesystem? I can change the drive letter - but I cant remove it. Making the drive go "offline" might work (wonder...) Anyways.

Just wondering (windows handling of interwoven filesystem is a very bad, already made the discovery even with ntfs mounting)

inoperable commented 2 months ago

a bit (un)surprsing, MSYS2 mount.exe umount.exe binaries are recognizing btrfs on Windows, but the noumount option makes it clear it won't help.

L:/msys64/usr/bin on /bin type ntfs (binary,noacl,auto)
C: on /c type ntfs (binary,noacl,posix=0,user,noumount,auto)
D: on /d type ntfs (binary,noacl,posix=0,user,noumount,auto)
H: on /h type btrfs (binary,noacl,posix=0,user,noumount,auto)
I: on /i type btrfs (binary,noacl,posix=0,user,noumount,auto)
K: on /k type btrfs (binary,noacl,posix=0,user,noumount,auto)
T: on /t type ntfs (binary,noacl,posix=0,user,noumount,auto)
W: on /w type ntfs (binary,noacl,posix=0,user,noumount,auto)
sskras commented 3 weeks ago

@inoperable commented on Apr 19:

MSYS2 mount.exe umount.exe binaries are recognizing btrfs on Windows

Yes, that's nice. And I think the FS type originates from Windows kernel drivers itself, not from MSYS2 runtime or its' tools. Eg. using WMI:

C:\Users\saukrs> wmic volume get caption,FileSystem
Caption                                            FileSystem
D:\                                                NTFS
C:\                                                NTFS
\\?\Volume{878041e1-48c2-484b-bcc1-507b0ff19c4c}\  NTFS
\\?\Volume{5feefb5c-468a-4da8-9fcc-0dfba19dcab8}\  FAT32
B:\                                                Btrfs

...

but the noumount option makes it clear it won't help.

L:/msys64/usr/bin on /bin type ntfs (binary,noacl,auto)
C: on /c type ntfs (binary,noacl,posix=0,user,noumount,auto)
D: on /d type ntfs (binary,noacl,posix=0,user,noumount,auto)
H: on /h type btrfs (binary,noacl,posix=0,user,noumount,auto)
I: on /i type btrfs (binary,noacl,posix=0,user,noumount,auto)
K: on /k type btrfs (binary,noacl,posix=0,user,noumount,auto)
T: on /t type ntfs (binary,noacl,posix=0,user,noumount,auto)
W: on /w type ntfs (binary,noacl,posix=0,user,noumount,auto)

I think this flag is just a stub telling user that volume mounts C:, D:, H:, I:, K:, T:, W: are managed by Windows drivers as opposed to the mounts emulated by MSYS2 itself: L:/msys64/usr/bin.

IMO nothing prevents to extend umount.exe to do what mountvol does.

Eg. I had drive B: mounted from volume \\?\Volume{fa3a3576-7814-093e-56e8-64872827783d}\:

C:\Users\saukrs> mountvol
Creates, deletes, or lists a volume mount point.

MOUNTVOL [drive:]path VolumeName
MOUNTVOL [drive:]path /D
MOUNTVOL [drive:]path /L
MOUNTVOL [drive:]path /P
MOUNTVOL /R
MOUNTVOL /N
MOUNTVOL /E
MOUNTVOL drive: /S

    path        Specifies the existing NTFS directory where the mount
                point will reside.
    VolumeName  Specifies the volume name that is the target of the mount
                point.
    /D          Removes the volume mount point from the specified directory.
    /L          Lists the mounted volume name for the specified directory.
    /P          Removes the volume mount point from the specified directory,
                dismounts the volume, and makes the volume not mountable.
                You can make the volume mountable again by creating a volume
                mount point.
    /R          Removes volume mount point directories and registry settings
                for volumes that are no longer in the system.
    /N          Disables automatic mounting of new volumes.
    /E          Re-enables automatic mounting of new volumes.
    /S          Mount the EFI System Partition on the given drive.

Possible values for VolumeName along with current mount points are:

    \\?\Volume{8317bf2b-9709-4f92-be0f-6f3f3dd83aa4}\
        D:\

    \\?\Volume{3b7e9709-77dc-4d88-ab05-e923b26d95a3}\
        C:\

    \\?\Volume{878041e1-48c2-484b-bcc1-507b0ff19c4c}\
        *** NO MOUNT POINTS ***

    \\?\Volume{5feefb5c-468a-4da8-9fcc-0dfba19dcab8}\
        *** NO MOUNT POINTS ***

    \\?\Volume{fa3a3576-7814-093e-56e8-64872827783d}\
        B:\
saukrs@DESKTOP-O7JE7JE MSYS /D/Downloads/_debug
$ mount
C:/msys64 on / type ntfs (binary,noacl,auto)
C:/msys64/usr/bin on /bin type ntfs (binary,noacl,auto)
B: on /b type btrfs (binary,noacl,posix=0,user,noumount,auto)
C: on /c type ntfs (binary,noacl,posix=0,user,noumount,auto)
D: on /d type ntfs (binary,noacl,posix=0,user,noumount,auto)

And I just dismounted it using the built-in Windows tool:

C:\Users\saukrs> mountvol B: /L
    \\?\Volume{fa3a3576-7814-093e-56e8-64872827783d}\

C:\Users\saukrs> sudo mountvol B: /P

C:\Users\saukrs> mountvol B: /L
The system cannot find the file specified.

C:\Users\saukrs> wmic volume get caption,FileSystem
Caption                                            FileSystem
D:\                                                NTFS
C:\                                                NTFS
\\?\Volume{878041e1-48c2-484b-bcc1-507b0ff19c4c}\  NTFS
\\?\Volume{5feefb5c-468a-4da8-9fcc-0dfba19dcab8}\  FAT32
\\?\Volume{fa3a3576-7814-093e-56e8-64872827783d}\
saukrs@DESKTOP-O7JE7JE MSYS /D/Downloads/_debug
$ mount
C:/msys64 on / type ntfs (binary,noacl,auto)
C:/msys64/usr/bin on /bin type ntfs (binary,noacl,auto)
C: on /c type ntfs (binary,noacl,posix=0,user,noumount,auto)
D: on /d type ntfs (binary,noacl,posix=0,user,noumount,auto)

B: is gone. umount.exe could do the same (given an elevated user access). I am just not sure if MSYS2/Cygwin folks are interested in it.

I instead would like to base such implementation on the Midipix project. :)

inoperable commented 3 weeks ago

mountvol B: /L

@sskras: to clarify, this worked for a mounted btrfs subvolume ? I tested this- and I didnt worked in my case. Hmmmm...

sskras commented 3 weeks ago

mountvol B: /L

@sskras: to clarify, this worked for a mounted btrfs subvolume ?

True. When comparing my 2nd and 4th terminal snippets, it can be seen that the BTRFS line is gone:

saukrs@DESKTOP-O7JE7JE MSYS ~/debug/mount-BTRFS
$ diff -u 01-BTRFS-mounted.txt 02-BTRFS-dismounted.txt
--- 01-BTRFS-mounted.txt        2024-06-11 07:56:01.936685100 +0300
+++ 02-BTRFS-dismounted.txt     2024-06-11 07:56:31.258897600 +0300
@@ -1,5 +1,4 @@
 C:/msys64 on / type ntfs (binary,noacl,auto)
 C:/msys64/usr/bin on /bin type ntfs (binary,noacl,auto)
-B: on /b type btrfs (binary,noacl,posix=0,user,noumount,auto)
 C: on /c type ntfs (binary,noacl,posix=0,user,noumount,auto)
 D: on /d type ntfs (binary,noacl,posix=0,user,noumount,auto)

Just in case, my Windows version:

C:\Users\saukrs> ver

Microsoft Windows [Version 10.0.19044.3086]

I tested this- and I didnt worked in my case. Hmmmm...

Was your prompt elevated? What did the command print? (Reminding just in case:)

sskras commented 3 weeks ago

PS. Well, I am not sure if this is a real BTRFS subvolume.

I had an empty partition on my system drive and used something like that from my MSYS2 environment:

$ mkbtrfs '\Device\Harddisk1\Partition3'

Later I changed the drive letter from E: to B: using Disk Manager graphical console, IIRC.