libexplain
1.4.D001
|
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 00008 * 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/errno.h> 00020 00021 #include <libexplain/buffer/eacces.h> 00022 #include <libexplain/buffer/efault.h> 00023 #include <libexplain/buffer/eintr.h> 00024 #include <libexplain/buffer/eio.h> 00025 #include <libexplain/buffer/eloop.h> 00026 #include <libexplain/buffer/enametoolong.h> 00027 #include <libexplain/buffer/enoent.h> 00028 #include <libexplain/buffer/enomem.h> 00029 #include <libexplain/buffer/enosys.h> 00030 #include <libexplain/buffer/enotdir.h> 00031 #include <libexplain/buffer/eoverflow.h> 00032 #include <libexplain/buffer/errno/generic.h> 00033 #include <libexplain/buffer/errno/path_resolution.h> 00034 #include <libexplain/buffer/errno/statfs.h> 00035 #include <libexplain/buffer/pathname.h> 00036 #include <libexplain/buffer/pointer.h> 00037 #include <libexplain/explanation.h> 00038 #include <libexplain/is_efault.h> 00039 00040 00041 static void 00042 explain_buffer_errno_statfs_system_call(explain_string_buffer_t *sb, int errnum, 00043 const char *pathname, struct statfs *data) 00044 { 00045 (void)errnum; 00046 explain_string_buffer_puts(sb, "statfs(pathname = "); 00047 explain_buffer_pathname(sb, pathname); 00048 explain_string_buffer_puts(sb, ", data = "); 00049 explain_buffer_pointer(sb, data); 00050 explain_string_buffer_putc(sb, ')'); 00051 } 00052 00053 00054 static void 00055 explain_buffer_errno_statfs_explanation(explain_string_buffer_t *sb, int errnum, 00056 const char *syscall_name, const char *pathname, struct statfs *data) 00057 { 00058 explain_final_t final_component; 00059 00060 /* 00061 * http://www.opengroup.org/onlinepubs/009695399/functions/statfs.html 00062 */ 00063 (void)data; 00064 explain_final_init(&final_component); 00065 switch (errnum) 00066 { 00067 case EACCES: 00068 explain_buffer_eacces(sb, pathname, "pathname", &final_component); 00069 break; 00070 00071 case EFAULT: 00072 if (explain_is_efault_path(pathname)) 00073 explain_buffer_efault(sb, "pathname"); 00074 else 00075 explain_buffer_efault(sb, "data"); 00076 break; 00077 00078 case EINTR: 00079 explain_buffer_eintr(sb, syscall_name); 00080 break; 00081 00082 case EIO: 00083 explain_buffer_eio_path(sb, pathname); 00084 break; 00085 00086 case ELOOP: 00087 explain_buffer_eloop(sb, pathname, "pathname", &final_component); 00088 break; 00089 00090 case ENAMETOOLONG: 00091 explain_buffer_enametoolong(sb, pathname, "pathname", &final_component); 00092 break; 00093 00094 case ENOENT: 00095 explain_buffer_enoent(sb, pathname, "pathname", &final_component); 00096 break; 00097 00098 case ENOMEM: 00099 explain_buffer_enomem_kernel(sb); 00100 break; 00101 00102 case ENOSYS: 00103 #if defined(EOPNOTSUPP) && EOPNOTSUPP != ENOSYS 00104 case EOPNOTSUPP: 00105 #endif 00106 explain_buffer_enosys_pathname(sb, pathname, "pathname", syscall_name); 00107 break; 00108 00109 case ENOTDIR: 00110 explain_buffer_enotdir(sb, pathname, "pathname", &final_component); 00111 break; 00112 00113 case EOVERFLOW: 00114 explain_buffer_eoverflow(sb); 00115 break; 00116 00117 default: 00118 explain_buffer_errno_generic(sb, errnum, syscall_name); 00119 break; 00120 } 00121 } 00122 00123 00124 void 00125 explain_buffer_errno_statfs(explain_string_buffer_t *sb, int errnum, 00126 const char *pathname, struct statfs *data) 00127 { 00128 explain_explanation_t exp; 00129 00130 explain_explanation_init(&exp, errnum); 00131 explain_buffer_errno_statfs_system_call 00132 ( 00133 &exp.system_call_sb, 00134 errnum, 00135 pathname, 00136 data 00137 ); 00138 explain_buffer_errno_statfs_explanation 00139 ( 00140 &exp.explanation_sb, 00141 errnum, 00142 "statfs", 00143 pathname, 00144 data 00145 ); 00146 explain_explanation_assemble(&exp, sb); 00147 } 00148 00149 00150 /* vim: set ts=8 sw=4 et : */