libexplain  1.4.D001
libexplain/buffer/mtop.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/sys/mtio.h>
00020 
00021 #include <libexplain/buffer/mtop.h>
00022 #include <libexplain/buffer/pointer.h>
00023 #include <libexplain/parse_bits.h>
00024 #include <libexplain/is_efault.h>
00025 #include <libexplain/sizeof.h>
00026 
00027 
00028 static void
00029 explain_buffer_mtop_op(explain_string_buffer_t *sb, int data)
00030 {
00031     static const explain_parse_bits_table_t table[] =
00032     {
00033 #ifdef MTBSF
00034         { "MTBSF", MTBSF },
00035 #endif
00036 #ifdef MTBSFM
00037         { "MTBSFM", MTBSFM },
00038 #endif
00039 #ifdef MTBSR
00040         { "MTBSR", MTBSR },
00041 #endif
00042 #ifdef MTBSS
00043         { "MTBSS", MTBSS },
00044 #endif
00045 #ifdef MTCOMPRESSION
00046         { "MTCOMPRESSION", MTCOMPRESSION },
00047 #endif
00048 #ifdef MTEOM
00049         { "MTEOM", MTEOM },
00050 #endif
00051 #ifdef MTERASE
00052         { "MTERASE", MTERASE },
00053 #endif
00054 #ifdef MTFSF
00055         { "MTFSF", MTFSF },
00056 #endif
00057 #ifdef MTFSFM
00058         { "MTFSFM", MTFSFM },
00059 #endif
00060 #ifdef MTFSR
00061         { "MTFSR", MTFSR },
00062 #endif
00063 #ifdef MTFSS
00064         { "MTFSS", MTFSS },
00065 #endif
00066 #ifdef MTGRSZ
00067         /* not linux: get record size */
00068         { "MTGRSZ", MTGRSZ },
00069 #endif
00070 #ifdef MTLOAD
00071         { "MTLOAD", MTLOAD },
00072 #endif
00073 #ifdef MTLOCK
00074         { "MTLOCK", MTLOCK },
00075 #endif
00076 #ifdef MTMKPART
00077         { "MTMKPART", MTMKPART },
00078 #endif
00079 #ifdef MTNBSF
00080         { "MTNBSF", MTNBSF },
00081 #endif
00082 #ifdef MTNFSF
00083         { "MTNFSF", MTNFSF },
00084 #endif
00085 #ifdef MTNOP
00086         { "MTNOP", MTNOP },
00087 #endif
00088 #ifdef MTOFFL
00089         { "MTOFFL", MTOFFL },
00090 #endif
00091 #ifdef MTRAS1
00092         { "MTRAS1", MTRAS1 },
00093 #endif
00094 #ifdef MTRAS2
00095         { "MTRAS2", MTRAS2 },
00096 #endif
00097 #ifdef MTRAS3
00098         { "MTRAS3", MTRAS3 },
00099 #endif
00100 #ifdef MTRESET
00101         { "MTRESET", MTRESET },
00102 #endif
00103 #ifdef MTRETEN
00104         { "MTRETEN", MTRETEN },
00105 #endif
00106 #ifdef MTREW
00107         { "MTREW", MTREW },
00108 #endif
00109 #ifdef MTSEEK
00110         { "MTSEEK", MTSEEK },
00111 #endif
00112 #ifdef MTSETBLK
00113         { "MTSETBLK", MTSETBLK },
00114 #endif
00115 #ifdef MTSETDENSITY
00116         { "MTSETDENSITY", MTSETDENSITY },
00117 #endif
00118 #ifdef MTSETDRVBUFFER
00119         { "MTSETDRVBUFFER", MTSETDRVBUFFER },
00120 #endif
00121 #ifdef MTSETPART
00122         { "MTSETPART", MTSETPART },
00123 #endif
00124 #ifdef MTSRSZ
00125         /* Solaris version of MTSETBLK */
00126         { "MTSRSZ", MTSRSZ },
00127 #endif
00128 #ifdef MTTELL
00129         { "MTTELL", MTTELL },
00130 #endif
00131 #ifdef MTUNLOAD
00132         { "MTUNLOAD", MTUNLOAD },
00133 #endif
00134 #ifdef MTUNLOCK
00135         { "MTUNLOCK", MTUNLOCK },
00136 #endif
00137 #ifdef MTWEOF
00138         { "MTWEOF", MTWEOF },
00139 #endif
00140 #ifdef MTWSM
00141         { "MTWSM", MTWSM },
00142 #endif
00143     };
00144 
00145     explain_parse_bits_print_single(sb, data, table, SIZEOF(table));
00146 }
00147 
00148 
00149 void
00150 explain_buffer_mtop(explain_string_buffer_t *sb,
00151     const struct mtop *data)
00152 {
00153     if (explain_is_efault_pointer(data, sizeof(*data)))
00154         explain_buffer_pointer(sb, data);
00155     else
00156     {
00157         explain_string_buffer_puts(sb, "{ mt_top = ");
00158         explain_buffer_mtop_op(sb, data->mt_op);
00159         explain_string_buffer_puts(sb, ", mt_count = ");
00160         switch (data->mt_op)
00161         {
00162 #ifdef MTLOAD
00163 #ifdef MT_ST_HPLOADER_OFFSET
00164         case MTLOAD:
00165             if (data->mt_count & MT_ST_HPLOADER_OFFSET)
00166                 explain_string_buffer_puts(sb, "MT_ST_HPLOADER_OFFSET | ");
00167             explain_string_buffer_printf
00168             (
00169                 sb,
00170                 "%ld",
00171                 (long)(data->mt_count & ~MT_ST_HPLOADER_OFFSET)
00172             );
00173             break;
00174 #endif
00175 #endif
00176 
00177 #ifdef MTSETDENSITY
00178         case MTSETDENSITY:
00179 #ifdef MT_ST_WRITE_THRESHOLD
00180             if (data->mt_count & MT_ST_WRITE_THRESHOLD)
00181             {
00182                 explain_string_buffer_puts(sb, "MT_ST_WRITE_THRESHOLD | ");
00183                 explain_string_buffer_printf
00184                 (
00185                     sb,
00186                     "%ld",
00187                     (long)(data->mt_count & 0x0FFFFFFF)
00188                 );
00189                 break;
00190             }
00191 #endif
00192             explain_string_buffer_printf(sb, "%ld", (long)data->mt_count);
00193             break;
00194 #endif
00195 
00196         default:
00197             explain_string_buffer_printf(sb, "%ld", (long)data->mt_count);
00198             break;
00199         }
00200         explain_string_buffer_puts(sb, " }");
00201     }
00202 }
00203 
00204 
00205 /* vim: set ts=8 sw=4 et : */