Solved determine mounts in a non-screenscrapeish way?

Given a current mount's node, I'd like to get its special, and vice-versa too, but for a computer (e.g. script) rather than for a human.

I know I can get the map of specials and nodes for what's currently mounted via either the mount command or the df command, but both of these produce output that really seems intended for human consumption (and I didn't notice any options in their man pages to produce output more suitable for a computer, though I certainly could've overlooked or misinterpreted such options).

I can of course write a script to parse the output of either of those commands for the information I'm looking for, but I'd much rather just have an explicit way that doesn't rely upon me knowing about and correctly accounting for all possible edge cases (simple example: whitespace in the node name). For example, something like the following hypothetical commands:

Code:
# specialfromnode /blah/bling
/dev/da3p7
# nodefromspecial /dev/da3p7
/blah/bling

Is there such a thing? I'm hoping for a built-in command, but (for example) a port would do. Or even something like a kernel call, though I'd prefer to avoid that sort of thing if possible.

Thanks in advance.
 
with jq from ports: mount --libxo:J | jq -r '.mount.mounted | map(select(.node=="/"))[0].special'

this returns the special for the root mount. the other query should be a similar pattern.
 
Back
Top