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

Add protable wrappers for the block device IOCTLs #1374

Closed
aj-bagwell opened this issue Jan 12, 2021 · 4 comments
Closed

Add protable wrappers for the block device IOCTLs #1374

aj-bagwell opened this issue Jan 12, 2021 · 4 comments

Comments

@aj-bagwell
Copy link

Add a portable and safe way of getting things like the size of block device (e.g. USB sticks or SD cards).

Other people (#1006 & #573) have had issue using the ioctl directly so it would be nice to have a safe simple wrapper.

It should have:

  • a way to get the size of a block (BLKSSZGET)
  • a way to get the size of the disc in bytes (BLKGETSIZE64)
  • a way to get the number of block

It would be nice to support the other BLK* ioctls

  • re-read partion table (BLKRRPART)
  • discard a range of blocks (BLKDISCARD)
  • zero a range of block (BLKZEROOUT)
  • check if the underlying medai supports something like TRIM that zeros when a block is discarded (BLKDISCARDZEROS)
@asomers
Copy link
Member

asomers commented Jan 13, 2021

I think this is really beyond the scope of Nix. We define the ioctl macros, but we shouldn't also wrap every single ioctl. There are tons.

@posborne
Copy link
Member

I agree with @asomers. This is good functionality but it might make sense to have it live in its own crate which in turn depends on Nix. The scope of nix itself would be quite large and difficult to maintain if we tried to provide more than basic safety over the lower level calls. In addition, defining a portable API, which is a good goal in general, works against the goals of nix to safely expose the full underlying functionality of supported operating systems.

Hopefully these comments make sense. I've personally had use of such functionality on block devices, so an abstraction like this is far from useless. Just might need to find a different home.

@aj-bagwell
Copy link
Author

Thanks for fast replies, I was not sure if nix was the right place, for it. I'll look into turning it into a stand alone crate.

@aj-bagwell
Copy link
Author

Finally got round to making a block-devs crate with this code, just in case any one else is interested.

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

Successfully merging a pull request may close this issue.

3 participants