Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions service/storage_devices.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions service/storage_devices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading