libexplain  1.4.D001
libexplain/buffer/floppy_drive_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_drive_struct.h>
00022 #include <libexplain/buffer/int.h>
00023 #include <libexplain/buffer/long.h>
00024 #include <libexplain/buffer/pointer.h>
00025 #include <libexplain/buffer/short.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_drive_struct_flags(explain_string_buffer_t *sb,
00035     unsigned long data)
00036 {
00037     static const explain_parse_bits_table_t table[] =
00038     {
00039         { "FD_NEED_TWADDLE", FD_NEED_TWADDLE },
00040         { "FD_VERIFY", FD_VERIFY },
00041         { "FD_DISK_NEWCHANGE", FD_DISK_NEWCHANGE },
00042         { "FD_DISK_CHANGED", FD_DISK_CHANGED },
00043         { "FD_DISK_WRITABLE", FD_DISK_WRITABLE },
00044     };
00045 
00046     explain_parse_bits_print(sb, data, table, SIZEOF(table));
00047 };
00048 
00049 
00050 void
00051 explain_buffer_floppy_drive_struct(explain_string_buffer_t *sb,
00052     const struct floppy_drive_struct *data)
00053 {
00054     if (explain_is_efault_pointer(data, sizeof(*data)))
00055     {
00056         explain_buffer_pointer(sb, data);
00057         return;
00058     }
00059 
00060     explain_string_buffer_puts(sb, "{ flags = ");
00061     explain_buffer_floppy_drive_struct_flags(sb, data->flags);
00062     if (data->spinup_date)
00063     {
00064         explain_string_buffer_puts(sb, ", spinup_date = ");
00065         explain_buffer_ulong(sb, data->spinup_date);
00066     }
00067     if (data->select_date)
00068     {
00069         explain_string_buffer_puts(sb, ", select_date = ");
00070         explain_buffer_ulong(sb, data->select_date);
00071     }
00072     if (data->first_read_date)
00073     {
00074         explain_string_buffer_puts(sb, ", first_read_date = ");
00075         explain_buffer_ulong(sb, data->first_read_date);
00076     }
00077     if (data->probed_format)
00078     {
00079         explain_string_buffer_puts(sb, ", probed_format = ");
00080         explain_buffer_short(sb, data->probed_format);
00081     }
00082     if (data->track)
00083     {
00084         explain_string_buffer_puts(sb, ", track = ");
00085         explain_buffer_short(sb, data->track);
00086     }
00087     if (data->maxblock)
00088     {
00089         explain_string_buffer_puts(sb, ", maxblock = ");
00090         explain_buffer_short(sb, data->maxblock);
00091     }
00092     if (data->maxtrack)
00093     {
00094         explain_string_buffer_puts(sb, ", maxtrack = ");
00095         explain_buffer_short(sb, data->maxtrack);
00096     }
00097     if (data->generation)
00098     {
00099         explain_string_buffer_puts(sb, ", generation = ");
00100         explain_buffer_int(sb, data->generation);
00101     }
00102     if (data->keep_data)
00103     {
00104         explain_string_buffer_puts(sb, ", keep_data = ");
00105         explain_buffer_int(sb, data->keep_data);
00106     }
00107     if (data->fd_ref)
00108     {
00109         explain_string_buffer_puts(sb, ", fd_ref = ");
00110         explain_buffer_int(sb, data->fd_ref);
00111     }
00112     if (data->fd_device)
00113     {
00114         explain_string_buffer_puts(sb, ", fd_device = ");
00115         explain_buffer_int(sb, data->fd_device);
00116     }
00117     if (data->last_checked)
00118     {
00119         explain_string_buffer_puts(sb, ", last_checked = ");
00120         explain_buffer_ulong(sb, data->last_checked);
00121     }
00122     if (data->dmabuf)
00123     {
00124         explain_string_buffer_puts(sb, ", dmabuf = ");
00125         explain_buffer_pointer(sb, data->dmabuf);
00126     }
00127     if (data->bufblocks)
00128     {
00129         explain_string_buffer_puts(sb, ", bufblocks = ");
00130         explain_buffer_int(sb, data->bufblocks);
00131     }
00132     explain_string_buffer_puts(sb, " }");
00133 }
00134 
00135 #else
00136 
00137 void
00138 explain_buffer_floppy_drive_struct(explain_string_buffer_t *sb,
00139     const struct floppy_drive_struct *data)
00140 {
00141     explain_buffer_pointer(sb, data);
00142 }
00143 
00144 #endif
00145 
00146 
00147 /* vim: set ts=8 sw=4 et : */