libexplain
1.4.D001
|
00001 /* 00002 * libexplain - Explain errno values returned by libc functions 00003 * Copyright (C) 2009, 2011, 2013 Peter Miller 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU Lesser General Public License as 00007 * published by the Free Software Foundation; either version 3 of the 00008 * License, or (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Lesser General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Lesser General Public License 00016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00017 */ 00018 00019 #include <libexplain/buffer/dvd_struct.h> 00020 #include <libexplain/buffer/hexdump.h> 00021 #include <libexplain/buffer/int.h> 00022 #include <libexplain/buffer/long.h> 00023 #include <libexplain/buffer/pointer.h> 00024 #include <libexplain/is_efault.h> 00025 #include <libexplain/parse_bits.h> 00026 #include <libexplain/sizeof.h> 00027 00028 00029 #ifdef HAVE_LINUX_CDROM_H 00030 00031 static void 00032 explain_buffer_dvd_struct_type(explain_string_buffer_t *sb, int value) 00033 { 00034 static const explain_parse_bits_table_t table[] = 00035 { 00036 { "DVD_STRUCT_PHYSICAL", DVD_STRUCT_PHYSICAL }, 00037 { "DVD_STRUCT_COPYRIGHT", DVD_STRUCT_COPYRIGHT }, 00038 { "DVD_STRUCT_DISCKEY", DVD_STRUCT_DISCKEY }, 00039 { "DVD_STRUCT_BCA", DVD_STRUCT_BCA }, 00040 { "DVD_STRUCT_MANUFACT", DVD_STRUCT_MANUFACT }, 00041 }; 00042 00043 return explain_parse_bits_print_single(sb, value, table, SIZEOF(table)); 00044 } 00045 00046 00047 static void 00048 explain_buffer_dvd_layer(explain_string_buffer_t *sb, 00049 const struct dvd_layer *data) 00050 { 00051 explain_string_buffer_puts(sb, "{ book_version = "); 00052 explain_buffer_int(sb, data->book_version); 00053 explain_string_buffer_puts(sb, ", book_type = "); 00054 explain_buffer_int(sb, data->book_type); 00055 explain_string_buffer_puts(sb, ", min_rate = "); 00056 explain_buffer_int(sb, data->min_rate); 00057 explain_string_buffer_puts(sb, ", disc_size = "); 00058 explain_buffer_int(sb, data->disc_size); 00059 explain_string_buffer_puts(sb, ", layer_type = "); 00060 explain_buffer_int(sb, data->layer_type); 00061 explain_string_buffer_puts(sb, ", track_path = "); 00062 explain_buffer_int(sb, data->track_path); 00063 explain_string_buffer_puts(sb, ", nlayers = "); 00064 explain_buffer_int(sb, data->nlayers); 00065 explain_string_buffer_puts(sb, ", track_density = "); 00066 explain_buffer_int(sb, data->track_density); 00067 explain_string_buffer_puts(sb, ", linear_density = "); 00068 explain_buffer_int(sb, data->linear_density); 00069 explain_string_buffer_puts(sb, ", bca = "); 00070 explain_buffer_int(sb, data->bca); 00071 explain_string_buffer_puts(sb, ", start_sector = "); 00072 explain_buffer_ulong(sb, data->start_sector); 00073 explain_string_buffer_puts(sb, ", end_sector = "); 00074 explain_buffer_ulong(sb, data->end_sector); 00075 explain_string_buffer_puts(sb, ", end_sector_l0 = "); 00076 explain_buffer_ulong(sb, data->end_sector_l0); 00077 explain_string_buffer_puts(sb, " }"); 00078 } 00079 00080 00081 static void 00082 explain_buffer_dvd_physical(explain_string_buffer_t *sb, 00083 const struct dvd_physical *data) 00084 { 00085 size_t j; 00086 00087 explain_string_buffer_puts(sb, "{ type = "); 00088 explain_buffer_dvd_struct_type(sb, data->type); 00089 explain_string_buffer_puts(sb, ", layer_num = "); 00090 explain_buffer_int(sb, data->layer_num); 00091 explain_string_buffer_puts(sb, ", layer = {"); 00092 for (j = 0; j < SIZEOF(data->layer); ++j) 00093 explain_buffer_dvd_layer(sb, &data->layer[j]); 00094 explain_string_buffer_puts(sb, "}}"); 00095 } 00096 00097 00098 static void 00099 explain_buffer_dvd_copyright(explain_string_buffer_t *sb, 00100 const struct dvd_copyright *data) 00101 { 00102 explain_string_buffer_puts(sb, "{ type = "); 00103 explain_buffer_dvd_struct_type(sb, data->type); 00104 explain_string_buffer_puts(sb, ", layer_num = "); 00105 explain_buffer_int(sb, data->layer_num); 00106 explain_string_buffer_puts(sb, ", cpst = {"); 00107 explain_buffer_int(sb, data->cpst); 00108 explain_string_buffer_puts(sb, ", rmi = {"); 00109 explain_buffer_int(sb, data->rmi); 00110 explain_string_buffer_puts(sb, " }"); 00111 } 00112 00113 00114 static void 00115 explain_buffer_dvd_disckey(explain_string_buffer_t *sb, 00116 const struct dvd_disckey *data) 00117 { 00118 explain_string_buffer_puts(sb, "{ type = "); 00119 explain_buffer_dvd_struct_type(sb, data->type); 00120 explain_string_buffer_puts(sb, ", agid = "); 00121 explain_buffer_int(sb, data->agid); 00122 explain_string_buffer_puts(sb, ", value = {"); 00123 explain_buffer_hexdump(sb, data->value, 8); 00124 explain_string_buffer_puts(sb, " ... }}"); 00125 } 00126 00127 00128 static void 00129 explain_buffer_dvd_bca(explain_string_buffer_t *sb, 00130 const struct dvd_bca *data) 00131 { 00132 explain_string_buffer_puts(sb, "{ type = "); 00133 explain_buffer_dvd_struct_type(sb, data->type); 00134 explain_string_buffer_puts(sb, ", len = "); 00135 explain_buffer_int(sb, data->len); 00136 explain_string_buffer_puts(sb, ", value = {"); 00137 if (data->len > 0) 00138 { 00139 size_t len; 00140 00141 len = data->len; 00142 if (len > sizeof(data->value)) 00143 len = sizeof(data->value); 00144 if (len > 8) 00145 { 00146 explain_buffer_hexdump(sb, data->value, 8); 00147 explain_string_buffer_puts(sb, " ..."); 00148 } 00149 else 00150 explain_buffer_hexdump(sb, data->value, len); 00151 explain_string_buffer_puts(sb, "}"); 00152 } 00153 explain_string_buffer_puts(sb, " }"); 00154 } 00155 00156 00157 static void 00158 explain_buffer_dvd_manufact(explain_string_buffer_t *sb, 00159 const struct dvd_manufact *data) 00160 { 00161 explain_string_buffer_puts(sb, "{ type = "); 00162 explain_buffer_dvd_struct_type(sb, data->type); 00163 explain_string_buffer_puts(sb, ", layer_num = "); 00164 explain_buffer_int(sb, data->layer_num); 00165 explain_string_buffer_puts(sb, ", len = "); 00166 explain_buffer_int(sb, data->len); 00167 explain_string_buffer_puts(sb, ", value = {"); 00168 if (data->len > 0) 00169 { 00170 size_t len; 00171 00172 len = data->len; 00173 if (len > sizeof(data->value)) 00174 len = sizeof(data->value); 00175 if (len > 8) 00176 { 00177 explain_buffer_hexdump(sb, data->value, 8); 00178 explain_string_buffer_puts(sb, " ..."); 00179 } 00180 else 00181 explain_buffer_hexdump(sb, data->value, len); 00182 explain_string_buffer_puts(sb, "}"); 00183 } 00184 explain_string_buffer_puts(sb, " }"); 00185 } 00186 00187 00188 void 00189 explain_buffer_dvd_struct(explain_string_buffer_t *sb, 00190 const dvd_struct *data) 00191 { 00192 if (explain_is_efault_pointer(data, sizeof(*data))) 00193 { 00194 explain_buffer_pointer(sb, data); 00195 return; 00196 } 00197 00198 switch (data->type) 00199 { 00200 case DVD_STRUCT_PHYSICAL: 00201 explain_buffer_dvd_physical(sb, &data->physical); 00202 break; 00203 00204 case DVD_STRUCT_COPYRIGHT: 00205 explain_buffer_dvd_copyright(sb, &data->copyright); 00206 break; 00207 00208 case DVD_STRUCT_DISCKEY: 00209 explain_buffer_dvd_disckey(sb, &data->disckey); 00210 break; 00211 00212 case DVD_STRUCT_BCA: 00213 explain_buffer_dvd_bca(sb, &data->bca); 00214 break; 00215 00216 case DVD_STRUCT_MANUFACT: 00217 explain_buffer_dvd_manufact(sb, &data->manufact); 00218 break; 00219 00220 default: 00221 explain_string_buffer_puts(sb, "{ type = "); 00222 explain_buffer_dvd_struct_type(sb, data->type); 00223 explain_string_buffer_puts(sb, " }"); 00224 break; 00225 } 00226 } 00227 00228 #else 00229 00230 void 00231 explain_buffer_dvd_struct(explain_string_buffer_t *sb, const void *data) 00232 { 00233 explain_buffer_pointer(sb, data); 00234 } 00235 00236 #endif 00237 00238 00239 /* vim: set ts=8 sw=4 et : */