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 00006 * it under the terms of the GNU Lesser General Public License as 00007 * published by the Free Software Foundation; either version 3 of the 00008 * License, or (at 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/limits.h> /* for PATH_MAX on Solaris */ 00020 #include <libexplain/ac/sys/param.h> /* for PATH_MAX except Solaris */ 00021 #include <libexplain/ac/sys/stat.h> 00022 00023 #include <libexplain/buffer/device_name.h> 00024 #include <libexplain/buffer/enosys.h> 00025 #include <libexplain/buffer/file_type.h> 00026 #include <libexplain/buffer/mount_point.h> 00027 #include <libexplain/buffer/pointer.h> 00028 #include <libexplain/is_efault.h> 00029 00030 00031 static void 00032 explain_buffer_enosys_generic(explain_string_buffer_t *sb, const char *caption, 00033 const char *syscall_name) 00034 { 00035 explain_string_buffer_printf 00036 ( 00037 sb, 00038 /* 00039 * xgettext: This error message is issued to explain an ENOSYS 00040 * or EOPNOTSUPP or ENOTTY error, in the generic case. There are 00041 * more specific messages, try to use those instead. 00042 * 00043 * %1$s => the name of the offending system call argument 00044 * %2$s => the name of the offending system call 00045 */ 00046 i18n("%s is not associated with an object to which %s can be applied"), 00047 caption, 00048 syscall_name 00049 ); 00050 } 00051 00052 00053 static void 00054 the_device_does_not_support_the_system_call(explain_string_buffer_t *sb, 00055 const char *file_type, const char *caption, const char *syscall_name) 00056 { 00057 explain_string_buffer_printf_gettext 00058 ( 00059 sb, 00060 /* 00061 * xgettext: this error message is issued to explain an ENOSYS 00062 * or EOPNOTSUPP error in the case where a system call is not 00063 * supported for a particular device (or perhapse si not 00064 * supported by the device driver). 00065 * 00066 * %1$s => the type of the special file (already translated) 00067 * %2$s => the name of the offending system call. 00068 */ 00069 i18n("%s is a %s that does not support the %s system call"), 00070 caption, 00071 file_type, 00072 syscall_name 00073 ); 00074 } 00075 00076 00077 static void 00078 explain_buffer_enosys_stat(explain_string_buffer_t *sb, const struct stat *st, 00079 const char *caption, const char *syscall_name) 00080 { 00081 switch (st->st_mode & S_IFMT) 00082 { 00083 case S_IFREG: 00084 case S_IFDIR: 00085 case S_IFLNK: 00086 { 00087 char mount_point[PATH_MAX + 1]; 00088 explain_string_buffer_t mount_point_buf; 00089 00090 explain_string_buffer_init 00091 ( 00092 &mount_point_buf, 00093 mount_point, 00094 sizeof(mount_point) 00095 ); 00096 if (explain_buffer_mount_point_stat(&mount_point_buf, st) >= 0) 00097 { 00098 explain_string_buffer_printf_gettext 00099 ( 00100 sb, 00101 /* 00102 * xgettext: this error message is issued to explain 00103 * an ENOSYS or EOPNOTSUPP error in the case where a 00104 * file system does not support a particular system 00105 * call. 00106 * 00107 * %1$s => the mount point of the file system, 00108 * in parentheses 00109 * %2$s => the name of the offending system call. 00110 */ 00111 i18n("the file system %s does not support the %s system " 00112 "call"), 00113 mount_point, 00114 syscall_name 00115 ); 00116 } 00117 else 00118 { 00119 explain_string_buffer_printf_gettext 00120 ( 00121 sb, 00122 /* 00123 * xgettext: this error message is issued to explain 00124 * an ENOSYS or EOPNOTSUPP error in the case where a 00125 * file system does not support a particular system 00126 * call. 00127 * 00128 * %1$s => the name of the offending system call. 00129 */ 00130 i18n("the file system does not support the %s system call"), 00131 syscall_name 00132 ); 00133 } 00134 } 00135 break; 00136 00137 case S_IFBLK: 00138 case S_IFCHR: 00139 { 00140 struct stat st2; 00141 char device_name[150]; 00142 explain_string_buffer_t device_name_buf; 00143 char file_type[FILE_TYPE_BUFFER_SIZE_MIN]; 00144 explain_string_buffer_t file_type_buf; 00145 00146 explain_string_buffer_init 00147 ( 00148 &file_type_buf, 00149 file_type, 00150 sizeof(file_type) 00151 ); 00152 explain_buffer_file_type_st(&file_type_buf, st); 00153 explain_string_buffer_init 00154 ( 00155 &device_name_buf, 00156 device_name, 00157 sizeof(device_name) 00158 ); 00159 if 00160 ( 00161 explain_buffer_device_name(&device_name_buf, st->st_dev, &st2) 00162 >= 00163 0 00164 ) 00165 { 00166 explain_string_buffer_printf_gettext 00167 ( 00168 sb, 00169 /* 00170 * xgettext: this error message is issued to explain 00171 * an ENOSYS or EOPNOTSUPP error in the case where 00172 * a system call is not supported for a particular 00173 * device (or perhapse not supported by the device 00174 * driver). 00175 * 00176 * %1$s => the file system path of the device special file 00177 * %2$s => the type of the special file (already translated) 00178 * %3$s => the name of the offending system call. 00179 */ 00180 i18n("the %s %s does not support the %s system call"), 00181 device_name, 00182 file_type, 00183 syscall_name 00184 ); 00185 } 00186 else 00187 { 00188 the_device_does_not_support_the_system_call 00189 ( 00190 sb, 00191 file_type, 00192 caption, 00193 syscall_name 00194 ); 00195 } 00196 } 00197 break; 00198 00199 default: 00200 { 00201 char file_type[FILE_TYPE_BUFFER_SIZE_MIN]; 00202 explain_string_buffer_t file_type_buf; 00203 00204 explain_string_buffer_init 00205 ( 00206 &file_type_buf, 00207 file_type, 00208 sizeof(file_type) 00209 ); 00210 explain_buffer_file_type_st(&file_type_buf, st); 00211 the_device_does_not_support_the_system_call 00212 ( 00213 sb, 00214 file_type, 00215 caption, 00216 syscall_name 00217 ); 00218 } 00219 break; 00220 } 00221 } 00222 00223 00224 void 00225 explain_buffer_enosys_fildes(explain_string_buffer_t *sb, int fildes, 00226 const char *caption, const char *syscall_name) 00227 { 00228 struct stat st; 00229 00230 if (fstat(fildes, &st) >= 0) 00231 explain_buffer_enosys_stat(sb, &st, caption, syscall_name); 00232 else 00233 explain_buffer_enosys_generic(sb, caption, syscall_name); 00234 } 00235 00236 00237 void 00238 explain_buffer_enosys_pathname(explain_string_buffer_t *sb, 00239 const char *pathname, const char *caption, const char *syscall_name) 00240 { 00241 struct stat st; 00242 00243 if (stat(pathname, &st) >= 0) 00244 explain_buffer_enosys_stat(sb, &st, caption, syscall_name); 00245 else 00246 explain_buffer_enosys_generic(sb, caption, syscall_name); 00247 } 00248 00249 00250 void 00251 explain_buffer_enosys_acl(explain_string_buffer_t *sb, const char *caption, 00252 const char *syscall_name) 00253 { 00254 explain_string_buffer_printf 00255 ( 00256 sb, 00257 i18n 00258 ( 00259 /* 00260 * xgettext: This error message is issued to explain an ENOSYS 00261 * or EOPNOTSUPP or ENOTSUP error, when returned by one of the 00262 * ACL functions. 00263 * 00264 * %1$s => the name of the offending system call argument 00265 * %2$s => the name of the offending system call 00266 */ 00267 "the %s argument is not associated with an object to which the " 00268 "%s system call can be applied, or the file system on which the " 00269 "file is located may not support ACLs, or ACLs are disabled, or " 00270 "this host system does not support ACLs" 00271 ), 00272 caption, 00273 syscall_name 00274 ); 00275 } 00276 00277 00278 /* vim: set ts=8 sw=4 et : */