libexplain
1.4.D001
|
00001 /* 00002 * libexplain - Explain errno values returned by libc functions 00003 * Copyright (C) 2009-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/linux/fs.h> 00021 #include <libexplain/ac/sys/ioctl.h> 00022 00023 #include <libexplain/buffer/blkpg_ioctl_arg.h> 00024 #include <libexplain/iocontrol/blkpg.h> 00025 00026 00027 #ifdef BLKPG 00028 00029 static void 00030 print_data(const explain_iocontrol_t *p, explain_string_buffer_t *sb, 00031 int errnum, int fildes, int request, const void *data) 00032 { 00033 (void)p; 00034 (void)errnum; 00035 (void)fildes; 00036 (void)request; 00037 explain_buffer_blkpg_ioctl_arg(sb, data); 00038 } 00039 00040 00041 static void 00042 print_explanation(const explain_iocontrol_t *p, explain_string_buffer_t *sb, 00043 int errnum, int fildes, int request, const void *data) 00044 { 00045 switch (errnum) 00046 { 00047 case EACCES: 00048 goto generic; 00049 00050 case EFAULT: 00051 { 00052 const struct blkpg_ioctl_arg *ap; 00053 const struct blkpg_partition *pp; 00054 00055 ap = data; 00056 if (explain_is_efault_pointer(ap, sizeof(*ap))) 00057 { 00058 explain_buffer_efault(sb, "data"); 00059 break; 00060 } 00061 pp = ap->data; 00062 if (explain_is_efault_pointer(pp, sizeof(*pp))) 00063 { 00064 explain_buffer_efault(sb, "data->data"); 00065 break; 00066 } 00067 } 00068 goto generic; 00069 00070 case EINVAL: 00071 { 00072 const struct blkpg_ioctl_arg *ap; 00073 const struct blkpg_partition *pp; 00074 long n; 00075 00076 if (!disk_partitionable(fildes)) 00077 if (disk_max_parts(disk) > 1) 00078 { 00079 explain_buffer_enosys_fildes(sb, fildes); 00080 return; 00081 } 00082 00083 ap = data; 00084 switch (ap->op) 00085 { 00086 case BLKPG_ADD_PARTITION: 00087 case BLKPG_DEL_PARTITION: 00088 pp = ap->data; 00089 if (pp->pno <= 0) 00090 { 00091 explain_buffer_einval_too_small(sb, "data->pno", pp->pno); 00092 return; 00093 } 00094 if (pp->start & 511) 00095 { 00096 explain_buffer_einval_multiple(sb, "data->start", 512); 00097 return; 00098 } 00099 n = pp->start >> 9; 00100 if (n < 0) 00101 { 00102 explain_buffer_einval_vague(sb, "data->start"); 00103 return; 00104 } 00105 if (pp->length & 511) 00106 { 00107 explain_buffer_einval_multiple(sb, "data->length", 512); 00108 return; 00109 } 00110 n = pp->length >> 9; 00111 if (n < 0) 00112 { 00113 explain_buffer_einval_vague(sb, "data->length"); 00114 return; 00115 } 00116 break; 00117 00118 default: 00119 explain_buffer_einval_vague(sb, "data->op"); 00120 return; 00121 } 00122 } 00123 goto generic; 00124 00125 case ENXIO: 00126 explain_buffer_einval_vague(sb, "data->data->pno"); 00127 break; 00128 00129 case EBUSY: 00130 goto generic; 00131 00132 default: 00133 generic: 00134 explain_iocontrol_generic.print_explanation 00135 ( 00136 p, 00137 sb, 00138 errnum, 00139 fildes, 00140 request, 00141 data 00142 ); 00143 break; 00144 } 00145 } 00146 00147 00148 const explain_iocontrol_t explain_iocontrol_blkpg = 00149 { 00150 "BLKPG", /* name */ 00151 BLKPG, /* value */ 00152 0, /* disambiguate */ 00153 0, /* print_name */ 00154 print_data, 00155 print_explanation, 00156 0, /* print_data_returned */ 00157 sizeof(struct blkpg_ioctl_arg), /* data_size */ 00158 "struct blkpg_ioctl_arg *", /* data_type */ 00159 0, /* flags */ 00160 __FILE__, 00161 __LINE__, 00162 }; 00163 00164 #else /* ndef BLKPG */ 00165 00166 const explain_iocontrol_t explain_iocontrol_blkpg = 00167 { 00168 0, /* name */ 00169 0, /* value */ 00170 0, /* disambiguate */ 00171 0, /* print_name */ 00172 0, /* print_data */ 00173 0, /* print_explanation */ 00174 0, /* print_data_returned */ 00175 0, /* data_size */ 00176 0, /* data_type */ 00177 0, /* flags */ 00178 __FILE__, 00179 __LINE__, 00180 }; 00181 00182 #endif /* BLKPG */ 00183 00184 00185 /* vim: set ts=8 sw=4 et : */