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

Additional examples for ioctl #573

Closed
beamspease opened this issue Apr 12, 2017 · 5 comments · Fixed by #670
Closed

Additional examples for ioctl #573

beamspease opened this issue Apr 12, 2017 · 5 comments · Fixed by #670
Labels

Comments

@beamspease
Copy link

Some additional examples for ioctl would be very helpful. It's taken me a bit to figure out how I'm supposed to do BLKSZGET. Thanks.

@Susurrus
Copy link
Contributor

Since you've already figured out how to use ioctl for BLKSZGET and have code for it, would you be willing to submit something as an example?

@Susurrus Susurrus added the A-docs label Jun 4, 2017
@Susurrus
Copy link
Contributor

Susurrus commented Jul 3, 2017

@beamspease Just wanted to ping you on this. Would love to get your examples into our documentation.

@roblabla
Copy link
Contributor

roblabla commented Jul 4, 2017

I'm not sure what BLKSZGET is, but for BLKBSZGET, here's how it goes.

You can see here that it's a read ioctl. Meaning the ioctl will return stuff to us.

From this, we know the ioctl should be written like so :

/// Get block device soft block size
ioctl!(read blkbszget with 0x12; 112; size_t)

@Susurrus
Copy link
Contributor

Susurrus commented Jul 6, 2017

I'd love to get this written up as a proper example. Something like.

/// To use the `ioctl!` macro, you'll need to reference existing documentation. Many macros are defined 
/// using the `IO()`, `IOR()`, and `IOW()` macros. This is handled by the `ioctl!` macro in `nix`, but the
/// arguments to it need to be passed in to `ioctl!`.
///
/// As an example, the BLKBSZGET ioctl is defined as `#define BLKBSZGET _IOR(0x12,112,size_t)`.
/// Because it uses the `IOR()` macro, we can tell it's a `read` ioctl. So to write this using `ioctl!` it would
/// look like `ioctl!(read blkbszget with 0x12; 112; size_t)`. This macro would generate a function that
/// looks like: `pub unsafe fn blkbszget(fd: nix::sys::ioctl::libc::c_int, val: *mut size_t) ->
/// nix::Result<nix::sys::ioctl::libc::c_int>`. Therefore this ioctl will write data into the given `size_t`
/// variable.

@Susurrus
Copy link
Contributor

@beamspease Could you check out #670 and let me know if that would be in line with what you'd like in the docs for ioctl!?

bors bot added a commit that referenced this issue Jul 21, 2017
670: Improve ioctl docs r=asomers

Integrates suggestions and comments made in #641. Basically we hid a lot of the internal workings of things and also revised the docs to make it more clear the exact API that `nix` is exposing.

There is a small amount of code cleanup I did in the macros. I also fixed the `bad` version of the `ioctl!` macro and also added a `bad none` version for use with no-data, hardcoded-number `ioctl`s.

Would appreciate any and all feedback. Please especially fetch this code locally and generate the pretty docs for it (`cargo doc --no-deps --open`) so you can see what our users will see.

Closes #641.
Closes #573.

cc @cmr @roblabla
@bors bors bot closed this as completed in #670 Jul 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants