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