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 it 00006 * under the terms of the GNU Lesser General Public License as published by 00007 * the Free Software Foundation; either version 3 of the License, or (at your 00008 * option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful,but WITHOUT 00011 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 00013 * 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/ac/sys/ioctl.h> 00020 #include <libexplain/ac/errno.h> 00021 #include <libexplain/ac/linux/ata.h> 00022 #include <libexplain/ac/linux/hdreg.h> 00023 00024 #include <libexplain/buffer/efault.h> 00025 #include <libexplain/buffer/pointer.h> 00026 #include <libexplain/buffer/short.h> 00027 #include <libexplain/iocontrol/generic.h> 00028 #include <libexplain/iocontrol/hdio_get_identity.h> 00029 00030 #ifdef HDIO_GET_IDENTITY 00031 00032 00033 static void 00034 print_data(const explain_iocontrol_t *p, explain_string_buffer_t *sb, int 00035 errnum, int fildes, int request, const void *data) 00036 { 00037 (void)p; 00038 (void)errnum; 00039 (void)fildes; 00040 (void)request; 00041 explain_buffer_pointer(sb, data); 00042 } 00043 00044 00045 static void 00046 print_explanation(const explain_iocontrol_t *p, explain_string_buffer_t *sb, int 00047 errnum, int fildes, int request, const void *data) 00048 { 00049 switch (errnum) 00050 { 00051 case EFAULT: 00052 explain_buffer_efault(sb, "data"); 00053 break; 00054 00055 default: 00056 explain_iocontrol_generic_print_explanation 00057 ( 00058 p, 00059 sb, 00060 errnum, 00061 fildes, 00062 request, 00063 data 00064 ); 00065 break; 00066 } 00067 } 00068 00069 00070 #ifdef HAVE_LINUX_ATA_H 00071 00072 static void 00073 explain_buffer_ata_identity(explain_string_buffer_t *sb, int data) 00074 { 00075 static const explain_parse_bits_table_t table[] = 00076 { 00077 { "ATA_ID_CONFIG", ATA_ID_CONFIG }, 00078 { "ATA_ID_CYLS", ATA_ID_CYLS }, 00079 { "ATA_ID_HEADS", ATA_ID_HEADS }, 00080 { "ATA_ID_SECTORS", ATA_ID_SECTORS }, 00081 { "ATA_ID_SERNO", ATA_ID_SERNO }, 00082 { "ATA_ID_BUF_SIZE", ATA_ID_BUF_SIZE }, 00083 { "ATA_ID_FW_REV", ATA_ID_FW_REV }, 00084 { "ATA_ID_PROD", ATA_ID_PROD }, 00085 { "ATA_ID_MAX_MULTSECT", ATA_ID_MAX_MULTSECT }, 00086 { "ATA_ID_DWORD_IO", ATA_ID_DWORD_IO }, 00087 { "ATA_ID_CAPABILITY", ATA_ID_CAPABILITY }, 00088 { "ATA_ID_OLD_PIO_MODES", ATA_ID_OLD_PIO_MODES }, 00089 { "ATA_ID_OLD_DMA_MODES", ATA_ID_OLD_DMA_MODES }, 00090 { "ATA_ID_FIELD_VALID", ATA_ID_FIELD_VALID }, 00091 { "ATA_ID_CUR_CYLS", ATA_ID_CUR_CYLS }, 00092 { "ATA_ID_CUR_HEADS", ATA_ID_CUR_HEADS }, 00093 { "ATA_ID_CUR_SECTORS", ATA_ID_CUR_SECTORS }, 00094 { "ATA_ID_MULTSECT", ATA_ID_MULTSECT }, 00095 { "ATA_ID_LBA_CAPACITY", ATA_ID_LBA_CAPACITY }, 00096 { "ATA_ID_SWDMA_MODES", ATA_ID_SWDMA_MODES }, 00097 { "ATA_ID_MWDMA_MODES", ATA_ID_MWDMA_MODES }, 00098 { "ATA_ID_PIO_MODES", ATA_ID_PIO_MODES }, 00099 { "ATA_ID_EIDE_DMA_MIN", ATA_ID_EIDE_DMA_MIN }, 00100 { "ATA_ID_EIDE_DMA_TIME", ATA_ID_EIDE_DMA_TIME }, 00101 { "ATA_ID_EIDE_PIO", ATA_ID_EIDE_PIO }, 00102 { "ATA_ID_EIDE_PIO_IORDY", ATA_ID_EIDE_PIO_IORDY }, 00103 { "ATA_ID_QUEUE_DEPTH", ATA_ID_QUEUE_DEPTH }, 00104 { "ATA_ID_MAJOR_VER", ATA_ID_MAJOR_VER }, 00105 { "ATA_ID_COMMAND_SET_1", ATA_ID_COMMAND_SET_1 }, 00106 { "ATA_ID_COMMAND_SET_2", ATA_ID_COMMAND_SET_2 }, 00107 { "ATA_ID_CFSSE", ATA_ID_CFSSE }, 00108 { "ATA_ID_CFS_ENABLE_1", ATA_ID_CFS_ENABLE_1 }, 00109 { "ATA_ID_CFS_ENABLE_2", ATA_ID_CFS_ENABLE_2 }, 00110 { "ATA_ID_CSF_DEFAULT", ATA_ID_CSF_DEFAULT }, 00111 { "ATA_ID_UDMA_MODES", ATA_ID_UDMA_MODES }, 00112 { "ATA_ID_HW_CONFIG", ATA_ID_HW_CONFIG }, 00113 { "ATA_ID_SPG", ATA_ID_SPG }, 00114 { "ATA_ID_LBA_CAPACITY_2", ATA_ID_LBA_CAPACITY_2 }, 00115 { "ATA_ID_LAST_LUN", ATA_ID_LAST_LUN }, 00116 { "ATA_ID_DLF", ATA_ID_DLF }, 00117 { "ATA_ID_CSFO", ATA_ID_CSFO }, 00118 { "ATA_ID_CFA_POWER", ATA_ID_CFA_POWER }, 00119 { "ATA_ID_CFA_KEY_MGMT", ATA_ID_CFA_KEY_MGMT }, 00120 { "ATA_ID_CFA_MODES", ATA_ID_CFA_MODES }, 00121 { "ATA_ID_DATA_SET_MGMT", ATA_ID_DATA_SET_MGMT }, 00122 { "ATA_ID_ROT_SPEED", ATA_ID_ROT_SPEED }, 00123 { "track_bytes", 4 }, 00124 { "sector_bytes", 5 }, 00125 { "buf_type", 20 }, 00126 { "ecc_bytes", 22 }, 00127 { "cur_capacity", 57 }, 00128 }; 00129 00130 explain_parse_bits_print_single(sb, data, table, SIZEOF(table)); 00131 } 00132 00133 00134 static void 00135 explain_buffer_ata_identity(explain_string_buffer_t *sb, const short *data) 00136 { 00137 if (explain_is_efault_pointer(data, ATA_ID_WORDS * sizeof(*data))) 00138 { 00139 explain_buffer_pointer(sb, data); 00140 return; 00141 } 00142 00143 explain_string_buffer_putc(sb, '{'); 00144 comma = 0; 00145 for (j = 0; j < ATA_ID_WORDS; ++j) 00146 { 00147 if (data[j]) 00148 { 00149 if (comma) 00150 explain_string_buffer_puts(sb, ", "); 00151 explain_buffer_ata_id(sb, j); 00152 explain_string_buffer_puts(sb, " = "); 00153 switch (j) 00154 { 00155 case ATA_ID_SERNO: 00156 explain_string_buffer_putsu_quoted_n 00157 ( 00158 sb, 00159 &data[j], 00160 ATA_ID_SERNO_LEN 00161 ); 00162 break; 00163 00164 case ATA_ID_FW_REV: 00165 explain_string_buffer_putsu_quoted_n 00166 ( 00167 sb, 00168 &data[j], 00169 ATA_FW_REV_LEN 00170 ); 00171 break; 00172 00173 case ATA_ID_PROD: 00174 explain_string_buffer_putsu_quoted_n 00175 ( 00176 sb, 00177 &data[j], 00178 ATA_ID_PROD_LEN 00179 ); 00180 break; 00181 00182 case 57: 00183 case ATA_ID_LBA_CAPACITY: 00184 case ATA_ID_SPG: 00185 explain_string_buffer_printf 00186 ( 00187 sb, 00188 "0x%lX", 00189 ata_id_u32(data, j) 00190 ); 00191 break; 00192 00193 case ATA_ID_LBA_CAPACITY_2: 00194 explain_string_buffer_printf 00195 ( 00196 sb, 00197 "0x%llX", 00198 ata_id_u64(data, j) 00199 ); 00200 break; 00201 00202 default: 00203 explain_string_buffer_printf(sb, "0x%hX", data[j]); 00204 break; 00205 } 00206 comma = 1; 00207 } 00208 } 00209 explain_string_buffer_putc(sb, " }"); 00210 } 00211 00212 #else 00213 00214 static void 00215 explain_buffer_ata_identity(explain_string_buffer_t *sb, const short *data) 00216 { 00217 explain_buffer_pointer(sb, data); 00218 } 00219 00220 #endif 00221 00222 00223 static void 00224 print_data_returned(const explain_iocontrol_t *p, explain_string_buffer_t *sb, 00225 int errnum, int fildes, int request, const void *data) 00226 { 00227 (void)p; 00228 (void)errnum; 00229 (void)fildes; 00230 (void)request; 00231 explain_buffer_ata_identity(sb, data); 00232 } 00233 00234 00235 const explain_iocontrol_t explain_iocontrol_hdio_get_identity = 00236 { 00237 "HDIO_GET_IDENTITY", /* name */ 00238 HDIO_GET_IDENTITY, /* value */ 00239 0, /* disambiguate */ 00240 0, /* print_name */ 00241 print_data, 00242 print_explanation, 00243 print_data_returned, 00244 #ifdef HAVE_LINUX_ATA_H 00245 sizeof(short[ATA_ID_WORDS]), /* data_size */ 00246 "short[ATA_ID_WORDS]", /* data_type */ 00247 #else 00248 sizeof(short[256]), /* data_size */ 00249 "short[256]", /* data_type */ 00250 #endif 00251 IOCONTROL_FLAG_NON_META, /* flags */ 00252 __FILE__, 00253 __LINE__, 00254 }; 00255 00256 #else /* ndef HDIO_GET_IDENTITY */ 00257 00258 const explain_iocontrol_t explain_iocontrol_hdio_get_identity = 00259 { 00260 0, /* name */ 00261 0, /* value */ 00262 0, /* disambiguate */ 00263 0, /* print_name */ 00264 0, /* print_data */ 00265 0, /* print_explanation */ 00266 0, /* print_data_returned */ 00267 0, /* data_size */ 00268 0, /* data_type */ 00269 0, /* flags */ 00270 __FILE__, 00271 __LINE__, 00272 }; 00273 00274 #endif /* HDIO_GET_IDENTITY */ 00275 00276 00277 /* vim: set ts=8 sw=4 et : */