From 41c0335f1996b9e2f1fb1cbeda3093db25b858e0 Mon Sep 17 00:00:00 2001 From: Gary Date: Tue, 22 Sep 2026 22:40:54 +0200 Subject: [PATCH] fix(disk): keep encrypted volumes from being offered for formatting A locked LUKS container or a BitLocker volume mounts nothing and holds a format CasaOS cannot read, so its disk was listed as available storage with formatting as the only action. Both signatures now count as in use, like RAID, LVM and ZFS members. An opened LUKS stack (dm-crypt, LVM, ext4 mounted from fstab, as reported upstream in IceWhaleTech/CasaOS-LocalStorage#73) was already kept out by the walk down the stack; it gets a test. --- service/storage_devices.go | 12 ++++++++---- service/storage_devices_test.go | 6 ++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/service/storage_devices.go b/service/storage_devices.go index f12bdfd..527074f 100644 --- a/service/storage_devices.go +++ b/service/storage_devices.go @@ -155,16 +155,20 @@ func StorageUsage(disks []model.LSBLKModel) FilesystemStats { } // DiskInUse says whether a disk holds anything that must not be offered for -// formatting: a filesystem or swap mounted anywhere below it, or a part of it -// that belongs to a RAID array, a volume group or a ZFS pool, whether or not -// that array, group or pool is assembled right now. +// formatting: a filesystem or swap mounted anywhere below it, a part of it that +// belongs to a RAID array, a volume group or a ZFS pool, whether or not that +// array, group or pool is assembled right now, or an encrypted volume (LUKS, +// BitLocker), open or not. A locked container mounts nothing and its format is +// not one CasaOS reads, so formatting was the only thing offered for it. func DiskInUse(disk model.LSBLKModel) bool { switch { case disk.MountPoint != "", strings.HasPrefix(disk.Type, "raid"), disk.FsType == "linux_raid_member", disk.FsType == "LVM2_member", - disk.FsType == "zfs_member": + disk.FsType == "zfs_member", + disk.FsType == "crypto_LUKS", + disk.FsType == "BitLocker": return true } for _, child := range disk.Children { diff --git a/service/storage_devices_test.go b/service/storage_devices_test.go index 7cb196c..5b5057b 100644 --- a/service/storage_devices_test.go +++ b/service/storage_devices_test.go @@ -173,6 +173,12 @@ func TestADiskIsInUseWhenAnythingBelowItIs(t *testing.T) { "a partition in a volume group": {Children: []model.LSBLKModel{{FsType: "LVM2_member"}}}, "a ZFS pool member": {FsType: "zfs_member"}, "swap on a partition": {Children: []model.LSBLKModel{{MountPoint: "[SWAP]"}}}, + "a locked LUKS partition": {Children: []model.LSBLKModel{{FsType: "crypto_LUKS"}}}, + "a BitLocker partition": {Children: []model.LSBLKModel{{FsType: "BitLocker"}}}, + // LUKS, then dm-crypt, then LVM, then ext4 mounted from fstab (upstream #73's box) + "an opened LUKS stack": {Children: []model.LSBLKModel{{FsType: "crypto_LUKS", Children: []model.LSBLKModel{ + {Type: "crypt", FsType: "LVM2_member", Children: []model.LSBLKModel{{Type: "lvm", FsType: "ext4", MountPoint: "/mnt/sata"}}}, + }}}}, } { if !DiskInUse(disk) { t.Errorf("%s: offered for formatting", name)