PartitionEditor: Add the beginnings of a partition editor :^)
This adds a new application PartitionEditor which will eventually be
used to create and edit partition tables. Since LibPartition does not
know how to write partition tables yet, it is currently read-only.
Devices are discovered by scanning /dev for block device files.
Since block devices are chmod 600, PartitionEditor be must run as root.
By default Serenity uses the entire disk for the ext2 filesystem
without a partition table. This isn't useful for testing as the
partition list for the default disk will be empty. To test properly,
I created a few disk images using various partitioning schemes
(MBR, EBR, and GPT) and attached them using the following command:
export SERENITY_EXTRA_QEMU_ARGS="
-drive file=/path/to/mbr.img,format=raw,index=1,media=disk
-drive file=/path/to/ebr.img,format=raw,index=2,media=disk
-drive file=/path/to/gpt.img,format=raw,index=3,media=disk"
2022-06-27 23:48:30 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2022, Samuel Bowman <sam@sambowman.tech>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <Applications/PartitionEditor/PartitionEditorWindowGML.h>
|
|
|
|
|
#include <Applications/PartitionEditor/PartitionModel.h>
|
2023-03-02 14:47:27 -03:00
|
|
|
#include <LibCore/Directory.h>
|
PartitionEditor: Add the beginnings of a partition editor :^)
This adds a new application PartitionEditor which will eventually be
used to create and edit partition tables. Since LibPartition does not
know how to write partition tables yet, it is currently read-only.
Devices are discovered by scanning /dev for block device files.
Since block devices are chmod 600, PartitionEditor be must run as root.
By default Serenity uses the entire disk for the ext2 filesystem
without a partition table. This isn't useful for testing as the
partition list for the default disk will be empty. To test properly,
I created a few disk images using various partitioning schemes
(MBR, EBR, and GPT) and attached them using the following command:
export SERENITY_EXTRA_QEMU_ARGS="
-drive file=/path/to/mbr.img,format=raw,index=1,media=disk
-drive file=/path/to/ebr.img,format=raw,index=2,media=disk
-drive file=/path/to/gpt.img,format=raw,index=3,media=disk"
2022-06-27 23:48:30 -03:00
|
|
|
#include <LibCore/System.h>
|
2023-03-21 12:35:30 -03:00
|
|
|
#include <LibFileSystem/FileSystem.h>
|
PartitionEditor: Add the beginnings of a partition editor :^)
This adds a new application PartitionEditor which will eventually be
used to create and edit partition tables. Since LibPartition does not
know how to write partition tables yet, it is currently read-only.
Devices are discovered by scanning /dev for block device files.
Since block devices are chmod 600, PartitionEditor be must run as root.
By default Serenity uses the entire disk for the ext2 filesystem
without a partition table. This isn't useful for testing as the
partition list for the default disk will be empty. To test properly,
I created a few disk images using various partitioning schemes
(MBR, EBR, and GPT) and attached them using the following command:
export SERENITY_EXTRA_QEMU_ARGS="
-drive file=/path/to/mbr.img,format=raw,index=1,media=disk
-drive file=/path/to/ebr.img,format=raw,index=2,media=disk
-drive file=/path/to/gpt.img,format=raw,index=3,media=disk"
2022-06-27 23:48:30 -03:00
|
|
|
#include <LibGUI/Application.h>
|
|
|
|
|
#include <LibGUI/ComboBox.h>
|
|
|
|
|
#include <LibGUI/ItemListModel.h>
|
|
|
|
|
#include <LibGUI/Menu.h>
|
|
|
|
|
#include <LibGUI/MessageBox.h>
|
|
|
|
|
#include <LibGUI/TableView.h>
|
2022-06-28 01:11:42 -03:00
|
|
|
#include <unistd.h>
|
PartitionEditor: Add the beginnings of a partition editor :^)
This adds a new application PartitionEditor which will eventually be
used to create and edit partition tables. Since LibPartition does not
know how to write partition tables yet, it is currently read-only.
Devices are discovered by scanning /dev for block device files.
Since block devices are chmod 600, PartitionEditor be must run as root.
By default Serenity uses the entire disk for the ext2 filesystem
without a partition table. This isn't useful for testing as the
partition list for the default disk will be empty. To test properly,
I created a few disk images using various partitioning schemes
(MBR, EBR, and GPT) and attached them using the following command:
export SERENITY_EXTRA_QEMU_ARGS="
-drive file=/path/to/mbr.img,format=raw,index=1,media=disk
-drive file=/path/to/ebr.img,format=raw,index=2,media=disk
-drive file=/path/to/gpt.img,format=raw,index=3,media=disk"
2022-06-27 23:48:30 -03:00
|
|
|
|
2022-12-04 15:02:33 -03:00
|
|
|
static Vector<DeprecatedString> get_device_paths()
|
PartitionEditor: Add the beginnings of a partition editor :^)
This adds a new application PartitionEditor which will eventually be
used to create and edit partition tables. Since LibPartition does not
know how to write partition tables yet, it is currently read-only.
Devices are discovered by scanning /dev for block device files.
Since block devices are chmod 600, PartitionEditor be must run as root.
By default Serenity uses the entire disk for the ext2 filesystem
without a partition table. This isn't useful for testing as the
partition list for the default disk will be empty. To test properly,
I created a few disk images using various partitioning schemes
(MBR, EBR, and GPT) and attached them using the following command:
export SERENITY_EXTRA_QEMU_ARGS="
-drive file=/path/to/mbr.img,format=raw,index=1,media=disk
-drive file=/path/to/ebr.img,format=raw,index=2,media=disk
-drive file=/path/to/gpt.img,format=raw,index=3,media=disk"
2022-06-27 23:48:30 -03:00
|
|
|
{
|
2022-12-04 15:02:33 -03:00
|
|
|
auto device_paths = Vector<DeprecatedString>();
|
2023-03-02 14:47:27 -03:00
|
|
|
// FIXME: Propagate errors.
|
|
|
|
|
(void)Core::Directory::for_each_entry("/dev"sv, Core::DirIterator::Flags::SkipParentAndBaseDir, [&](auto const& entry, auto const& directory) -> ErrorOr<IterationDecision> {
|
|
|
|
|
auto full_path = LexicalPath::join(directory.path().string(), entry.name).string();
|
2023-03-21 12:35:30 -03:00
|
|
|
if (FileSystem::is_block_device(full_path))
|
2023-03-02 14:47:27 -03:00
|
|
|
device_paths.append(full_path);
|
|
|
|
|
return IterationDecision::Continue;
|
|
|
|
|
});
|
PartitionEditor: Add the beginnings of a partition editor :^)
This adds a new application PartitionEditor which will eventually be
used to create and edit partition tables. Since LibPartition does not
know how to write partition tables yet, it is currently read-only.
Devices are discovered by scanning /dev for block device files.
Since block devices are chmod 600, PartitionEditor be must run as root.
By default Serenity uses the entire disk for the ext2 filesystem
without a partition table. This isn't useful for testing as the
partition list for the default disk will be empty. To test properly,
I created a few disk images using various partitioning schemes
(MBR, EBR, and GPT) and attached them using the following command:
export SERENITY_EXTRA_QEMU_ARGS="
-drive file=/path/to/mbr.img,format=raw,index=1,media=disk
-drive file=/path/to/ebr.img,format=raw,index=2,media=disk
-drive file=/path/to/gpt.img,format=raw,index=3,media=disk"
2022-06-27 23:48:30 -03:00
|
|
|
return device_paths;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|
|
|
|
{
|
2023-03-14 21:28:34 -03:00
|
|
|
TRY(Core::System::unveil("/dev", "r"));
|
|
|
|
|
TRY(Core::System::unveil("/res", "r"));
|
|
|
|
|
TRY(Core::System::unveil("/proc", "r"));
|
|
|
|
|
TRY(Core::System::unveil("/tmp/session/%sid/portal/clipboard", "rw"));
|
|
|
|
|
TRY(Core::System::unveil("/tmp/portal/window", "rw"));
|
|
|
|
|
TRY(Core::System::unveil(nullptr, nullptr));
|
|
|
|
|
|
PartitionEditor: Add the beginnings of a partition editor :^)
This adds a new application PartitionEditor which will eventually be
used to create and edit partition tables. Since LibPartition does not
know how to write partition tables yet, it is currently read-only.
Devices are discovered by scanning /dev for block device files.
Since block devices are chmod 600, PartitionEditor be must run as root.
By default Serenity uses the entire disk for the ext2 filesystem
without a partition table. This isn't useful for testing as the
partition list for the default disk will be empty. To test properly,
I created a few disk images using various partitioning schemes
(MBR, EBR, and GPT) and attached them using the following command:
export SERENITY_EXTRA_QEMU_ARGS="
-drive file=/path/to/mbr.img,format=raw,index=1,media=disk
-drive file=/path/to/ebr.img,format=raw,index=2,media=disk
-drive file=/path/to/gpt.img,format=raw,index=3,media=disk"
2022-06-27 23:48:30 -03:00
|
|
|
TRY(Core::System::pledge("stdio recvfd sendfd rpath unix"));
|
|
|
|
|
|
2023-05-05 01:24:53 -03:00
|
|
|
auto app = TRY(GUI::Application::create(arguments));
|
PartitionEditor: Add the beginnings of a partition editor :^)
This adds a new application PartitionEditor which will eventually be
used to create and edit partition tables. Since LibPartition does not
know how to write partition tables yet, it is currently read-only.
Devices are discovered by scanning /dev for block device files.
Since block devices are chmod 600, PartitionEditor be must run as root.
By default Serenity uses the entire disk for the ext2 filesystem
without a partition table. This isn't useful for testing as the
partition list for the default disk will be empty. To test properly,
I created a few disk images using various partitioning schemes
(MBR, EBR, and GPT) and attached them using the following command:
export SERENITY_EXTRA_QEMU_ARGS="
-drive file=/path/to/mbr.img,format=raw,index=1,media=disk
-drive file=/path/to/ebr.img,format=raw,index=2,media=disk
-drive file=/path/to/gpt.img,format=raw,index=3,media=disk"
2022-06-27 23:48:30 -03:00
|
|
|
|
|
|
|
|
TRY(Core::System::pledge("stdio recvfd sendfd rpath"));
|
|
|
|
|
|
2022-08-13 18:17:01 -03:00
|
|
|
auto app_icon = TRY(GUI::Icon::try_create_default_icon("app-partition-editor"sv));
|
PartitionEditor: Add the beginnings of a partition editor :^)
This adds a new application PartitionEditor which will eventually be
used to create and edit partition tables. Since LibPartition does not
know how to write partition tables yet, it is currently read-only.
Devices are discovered by scanning /dev for block device files.
Since block devices are chmod 600, PartitionEditor be must run as root.
By default Serenity uses the entire disk for the ext2 filesystem
without a partition table. This isn't useful for testing as the
partition list for the default disk will be empty. To test properly,
I created a few disk images using various partitioning schemes
(MBR, EBR, and GPT) and attached them using the following command:
export SERENITY_EXTRA_QEMU_ARGS="
-drive file=/path/to/mbr.img,format=raw,index=1,media=disk
-drive file=/path/to/ebr.img,format=raw,index=2,media=disk
-drive file=/path/to/gpt.img,format=raw,index=3,media=disk"
2022-06-27 23:48:30 -03:00
|
|
|
|
2023-09-16 08:51:33 -03:00
|
|
|
auto window = GUI::Window::construct();
|
PartitionEditor: Add the beginnings of a partition editor :^)
This adds a new application PartitionEditor which will eventually be
used to create and edit partition tables. Since LibPartition does not
know how to write partition tables yet, it is currently read-only.
Devices are discovered by scanning /dev for block device files.
Since block devices are chmod 600, PartitionEditor be must run as root.
By default Serenity uses the entire disk for the ext2 filesystem
without a partition table. This isn't useful for testing as the
partition list for the default disk will be empty. To test properly,
I created a few disk images using various partitioning schemes
(MBR, EBR, and GPT) and attached them using the following command:
export SERENITY_EXTRA_QEMU_ARGS="
-drive file=/path/to/mbr.img,format=raw,index=1,media=disk
-drive file=/path/to/ebr.img,format=raw,index=2,media=disk
-drive file=/path/to/gpt.img,format=raw,index=3,media=disk"
2022-06-27 23:48:30 -03:00
|
|
|
window->set_title("Partition Editor");
|
|
|
|
|
window->resize(640, 400);
|
|
|
|
|
window->set_icon(app_icon.bitmap_for_size(16));
|
|
|
|
|
|
2022-06-28 01:11:42 -03:00
|
|
|
if (getuid() != 0) {
|
|
|
|
|
auto error_message = "PartitionEditor must be run as root in order to open raw block devices and read partition tables."sv;
|
|
|
|
|
GUI::MessageBox::show_error(window, error_message);
|
|
|
|
|
return Error::from_string_view(error_message);
|
|
|
|
|
}
|
PartitionEditor: Add the beginnings of a partition editor :^)
This adds a new application PartitionEditor which will eventually be
used to create and edit partition tables. Since LibPartition does not
know how to write partition tables yet, it is currently read-only.
Devices are discovered by scanning /dev for block device files.
Since block devices are chmod 600, PartitionEditor be must run as root.
By default Serenity uses the entire disk for the ext2 filesystem
without a partition table. This isn't useful for testing as the
partition list for the default disk will be empty. To test properly,
I created a few disk images using various partitioning schemes
(MBR, EBR, and GPT) and attached them using the following command:
export SERENITY_EXTRA_QEMU_ARGS="
-drive file=/path/to/mbr.img,format=raw,index=1,media=disk
-drive file=/path/to/ebr.img,format=raw,index=2,media=disk
-drive file=/path/to/gpt.img,format=raw,index=3,media=disk"
2022-06-27 23:48:30 -03:00
|
|
|
|
2023-09-18 21:13:48 -03:00
|
|
|
auto widget = window->set_main_widget<GUI::Widget>();
|
2023-01-07 09:38:23 -03:00
|
|
|
TRY(widget->load_from_gml(partition_editor_window_gml));
|
PartitionEditor: Add the beginnings of a partition editor :^)
This adds a new application PartitionEditor which will eventually be
used to create and edit partition tables. Since LibPartition does not
know how to write partition tables yet, it is currently read-only.
Devices are discovered by scanning /dev for block device files.
Since block devices are chmod 600, PartitionEditor be must run as root.
By default Serenity uses the entire disk for the ext2 filesystem
without a partition table. This isn't useful for testing as the
partition list for the default disk will be empty. To test properly,
I created a few disk images using various partitioning schemes
(MBR, EBR, and GPT) and attached them using the following command:
export SERENITY_EXTRA_QEMU_ARGS="
-drive file=/path/to/mbr.img,format=raw,index=1,media=disk
-drive file=/path/to/ebr.img,format=raw,index=2,media=disk
-drive file=/path/to/gpt.img,format=raw,index=3,media=disk"
2022-06-27 23:48:30 -03:00
|
|
|
|
|
|
|
|
auto device_paths = get_device_paths();
|
|
|
|
|
|
|
|
|
|
auto partition_model = PartitionEditor::PartitionModel::create();
|
|
|
|
|
TRY(partition_model->set_device_path(device_paths.first()));
|
|
|
|
|
|
|
|
|
|
auto& device_combobox = *widget->find_descendant_of_type_named<GUI::ComboBox>("device_combobox");
|
2022-12-04 15:02:33 -03:00
|
|
|
device_combobox.set_model(GUI::ItemListModel<DeprecatedString>::create(device_paths));
|
PartitionEditor: Add the beginnings of a partition editor :^)
This adds a new application PartitionEditor which will eventually be
used to create and edit partition tables. Since LibPartition does not
know how to write partition tables yet, it is currently read-only.
Devices are discovered by scanning /dev for block device files.
Since block devices are chmod 600, PartitionEditor be must run as root.
By default Serenity uses the entire disk for the ext2 filesystem
without a partition table. This isn't useful for testing as the
partition list for the default disk will be empty. To test properly,
I created a few disk images using various partitioning schemes
(MBR, EBR, and GPT) and attached them using the following command:
export SERENITY_EXTRA_QEMU_ARGS="
-drive file=/path/to/mbr.img,format=raw,index=1,media=disk
-drive file=/path/to/ebr.img,format=raw,index=2,media=disk
-drive file=/path/to/gpt.img,format=raw,index=3,media=disk"
2022-06-27 23:48:30 -03:00
|
|
|
device_combobox.set_only_allow_values_from_model(true);
|
|
|
|
|
device_combobox.set_selected_index(0);
|
|
|
|
|
device_combobox.on_change = [&](auto const& path, auto const&) {
|
|
|
|
|
auto result = partition_model->set_device_path(path);
|
|
|
|
|
if (result.is_error())
|
2022-12-04 15:02:33 -03:00
|
|
|
GUI::MessageBox::show_error(window, DeprecatedString::formatted("No partition table found for device {}", path));
|
PartitionEditor: Add the beginnings of a partition editor :^)
This adds a new application PartitionEditor which will eventually be
used to create and edit partition tables. Since LibPartition does not
know how to write partition tables yet, it is currently read-only.
Devices are discovered by scanning /dev for block device files.
Since block devices are chmod 600, PartitionEditor be must run as root.
By default Serenity uses the entire disk for the ext2 filesystem
without a partition table. This isn't useful for testing as the
partition list for the default disk will be empty. To test properly,
I created a few disk images using various partitioning schemes
(MBR, EBR, and GPT) and attached them using the following command:
export SERENITY_EXTRA_QEMU_ARGS="
-drive file=/path/to/mbr.img,format=raw,index=1,media=disk
-drive file=/path/to/ebr.img,format=raw,index=2,media=disk
-drive file=/path/to/gpt.img,format=raw,index=3,media=disk"
2022-06-27 23:48:30 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
auto& partition_table_view = *widget->find_descendant_of_type_named<GUI::TableView>("partition_table_view");
|
|
|
|
|
partition_table_view.set_model(partition_model);
|
|
|
|
|
partition_table_view.set_focus(true);
|
|
|
|
|
|
2023-08-14 05:44:42 -03:00
|
|
|
auto file_menu = window->add_menu("&File"_string);
|
|
|
|
|
file_menu->add_action(GUI::CommonActions::make_quit_action([&](auto&) {
|
PartitionEditor: Add the beginnings of a partition editor :^)
This adds a new application PartitionEditor which will eventually be
used to create and edit partition tables. Since LibPartition does not
know how to write partition tables yet, it is currently read-only.
Devices are discovered by scanning /dev for block device files.
Since block devices are chmod 600, PartitionEditor be must run as root.
By default Serenity uses the entire disk for the ext2 filesystem
without a partition table. This isn't useful for testing as the
partition list for the default disk will be empty. To test properly,
I created a few disk images using various partitioning schemes
(MBR, EBR, and GPT) and attached them using the following command:
export SERENITY_EXTRA_QEMU_ARGS="
-drive file=/path/to/mbr.img,format=raw,index=1,media=disk
-drive file=/path/to/ebr.img,format=raw,index=2,media=disk
-drive file=/path/to/gpt.img,format=raw,index=3,media=disk"
2022-06-27 23:48:30 -03:00
|
|
|
app->quit();
|
|
|
|
|
}));
|
|
|
|
|
|
2023-08-14 05:44:42 -03:00
|
|
|
auto help_menu = window->add_menu("&Help"_string);
|
2023-08-14 05:14:27 -03:00
|
|
|
help_menu->add_action(GUI::CommonActions::make_command_palette_action(window));
|
2023-09-13 16:34:46 -03:00
|
|
|
help_menu->add_action(GUI::CommonActions::make_about_action("Partition Editor"_string, app_icon, window));
|
PartitionEditor: Add the beginnings of a partition editor :^)
This adds a new application PartitionEditor which will eventually be
used to create and edit partition tables. Since LibPartition does not
know how to write partition tables yet, it is currently read-only.
Devices are discovered by scanning /dev for block device files.
Since block devices are chmod 600, PartitionEditor be must run as root.
By default Serenity uses the entire disk for the ext2 filesystem
without a partition table. This isn't useful for testing as the
partition list for the default disk will be empty. To test properly,
I created a few disk images using various partitioning schemes
(MBR, EBR, and GPT) and attached them using the following command:
export SERENITY_EXTRA_QEMU_ARGS="
-drive file=/path/to/mbr.img,format=raw,index=1,media=disk
-drive file=/path/to/ebr.img,format=raw,index=2,media=disk
-drive file=/path/to/gpt.img,format=raw,index=3,media=disk"
2022-06-27 23:48:30 -03:00
|
|
|
|
|
|
|
|
window->show();
|
|
|
|
|
return app->exec();
|
|
|
|
|
}
|