libexplain  1.4.D001
libexplain/buffer/errno/mknod.c
Go to the documentation of this file.
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 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
00012  * ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNULesser
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/dev_t.h>
00022 #include <libexplain/buffer/eacces.h>
00023 #include <libexplain/buffer/eexist.h>
00024 #include <libexplain/buffer/eexist.h>
00025 #include <libexplain/buffer/efault.h>
00026 #include <libexplain/buffer/einval.h>
00027 #include <libexplain/buffer/eloop.h>
00028 #include <libexplain/buffer/enametoolong.h>
00029 #include <libexplain/buffer/enoent.h>
00030 #include <libexplain/buffer/enomem.h>
00031 #include <libexplain/buffer/enospc.h>
00032 #include <libexplain/buffer/enotdir.h>
00033 #include <libexplain/buffer/eperm.h>
00034 #include <libexplain/buffer/erofs.h>
00035 #include <libexplain/buffer/errno/generic.h>
00036 #include <libexplain/buffer/errno/mknod.h>
00037 #include <libexplain/buffer/errno/path_resolution.h>
00038 #include <libexplain/buffer/pathname.h>
00039 #include <libexplain/buffer/stat_mode.h>
00040 #include <libexplain/explanation.h>
00041 
00042 
00043 static void
00044 explain_buffer_errno_mknod_system_call(explain_string_buffer_t *sb, int errnum,
00045     const char *pathname, mode_t mode, dev_t dev)
00046 {
00047     (void)errnum;
00048     explain_string_buffer_puts(sb, "mknod(pathname = ");
00049     explain_buffer_pathname(sb, pathname);
00050     explain_string_buffer_puts(sb, ", mode = ");
00051     explain_buffer_stat_mode(sb, mode);
00052     explain_string_buffer_puts(sb, ", dev = ");
00053     explain_buffer_dev_t(sb, dev);
00054     explain_string_buffer_putc(sb, ')');
00055 }
00056 
00057 
00058 void
00059 explain_buffer_errno_mknod_explanation(explain_string_buffer_t *sb, int errnum,
00060     const char *syscall_name, const char *pathname, mode_t mode, dev_t dev)
00061 {
00062     explain_final_t fc;
00063 
00064     (void)dev;
00065     explain_final_init(&fc);
00066     fc.must_exist = 0;
00067     fc.must_not_exist = 1;
00068     fc.want_to_create = 1;
00069     fc.follow_symlink = 0;
00070     fc.st_mode = mode;
00071 
00072     /*
00073      * http://www.opengroup.org/onlinepubs/009695399/functions/mknod.html
00074      */
00075     switch (errnum)
00076     {
00077     case EEXIST:
00078         explain_buffer_eexist(sb, pathname);
00079         break;
00080 
00081     case EACCES:
00082         explain_buffer_eacces(sb, pathname, "pathname", &fc);
00083         break;
00084 
00085     case EFAULT:
00086         explain_buffer_efault(sb, "pathname");
00087         break;
00088 
00089     case ELOOP:
00090         explain_buffer_eloop(sb, pathname, "pathname", &fc);
00091         break;
00092 
00093     case ENAMETOOLONG:
00094         explain_buffer_enametoolong(sb, pathname, "pathname", &fc);
00095         break;
00096 
00097     case ENOENT:
00098         explain_buffer_enoent(sb, pathname, "pathname", &fc);
00099         break;
00100 
00101     case ENOMEM:
00102         explain_buffer_enomem_kernel(sb);
00103         break;
00104 
00105     case ENOSPC:
00106         explain_buffer_enospc(sb, pathname, "pathname");
00107         break;
00108 
00109     case ENOTDIR:
00110         explain_buffer_enotdir(sb, pathname, "pathname", &fc);
00111         break;
00112 
00113     case EPERM:
00114         explain_buffer_eperm_mknod(sb, pathname, "pathname", mode);
00115         break;
00116 
00117     case EROFS:
00118         explain_buffer_erofs(sb, pathname, "pathname");
00119         break;
00120 
00121     case EINVAL:
00122         explain_buffer_einval_mknod(sb, mode, "mode", syscall_name);
00123         break;
00124 
00125     default:
00126         explain_buffer_errno_generic(sb, errnum, syscall_name);
00127         break;
00128     }
00129 }
00130 
00131 
00132 void
00133 explain_buffer_errno_mknod(explain_string_buffer_t *sb, int errnum,
00134     const char *pathname, mode_t mode, dev_t dev)
00135 {
00136     explain_explanation_t exp;
00137 
00138     explain_explanation_init(&exp, errnum);
00139     explain_buffer_errno_mknod_system_call(&exp.system_call_sb, errnum,
00140         pathname, mode, dev);
00141     explain_buffer_errno_mknod_explanation(&exp.explanation_sb, errnum, "mknod",
00142         pathname, mode, dev);
00143     explain_explanation_assemble(&exp, sb);
00144 }
00145 
00146 
00147 /* vim: set ts=8 sw=4 et : */