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)