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

Weird ioctl_readwrite! behaviour for values above 10 #2623

Open
mekanix opened this issue Apr 4, 2025 · 2 comments
Open

Weird ioctl_readwrite! behaviour for values above 10 #2623

mekanix opened this issue Apr 4, 2025 · 2 comments

Comments

@mekanix
Copy link

mekanix commented Apr 4, 2025

I'm trying to implement crate to make OSS (audio on FreeBSD) handling easier, and this is the part of code that is behaving strangely

const SNDCTL_DSP_MAGIC: u8 = b'P';
const SNDCTL_DSP_COOKEDMODE: u8 = 30;
nix::ioctl_readwrite!(oss_set_cooked, SNDCTL_DSP_MAGIC, SNDCTL_DSP_COOKEDMODE, i32);

Later I call it like this

let mut cooked: i32 = 0;
oss_set_cooked(fd, &mut cooked).expect("Failed to disable cooked mode");

When I use truss to look at the syscalls, I get this

# truss target/debug/deps/oss-10d0d16316d09bcd --ignored 2>&1 | grep -A1 dsp
openat(AT_FDCWD,"/dev/dsp4",O_WRONLY|O_CLOEXEC,00) = 4 (0x4)
ioctl(4,0xc004501e { IORW 0x50('P'), 30, 4 },0x2fa2c9fc85ec) ERR#22 'Invalid argument'

But if I change SNDCTL_DSP_COOKEDMODE to 9 for example, this is what I get

# truss target/debug/deps/oss-10d0d16316d09bcd --ignored 2>&1 | grep -A1 dsp
openat(AT_FDCWD,"/dev/dsp4",O_WRONLY|O_CLOEXEC,00) = 4 (0x4)
ioctl(4,SNDCTL_DSP_SUBDIVIDE,0x157e572ad5ec)	 ERR#22 'Invalid argument'

Can you help me debug this, please? I'm new to Rust, but not new to FreeBSD. Thank you!

@asomers
Copy link
Member

asomers commented Apr 5, 2025

Hi Goran! I think you're close, but you should use ioctl_write! instead of ioctl_readwrite!. That affects the calculation of the second argument of ioctl.

@mekanix
Copy link
Author

mekanix commented Apr 5, 2025

If I use nix::ioctl_write_int!(oss_set_cooked, SNDCTL_DSP_MAGIC, SNDCTL_DSP_COOKEDMODE); I get the same result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants