Skip to content

Commit

Permalink
storage: Show partition types symbolically and allow editing
Browse files Browse the repository at this point in the history
  • Loading branch information
mvollmer committed Jan 3, 2024
1 parent ea9a84d commit bc80c3b
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 4 deletions.
70 changes: 67 additions & 3 deletions pkg/storaged/partitions/partition.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ import { Alert } from "@patternfly/react-core/dist/esm/components/Alert/index.js
import { CardBody } from "@patternfly/react-core/dist/esm/components/Card/index.js";
import { DescriptionList } from "@patternfly/react-core/dist/esm/components/DescriptionList/index.js";

import { StorageButton } from "../storage-controls.jsx";
import { dialog_open, init_active_usage_processes, BlockingMessage, TeardownMessage } from "../dialog.jsx";
import { StorageButton, StorageLink } from "../storage-controls.jsx";
import {
dialog_open,
SelectOne, TextInput,
init_active_usage_processes, BlockingMessage, TeardownMessage
} from "../dialog.jsx";
import { block_name, fmt_size, get_active_usage, teardown_active_usage, reload_systemd } from "../utils.js";
import { check_unused_space, get_resize_info, free_space_after_part, grow_dialog, shrink_dialog } from "../block/resize.jsx";
import { StorageCard, StorageDescription, new_card, navigate_away_from_card } from "../pages.jsx";
Expand Down Expand Up @@ -118,6 +122,62 @@ const PartitionCard = ({ card, block, unused_space_warning, resize_info }) => {
return grow_dialog(client, block_part, resize_info, true);
}

const gpt_type_names = {
"21686148-6449-6E6F-744E-656564454649": _("BIOS boot partition"),
"C12A7328-F81F-11D2-BA4B-00A0C93EC93B": _("EFI system partition"),
"9E1A2D38-C612-4316-AA26-8B49521E5A8B": _("PowerPC PReP boot partition"),
"0657FD6D-A4AB-43C4-84E5-0933C84B4F4F": _("Linux swap space"),
"0FC63DAF-8483-4772-8E79-3D69D8477DE4": _("Linux filesystem data"),
"E6D6D379-F507-44C2-A23C-238F2A3DF928": _("Logical Volume Manager partition"),
};

const mbr_type_names = {
"0XEF": _("EFI system partition"),
"0X82": _("Linux swap space"),
"0X83": _("Linux filesystem data"),
"0X8E": _("Logical Volume Manager partition"),
};

function partition_type_name(type) {
const t = type.toUpperCase();
return gpt_type_names[t] || mbr_type_names[t] || type;
}

function set_type_dialog() {
const block_ptable = client.blocks_ptable[block_part.Table];
if (!block_ptable)
return;

const type_names = block_ptable.Type == "dos" ? mbr_type_names : gpt_type_names;
const choices = Object.keys(type_names).map(k => ({ value: k, title: type_names[k] }));
choices.push({ title: _("Custom"), value: "custom" });

dialog_open({
Title: cockpit.format(_("Set partition type of $0"), block_name(block)),
Fields: [
SelectOne("type", _("Type"),
{
value: (type_names[block_part.Type.toUpperCase()]
? block_part.Type.toUpperCase()
: "custom"),
choices,
}),
TextInput("custom", _("Custom type"),
{
value: block_part.Type,
visible: vals => vals.type == "custom",
}),
],
Action: {
Title: _("Save"),
action: async function (vals) {
const t = vals.type == "custom" ? vals.custom : vals.type;
await block_part.SetType(t, { });
}
},
});
}

return (
<StorageCard card={card}
alert={unused_space &&
Expand All @@ -139,7 +199,11 @@ const PartitionCard = ({ card, block, unused_space_warning, resize_info }) => {
<DescriptionList className="pf-m-horizontal-on-sm">
<StorageDescription title={_("Name")} value={block_part.Name || "-"} />
<StorageDescription title={_("UUID")} value={block_part.UUID} />
<StorageDescription title={_("Type")} value={block_part.Type} />
<StorageDescription title={_("Type")}
value={partition_type_name(block_part.Type)}
action={<StorageLink onClick={set_type_dialog}>
{_("edit")}
</StorageLink>} />
{ !unused_space &&
<StorageDescription title={_("Size")} value={fmt_size(block_part.Size)} />
}
Expand Down
59 changes: 59 additions & 0 deletions test/verify/check-storage-partitions
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,65 @@ class TestStoragePartitions(storagelib.StorageCase):
b.wait_visible(self.card_button("Partition", "Grow") + ":disabled")
b.wait_in_text(self.card_desc("Partition", "Size"), "103 MB")

def testType(self):
b = self.browser

self.login_and_go("/storage")

disk = self.add_ram_disk(100)
self.click_card_row("Storage", name=disk)

# GPT

self.click_card_dropdown("Solid State Drive", "Create partition table")
self.dialog({"type": "gpt"})
b.wait_text(self.card_row_col("GPT partitions", 1, 1), "Free space")

self.click_dropdown(self.card_row("GPT partitions", 1), "Create partition")
self.dialog({"type": "empty"})

self.click_card_row("GPT partitions", 1)
b.wait_text(self.card_desc("Partition", "Type"), "Linux filesystem data")
b.click(self.card_desc_action("Partition", "Type"))
self.dialog({"type": "C12A7328-F81F-11D2-BA4B-00A0C93EC93B"})
b.wait_text(self.card_desc("Partition", "Type"), "EFI system partition")
b.click(self.card_desc_action("Partition", "Type"))
self.dialog_wait_open()
self.dialog_set_val("type", "custom")
self.dialog_set_val("custom", "bla bla")
self.dialog_apply()
self.dialog_wait_alert("Given type `bla bla' is not a valid UUID")
self.dialog_set_val("custom", "7D0359A3-02B3-4F0A-865C-654403E70625")
self.dialog_apply()
self.dialog_wait_close()
b.wait_text(self.card_desc("Partition", "Type"), "7d0359a3-02b3-4f0a-865c-654403e70625")

# DOS

b.click(self.card_parent_link())
self.click_card_dropdown("Solid State Drive", "Create partition table")
self.dialog({"type": "dos"})
b.wait_text(self.card_row_col("DOS partitions", 1, 1), "Free space")

self.click_dropdown(self.card_row("DOS partitions", 1), "Create partition")
self.dialog({"size": 100, "type": "empty"})

self.click_card_row("DOS partitions", 1)
b.wait_text(self.card_desc("Partition", "Type"), "Linux filesystem data")
b.click(self.card_desc_action("Partition", "Type"))
self.dialog({"type": "0XEF"})
b.wait_text(self.card_desc("Partition", "Type"), "EFI system partition")
b.click(self.card_desc_action("Partition", "Type"))
self.dialog_wait_open()
self.dialog_set_val("type", "custom")
self.dialog_set_val("custom", "bla bla")
self.dialog_apply()
self.dialog_wait_alert("Given type `bla bla' is not a valid") # sic
self.dialog_set_val("custom", "0xC8")
self.dialog_apply()
self.dialog_wait_close()
b.wait_text(self.card_desc("Partition", "Type"), "0xc8")


if __name__ == '__main__':
testlib.test_main()

0 comments on commit bc80c3b

Please sign in to comment.