libexplain  1.4.D001
libexplain/buffer/floppy_struct.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_struct.h>
00022 #include <libexplain/buffer/int.h>
00023 #include <libexplain/buffer/pathname.h>
00024 #include <libexplain/buffer/pointer.h>
00025 #include <libexplain/is_efault.h>
00026 
00027 
00028 #ifdef HAVE_LINUX_FD_H
00029 
00030 void
00031 explain_buffer_floppy_struct(explain_string_buffer_t *sb,
00032     const struct floppy_struct *data)
00033 {
00034     unsigned int    n;
00035 
00036     if (explain_is_efault_pointer(data, sizeof(*data)))
00037     {
00038         explain_buffer_pointer(sb, data);
00039         return;
00040     }
00041 
00042     explain_string_buffer_puts(sb, "{ size = ");
00043     explain_buffer_uint(sb, data->size);
00044     explain_string_buffer_puts(sb, ", sect = ");
00045     explain_buffer_uint(sb, data->sect);
00046     explain_string_buffer_puts(sb, ", head = ");
00047     explain_buffer_uint(sb, data->head);
00048     explain_string_buffer_puts(sb, ", track = ");
00049     explain_buffer_uint(sb, data->track);
00050     explain_string_buffer_puts(sb, ", stretch = ");
00051 
00052     /*
00053      * bit 0 !=0 means double track steps
00054      * bit 1 != 0 means swap sides
00055      * bits 2..9 give the first sector
00056      *   number (the LSB is flipped)
00057      */
00058     n = data->stretch;
00059     if (n & FD_STRETCH)
00060     {
00061         explain_string_buffer_puts(sb, "FD_STRETCH | ");
00062         n &= ~FD_STRETCH;
00063     }
00064     if (n & FD_SWAPSIDES)
00065     {
00066         explain_string_buffer_puts(sb, "FD_SWAPSIDES | ");
00067         n &= ~FD_SWAPSIDES;
00068     }
00069 #ifdef FD_SECTBASEMASK
00070     explain_string_buffer_printf(sb, "FD_MKSECTBASE(%d)", FD_SECTBASE(data));
00071     n &= ~FD_SECTBASEMASK;
00072 #endif
00073     if (n)
00074         explain_string_buffer_printf(sb, " | 0x%X", n);
00075 
00076     explain_string_buffer_puts(sb, ", gap = ");
00077     explain_buffer_int(sb, data->gap);
00078     explain_string_buffer_puts(sb, ", rate = ");
00079 
00080     n = data->rate;
00081     if (n & FD_PERP)
00082     {
00083         explain_string_buffer_puts(sb, "FD_PERP | ");
00084         n &= ~FD_PERP;
00085     }
00086     if (n & FD_2M)
00087     {
00088         explain_string_buffer_puts(sb, "FD_2M | ");
00089         n &= ~FD_2M;
00090     }
00091     explain_buffer_int(sb, n & FD_SIZECODEMASK);
00092     n &= ~FD_SIZECODEMASK;
00093     if (n)
00094         explain_string_buffer_printf(sb, " | 0x%X", n);
00095 
00096     explain_string_buffer_puts(sb, ", spec1 = ");
00097     explain_buffer_int(sb, data->spec1);
00098     explain_string_buffer_puts(sb, ", fmt_gap = ");
00099     explain_buffer_int(sb, data->fmt_gap);
00100     explain_string_buffer_puts(sb, ", name = ");
00101     explain_buffer_pathname(sb, data->name);
00102     explain_string_buffer_puts(sb, " }");
00103 }
00104 
00105 #else
00106 
00107 void
00108 explain_buffer_floppy_struct(explain_string_buffer_t *sb,
00109     const struct floppy_struct *data)
00110 {
00111     explain_buffer_pointer(sb, data);
00112 }
00113 
00114 #endif
00115 
00116 
00117 /* vim: set ts=8 sw=4 et : */