1.\" 2.\" Copyright (c) 2013, 2015 Spectra Logic Corporation 3.\" All rights reserved. 4.\" 5.\" Redistribution and use in source and binary forms, with or without 6.\" modification, are permitted provided that the following conditions 7.\" are met: 8.\" 1. Redistributions of source code must retain the above copyright 9.\" notice, this list of conditions, and the following disclaimer, 10.\" without modification. 11.\" 2. Redistributions in binary form must reproduce at minimum a disclaimer 12.\" substantially similar to the "NO WARRANTY" disclaimer below 13.\" ("Disclaimer") and any redistribution must be conditioned upon 14.\" including a substantially similar Disclaimer requirement for further 15.\" binary redistribution. 16.\" 17.\" NO WARRANTY 18.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19.\" "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20.\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 21.\" A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22.\" HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 27.\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28.\" POSSIBILITY OF SUCH DAMAGES. 29.\" 30.\" Authors: Ken Merry (Spectra Logic Corporation) 31.\" 32.\" $FreeBSD$ 33.\" 34.Dd February 13, 2015 35.Dt MT 3 36.Os 37.Sh NAME 38.Nm 39.Nm mt_start_element , 40.Nm mt_end_element , 41.Nm mt_char_handler , 42.Nm mt_status_tree_sbuf , 43.Nm mt_status_tree_print , 44.Nm mt_status_entry_free , 45.Nm mt_status_free , 46.Nm mt_entry_sbuf , 47.Nm mt_param_parent_print , 48.Nm mt_param_entry_print , 49.Nm mt_protect_print , 50.Nm mt_param_list , 51.Nm mt_density_name , 52.Nm mt_density_bp , 53.Nm mt_density_num , 54.Nm mt_get_xml_str , 55.Nm mt_get_status 56.Nd Magnetic Tape library 57.Sh LIBRARY 58.Lb libmt 59.Sh SYNOPSIS 60.In sys/sbuf.h 61.In bsdxml.h 62.In mtlib.h 63.Ft void 64.Fo mt_start_element 65.Fa "void *user_data" 66.Fa "const char *name" 67.Fa "const char **attr" 68.Fc 69.Ft void 70.Fo mt_end_element 71.Fa "void *user_data" 72.Fa "const char *name" 73.Fc 74.Ft void 75.Fo mt_char_handler 76.Fa "void *user_data" 77.Fa "const XML_Char *str" 78.Fa "int len" 79.Fc 80.Ft void 81.Fo mt_status_tree_sbuf 82.Fa "struct sbuf *sb" 83.Fa "struct mt_status_entry *entry" 84.Fa "int indent" 85.Fa "void (*sbuf_func)(struct sbuf *sb, struct mt_status_entry *entry, void *arg)" 86.Fa "void *arg" 87.Fc 88.Ft void 89.Fo mt_status_tree_print 90.Fa "struct mt_status_entry *entry" 91.Fa "int indent" 92.Fa "void (*print_func)(struct mt_status_entry *entry, void *arg)" 93.Fa "void *arg" 94.Fc 95.Ft "struct mt_status_entry *" 96.Fo mt_entry_find 97.Fa "struct mt_status_entry *entry" 98.Fa "char *name" 99.Fc 100.Ft "struct mt_status_entry *" 101.Fo mt_status_entry_find 102.Fa "struct mt_status_data *status_data" 103.Fa "char *name" 104.Fc 105.Ft void 106.Fo mt_status_entry_free 107.Fa "struct mt_status_entry *entry)" 108.Fc 109.Ft void 110.Fo mt_status_free 111.Fa "struct mt_status_data *status_data" 112.Fc 113.Ft void 114.Fo mt_entry_sbuf 115.Fa "struct sbuf *sb" 116.Fa "struct mt_status_entry *entry" 117.Fa "char *fmt" 118.Fc 119.Ft void 120.Fo mt_param_parent_sbuf 121.Fa "struct sbuf *sb" 122.Fa "struct mt_status_entry *entry" 123.Fa "struct mt_print_params *print_params" 124.Fc 125.Ft void 126.Fo mt_param_parent_print 127.Fa "struct mt_status_entry *entry" 128.Fa "struct mt_print_params *print_params" 129.Fc 130.Ft void 131.Fo mt_param_entry_sbuf 132.Fa "struct sbuf *sb" 133.Fa "struct mt_status_entry *entry" 134.Fa "void *arg" 135.Fc 136.Ft void 137.Fo mt_param_entry_print 138.Fa "struct mt_status_entry *entry" 139.Fa "void *arg" 140.Fc 141.Ft int 142.Fo mt_protect_print 143.Fa "struct mt_status_data *status_data" 144.Fa "int verbose" 145.Fc 146.Ft int 147.Fo mt_param_list 148.Fa "struct mt_status_data *status_data" 149.Fa "char *param_name" 150.Fa "int quiet" 151.Fc 152.Ft "const char *" 153.Fo mt_density_name 154.Fa "int density_num" 155.Fc 156.Ft int 157.Fo mt_density_bp 158.Fa "int density_num" 159.Fa "int bpi" 160.Fc 161.Ft int 162.Fo mt_density_num 163.Fa "const char *density_name" 164.Fc 165.Ft int 166.Fo mt_get_status 167.Fa "char *xml_str" 168.Fa "struct mt_status_data *status_data" 169.Fc 170.Sh DESCRIPTION 171The MT library consists of a number of functions designed to aid in 172interacting with the 173.Xr sa 4 174driver. 175The 176.Xr sa 4 177driver returns some status data as XML-formatted strings, and 178the primary purpose of this library is to make it easier for the 179software developer to parse those strings and extract the status values. 180.Pp 181The 182.Fn mt_start_element , 183.Fn mt_end_element , 184and 185.Fn mt_char_handler 186functions are designed to work with the 187.Xr libbbsdxml 3 188library, which is an XML parsing library. 189The user data for the XML parser should be set with 190.Fn XML_SetUserData 191to a zeroed struct 192mt_status_data with the entries list initialized. 193The element handlers for the XML parser should be set to 194.Fn mt_start_element 195and 196.Fn mt_end_element 197with 198.Fn XML_SetElementHandler . 199The character data handler should be set to 200.Fn mt_char_handler 201with the 202.Fn XML_SetCharacterDataHandler 203function. 204The error member of the status_data structure will be set to 0 if parsing 205is successful, and non-zero if parsing failed. 206In the event of a failure, the error_str member will contain an error 207message describing the failure. 208These functions will build a tree of tape driver status data that can be 209searched and printed using the other functions in this library. 210.Pp 211.Fn mt_status_tree_sbuf 212takes the root node of a tree of 213.Xr sa 4 214driver status information, and displays it in an 215.Xr sbuf 9 . 216The 217.Ar sb 218argument is the destination sbuf. 219The 220.Ar entry 221argument is the root of the tree. 222The 223.Ar indent 224argument is the number of characters to indent the output. 225Each recursive call to 226.Fn mt_status_tree_sbuf 227will have the indent level incremented by 2. 228The 229.Ar sbuf_func 230argument is for a user-supplied alternate printing function. 231If it is non-NULL, it will be called instead of the default output printing 232code. 233The 234.Ar arg 235argument is an argument for the 236.Ar sbuf_func 237function. 238.Pp 239The 240.Fn mt_status_tree_print 241function is the same as the 242.Fn mt_status_tree_sbuf 243function, except that the tree is printed to standard out instead of to a 244sbuf. 245.Pp 246The 247.Fn mt_entry_find 248function returns the first entry in the tree starting at 249.Ar entry 250that matches 251.Ar name . 252The supplied node name can be a single level name like "foo", or it can 253specify mulitple node names that must be matched, for instance "foo.bar.baz". 254In the case of a single level name, it will match any node beneath 255.Ar entry 256that matches 257.Ar name . 258In the case of a multi-level name like "foo.bar.baz", it will return the 259first entry named "baz" whose immediate parent is "bar" and where the 260parent of "bar" is named "foo". 261.Pp 262The 263.Fn mt_status_entry_find 264is the same as 265.Fn mt_entry_find , 266except that it operates on the top level mt_status_data and all 267mt_status_entry nodes below it instead of just an mt_status_entry 268structure. 269.Pp 270The 271.Fn mt_status_entry_free 272function frees the tree of status data underneath 273.Ar entry . 274.Pp 275The 276.Fn mt_status_free 277function frees the tree of status data underneath 278.Ar status_data . 279.Pp 280The 281.Fn mt_entry_sbuf 282function prints 283.Ar entry 284to the supplied sbuf 285.Ar sb , 286optionally using the 287.Xr printf 3 288format 289.Ar fmt . 290If 291.Ar fmt 292is NULL, then 293.Fn mt_entry_sbuf 294will render integer types in base 10 without special formatting and all 295other types as they were rendered in the XML. 296.Pp 297.Fn mt_param_parent_sbuf 298prints the parents of the given 299.Ar entry 300to the supplied sbuf 301.Ar sb 302subject to the print parameters 303.Ar print_params . 304The result will be formatted with a period between each level, like 305"foo.bar.baz". 306.Pp 307.Fn mt_param_parent_print 308is like 309.Fn mt_param_parent_sbuf 310except that it prints the results to standard output instead of an sbuf. 311.Pp 312.Fn mt_param_entry_sbuf 313prints the 314.Ar entry 315to the given sbuf 316.Ar sb . 317The argument 318.Ar arg 319is a pointer to struct mt_print_params, which allows the caller to control 320the printing output. 321This function is intended to be supplied as an argument to 322.Fn mt_status_tree_sbuf . 323.Pp 324.Fn mt_param_entry_print 325is like 326.Fn mt_param_entry_sbuf 327except that it prints to standard output instead of an sbuf. 328It is intended to be used as an argument to 329.Fn mt_status_tree_print . 330.Pp 331.Fn mt_protect_print 332prints tape drive protection information from the supplied 333.Ar status_data 334beginning at the node name defined as the root node for protection data. 335If the 336.Ar verbose 337argument is non-zero, protection entry descriptions will be printed. 338If it is zero, protection entry descriptions will not be printed. 339.Pp 340.Fn mt_param_list 341prints tape driver parameters information from the supplied 342.Ar status_data . 343If the 344.Ar param_name 345is non-NULL, only the named parameter will be printed. 346If 347.Ar quiet 348is non-zero, parameter descriptions will be omitted in the output. 349.Pp 350.Fn mt_density_name 351Returns a text identifier for the supplied numeric 352.Ar density_num . 353The 354.Ar density_num 355should currently be a value between 0 and 255 inclusive, since that is the 356valid range for 357.Tn SCSI 358density code values. 359See below for notes on the return values. 360.Pp 361.Fn mt_density_bp 362Returns the bits per inch or bits per mm values for a given density entry 363specified by the 364.Ar density_num . 365If the 366.Ar bpi 367argument is non-zero, the bits per inch value is returned. 368Otherwise, the bits per mm value is returned. 369.Pp 370.Fn mt_density_num 371returns a numeric value for a text density description. 372It does a case-insensitive comparison of density names in the density table 373to the supplied density name. 374.Pp 375.Fn mt_get_xml_str 376gets the current XML status / parameter string from the sa(4) driver 377instance referenced by the open file descriptor 378.Ar mtfd . 379The 380.Xr mtio 4 381.Xr ioctl 2 382to be used is supplied as the 383.Ar cmd 384argument. 385Currently the 386.Fn mt_get_xml_str 387function will work with the 388.Dv MTIOCEXTGET 389and 390.Dv MTIOCPARAMGET 391ioctls. 392The supplied 393.Ar xml_str 394will be filled in with a pointer to the complete XML status string. 395Multiple calls to the given 396.Xr ioctl 2 397are made and more space is malloced until all of the XML string is fetched. 398The string returned in the 399.Ar xml_str 400argument should be freed when it is no longer in use. 401.Sh RETURN VALUES 402.Fn mt_entry_find 403returns the first matching entry, or NULL if it fails to find a match. 404.Pp 405.Fn mt_status_entry_find 406returns the first matching entry, or NULL if it fails to find a match. 407.Pp 408.Fn mt_protect_print 409Returns 0 for success, and non-zero for failure. 410.Fn mt_protect_print 411can only fail if it cannot find protection information in the supplied 412status data. 413.Pp 414.Fn mt_param_list 415Returns 0 for success and non-zero for failure. 416.Fn mt_param_list 417can only fail if it cannot find parameter information in the supplied 418status data. 419.Pp 420.Fn mt_density_name 421returns a text description of a numeric density. 422The special density value 0 is decoded as "default". 423The special density value 0x7f is decoded as "same". 424If the density is not known, 425.Fn mt_density_name 426will return "UNKNOWN". 427.Pp 428.Fn mt_density_bp 429returns the bits per inch value for the given density (if the 430.Ar bpi 431field is non-zero), the bits per mm value otherwise, or 0 if the supplied 432.Ar density_num 433is not in the density table or the table entry does not include bpi / bpmm 434values. 435.Pp 436.Fn mt_density_num 437returns a numeric density value between 0 and 255 for the supplied density 438name. 439It returns 0 if the density name is not recognized. 440.Pp 441.Fn mt_get_xml_str 442returns 0 for success, and -1 for failure. 443.Sh SEE ALSO 444.Xr mt 1 , 445.Xr mtio 4 , 446.Xr sa 4 447.Sh HISTORY 448The MT library first appeared in 449.Fx 10.1 . 450.Sh AUTHORS 451.An Ken Merry Aq ken@FreeBSD.org 452.Sh BUGS 453The library interface is not complete, and may change in the future. 454Application authors should not rely on the library interface to be 455consistent in the immediate future. 456