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