libexplain
1.4.D001
|
00001 /* 00002 * libexplain - Explain errno values returned by libc functions 00003 * Copyright (C) 2008, 2009, 2012, 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 00007 * it under the terms of the GNU Lesser General Public License as 00008 * published by the Free Software Foundation; either version 3 of the 00009 * License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public 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 00022 #include <libexplain/buffer/does_not_have_inode_modify_permission.h> 00023 #include <libexplain/buffer/eacces.h> 00024 #include <libexplain/buffer/efault.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/enotdir.h> 00031 #include <libexplain/buffer/erofs.h> 00032 #include <libexplain/buffer/errno/chmod.h> 00033 #include <libexplain/buffer/errno/generic.h> 00034 #include <libexplain/buffer/errno/path_resolution.h> 00035 #include <libexplain/buffer/permission_mode.h> 00036 #include <libexplain/buffer/pathname.h> 00037 #include <libexplain/buffer/pointer.h> 00038 #include <libexplain/capability.h> 00039 #include <libexplain/explanation.h> 00040 #include <libexplain/option.h> 00041 00042 00043 static void 00044 explain_buffer_errno_chmod_system_call(explain_string_buffer_t *sb, 00045 int errnum, const char *pathname, int mode) 00046 { 00047 (void)errnum; 00048 explain_string_buffer_puts(sb, "chmod(pathname = "); 00049 explain_buffer_pathname(sb, pathname); 00050 explain_string_buffer_puts(sb, ", mode = "); 00051 explain_buffer_permission_mode(sb, mode); 00052 explain_string_buffer_putc(sb, ')'); 00053 } 00054 00055 00056 static void 00057 explain_buffer_errno_chmod_explanation(explain_string_buffer_t *sb, 00058 int errnum, const char *pathname, int mode) 00059 { 00060 explain_final_t final_component; 00061 00062 explain_final_init(&final_component); 00063 final_component.want_to_modify_inode = 1; 00064 00065 explain_buffer_errno_chmod_explanation_fc 00066 ( 00067 sb, 00068 errnum, 00069 "chmod", 00070 pathname, 00071 mode, 00072 &final_component 00073 ); 00074 } 00075 00076 00077 void 00078 explain_buffer_errno_chmod_explanation_fc(explain_string_buffer_t *sb, 00079 int errnum, const char *syscall_name, const char *pathname, int mode, 00080 const explain_final_t *final_component) 00081 { 00082 (void)mode; 00083 switch (errnum) 00084 { 00085 case EACCES: 00086 explain_buffer_eacces(sb, pathname, "pathname", final_component); 00087 break; 00088 00089 case EFAULT: 00090 explain_buffer_efault(sb, "pathname"); 00091 break; 00092 00093 case EIO: 00094 explain_buffer_eio_path(sb, pathname); 00095 break; 00096 00097 case ELOOP: 00098 case EMLINK: /* BSD */ 00099 explain_buffer_eloop(sb, pathname, "pathname", final_component); 00100 break; 00101 00102 case ENAMETOOLONG: 00103 explain_buffer_enametoolong 00104 ( 00105 sb, 00106 pathname, 00107 "pathname", 00108 final_component 00109 ); 00110 break; 00111 00112 case ENOENT: 00113 explain_buffer_enoent(sb, pathname, "pathname", final_component); 00114 break; 00115 00116 case ENOMEM: 00117 explain_buffer_enomem_kernel(sb); 00118 break; 00119 00120 case ENOTDIR: 00121 explain_buffer_enotdir(sb, pathname, "pathname", final_component); 00122 break; 00123 00124 case EPERM: 00125 if 00126 ( 00127 explain_buffer_errno_path_resolution 00128 ( 00129 sb, 00130 errnum, 00131 pathname, 00132 "pathname", 00133 final_component 00134 ) 00135 ) 00136 { 00137 explain_buffer_does_not_have_inode_modify_permission_fd_st 00138 ( 00139 sb, 00140 (struct stat *)0, 00141 "pathname", 00142 &final_component->id 00143 ); 00144 } 00145 break; 00146 00147 case EROFS: 00148 explain_buffer_erofs(sb, pathname, "pathname"); 00149 break; 00150 00151 default: 00152 explain_buffer_errno_generic(sb, errnum, syscall_name); 00153 break; 00154 } 00155 } 00156 00157 00158 void 00159 explain_buffer_errno_chmod(explain_string_buffer_t *sb, int errnum, 00160 const char *pathname, int mode) 00161 { 00162 explain_explanation_t exp; 00163 00164 explain_explanation_init(&exp, errnum); 00165 explain_buffer_errno_chmod_system_call 00166 ( 00167 &exp.system_call_sb, 00168 errnum, 00169 pathname, 00170 mode 00171 ); 00172 explain_buffer_errno_chmod_explanation 00173 ( 00174 &exp.explanation_sb, 00175 errnum, 00176 pathname, 00177 mode 00178 ); 00179 explain_explanation_assemble(&exp, sb); 00180 } 00181 00182 00183 /* vim: set ts=8 sw=4 et : */