Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DBusStructures: add filesystem enum #800

Merged
merged 3 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 55 additions & 7 deletions common/DBusStructures.vala
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,58 @@ public struct InstallerDaemon.Disk {
Partition[] partitions;
}

public enum InstallerDaemon.FileSystem {
NONE,
BTRFS,
EXT2,
EXT3,
EXT4,
F2FS,
FAT16,
FAT32,
NTFS,
SWAP,
XFS,
LVM,
LUKS;

public unowned string to_string () {
switch (this) {
case BTRFS:
return "btrfs";
case EXT2:
return "ext2";
case EXT3:
return "ext3";
case EXT4:
return "ext4";
case F2FS:
return "f2fs";
case FAT16:
return "fat16";
case FAT32:
return "fat32";
case NTFS:
return "ntfs";
case SWAP:
return "swap";
case XFS:
return "xfs";
case LVM:
return "lvm";
case LUKS:
return "luks";
case NONE:
default:
return "none";
}
}
}

public struct InstallerDaemon.Partition {
string device_path;

Distinst.FileSystem filesystem;
FileSystem filesystem;

uint64 start_sector;
uint64 end_sector;
Expand Down Expand Up @@ -62,18 +110,18 @@ public struct InstallerDaemon.Mount {
string parent_disk;
string mount_point;
uint64 sectors;
Distinst.FileSystem filesystem;
FileSystem filesystem;
MountFlags flags;

public bool is_valid_boot_mount () {
return filesystem == Distinst.FileSystem.FAT16
|| filesystem == Distinst.FileSystem.FAT32;
return filesystem == FileSystem.FAT16
|| filesystem == FileSystem.FAT32;
}

public bool is_valid_root_mount () {
return filesystem != Distinst.FileSystem.FAT16
&& filesystem != Distinst.FileSystem.FAT32
&& filesystem != Distinst.FileSystem.NTFS;
return filesystem != FileSystem.FAT16
&& filesystem != FileSystem.FAT32
&& filesystem != FileSystem.NTFS;
}

public bool is_lvm () {
Expand Down
82 changes: 74 additions & 8 deletions daemon/Daemon.vala
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class InstallerDaemon.Daemon : GLib.Object {

partitions += Partition () {
device_path = string_from_utf8 (part.get_device_path ()),
filesystem = part.get_file_system (),
filesystem = to_common_fs (part.get_file_system ()),
start_sector = part.get_start_sector (),
end_sector = part.get_end_sector (),
sectors_used = part.sectors_used (disk.get_sector_size ()),
Expand Down Expand Up @@ -103,7 +103,7 @@ public class InstallerDaemon.Daemon : GLib.Object {

partitions += Partition () {
device_path = string_from_utf8 (part.get_device_path ()),
filesystem = part.get_file_system (),
filesystem = to_common_fs (part.get_file_system ()),
start_sector = part.get_start_sector (),
end_sector = part.get_end_sector (),
sectors_used = part.sectors_used (disk.get_sector_size ()),
Expand Down Expand Up @@ -149,7 +149,7 @@ public class InstallerDaemon.Daemon : GLib.Object {

partitions += Partition () {
device_path = string_from_utf8 (part.get_device_path ()),
filesystem = part.get_file_system (),
filesystem = to_common_fs (part.get_file_system ()),
start_sector = part.get_start_sector (),
end_sector = part.get_end_sector (),
sectors_used = part.sectors_used (disk.get_sector_size ()),
Expand Down Expand Up @@ -451,7 +451,7 @@ public class InstallerDaemon.Daemon : GLib.Object {
if (m.mount_point == "/boot/efi") {
if (m.is_valid_boot_mount ()) {
if (m.should_format ()) {
partition.format_with (m.filesystem);
partition.format_with (to_distinst_fs (m.filesystem));
}

partition.set_mount (m.mount_point);
Expand All @@ -460,7 +460,7 @@ public class InstallerDaemon.Daemon : GLib.Object {
throw new GLib.IOError.FAILED ("Unreachable code path -- EFI partition is invalid");
}
} else {
if (m.filesystem != Distinst.FileSystem.SWAP) {
if (m.filesystem != SWAP) {
partition.set_mount (m.mount_point);
}

Expand All @@ -469,7 +469,7 @@ public class InstallerDaemon.Daemon : GLib.Object {
}

if (m.should_format ()) {
partition.format_with (m.filesystem);
partition.format_with (to_distinst_fs (m.filesystem));
}
}
}
Expand Down Expand Up @@ -498,12 +498,12 @@ public class InstallerDaemon.Daemon : GLib.Object {
throw new GLib.IOError.FAILED ("could not find %s", m.partition_path);
}

if (m.filesystem != Distinst.FileSystem.SWAP) {
if (m.filesystem != SWAP) {
partition.set_mount (m.mount_point);
}

if (m.should_format ()) {
partition.format_and_keep_name (m.filesystem);
partition.format_and_keep_name (to_distinst_fs (m.filesystem));
}
}
}
Expand All @@ -513,6 +513,72 @@ public class InstallerDaemon.Daemon : GLib.Object {
builder.append_len ((string) input, input.length);
return (owned) builder.str;
}

private InstallerDaemon.FileSystem to_common_fs (Distinst.FileSystem fs) {
switch (fs) {
case BTRFS:
return InstallerDaemon.FileSystem.BTRFS;
case EXT2:
return InstallerDaemon.FileSystem.EXT2;
case EXT3:
return InstallerDaemon.FileSystem.EXT3;
case EXT4:
return InstallerDaemon.FileSystem.EXT4;
case F2FS:
return InstallerDaemon.FileSystem.F2FS;
case FAT16:
return InstallerDaemon.FileSystem.FAT16;
case FAT32:
return InstallerDaemon.FileSystem.FAT32;
case NONE:
return InstallerDaemon.FileSystem.NONE;
case NTFS:
return InstallerDaemon.FileSystem.NTFS;
case SWAP:
return InstallerDaemon.FileSystem.SWAP;
case XFS:
return InstallerDaemon.FileSystem.XFS;
case LVM:
return InstallerDaemon.FileSystem.LVM;
case LUKS:
return InstallerDaemon.FileSystem.LUKS;
default:
return InstallerDaemon.FileSystem.NONE;
}
}

private Distinst.FileSystem to_distinst_fs (InstallerDaemon.FileSystem fs) {
switch (fs) {
case BTRFS:
return Distinst.FileSystem.BTRFS;
case EXT2:
return Distinst.FileSystem.EXT2;
case EXT3:
return Distinst.FileSystem.EXT3;
case EXT4:
return Distinst.FileSystem.EXT4;
case F2FS:
return Distinst.FileSystem.F2FS;
case FAT16:
return Distinst.FileSystem.FAT16;
case FAT32:
return Distinst.FileSystem.FAT32;
case NONE:
return Distinst.FileSystem.NONE;
case NTFS:
return Distinst.FileSystem.NTFS;
case SWAP:
return Distinst.FileSystem.SWAP;
case XFS:
return Distinst.FileSystem.XFS;
case LVM:
return Distinst.FileSystem.LVM;
case LUKS:
return Distinst.FileSystem.LUKS;
default:
return Distinst.FileSystem.NONE;
}
}
}

private void on_bus_acquired (GLib.DBusConnection connection, string name) {
Expand Down
14 changes: 7 additions & 7 deletions src/Objects/Mount.vala
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ public class Installer.Mount {
public string parent_disk;
public string mount_point;
public uint64 sectors;
public Distinst.FileSystem filesystem;
public InstallerDaemon.FileSystem filesystem;
public InstallerDaemon.MountFlags flags;
public PartitionMenu menu;

public Mount (string partition, string parent_disk, string mount,
uint64 sectors, InstallerDaemon.MountFlags flags, Distinst.FileSystem fs,
uint64 sectors, InstallerDaemon.MountFlags flags, InstallerDaemon.FileSystem fs,
PartitionMenu menu) {
filesystem = fs;
mount_point = mount;
Expand All @@ -40,14 +40,14 @@ public class Installer.Mount {
}

public bool is_valid_boot_mount () {
return filesystem == Distinst.FileSystem.FAT16
|| filesystem == Distinst.FileSystem.FAT32;
return filesystem == FAT16
|| filesystem == FAT32;
}

public bool is_valid_root_mount () {
return filesystem != Distinst.FileSystem.FAT16
&& filesystem != Distinst.FileSystem.FAT32
&& filesystem != Distinst.FileSystem.NTFS;
return filesystem != FAT16
&& filesystem != FAT32
&& filesystem != NTFS;
}

public bool is_lvm () {
Expand Down
2 changes: 1 addition & 1 deletion src/Views/PartitioningView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public class Installer.PartitioningView : AbstractInstallerView {
m.parent_disk,
m.partition_path,
m.mount_point,
Distinst.strfilesys (m.filesystem),
m.filesystem.to_string (),
m.should_format () ? "true" : "false"
);

Expand Down
2 changes: 1 addition & 1 deletion src/Widgets/DiskBar.vala
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class Installer.DiskBar: Gtk.Box {
add_legend (
p.partition.device_path,
p.get_partition_size () * 512,
Distinst.strfilesys (p.partition.filesystem),
p.partition.filesystem.to_string (),
p.volume_group,
p.menu
);
Expand Down
2 changes: 1 addition & 1 deletion src/Widgets/PartitionBar.vala
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class Installer.PartitionBar : Gtk.Box {
hexpand = true;
tooltip_text = partition.device_path;

add_css_class (Distinst.strfilesys (partition.filesystem));
add_css_class (partition.filesystem.to_string ());

bind_property ("icon", image, "gicon", SYNC_CREATE);
}
Expand Down
26 changes: 13 additions & 13 deletions src/Widgets/PartitionMenu.vala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class Installer.PartitionMenu : Gtk.Popover {
private bool is_lvm;
private string parent_disk;
private string partition_path;
private Distinst.FileSystem original_filesystem;
private InstallerDaemon.FileSystem original_filesystem;

private Granite.SwitchModelButton format_partition;
private Granite.SwitchModelButton use_partition;
Expand All @@ -40,7 +40,7 @@ public class Installer.PartitionMenu : Gtk.Popover {
// A reference to the parent which owns this menu.
private PartitionBar partition_bar;

public PartitionMenu (string path, string parent, Distinst.FileSystem fs,
public PartitionMenu (string path, string parent, InstallerDaemon.FileSystem fs,
bool lvm, SetMount set_mount, UnsetMount unset_mount,
MountSetFn mount_set, PartitionBar partition_bar) {
this.partition_bar = partition_bar;
Expand Down Expand Up @@ -205,13 +205,13 @@ public class Installer.PartitionMenu : Gtk.Popover {
disable_signals = false;

int select = 0;
if (fs == Distinst.FileSystem.FAT16 || fs == Distinst.FileSystem.FAT32) {
if (fs == InstallerDaemon.FileSystem.FAT16 || fs == InstallerDaemon.FileSystem.FAT32) {
if (mount_set (boot_partition)) {
select = 4;
} else {
select = 2;
}
} else if (fs == Distinst.FileSystem.SWAP) {
} else if (fs == InstallerDaemon.FileSystem.SWAP) {
select = 3;
} else if (mount_set ("/")) {
if (mount_set ("/home" )) {
Expand Down Expand Up @@ -258,7 +258,7 @@ public class Installer.PartitionMenu : Gtk.Popover {
private void update_values (SetMount set_mount) {
var mount = get_mount ();
var filesystem = mount == "swap"
? Distinst.FileSystem.SWAP
? InstallerDaemon.FileSystem.SWAP
: get_file_system ();

string? error = null;
Expand Down Expand Up @@ -290,22 +290,22 @@ public class Installer.PartitionMenu : Gtk.Popover {
return original_filesystem == get_file_system ();
}

private Distinst.FileSystem get_file_system () {
private InstallerDaemon.FileSystem get_file_system () {
switch (type.active) {
case 0:
return Distinst.FileSystem.EXT4;
return InstallerDaemon.FileSystem.EXT4;
case 1:
return Distinst.FileSystem.FAT16;
return InstallerDaemon.FileSystem.FAT16;
case 2:
return Distinst.FileSystem.FAT32;
return InstallerDaemon.FileSystem.FAT32;
case 3:
return Distinst.FileSystem.BTRFS;
return InstallerDaemon.FileSystem.BTRFS;
case 4:
return Distinst.FileSystem.XFS;
return InstallerDaemon.FileSystem.XFS;
case 5:
return Distinst.FileSystem.NTFS;
return InstallerDaemon.FileSystem.NTFS;
default:
return Distinst.FileSystem.NONE;
return InstallerDaemon.FileSystem.NONE;
}
}

Expand Down
Loading