Page MenuHomeFreeBSD

Add a tool to decode ioctl commands.
ClosedPublic

Authored by jhb on Jun 15 2016, 12:20 AM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Nov 19, 7:19 AM
Unknown Object (File)
Sun, Nov 17, 1:07 AM
Unknown Object (File)
Fri, Nov 8, 4:21 AM
Unknown Object (File)
Sep 30 2024, 12:33 AM
Unknown Object (File)
Sep 29 2024, 11:26 PM
Unknown Object (File)
Sep 17 2024, 11:28 AM
Unknown Object (File)
Sep 17 2024, 3:02 AM
Unknown Object (File)
Sep 8 2024, 8:02 PM
Subscribers

Details

Summary

Add a tool to decode ioctl commands.

One or more ioctl command values can be passed as arguments on the command
line. For each value, the command is broken down into it's sub parts
(direction, group, number, and length). In addition, if a commands has a
known name it is output via sysdecode_ioctlname().

I've had this in my private repo for a while as a standalone little tool,
but libsysdecode integration is simpler if this is in tools/tools/ perhaps.

Sample output:

./decioctl 0xc4d01902 0xc4e01902

command :  dir  grp num len   name

0xc4d01902: INOUT 25 2 1232 CAMIOCOMMAND
0xc4e01902: INOUT 25 2 1248

Test Plan
  • Run it against some constants avg@ pasted in IRC

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

jhb retitled this revision from to Add a tool to decode ioctl commands..
jhb updated this object.
jhb edited the test plan for this revision. (Show Details)
jhb added reviewers: kib, avg.
emaste added inline comments.
tools/tools/decioctl/decioctl.c
54 ↗(On Diff #17594)

Check for ERANGE too?

kib edited edge metadata.
kib added inline comments.
tools/tools/decioctl/decioctl.c
81 ↗(On Diff #17594)

Might be print both forms if the group value is printable.

This revision is now accepted and ready to land.Jun 15 2016, 6:19 AM
tools/tools/decioctl/decioctl.c
54 ↗(On Diff #17594)

Hmm, that seems like a bit of a PITA. It seems you have to explicit set errno to 0 before you call and then check errno if the return value is ULONG_MAX? Hmm, POSIX says that a successful strtol() (strtoll()) do not change errno if successful, so setting errno to 0 first and checking afterward should work in theory.

81 ↗(On Diff #17594)

Originally it only printed '%c' since most kernel source code that I've seen uses chars for the group. Apparently CAM uses 0x19 so I added the fallback yesterday. I could print both, it just makes the layout of the table wider. I'd rather print it as hex instead of decimal anyway.

tools/tools/decioctl/decioctl.c
54 ↗(On Diff #17594)

Yeah I wish there was a canonical strtol example. I think setting errno to 0 before and then checking *cp != '\0' || errno != 0 is OK for error checking.

jhb edited edge metadata.
  • Handle errors from strtol().
  • Adjust format.
This revision now requires review to proceed.Jun 15 2016, 6:08 PM

Updated output:

> ./decioctl 0xc4d01902 0xc4e01902 0x4004667f
  command :  dir  group num  len name
0xc4d01902: INOUT  0x19   2 1232 CAMIOCOMMAND
0xc4e01902: INOUT  0x19   2 1248
0x4004667f: OUT    'f'  127    4 FIONREAD
emaste added a reviewer: emaste.
This revision is now accepted and ready to land.Jun 15 2016, 6:09 PM
avg edited edge metadata.

Looks great!

This revision was automatically updated to reflect the committed changes.