repbuild r uses udisks

limine
ondra05 2022-12-03 17:47:10 +01:00
parent edbdf9456f
commit 76e2bd286b
1 changed files with 78 additions and 55 deletions

View File

@ -11,7 +11,10 @@ use std::{
os::fd::AsRawFd,
process::Command,
};
use udisks::{filesystem::UnMountOptions, manager::LoopSetupOptions};
use udisks::{
filesystem::{MountOptions, UnMountOptions},
manager::LoopSetupOptions,
};
struct Options {
pub subcommand: Subcommand,
@ -257,40 +260,52 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// Setup loopback device for disk.img, with partitions
// FIXME: don't do ths if running without changes
Command::new("sudo")
.arg("losetup")
.args(["-P", "/dev/loop0", "disk.img"])
.status()
.unwrap();
// Setup loop device
let disk_img = File::options().read(true).write(true).open("disk.img")?;
let dbus_conn = zbus::blocking::Connection::system()?;
let loopdev = udisks::manager::UDisks2ManagerProxyBlocking::new(&dbus_conn)?
.loop_setup(
disk_img.as_raw_fd().into(),
LoopSetupOptions {
no_user_interaction: true,
offset: 0,
size: 0,
readonly: false,
no_part_scan: false,
},
)?;
// mount the root fs to ./disk
Command::new("sudo")
.arg("mount")
.args(["/dev/loop0p1", "./disk"])
.status()
.unwrap();
let parts = udisks::partition::PartitionTableProxyBlocking::builder(&dbus_conn)
.destination("org.freedesktop.UDisks2")?
.path(loopdev)?
.build()?
.partitions()?;
let fsobjpath = parts.get(0).ok_or("missing boot partition")?;
let mountpoint =
udisks::filesystem::FilesystemProxyBlocking::builder(&dbus_conn)
.path(fsobjpath)?
.build()?
.mount(MountOptions {
no_user_interaction: true,
fs_type: String::new(),
mount_options: String::new(),
})?;
// copy the kernel over to ./disk/boot/kernel
Command::new("sudo")
.arg("cp")
Command::new("cp")
.arg("./target/x86_64-ableos/debug/ableos")
.arg("./disk/boot/kernel")
.arg(format!("{mountpoint}/boot/kernel"))
.status()
.unwrap();
// unmount the root fs
Command::new("sudo")
.arg("umount")
.arg("./disk")
.status()
.unwrap();
// remove loopback device
Command::new("sudo")
.arg("losetup")
.args(["-d", "/dev/loop0"])
.status()
.unwrap();
udisks::filesystem::FilesystemProxyBlocking::builder(&dbus_conn)
.path(fsobjpath)?
.build()?
.unmount(UnMountOptions {
no_user_interaction: true,
force: false,
})?;
// run qemu with "-S", "-gdb", "tcp:9000"
Command::new("qemu-system-x86_64")
@ -324,40 +339,48 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// Setup loopback device for disk.img, with partitions
// FIXME: don't do ths if running without changes
Command::new("sudo")
.arg("losetup")
.args(["-P", "/dev/loop0", "disk.img"])
.status()
.unwrap();
let disk_img = File::options().read(true).write(true).open("disk.img")?;
let dbus_conn = zbus::blocking::Connection::system()?;
let loopdev = udisks::manager::UDisks2ManagerProxyBlocking::new(&dbus_conn)?
.loop_setup(
disk_img.as_raw_fd().into(),
LoopSetupOptions {
no_user_interaction: true,
offset: 0,
size: 0,
readonly: false,
no_part_scan: false,
},
)?;
// mount the root fs to ./disk
Command::new("sudo")
.arg("mount")
.args(["/dev/loop0p1", "./disk"])
.status()
.unwrap();
let parts = udisks::partition::PartitionTableProxyBlocking::builder(&dbus_conn)
.destination("org.freedesktop.UDisks2")?
.path(loopdev)?
.build()?
.partitions()?;
let fsproxy = udisks::filesystem::FilesystemProxyBlocking::builder(&dbus_conn)
.path(&parts[0])?
.build()?;
// Obtain mountpoint
let mountpoint = loop {
if let Some(m) = fsproxy.mount_points()?.get(0) {
break m.to_string();
}
};
// copy the kernel over to ./disk/boot/kernel
Command::new("sudo")
.arg("cp")
Command::new("cp")
.arg("./target/x86_64-ableos/release/ableos")
.arg("./disk/boot/kernel")
.arg(format!("{mountpoint}/boot/kernel"))
.status()
.unwrap();
// unmount the root fs
Command::new("sudo")
.arg("umount")
.arg("./disk")
.status()
.unwrap();
// remove loopback device
Command::new("sudo")
.arg("losetup")
.args(["-d", "/dev/loop0"])
.status()
.unwrap();
fsproxy.unmount(UnMountOptions {
no_user_interaction: true,
force: false,
})?;
// run qemu
Command::new("qemu-system-x86_64")