libexplain  1.4.D001
libexplain/buffer/floppy_raw_cmd.c
Go to the documentation of this file.
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/ac/linux/fd.h>
00020 
00021 #include <libexplain/buffer/floppy_raw_cmd.h>
00022 #include <libexplain/buffer/hexdump.h>
00023 #include <libexplain/buffer/int.h>
00024 #include <libexplain/buffer/long.h>
00025 #include <libexplain/buffer/pointer.h>
00026 #include <libexplain/is_efault.h>
00027 #include <libexplain/parse_bits.h>
00028 #include <libexplain/sizeof.h>
00029 
00030 
00031 #ifdef HAVE_LINUX_FD_H
00032 
00033 static void
00034 explain_buffer_floppy_raw_cmd_flags(explain_string_buffer_t *sb, int value)
00035 {
00036     static const explain_parse_bits_table_t table[] =
00037     {
00038         { "FD_RAW_READ", FD_RAW_READ },
00039         { "FD_RAW_WRITE", FD_RAW_WRITE },
00040         { "FD_RAW_NO_MOTOR", FD_RAW_NO_MOTOR },
00041         { "FD_RAW_DISK_CHANGE", FD_RAW_DISK_CHANGE },
00042         { "FD_RAW_INTR", FD_RAW_INTR },
00043         { "FD_RAW_SPIN", FD_RAW_SPIN },
00044         { "FD_RAW_NO_MOTOR_AFTER", FD_RAW_NO_MOTOR_AFTER },
00045         { "FD_RAW_NEED_DISK", FD_RAW_NEED_DISK },
00046         { "FD_RAW_NEED_SEEK", FD_RAW_NEED_SEEK },
00047         { "FD_RAW_MORE", FD_RAW_MORE },
00048         { "FD_RAW_STOP_IF_FAILURE", FD_RAW_STOP_IF_FAILURE },
00049         { "FD_RAW_STOP_IF_SUCCESS", FD_RAW_STOP_IF_SUCCESS },
00050         { "FD_RAW_SOFTFAILURE", FD_RAW_SOFTFAILURE },
00051         { "FD_RAW_FAILURE", FD_RAW_FAILURE },
00052         { "FD_RAW_HARDFAILURE", FD_RAW_HARDFAILURE },
00053     };
00054 
00055     explain_parse_bits_print(sb, value, table, SIZEOF(table));
00056 }
00057 
00058 
00059 void
00060 explain_buffer_floppy_raw_cmd(explain_string_buffer_t *sb,
00061     const struct floppy_raw_cmd *data, int extra)
00062 {
00063     if (explain_is_efault_pointer(data, sizeof(*data)))
00064     {
00065         explain_buffer_pointer(sb, data);
00066         return;
00067     }
00068 
00069     explain_string_buffer_puts(sb, "{ flags = ");
00070     explain_buffer_floppy_raw_cmd_flags(sb, data->flags);
00071     if (data->data)
00072     {
00073         explain_string_buffer_puts(sb, ", data = ");
00074         explain_buffer_pointer(sb, data->data);
00075     }
00076 #if 0
00077     explain_string_buffer_puts(sb, ", kernel_data = ");
00078     explain_buffer_pointer(sb, data->kernel_data);
00079     explain_string_buffer_puts(sb, ", next = ");
00080     explain_buffer_pointer(sb, data->next);
00081 #endif
00082     if (data->length)
00083     {
00084         explain_string_buffer_puts(sb, ", length = ");
00085         explain_buffer_long(sb, data->length);
00086     }
00087     if (data->phys_length)
00088     {
00089         explain_string_buffer_puts(sb, ", phys_length = ");
00090         explain_buffer_long(sb, data->phys_length);
00091     }
00092     if (data->buffer_length)
00093     {
00094         explain_string_buffer_puts(sb, ", buffer_length = ");
00095         explain_buffer_int(sb, data->buffer_length);
00096     }
00097     if (data->rate)
00098     {
00099         explain_string_buffer_puts(sb, ", rate = ");
00100         explain_buffer_int(sb, data->rate);
00101     }
00102     if (data->cmd_count)
00103     {
00104         int             n;
00105 
00106         explain_string_buffer_puts(sb, ", cmd_count = ");
00107         explain_buffer_int(sb, data->cmd_count);
00108 
00109         n = data->cmd_count;
00110         if (n > (int)sizeof(data->cmd))
00111             n = sizeof(data->cmd);
00112         if (n > 0)
00113         {
00114             explain_string_buffer_puts(sb, ", cmd = ");
00115             explain_buffer_hexdump(sb, data->cmd, n);
00116         }
00117     }
00118 
00119     if (extra && data->reply_count)
00120     {
00121         int             n;
00122 
00123         explain_string_buffer_puts(sb, ", reply_count = ");
00124         explain_buffer_int(sb, data->reply_count);
00125 
00126         n = data->reply_count;
00127         if (n > (int)sizeof(data->reply))
00128             n = sizeof(data->reply);
00129         if (n > 0)
00130         {
00131             explain_string_buffer_puts(sb, ", reply = ");
00132             explain_buffer_hexdump(sb, data->reply, n);
00133         }
00134     }
00135 
00136     if (data->track)
00137     {
00138         explain_string_buffer_puts(sb, ", track = ");
00139         explain_buffer_int(sb, data->track);
00140     }
00141     if (extra && data->resultcode)
00142     {
00143         explain_string_buffer_puts(sb, ", resultcode = ");
00144         explain_buffer_int(sb, data->resultcode);
00145     }
00146     explain_string_buffer_puts(sb, " }");
00147 }
00148 
00149 #else
00150 
00151 void
00152 explain_buffer_floppy_raw_cmd(explain_string_buffer_t *sb,
00153     const struct floppy_raw_cmd *data, int extra)
00154 {
00155     (void)extra;
00156     explain_buffer_pointer(sb, data);
00157 }
00158 
00159 #endif
00160 
00161 
00162 /* vim: set ts=8 sw=4 et : */