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/linux/blkpg.h> 00020 00021 #include <libexplain/buffer/blkpg_ioctl_arg.h> 00022 #include <libexplain/buffer/int.h> 00023 #include <libexplain/buffer/long_long.h> 00024 #include <libexplain/buffer/pointer.h> 00025 #include <libexplain/is_efault.h> 00026 #include <libexplain/parse_bits.h> 00027 #include <libexplain/sizeof.h> 00028 00029 00030 #ifdef HAVE_LINUX_BLKPG_H 00031 00032 static void 00033 explain_buffer_blkpg_op(explain_string_buffer_t *sb, int value) 00034 { 00035 static const explain_parse_bits_table_t table[] = 00036 { 00037 { "BLKPG_ADD_PARTITION", BLKPG_ADD_PARTITION }, 00038 { "BLKPG_DEL_PARTITION", BLKPG_DEL_PARTITION }, 00039 }; 00040 00041 explain_parse_bits_print_single(sb, value, table, SIZEOF(table)); 00042 } 00043 00044 00045 static void 00046 explain_buffer_blkpg_flags(explain_string_buffer_t *sb, int value) 00047 { 00048 /* no flags bits defined, yet */ 00049 explain_buffer_int(sb, value); 00050 } 00051 00052 00053 static void 00054 explain_buffer_blkpg_partition(explain_string_buffer_t *sb, 00055 const struct blkpg_partition *p) 00056 { 00057 if (explain_is_efault_pointer(p, sizeof(*p))) 00058 { 00059 explain_buffer_pointer(sb, p); 00060 return; 00061 } 00062 00063 explain_string_buffer_puts(sb, "{ start = "); 00064 explain_buffer_long_long(sb, p->start); 00065 explain_string_buffer_puts(sb, ", length = "); 00066 explain_buffer_long_long(sb, p->length); 00067 explain_string_buffer_puts(sb, ", pno = "); 00068 explain_buffer_int(sb, p->pno); 00069 explain_string_buffer_puts(sb, ", devname = "); 00070 explain_string_buffer_puts_quoted_n(sb, p->devname, sizeof(p->devname)); 00071 explain_string_buffer_puts(sb, ", volname = "); 00072 explain_string_buffer_puts_quoted_n(sb, p->volname, sizeof(p->volname)); 00073 explain_string_buffer_puts(sb, " }"); 00074 } 00075 00076 00077 void 00078 explain_buffer_blkpg_ioctl_arg(explain_string_buffer_t *sb, 00079 const struct blkpg_ioctl_arg *data) 00080 { 00081 if (explain_is_efault_pointer(data, sizeof(*data))) 00082 { 00083 explain_buffer_pointer(sb, data); 00084 return; 00085 } 00086 00087 explain_string_buffer_puts(sb, "{ op = "); 00088 explain_buffer_blkpg_op(sb, data->op); 00089 explain_string_buffer_puts(sb, ", flags = "); 00090 explain_buffer_blkpg_flags(sb, data->flags); 00091 switch (data->op) 00092 { 00093 case BLKPG_ADD_PARTITION: 00094 case BLKPG_DEL_PARTITION: 00095 explain_string_buffer_puts(sb, ", datalen = "); 00096 explain_buffer_int(sb, data->datalen); 00097 explain_string_buffer_puts(sb, ", data = "); 00098 explain_buffer_blkpg_partition(sb, data->data); 00099 break; 00100 00101 default: 00102 explain_string_buffer_puts(sb, ", datalen = "); 00103 explain_buffer_int(sb, data->datalen); 00104 explain_string_buffer_puts(sb, ", data = "); 00105 explain_buffer_pointer(sb, data->data); 00106 break; 00107 } 00108 explain_string_buffer_puts(sb, " }"); 00109 } 00110 00111 #else 00112 00113 void 00114 explain_buffer_blkpg_ioctl_arg(explain_string_buffer_t *sb, 00115 const struct blkpg_ioctl_arg *data) 00116 { 00117 explain_buffer_pointer(sb, data); 00118 } 00119 00120 #endif 00121 00122 00123 /* vim: set ts=8 sw=4 et : */