(DBus) How to use UDisks2 OpenDevice method?

I have a block object and I want to call the OpenDevice method on it.

// zbus = "1.1.1"
// zvariant = "2.1.0"

use std::error::Error;

fn main() -> Result<(), Box<dyn Error>> {
    let connection = zbus::Connection::new_system()?;
    let udisks_proxy = zbus::Proxy::new(
    let msg = udisks_proxy.call_method(
        &std::collections::HashMap::<String, zvariant::Value>::new(),
    let resp: Vec<zvariant::ObjectPath> = msg.body()?;
    for op in resp {
        let block = op.as_str();
        // print!("{} ==> ", block);
        let block_proxy = zbus::Proxy::new(

        let block_msg = block_proxy.get_property::<zvariant::ObjectPath>("Drive")?;
        let drive = block_msg.as_str();

        if drive.as_bytes().len() > 1 { // Eliminate "/"
            let drive_proxy = zbus::Proxy::new(

            let ejectable_msg = drive_proxy.get_property::<bool>("Ejectable")?;

            if ejectable_msg {
                // open the `block` in "w" mode with the O_SYNC flag 

Looking at the OpenDevice method, it appears that it accepts two arguments:

OpenDevice (IN  s     mode,
            IN  a{sv} options,
            OUT h     fd);
  1. How does this s mode and a{sv} options fit into the Body?

  2. In the options argument, what is the key and the value? I don't see how O_SYNC can be used here.

  1. By using a tuple, it's a heterogeneous container.
  2. Key is a &str ("flag") and mode is a zvariant::Value(I32):
let mut arg = std::collections::HashMap::<&str, zvariant::Value>::new();
                arg.insert("flags", zvariant::Value::I32(libc::O_SYNC));
                let fd: i32 = block_proxy.call_method("OpenDevice", &("rw", arg))?.body()?;

Now I have to debug this error:

Error: MethodError("org.freedesktop.UDisks2.Error.Failed", Some("Error opening device /dev/sdb: No medium found"), Msg { type: Error, sender: ":1.9", reply-serial: 27, body: Signature([115]) })

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.