Skip to content

Commit

Permalink
storage: Split "Erase" out from "Format" dialogs
Browse files Browse the repository at this point in the history
This allows us to make the format dialogs non-dangerous and primary,
and give them more descriptive names.

The "Create partition" version of the "Format" dialog now defaults to
"empty", and "empty" can not be encrypted. This makes it a very simple
dialog.
  • Loading branch information
mvollmer committed Apr 5, 2024
1 parent bcf8bb1 commit 20530fc
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 72 deletions.
59 changes: 36 additions & 23 deletions pkg/storaged/block/actions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import client from "../client";

import { format_disk } from "./format-disk-dialog.jsx";
import { format_dialog, add_encryption_dialog, encrypted_format_dialog } from "./format-dialog.jsx";
import { erase_dialog } from "./erase-dialog.jsx";

const _ = cockpit.gettext;

Expand All @@ -32,35 +33,47 @@ export function block_actions(block, kind) {
const excuse = block.ReadOnly ? _("Device is read-only") : null;
const actions = [];

if (client.blocks_available[block.path] && kind != "crypto")
actions.push({
title: _("Add encryption"),
action: () => add_encryption_dialog(client, block),
excuse,
});
if (client.blocks_available[block.path]) {
if (kind != "crypto") {
actions.push({
title: _("Add encryption"),
action: () => add_encryption_dialog(client, block),
excuse,
});
}

if (kind == "part")
actions.push({
title: _("Create partition table"),
action: () => format_disk(block),
danger: true,
excuse,
});
if (kind == "part") {
actions.push({
title: _("Create partitions"),
action: () => format_disk(block),
primary: true,
excuse,
});
}

if (kind == "crypto")
actions.push({
title: _("Format cleartext device"),
action: () => encrypted_format_dialog(client, block),
danger: true,
excuse,
});
else
if (kind == "crypto") {
actions.push({
title: _("Format cleartext device"),
action: () => encrypted_format_dialog(client, block),
primary: true,
excuse,
});
} else {
actions.push({
title: _("Format as filesystem"),
action: () => format_dialog(client, block.path),
primary: true,
excuse,
});
}
} else {
actions.push({
title: _("Format"),
action: () => format_dialog(client, block.path),
title: kind == "crypto" ? _("Erase cleartext device") : _("Erase"),
action: () => erase_dialog(block),
danger: true,
excuse,
});
}

return actions;
}
Expand Down
52 changes: 23 additions & 29 deletions pkg/storaged/block/format-dialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function format_dialog_internal(client, block, options) {
else if (create_partition)
title = cockpit.format(_("Create partition on $0"), block_name(block));
else
title = cockpit.format(_("Format $0"), block_name(block));
title = cockpit.format(_("Format $0 as filesystem"), block_name(block));

function is_filesystem(vals) {
return !add_encryption && vals.type != "empty" && vals.type != "dos-extended" && vals.type != "biosboot" && vals.type != "swap";
Expand All @@ -133,6 +133,8 @@ function format_dialog_internal(client, block, options) {
}

const filesystem_options = [];
if (create_partition)
add_fsys(true, { value: "empty", title: _("Empty") });
add_fsys("xfs", { value: "xfs", title: "XFS" });
add_fsys("ext4", { value: "ext4", title: "EXT4" });
if (client.features.btrfs)
Expand All @@ -146,7 +148,6 @@ function format_dialog_internal(client, block, options) {
if (block_ptable && client.anaconda.efi)
add_fsys(true, { value: "efi", title: "EFI system partition" });
}
add_fsys(true, { value: "empty", title: _("No filesystem") });
if (create_partition && enable_dos_extended)
add_fsys(true, { value: "dos-extended", title: _("Extended partition") });

Expand All @@ -155,7 +156,9 @@ function format_dialog_internal(client, block, options) {
}

let default_type = null;
if (content_block?.IdUsage == "filesystem" && is_supported(content_block.IdType))
if (create_partition)
default_type = "empty";
else if (content_block?.IdUsage == "filesystem" && is_supported(content_block.IdType))
default_type = content_block.IdType;
else {
const root_block = find_root_fsys_block();
Expand Down Expand Up @@ -283,6 +286,21 @@ function format_dialog_internal(client, block, options) {
Title: title,
Teardown: TeardownMessage(usage),
Fields: [
SizeSlider("size", _("Size"),
{
value: size,
max: size,
round: 1024 * 1024,
visible: function () {
return create_partition;
}
}),
SelectOne("type", _("Type"),
{
value: default_type,
choices: filesystem_options,
visible: () => !add_encryption,
}),
TextInput("name", _("Name"),
{
value: content_block?.IdLabel,
Expand All @@ -300,32 +318,11 @@ function format_dialog_internal(client, block, options) {
variant == "nomount");
}
}),
SelectOne("type", _("Type"),
{
value: default_type,
choices: filesystem_options,
visible: () => !add_encryption,
}),
SizeSlider("size", _("Size"),
{
value: size,
max: size,
round: 1024 * 1024,
visible: function () {
return create_partition;
}
}),
CheckBoxes("erase", _("Overwrite"),
{
fields: [
{ tag: "on", title: _("Overwrite existing data with zeros (slower)") }
],
}),
SelectOne("crypto", _("Encryption"),
{
choices: crypto_types,
value: default_crypto_type,
visible: vals => vals.type != "dos-extended" && vals.type != "biosboot" && vals.type != "efi" && !is_already_encrypted,
visible: vals => vals.type != "dos-extended" && vals.type != "biosboot" && vals.type != "efi" && vals.type != "empty" && !is_already_encrypted,
nested_fields: [
PassInput("passphrase", _("Passphrase"),
{
Expand Down Expand Up @@ -380,8 +377,7 @@ function format_dialog_internal(client, block, options) {
}
},
Action: {
Variants: action_variants,
Danger: (create_partition || add_encryption) ? null : _("Formatting erases all data on a storage device."),
Variants: default_type == "empty" ? action_variants_for_empty : action_variants,
wrapper: job_progress_wrapper(client, block.path, client.blocks_cleartext[block.path]?.path),
disable_on_error: usage.Teardown,
action: function (vals) {
Expand All @@ -408,8 +404,6 @@ function format_dialog_internal(client, block, options) {
const options = {
'tear-down': { t: 'b', v: true }
};
if (vals.erase.on)
options.erase = { t: 's', v: "zero" };
if (vals.name)
options.label = { t: 's', v: vals.name };

Expand Down
29 changes: 9 additions & 20 deletions pkg/storaged/block/format-disk-dialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import client from "../client";

import {
dialog_open,
SelectOne, CheckBoxes,
SelectOne,
BlockingMessage, TeardownMessage,
init_active_usage_processes
} from "../dialog.jsx";
Expand All @@ -43,10 +43,10 @@ export function format_disk(block) {
}

dialog_open({
Title: cockpit.format(_("Initialize disk $0"), block_name(block)),
Title: cockpit.format(_("Create partitions on $0"), block_name(block)),
Teardown: TeardownMessage(usage),
Fields: [
SelectOne("type", _("Partitioning"),
SelectOne("type", _("Type"),
{
value: "gpt",
choices: [
Expand All @@ -55,32 +55,21 @@ export function format_disk(block) {
value: "gpt",
title: _("Compatible with modern system and hard disks > 2TB (GPT)")
},
{ value: "empty", title: _("No partitioning") }
]
}),
CheckBoxes("erase", _("Overwrite"),
{
fields: [
{ tag: "on", title: _("Overwrite existing data with zeros (slower)") }
],
}),
],
Action: {
Title: _("Initialize"),
Danger: _("Initializing erases all data on a disk."),
Title: _("Create partition table"),
wrapper: job_progress_wrapper(client, block.path),
disable_on_error: usage.Teardown,
action: function (vals) {
action: async function (vals) {
const options = {
'tear-down': { t: 'b', v: true }
};
if (vals.erase.on)
options.erase = { t: 's', v: "zero" };
return teardown_active_usage(client, usage)
.then(function () {
return block.Format(vals.type, options);
})
.then(reload_systemd);

await teardown_active_usage(client, usage);
await block.Format(vals.type, options);
await reload_systemd();
}
},
Inits: [
Expand Down

0 comments on commit 20530fc

Please sign in to comment.