libexplain
1.4.D001
|
00001 /* 00002 * libexplain - a library of system-call-specific strerror replacements 00003 * Copyright (C) 2011, 2013 Peter Miller 00004 * Written by Peter Miller <pmiller@opensource.org.au> 00005 * 00006 * This program is free software; you can redistribute it and/or modify it 00007 * under the terms of the GNU Lesser General Public License as published by 00008 * the Free Software Foundation; either version 3 of the License, or (at your 00009 * option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, but WITHOUT 00012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 00014 * License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public License 00017 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00018 */ 00019 00020 #include <libexplain/ac/errno.h> 00021 #include <libexplain/ac/linux/videodev2.h> 00022 #include <libexplain/ac/string.h> 00023 #include <libexplain/ac/sys/ioctl.h> 00024 00025 #include <libexplain/buffer/dac.h> 00026 #include <libexplain/buffer/einval.h> 00027 #include <libexplain/buffer/eperm.h> 00028 #include <libexplain/buffer/is_the_null_pointer.h> 00029 #include <libexplain/buffer/v4l2_dbg_register.h> 00030 #include <libexplain/buffer/v4l2_register.h> 00031 #include <libexplain/iocontrol/generic.h> 00032 #include <libexplain/iocontrol/vidioc_dbg_s_register.h> 00033 #include <libexplain/is_efault.h> 00034 00035 #ifdef VIDIOC_DBG_S_REGISTER 00036 00037 00038 static void 00039 print_data(const explain_iocontrol_t *p, explain_string_buffer_t *sb, 00040 int errnum, int fildes, int request, const void *data) 00041 { 00042 (void)p; 00043 (void)errnum; 00044 (void)fildes; 00045 (void)request; 00046 #ifdef HAVE_V4L2_DBG_REGISTER 00047 explain_buffer_v4l2_dbg_register(sb, data, 1); 00048 #else 00049 explain_buffer_v4l2_register(sb, data, 1); 00050 #endif 00051 } 00052 00053 00054 static void 00055 print_explanation(const explain_iocontrol_t *p, explain_string_buffer_t *sb, 00056 int errnum, int fildes, int request, const void *data) 00057 { 00058 switch (errnum) 00059 { 00060 case EINVAL: 00061 if (!data) 00062 { 00063 explain_buffer_is_the_null_pointer(sb, "data"); 00064 return; 00065 } 00066 00067 { 00068 #ifdef HAVE_V4L2_DBG_REGISTER 00069 const struct v4l2_dbg_register *arg; 00070 struct v4l2_dbg_register try; 00071 #else 00072 const struct v4l2_register *arg; 00073 struct v4l2_register try; 00074 #endif 00075 00076 arg = data; 00077 if (explain_is_efault_pointer(arg, sizeof(*arg))) 00078 goto generic; 00079 00080 /* 00081 * See if we can fetch the given register. 00082 * If we can, it means the value is broken. 00083 */ 00084 try = *arg; 00085 if (ioctl(fildes, VIDIOC_DBG_G_REGISTER, &try) >= 0) 00086 { 00087 explain_buffer_einval_vague(sb, "data->val"); 00088 return; 00089 } 00090 } 00091 00092 /* 00093 * It could be the address is broken, or it could be this isn't 00094 * supported. Let's guess it's the latter. 00095 */ 00096 errnum = ENOTTY; 00097 goto generic; 00098 00099 case EPERM: 00100 explain_buffer_eperm_vague(sb, "ioctl VIDIOC_DBG_S_REGISTER"); 00101 explain_buffer_dac_sys_admin(sb); 00102 break; 00103 00104 default: 00105 generic: 00106 explain_iocontrol_generic_print_explanation 00107 ( 00108 p, 00109 sb, 00110 errnum, 00111 fildes, 00112 request, 00113 data 00114 ); 00115 break; 00116 } 00117 } 00118 00119 00120 static void 00121 print_data_returned(const explain_iocontrol_t *p, explain_string_buffer_t *sb, 00122 int errnum, int fildes, int request, const void *data) 00123 { 00124 (void)p; 00125 (void)errnum; 00126 (void)fildes; 00127 (void)request; 00128 #ifdef HAVE_V4L2_DBG_REGISTER 00129 explain_buffer_v4l2_dbg_register(sb, data, 1); 00130 #else 00131 explain_buffer_v4l2_register(sb, data, 1); 00132 #endif 00133 } 00134 00135 00136 const explain_iocontrol_t explain_iocontrol_vidioc_dbg_s_register = 00137 { 00138 "VIDIOC_DBG_S_REGISTER", /* name */ 00139 VIDIOC_DBG_S_REGISTER, /* value */ 00140 0, /* disambiguate */ 00141 0, /* print_name */ 00142 print_data, 00143 print_explanation, 00144 print_data_returned, 00145 #ifdef HAVE_V4L2_DBG_REGISTER 00146 sizeof(struct v4l2_dbg_register), /* data_size */ 00147 "struct v4l2_dbg_register *", /* data_type */ 00148 #else 00149 sizeof(struct v4l2_register), /* data_size */ 00150 "struct v4l2_register *", /* data_type */ 00151 #endif 00152 IOCONTROL_FLAG_RW, /* flags */ 00153 __FILE__, 00154 __LINE__, 00155 }; 00156 00157 #else /* ndef VIDIOC_DBG_S_REGISTER */ 00158 00159 const explain_iocontrol_t explain_iocontrol_vidioc_dbg_s_register = 00160 { 00161 0, /* name */ 00162 0, /* value */ 00163 0, /* disambiguate */ 00164 0, /* print_name */ 00165 0, /* print_data */ 00166 0, /* print_explanation */ 00167 0, /* print_data_returned */ 00168 0, /* data_size */ 00169 0, /* data_type */ 00170 0, /* flags */ 00171 __FILE__, 00172 __LINE__, 00173 }; 00174 00175 #endif /* VIDIOC_DBG_S_REGISTER */ 00176 00177 /* vim: set ts=8 sw=4 et : */