MT(3)
π MT(3) β Magnetic Tape library π
okay bestie, this is the MT(3) page from the Library Functions Manual, and it's literally all about the Magnetic Tape library. no cap, it's giving βmake XML tape status data make senseβ energy. π¦
π NAME π
the whole cast, in order, is:
mt_start_elementmt_end_elementmt_char_handlermt_status_tree_sbufmt_status_tree_printmt_status_entry_freemt_status_freemt_entry_sbufmt_param_parent_printmt_param_entry_printmt_protect_printmt_param_listmt_density_namemt_density_bpmt_density_nummt_get_xml_strmt_get_status
and yes, the whole thing is the Magnetic Tape library. periodt. π
πΈ LIBRARY πΈ
the library is literally βlibmtβ. that's the one, bestie. π
β¨ SYNOPSIS β¨
here's the exact code tea β copy it character for character:
#include <sys/sbuf.h>
#include <bsdxml.h>
#include <mtlib.h>
void
mt_start_element(void *user_data, const char *name, const char **attr);
void
mt_end_element(void *user_data, const char *name);
void
mt_char_handler(void *user_data, const XML_Char *str, int len);
void
mt_status_tree_sbuf(struct sbuf *sb, struct mt_status_entry *entry,
int indent,
void (*sbuf_func)(struct sbuf *sb, struct mt_status_entry *entry, void *arg),
void *arg);
void
mt_status_tree_print(struct mt_status_entry *entry, int indent,
void (*print_func)(struct mt_status_entry *entry, void *arg),
void *arg);
struct mt_status_entry *
mt_entry_find(struct mt_status_entry *entry, char *name);
struct mt_status_entry *
mt_status_entry_find(struct mt_status_data *status_data, char *name);
void
mt_status_entry_free(struct mt_status_entry *entry));
void
mt_status_free(struct mt_status_data *status_data);
void
mt_entry_sbuf(struct sbuf *sb, struct mt_status_entry *entry,
char *fmt);
void
mt_param_parent_sbuf(struct sbuf *sb, struct mt_status_entry *entry,
struct mt_print_params *print_params);
void
mt_param_parent_print(struct mt_status_entry *entry,
struct mt_print_params *print_params);
void
mt_param_entry_sbuf(struct sbuf *sb, struct mt_status_entry *entry,
void *arg);
void
mt_param_entry_print(struct mt_status_entry *entry, void *arg);
int
mt_protect_print(struct mt_status_data *status_data, int verbose);
int
mt_param_list(struct mt_status_data *status_data, char *param_name,
int quiet);
const char *
mt_density_name(int density_num);
int
mt_density_bp(int density_num, int bpi);
int
mt_density_num(const char *density_name);
int
mt_get_status(char *xml_str, struct mt_status_data *status_data);
π¦ DESCRIPTION π¦
the MT library is a bunch of functions made to help you vibe with the sa(4) driver. the sa(4) driver returns some status data as XML-formatted strings, and the primary purpose of this library is to make it easier for the software developer to parse those strings and extract the status values. β¨
mt_start_element(), mt_end_element(), and mt_char_handler() are designed to work with the libbsdxml(3) library, which is an XML parsing library. set the user data for the XML parser with XML_SetUserData() to a zeroed struct mt_status_data with the entries list initialized. set the element handlers for the XML parser to mt_start_element() and mt_end_element() with XML_SetElementHandler(). set the character data handler to mt_char_handler() with the XML_SetCharacterDataHandler() function. the error member of the status_data structure will be set to 0 if parsing is successful, and non-zero if parsing failed. if it fails, the error_str member will contain an error message describing the failure. these functions will build a tree of tape driver status data that can be searched and printed using the other functions in this library. π
mt_status_tree_sbuf()β takes the root node of a tree ofsa(4)driver status information, and displays it in ansbuf(9).sbis the destination sbuf,entryis the root of the tree, andindentis the number of characters to indent the output. each recursive call tomt_status_tree_sbuf()will have the indent level incremented by2.sbuf_funcis for a user-supplied alternate printing function; if it is non-NULL, it will be called instead of the default output printing code.argis an argument for thesbuf_funcfunction. πmt_status_tree_print()β same asmt_status_tree_sbuf(), except the tree is printed to standard out instead of to a sbuf. β¨mt_entry_find()β returns the first entry in the tree starting atentrythat matchesname. the supplied node name can be a single level name like"foo", or it can specify multiple node names that must be matched, for instance"foo.bar.baz". with a single level name, it will match any node beneathentrythat matchesname. with a multi-level name like"foo.bar.baz", it will return the first entry named"baz"whose immediate parent is"bar"and where the parent of"bar"is named"foo". π₯mt_status_entry_find()β same asmt_entry_find(), except it operates on the top levelmt_status_dataand allmt_status_entrynodes below it instead of just anmt_status_entrystructure. π¦mt_status_entry_free()β frees the tree of status data underneathentry. πmt_status_free()β frees the tree of status data underneathstatus_data. πmt_entry_sbuf()β printsentryto the supplied sbufsb, optionally using theprintf(3)formatfmt. iffmtisNULL, thenmt_entry_sbuf()will render integer types in base10without special formatting and all other types as they were rendered in the XML. πmt_param_parent_sbuf()β prints the parents of the givenentryto the supplied sbufsbsubject to the print parametersprint_params. the result will be formatted with a period between each level, like"foo.bar.baz". πmt_param_parent_print()β likemt_param_parent_sbuf()except it prints the results to standard output instead of an sbuf. π«Άmt_param_entry_sbuf()β prints theentryto the given sbufsb. the argumentargis a pointer tostruct mt_print_params, which allows the caller to control the printing output. this function is intended to be supplied as an argument tomt_status_tree_sbuf(). πΈmt_param_entry_print()β likemt_param_entry_sbuf()except it prints to standard output instead of an sbuf. it is intended to be used as an argument tomt_status_tree_print(). π§mt_protect_print()β prints tape drive protection information from the suppliedstatus_databeginning at the node name defined as the root node for protection data. if theverboseargument is non-zero, protection entry descriptions will be printed. if it is zero, protection entry descriptions will not be printed. πmt_param_list()β prints tape driver parameters information from the suppliedstatus_data. ifparam_nameis non-NULL, only the named parameter will be printed. ifquietis non-zero, parameter descriptions will be omitted in the output. πmt_density_name()β returns a text identifier for the supplied numericdensity_num.density_numshould currently be a value between0and255inclusive, since that is the valid range for SCSI density code values. see below for notes on the return values. βmt_density_bp()β returns the bits per inch or bits per mm values for a given density entry specified bydensity_num. if thebpiargument is non-zero, the bits per inch value is returned. otherwise, the bits per mm value is returned. πmt_density_num()β returns a numeric value for a text density description. it does a case-insensitive comparison of density names in the density table to the supplied density name. π¦mt_get_xml_str()β gets the current XML status / parameter string from thesa(4)driver instance referenced by the open file descriptormtfd. themtio(4)ioctl(2)to be used is supplied as thecmdargument. currentlymt_get_xml_str()will work with theMTIOCEXTGETandMTIOCPARAMGETioctls. the suppliedxml_strwill be filled in with a pointer to the complete XML status string. multiple calls to the givenioctl(2)are made and more space is malloced until all of the XML string is fetched. the string returned in thexml_strargument should be freed when it is no longer in use. π
π₯ RETURN VALUES π₯
mt_entry_find()β returns the first matching entry, orNULLif it fails to find a match. πmt_status_entry_find()β returns the first matching entry, orNULLif it fails to find a match. πmt_protect_print()β returns0for success, and non-zero for failure.mt_protect_print()can only fail if it cannot find protection information in the supplied status data. π«Άmt_param_list()β returns0for success and non-zero for failure.mt_param_list()can only fail if it cannot find parameter information in the supplied status data. π«Άmt_density_name()β returns a text description of a numeric density. the special density value0is decoded as"default". the special density value0x7fis decoded as"same". if the density is not known,mt_density_name()will return"UNKNOWN". βmt_density_bp()β returns the bits per inch value for the given density (if thebpifield is non-zero), the bits per mm value otherwise, or0if the supplieddensity_numis not in the density table or the table entry does not include bpi / bpmm values. πmt_density_num()β returns a numeric density value between0and255for the supplied density name. it returns0if the density name is not recognized. πmt_get_xml_str()β returns0for success, and-1for failure. π
π SEE ALSO π
go check out mt(1), mtio(4), and sa(4). bestie homework, but make it cute. π
β HISTORY β
the MT library first appeared in FreeBSD 10.1. iconic. π
π AUTHORS π
Ken Merry <ken@FreeBSD.org> π«Ά
π BUGS π
okay so real talk: the library interface is not complete, and may change in the future. application authors should not rely on the library interface to be consistent in the immediate future. π
π that's the tea! this page is from Debian, dated February 13, 2015. π
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- Copyright (c) 2013, 2015 Spectra Logic Corporation
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms