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/sys/ioctl.h> 00023 00024 #include <libexplain/buffer/dac.h> 00025 #include <libexplain/buffer/einval.h> 00026 #include <libexplain/buffer/eperm.h> 00027 #include <libexplain/buffer/is_the_null_pointer.h> 00028 #include <libexplain/buffer/v4l2_framebuffer.h> 00029 #include <libexplain/buffer/v4l2_pixel_format.h> 00030 #include <libexplain/capability.h> 00031 #include <libexplain/iocontrol/generic.h> 00032 #include <libexplain/iocontrol/vidioc_s_fbuf.h> 00033 #include <libexplain/is_efault.h> 00034 00035 #ifdef VIDIOC_S_FBUF 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 explain_buffer_v4l2_framebuffer(sb, data); 00047 } 00048 00049 00050 static void 00051 print_explanation(const explain_iocontrol_t *p, explain_string_buffer_t *sb, 00052 int errnum, int fildes, int request, const void *data) 00053 { 00054 switch (errnum) 00055 { 00056 case EINVAL: 00057 if (!data) 00058 { 00059 explain_buffer_is_the_null_pointer(sb, "data"); 00060 return; 00061 } 00062 00063 { 00064 struct v4l2_framebuffer g; 00065 00066 if (ioctl(fildes, VIDIOC_G_FBUF, &g) < 0 && errno == EPERM) 00067 { 00068 explain_string_buffer_puts 00069 ( 00070 sb, 00071 /* FIXME: i18n */ 00072 "the device does support output frame buffers" 00073 ); 00074 return; 00075 } 00076 } 00077 00078 { 00079 const struct v4l2_framebuffer *arg; 00080 00081 arg = data; 00082 if (explain_is_efault_pointer(arg, sizeof(*arg))) 00083 goto generic; 00084 switch (explain_v4l2_pixel_format_check(arg->fmt.pixelformat)) 00085 { 00086 case explain_v4l2_pixel_format_check_ok: 00087 break; 00088 00089 case explain_v4l2_pixel_format_check_nosuch: 00090 default: 00091 explain_buffer_einval_vague(sb, "data->fmt.pixelformat"); 00092 return; 00093 } 00094 } 00095 00096 explain_buffer_einval_vague(sb, "data"); 00097 return; 00098 00099 case EPERM: 00100 if (!explain_capability_sys_admin() && !explain_capability_sys_rawio()) 00101 { 00102 explain_buffer_eperm_vague(sb, "ioctl VIDIOC_S_FBUF"); 00103 explain_buffer_dac_sys_rawio(sb); 00104 return; 00105 } 00106 00107 /* no idea */ 00108 goto generic; 00109 00110 default: 00111 generic: 00112 explain_iocontrol_generic_print_explanation 00113 ( 00114 p, 00115 sb, 00116 errnum, 00117 fildes, 00118 request, 00119 data 00120 ); 00121 break; 00122 } 00123 } 00124 00125 00126 const explain_iocontrol_t explain_iocontrol_vidioc_s_fbuf = 00127 { 00128 "VIDIOC_S_FBUF", /* name */ 00129 VIDIOC_S_FBUF, /* value */ 00130 0, /* disambiguate */ 00131 0, /* print_name */ 00132 print_data, 00133 print_explanation, 00134 0, /* print_data_returned */ 00135 sizeof(struct v4l2_framebuffer), /* data_size */ 00136 "struct v4l2_framebuffer *", /* data_type */ 00137 0, /* flags */ 00138 __FILE__, 00139 __LINE__, 00140 }; 00141 00142 #else /* ndef VIDIOC_S_FBUF */ 00143 00144 const explain_iocontrol_t explain_iocontrol_vidioc_s_fbuf = 00145 { 00146 0, /* name */ 00147 0, /* value */ 00148 0, /* disambiguate */ 00149 0, /* print_name */ 00150 0, /* print_data */ 00151 0, /* print_explanation */ 00152 0, /* print_data_returned */ 00153 0, /* data_size */ 00154 0, /* data_type */ 00155 0, /* flags */ 00156 __FILE__, 00157 __LINE__, 00158 }; 00159 00160 #endif /* VIDIOC_S_FBUF */ 00161 00162 /* vim: set ts=8 sw=4 et : */