Debian Codegraph @

pkg/storaged/partitions/format-disk-dialog.jsx

raw
1 /*
2 * Copyright (C) 2023 Red Hat, Inc.
3 * SPDX-License-Identifier: LGPL-2.1-or-later
4 */
5
6 import cockpit from "cockpit";
7 import client from "../client";
8
9 import {
10 dialog_open,
11 SelectOne, CheckBoxes,
12 BlockingMessage, TeardownMessage,
13 init_teardown_usage
14 } from "../dialog.jsx";
15 import { get_active_usage, block_name, teardown_active_usage, reload_systemd } from "../utils.js";
16 import { job_progress_wrapper } from "../jobs-panel.jsx";
17
18 const _ = cockpit.gettext;
19
20 export function format_disk(block) {
21 const usage = get_active_usage(client, block.path, _("initialize"), _("delete"));
22
23 if (usage.Blocking) {
24 dialog_open({
25 Title: cockpit.format(_("$0 is in use"), block_name(block)),
26 Body: BlockingMessage(usage),
27 });
28 return;
29 }
30
31 dialog_open({
32 Title: cockpit.format(_("Initialize disk $0"), block_name(block)),
33 Teardown: TeardownMessage(usage),
34 Fields: [
35 SelectOne("type", _("Partitioning"),
36 {
37 value: "gpt",
38 choices: [
39 { value: "dos", title: _("Compatible with all systems and devices (MBR)") },
40 {
41 value: "gpt",
42 title: _("Compatible with modern system and hard disks > 2TB (GPT)")
43 },
44 { value: "empty", title: _("No partitioning") }
45 ]
46 }),
47 CheckBoxes("erase", _("Overwrite"),
48 {
49 fields: [
50 { tag: "on", title: _("Overwrite existing data with zeros (slower)") }
51 ],
52 }),
53 ],
54 Action: {
55 Title: _("Initialize"),
56 Danger: _("Initializing erases all data on a disk."),
57 wrapper: job_progress_wrapper(client, block.path),
58 disable_on_error: usage.Teardown,
59 action: function (vals) {
60 const options = {
61 'tear-down': { t: 'b', v: true }
62 };
63 if (vals.erase.on)
64 options.erase = { t: 's', v: "zero" };
65 return teardown_active_usage(client, usage)
66 .then(function () {
67 return block.Format(vals.type, options);
68 })
69 .then(reload_systemd);
70 }
71 },
72 Inits: [
73 init_teardown_usage(client, usage)
74 ]
75 });
76 }