libexplain
1.4.D001
|
00001 /* 00002 * libexplain - Explain errno values returned by libc functions 00003 * Copyright (C) 2009, 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/buffer/enospc.h> 00020 #include <libexplain/buffer/gettext.h> 00021 #include <libexplain/buffer/mount_point.h> 00022 00023 00024 void 00025 explain_buffer_enospc(explain_string_buffer_t *sb, const char *pathname, 00026 const char *pathname_caption) 00027 { 00028 char mntpt[100]; 00029 explain_string_buffer_t mntpt_sb; 00030 00031 explain_string_buffer_init(&mntpt_sb, mntpt, sizeof(mntpt)); 00032 if (explain_buffer_mount_point(&mntpt_sb, pathname) < 0) 00033 explain_buffer_mount_point_dirname(&mntpt_sb, pathname); 00034 explain_string_buffer_printf_gettext 00035 ( 00036 sb, 00037 /* 00038 * xgettext: This message is used to provide an 00039 * explanation for and ENOSPC error returned by an 00040 * open(2) system call, in the case where there is no 00041 * more room for a new file. 00042 * 00043 * %1$s => The name of the problematic system call argument 00044 * %2$s => The file system mount point and usage, 00045 * in parentheses 00046 */ 00047 i18n("the file system containing %s %s has no space for a new " 00048 "directory entry"), 00049 pathname_caption, 00050 mntpt 00051 ); 00052 /* FIXME: has no blocks left or has no inodes left? */ 00053 /* FIXME: ENOSPC can be caused by quota system, too. */ 00054 } 00055 00056 00057 void 00058 explain_buffer_enospc_fildes(explain_string_buffer_t *sb, int fildes, 00059 const char *fildes_caption) 00060 { 00061 struct stat st; 00062 00063 if (fstat(fildes, &st) == 0) 00064 { 00065 if (S_ISBLK(st.st_mode) || S_ISCHR(st.st_mode)) 00066 { 00067 explain_string_buffer_printf_gettext 00068 ( 00069 sb, 00070 /* 00071 * xgettext: This error message is used to explain an 00072 * ENOSPC error, in the case where a device has no space 00073 * for more data. 00074 * 00075 * %1$s => The name of the offending syscall argument. 00076 */ 00077 i18n("the device referred to by %s has no more space for data"), 00078 fildes_caption 00079 ); 00080 } 00081 else 00082 { 00083 char mntpt[100]; 00084 explain_string_buffer_t mntpt_sb; 00085 00086 explain_string_buffer_init(&mntpt_sb, mntpt, sizeof(mntpt)); 00087 explain_buffer_mount_point_stat(&mntpt_sb, &st); 00088 00089 explain_string_buffer_printf_gettext 00090 ( 00091 sb, 00092 /* 00093 * xgettext: This error message is used to explain an 00094 * ENOSPC error, in the case where a file system has no 00095 * room to increase the size of a file. 00096 * 00097 * %1$s => The name of the problematic system call argument 00098 * %2$s => The file system mount point and usage, 00099 * in parentheses 00100 */ 00101 i18n("the file system containing %s %s has no more space for " 00102 "data"), 00103 fildes_caption, 00104 mntpt 00105 ); 00106 } 00107 } 00108 else 00109 { 00110 explain_buffer_gettext 00111 ( 00112 sb, 00113 /* 00114 * xgettext: This error message is used to explain an 00115 * ENOSPC error, in the case where more specific information 00116 * is not available. 00117 */ 00118 i18n("the device containing the file referred to by the file " 00119 "descriptor has no space for the data; or, the file system " 00120 "containing the file has no space for the data") 00121 ); 00122 } 00123 } 00124 00125 00126 /* vim: set ts=8 sw=4 et : */