libexplain  1.4.D001
libexplain/iocontrol/hdio_drive_task.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 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/hdreg.h>
00022 
00023 #include <libexplain/buffer/char_data.h>
00024 #include <libexplain/buffer/dac.h>
00025 #include <libexplain/buffer/efault.h>
00026 #include <libexplain/buffer/is_the_null_pointer.h>
00027 #include <libexplain/capability.h>
00028 #include <libexplain/iocontrol/generic.h>
00029 #include <libexplain/iocontrol/hdio_drive_task.h>
00030 
00031 #ifdef HDIO_DRIVE_TASK
00032 
00033 
00034 static void
00035 print_data(const explain_iocontrol_t *p, explain_string_buffer_t *sb, int
00036     errnum, int fildes, int request, const void *data)
00037 {
00038     (void)p;
00039     (void)errnum;
00040     (void)fildes;
00041     (void)request;
00042     explain_buffer_char_data(sb, data, 7);
00043 }
00044 
00045 
00046 static void
00047 print_explanation(const explain_iocontrol_t *p, explain_string_buffer_t *sb, int
00048     errnum, int fildes, int request, const void *data)
00049 {
00050     switch (errnum)
00051     {
00052     case EACCES:
00053         if (!explain_capability_sys_admin())
00054         {
00055             explain_buffer_dac_sys_admin(sb);
00056             break;
00057         }
00058         if (!explain_capability_sys_rawio())
00059         {
00060             explain_buffer_dac_sys_rawio(sb);
00061             break;
00062         }
00063         goto generic;
00064 
00065     case EFAULT:
00066         explain_buffer_efault(sb, "data");
00067         break;
00068 
00069     case EINVAL:
00070         if (!data)
00071         {
00072             explain_buffer_is_the_null_pointer(sb, "data");
00073             break;
00074         }
00075         goto generic;
00076 
00077     case EIO:
00078     case ENOMEM:
00079         goto generic;
00080 
00081     default:
00082         generic:
00083         explain_iocontrol_generic_print_explanation
00084         (
00085             p,
00086             sb,
00087             errnum,
00088             fildes,
00089             request,
00090             data
00091         );
00092         break;
00093     }
00094 }
00095 
00096 
00097 const explain_iocontrol_t explain_iocontrol_hdio_drive_task =
00098 {
00099     "HDIO_DRIVE_TASK", /* name */
00100     HDIO_DRIVE_TASK, /* value */
00101     0, /* disambiguate */
00102     0, /* print_name */
00103     print_data,
00104     print_explanation,
00105     print_data,
00106     sizeof(char[7]), /* data_size */
00107     "char[7]", /* data_type */
00108     IOCONTROL_FLAG_SIZE_DOES_NOT_AGREE, /* flags */
00109     __FILE__,
00110     __LINE__,
00111 };
00112 
00113 #else /* ndef HDIO_DRIVE_TASK */
00114 
00115 const explain_iocontrol_t explain_iocontrol_hdio_drive_task =
00116 {
00117     0, /* name */
00118     0, /* value */
00119     0, /* disambiguate */
00120     0, /* print_name */
00121     0, /* print_data */
00122     0, /* print_explanation */
00123     0, /* print_data_returned */
00124     0, /* data_size */
00125     0, /* data_type */
00126     0, /* flags */
00127     __FILE__,
00128     __LINE__,
00129 };
00130 
00131 #endif /* HDIO_DRIVE_TASK */
00132 
00133 
00134 /* vim: set ts=8 sw=4 et : */