xref: /freebsd/lib/libmt/mtlib.h (revision 123af6ec70016f5556da5972d4d63c7d175c06d3)
1 /*-
2  * Copyright (c) 2013, 2014 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 
35 #ifndef	_MTLIB_H
36 #define	_MTLIB_H
37 
38 typedef enum {
39 	MT_TYPE_NONE,
40 	MT_TYPE_STRING,
41 	MT_TYPE_INT,
42 	MT_TYPE_UINT,
43 	MT_TYPE_NODE
44 } mt_variable_type;
45 
46 struct mt_status_nv {
47 	char *name;
48 	char *value;
49 	STAILQ_ENTRY(mt_status_nv) links;
50 };
51 
52 struct mt_status_entry {
53 	char *entry_name;
54 	char *value;
55 	uint64_t value_unsigned;
56 	int64_t value_signed;
57 	char *fmt;
58 	char *desc;
59 	size_t size;
60 	mt_variable_type var_type;
61 	struct mt_status_entry *parent;
62 	STAILQ_HEAD(, mt_status_nv) nv_list;
63 	STAILQ_HEAD(, mt_status_entry) child_entries;
64 	STAILQ_ENTRY(mt_status_entry) links;
65 };
66 
67 struct mt_status_data {
68 	int level;
69 	struct sbuf *cur_sb[32];
70 	struct mt_status_entry *cur_entry[32];
71 	int error;
72 	char error_str[128];
73 	STAILQ_HEAD(, mt_status_entry) entries;
74 };
75 
76 typedef enum {
77 	MT_PF_NONE		= 0x00,
78 	MT_PF_VERBOSE		= 0x01,
79 	MT_PF_FULL_PATH		= 0x02,
80 	MT_PF_INCLUDE_ROOT	= 0x04
81 } mt_print_flags;
82 
83 struct mt_print_params {
84 	mt_print_flags flags;
85 	char root_name[64];
86 };
87 
88 __BEGIN_DECLS
89 void mt_start_element(void *user_data, const char *name, const char **attr);
90 void mt_end_element(void *user_data, const char *name);
91 void mt_char_handler(void *user_data, const XML_Char *str, int len);
92 void mt_status_tree_sbuf(struct sbuf *sb, struct mt_status_entry *entry,
93 			 int indent, void (*sbuf_func)(struct sbuf *sb,
94 			 struct mt_status_entry *entry, void *arg), void *arg);
95 void mt_status_tree_print(struct mt_status_entry *entry, int indent,
96 			  void (*print_func)(struct mt_status_entry *entry,
97 			  void *arg), void *arg);
98 struct mt_status_entry *mt_entry_find(struct mt_status_entry *entry,
99 				      char *name);
100 struct mt_status_entry *mt_status_entry_find(struct mt_status_data *status_data,
101 					     char *name);
102 void mt_status_entry_free(struct mt_status_entry *entry);
103 void mt_status_free(struct mt_status_data *status_data);
104 void mt_entry_sbuf(struct sbuf *sb, struct mt_status_entry *entry, char *fmt);
105 void mt_param_parent_print(struct mt_status_entry *entry,
106 			   struct mt_print_params *print_params);
107 void mt_param_parent_sbuf(struct sbuf *sb, struct mt_status_entry *entry,
108 			  struct mt_print_params *print_params);
109 void mt_param_entry_sbuf(struct sbuf *sb, struct mt_status_entry *entry,
110 			 void *arg);
111 void mt_param_entry_print(struct mt_status_entry *entry, void *arg);
112 int mt_protect_print(struct mt_status_data *status_data, int verbose);
113 int mt_param_list(struct mt_status_data *status_data, char *param_name,
114 		  int quiet);
115 const char *mt_density_name(int density_num);
116 int mt_density_bp(int density_num, int bpi);
117 int mt_density_num(const char *density_name);
118 int mt_get_xml_str(int mtfd, unsigned long cmd, char **xml_str);
119 int mt_get_status(char *xml_str, struct mt_status_data *status_data);
120 __END_DECLS
121 
122 #endif /* _MTLIB_H */
123