Skip to content

Commit

Permalink
storage: Offer "Format" on "Encryption" card
Browse files Browse the repository at this point in the history
  • Loading branch information
mvollmer committed Apr 5, 2024
1 parent d83096d commit 87fb4c6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
16 changes: 10 additions & 6 deletions pkg/storaged/block/actions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,25 @@ import cockpit from "cockpit";
import client from "../client";

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

const _ = cockpit.gettext;

export function block_actions(block, partitionable) {
export function block_actions(block, kind) {
if (!block || block.Size === 0)
return [];

const excuse = block.ReadOnly ? _("Device is read-only") : null;
const actions = [];

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

if (partitionable)
if (kind == "part")
actions.push({
title: _("Create partition table"),
action: () => format_disk(block),
Expand All @@ -49,7 +49,7 @@ export function block_actions(block, partitionable) {

actions.push({
title: _("Format"),
action: () => format_dialog(client, block.path),
action: () => kind == "crypto" ? encrypted_format_dialog(client, block) : format_dialog(client, block.path),
danger: true,
excuse,
});
Expand All @@ -58,5 +58,9 @@ export function block_actions(block, partitionable) {
}

export function partitionable_block_actions(block) {
return block_actions(block, true);
return block_actions(block, "part");
}

export function encrypted_block_actions(block) {
return block_actions(block, "crypto");
}
7 changes: 6 additions & 1 deletion pkg/storaged/block/format-dialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ export function add_encryption_dialog(client, block) {
return format_dialog_internal(client, block.path, { add_encryption: true });
}

export function encrypted_format_dialog(client, block) {
return format_dialog_internal(client, block.path, { is_encrypted: true });
}

function find_root_fsys_block() {
const root = client.anaconda?.mount_point_prefix || "/";
for (const p in client.blocks) {
Expand All @@ -121,6 +125,7 @@ function find_root_fsys_block() {

function format_dialog_internal(client, path, options) {
const { start, size, enable_dos_extended, old_luks_version, add_encryption } = options;
const is_already_encrypted = options.is_encrypted;
const block = client.blocks[path];
const block_part = client.blocks_part[path];
const block_ptable = client.blocks_ptable[path] || client.blocks_ptable[block_part?.Table];
Expand Down Expand Up @@ -355,7 +360,7 @@ function format_dialog_internal(client, path, options) {
{
choices: crypto_types,
value: default_crypto_type,
visible: vals => vals.type != "dos-extended" && vals.type != "biosboot" && vals.type != "efi",
visible: vals => vals.type != "dos-extended" && vals.type != "biosboot" && vals.type != "efi" && !is_already_encrypted,
nested_fields: [
PassInput("passphrase", _("Passphrase"),
{
Expand Down
6 changes: 4 additions & 2 deletions pkg/storaged/crypto/encryption.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { is_mounted } from "../filesystem/utils.jsx";
import { StorageLink } from "../storage-controls.jsx";
import { CryptoKeyslots } from "./keyslots.jsx";
import { lock, unlock } from "./actions.jsx";
import { encrypted_block_actions } from "../block/actions.jsx";

const _ = cockpit.gettext;

Expand All @@ -48,17 +49,18 @@ export function make_encryption_card(next, block, is_filesystem) {
component: EncryptionCard,
props: { block },
actions: [
(content_block && !is_filesystem) &&
content_block &&
{
title: _("Lock"),
action: () => lock(block),
},
(!content_block && !is_filesystem) &&
!content_block &&
{
title: _("Unlock"),
primary: !is_filesystem,
action: () => unlock(block),
},
...(content_block ? encrypted_block_actions(content_block) : []),
]
});
}
Expand Down

0 comments on commit 87fb4c6

Please sign in to comment.