Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F146553191
D55524.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
D55524.diff
View Options
diff --git a/usr.sbin/diskinfo/Makefile b/usr.sbin/diskinfo/Makefile
--- a/usr.sbin/diskinfo/Makefile
+++ b/usr.sbin/diskinfo/Makefile
@@ -1,7 +1,7 @@
PROG= diskinfo
MAN= diskinfo.8
-LIBADD= util
+LIBADD= util xo
.include <bsd.prog.mk>
diff --git a/usr.sbin/diskinfo/diskinfo.8 b/usr.sbin/diskinfo/diskinfo.8
--- a/usr.sbin/diskinfo/diskinfo.8
+++ b/usr.sbin/diskinfo/diskinfo.8
@@ -27,7 +27,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd March 5, 2024
+.Dd February 25, 2026
.Dt DISKINFO 8
.Os
.Sh NAME
@@ -36,6 +36,7 @@
.Sh SYNOPSIS
.Nm
.Op Fl citSvw
+.Op Fl -libxo
.Ar disk ...
.Nm
.Op Fl l
@@ -51,10 +52,22 @@
utility prints out information about a disk device,
and optionally runs a naive performance test on the device.
.Pp
+The
+.Nm
+utility generates output via
+.Xr libxo 3
+in a selection of different human and machine readable formats.
+See
+.Xr xo_parse_args 3
+for details on command line arguments.
+.Pp
The following options are available:
.Bl -tag -width ".Fl v"
.It Fl v
Print fields one per line with a descriptive comment.
+Non-text output enabled by
+.Fl -libxo
+will always produce the same data as this flag, and nothing else.
.It Fl c
Perform a simple measurement of the I/O read command overhead.
.It Fl i
@@ -95,8 +108,16 @@
devices with corresponding serial numbers:
.Pp
.Dl diskinfo -ls /dev/da?
+.Pp
+Display disk information for
+.Pa /dev/ada0
+in JSON format:
+.Pp
+.Dl diskinfo --libxo json /dev/ada0
.Sh SEE ALSO
-.Xr da 4
+.Xr da 4 ,
+.Xr libxo 3 ,
+.Xr xo_parse_args 3
.Sh HISTORY
The
.Nm
diff --git a/usr.sbin/diskinfo/diskinfo.c b/usr.sbin/diskinfo/diskinfo.c
--- a/usr.sbin/diskinfo/diskinfo.c
+++ b/usr.sbin/diskinfo/diskinfo.c
@@ -41,6 +41,7 @@
#include <errno.h>
#include <fcntl.h>
#include <libutil.h>
+#include <libxo/xo.h>
#include <paths.h>
#include <err.h>
#include <geom/geom_disk.h>
@@ -91,6 +92,10 @@
u_int sectorsize, fwsectors, fwheads, zoned = 0, isreg;
uint32_t zone_mode;
+ argc = xo_parse_args(argc, argv);
+ if (argc < 0)
+ exit(1);
+
while ((ch = getopt(argc, argv, "cilpsStvw")) != -1) {
switch (ch) {
case 'c':
@@ -146,6 +151,7 @@
if (posix_memalign((void **)&buf, PAGE_SIZE, MAXTX))
errx(1, "Can't allocate memory buffer");
+ xo_open_list("disk");
for (i = 0; i < argc; i++) {
fd = open(argv[i], (opt_w ? O_RDWR : O_RDONLY) | O_DIRECT);
if (fd < 0 && errno == ENOENT && *argv[i] != '/') {
@@ -222,6 +228,44 @@
if (error == 0)
zoned = 1;
}
+ /* Emit structured data for non-text output */
+ if (xo_get_style(NULL) != XO_STYLE_TEXT) {
+ xo_open_instance("disk");
+ xo_emit("{e:device/%s}", argv[i]);
+ xo_emit("{e:sectorsize/%u}", sectorsize);
+ xo_emit("{e:mediasize/%jd}", (intmax_t)mediasize);
+ humanize_number(tstr, 5, (int64_t)mediasize, "",
+ HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL);
+ xo_emit("{e:mediasize_human/%s}", tstr);
+ xo_emit("{e:mediasize_sectors/%jd}", (intmax_t)mediasize/sectorsize);
+ xo_emit("{e:stripesize/%jd}", (intmax_t)stripesize);
+ xo_emit("{e:stripeoffset/%jd}", (intmax_t)stripeoffset);
+ if (fwsectors != 0 && fwheads != 0) {
+ xo_emit("{e:cylinders/%jd}", (intmax_t)mediasize /
+ (fwsectors * fwheads * sectorsize));
+ xo_emit("{e:heads/%u}", fwheads);
+ xo_emit("{e:sectors/%u}", fwsectors);
+ }
+ strlcpy(arg.name, "GEOM::descr", sizeof(arg.name));
+ arg.len = sizeof(arg.value.str);
+ if (ioctl(fd, DIOCGATTR, &arg) == 0)
+ xo_emit("{e:description/%s}", arg.value.str);
+ if (ioctl(fd, DIOCGIDENT, ident) == 0)
+ xo_emit("{e:ident/%s}", ident);
+ strlcpy(arg.name, "GEOM::attachment", sizeof(arg.name));
+ arg.len = sizeof(arg.value.str);
+ if (ioctl(fd, DIOCGATTR, &arg) == 0)
+ xo_emit("{e:attachment/%s}", arg.value.str);
+ if (ioctl(fd, DIOCGPHYSPATH, physpath) == 0)
+ xo_emit("{e:physpath/%s}", physpath);
+ xo_emit("{e:trim_support/%s}", candelete(fd) ? "Yes" : "No");
+ rotationrate(fd, rrate, sizeof(rrate));
+ xo_emit("{e:rotation_rate/%s}", rrate);
+ if (zoned != 0)
+ xo_emit("{e:zone_mode/%s}", zone_desc);
+ xo_close_instance("disk");
+ goto out;
+ }
if (!opt_v) {
printf("%s", argv[i]);
printf("\t%u", sectorsize);
@@ -283,7 +327,9 @@
out:
close(fd);
}
+ xo_close_list("disk");
free(buf);
+ xo_finish();
exit (exitval);
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Mar 4, 2:47 PM (2 h, 30 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
29246786
Default Alt Text
D55524.diff (4 KB)
Attached To
Mode
D55524: diskinfo: Add libxo support to diskinfo
Attached
Detach File
Event Timeline
Log In to Comment