musl-prints.patch (8534B)
1 --- a/reiserfscore/prints.c 2 +++ b/reiserfscore/prints.c 3 @@ -7,8 +7,11 @@ 4 5 #include "includes.h" 6 #include <stdarg.h> 7 +#include <stdint.h> 8 #include <limits.h> 9 +#if defined(__GLIBC__) 10 #include <printf.h> 11 +#endif 12 #include <limits.h> 13 #include <time.h> 14 15 @@ -16,6 +19,38 @@ 16 # include <uuid/uuid.h> 17 #endif 18 19 + 20 +char ftypelet (mode_t mode) 21 +{ 22 + if (S_ISBLK (mode)) 23 + return 'b'; 24 + if (S_ISCHR (mode)) 25 + return 'c'; 26 + if (S_ISDIR (mode)) 27 + return 'd'; 28 + if (S_ISREG (mode)) 29 + return '-'; 30 + if (S_ISFIFO (mode)) 31 + return 'p'; 32 + if (S_ISLNK (mode)) 33 + return 'l'; 34 + if (S_ISSOCK (mode)) 35 + return 's'; 36 + return '?'; 37 +} 38 + 39 + 40 +static int rwx (FILE * stream, mode_t mode) 41 +{ 42 + return fprintf (stream, "%c%c%c", 43 + (mode & S_IRUSR) ? 'r' : '-', 44 + (mode & S_IWUSR) ? 'w' : '-', 45 + (mode & S_IXUSR) ? 'x' : '-'); 46 +} 47 + 48 +#if defined(__GLIBC__) 49 + 50 + 51 #ifndef HAVE_REGISTER_PRINTF_SPECIFIER 52 #define register_printf_specifier(x, y, z) register_printf_function(x, y, z) 53 static int arginfo_ptr(const struct printf_info *info, size_t n, int *argtypes) 54 @@ -129,33 +164,6 @@ static int print_disk_child(FILE * stream, 55 FPRINTF; 56 } 57 58 -char ftypelet(mode_t mode) 59 -{ 60 - if (S_ISBLK(mode)) 61 - return 'b'; 62 - if (S_ISCHR(mode)) 63 - return 'c'; 64 - if (S_ISDIR(mode)) 65 - return 'd'; 66 - if (S_ISREG(mode)) 67 - return '-'; 68 - if (S_ISFIFO(mode)) 69 - return 'p'; 70 - if (S_ISLNK(mode)) 71 - return 'l'; 72 - if (S_ISSOCK(mode)) 73 - return 's'; 74 - return '?'; 75 -} 76 - 77 -static int rwx(FILE * stream, mode_t mode) 78 -{ 79 - return fprintf(stream, "%c%c%c", 80 - (mode & S_IRUSR) ? 'r' : '-', 81 - (mode & S_IWUSR) ? 'w' : '-', 82 - (mode & S_IXUSR) ? 'x' : '-'); 83 -} 84 - 85 /* %M */ 86 static int print_sd_mode(FILE * stream, 87 const struct printf_info *info, 88 @@ -211,6 +219,140 @@ void reiserfs_warning(FILE * fp, const char *fmt, ...) 89 va_end(args); 90 } 91 92 +#else /* defined(__GLIBC__) */ 93 + 94 +typedef void* void_ptr; 95 + 96 +void reiserfs_warning (FILE * fp, const char * fmt, ...) 97 +{ 98 + char * buffer; 99 + int len; 100 + char format_buf[32]; 101 + char* dst = format_buf; 102 + char* end = &dst[30]; 103 + const struct buffer_head * bh; 104 + const struct item_head * ih; 105 + const struct disk_child * dc; 106 + const struct reiserfs_key * key; 107 + uint16_t mode; 108 +#if defined(HAVE_LIBUUID) && defined(HAVE_UUID_UUID_H) 109 + const unsigned char *uuid; 110 + char uuid_buf[37]; 111 +#endif 112 + va_list args; 113 + int esc = 0; 114 + 115 + va_start (args, fmt); 116 + while (*fmt) { 117 + int ch = *fmt++; 118 + if (esc) { 119 + switch (ch) { 120 + case '%': 121 + fputc(ch, fp); 122 + esc = 0; 123 + break; 124 + case 'b': // block head 125 + bh = (const struct buffer_head *) va_arg(args, void_ptr); 126 + len = asprintf(&buffer, "level=%d, nr_items=%d, free_space=%d rdkey", 127 + B_LEVEL (bh), B_NR_ITEMS (bh), B_FREE_SPACE (bh)); 128 + *dst++ = 's'; 129 + *dst = '\0'; 130 + fprintf(fp, format_buf, buffer); 131 + esc = 0; 132 + break; 133 + case 'K': // short key 134 + key = (const struct reiserfs_key *) va_arg(args, void_ptr); 135 + len = asprintf(&buffer, "[%u %u]", get_key_dirid (key), 136 + get_key_objectid (key)); 137 + *dst++ = 's'; 138 + *dst = '\0'; 139 + fprintf(fp, format_buf, buffer); 140 + esc = 0; 141 + break; 142 + case 'k': // key 143 + key = (const struct reiserfs_key *) va_arg(args, void_ptr); 144 + len = asprintf(&buffer, "[%u %u 0x%Lx %s (%d)]", 145 + get_key_dirid (key), get_key_objectid (key), 146 + (unsigned long long)get_offset (key), key_of_what (key), get_type (key)); 147 + *dst++ = 's'; 148 + *dst = '\0'; 149 + fprintf(fp, format_buf, buffer); 150 + esc = 0; 151 + break; 152 + case 'H': // item head 153 + ih = (const struct item_head *) va_arg(args, void_ptr); 154 + len = asprintf(&buffer, "%u %u 0x%Lx %s (%d), " 155 + "len %u, location %u entry count %u, fsck need %u, format %s", 156 + get_key_dirid (&ih->ih_key), get_key_objectid (&ih->ih_key), 157 + (unsigned long long)get_offset (&ih->ih_key), key_of_what (&ih->ih_key), 158 + get_type (&ih->ih_key), get_ih_item_len (ih), get_ih_location (ih), 159 + get_ih_entry_count (ih), get_ih_flags (ih), 160 + get_ih_key_format (ih) == KEY_FORMAT_2 ? 161 + "new" : 162 + ((get_ih_key_format (ih) == KEY_FORMAT_1) ? "old" : "BAD")); 163 + *dst++ = 's'; 164 + *dst = '\0'; 165 + fprintf(fp, format_buf, buffer); 166 + esc = 0; 167 + break; 168 + case 'y': // disk child 169 + dc = (const struct disk_child *) va_arg(args, void_ptr); 170 + len = asprintf(&buffer, "[dc_number=%u, dc_size=%u]", get_dc_child_blocknr (dc), 171 + get_dc_child_size (dc)); 172 + *dst++ = 's'; 173 + *dst = '\0'; 174 + fprintf(fp, format_buf, buffer); 175 + esc = 0; 176 + break; 177 + case 'M': // sd mode 178 + mode = (mode_t) va_arg(args, void_ptr); 179 + fputc(ftypelet (mode), fp); 180 + rwx (fp, (mode & 0700) << 0); 181 + rwx (fp, (mode & 0070) << 3); 182 + rwx (fp, (mode & 0007) << 6); 183 + esc = 0; 184 + break; 185 + case 'U': // UUID 186 +#if defined(HAVE_LIBUUID) && defined(HAVE_UUID_UUID_H) 187 + uuid = (const unsigned char *) va_arg(args, void_ptr); 188 + uuid_buf[36] = '\0'; 189 + uuid_unparse(uuid, uuid_buf); 190 + fprintf(fp, "%s", uuid_buf); 191 +#else 192 + fprintf(fp, "<no libuuid installed>"); 193 +#endif 194 + esc = 0; 195 + break; 196 + case '-': case '+': case '#': case '.': 197 + case '0': case '1': case '2': case '3': case '4': 198 + case '5': case '6': case '7': case '8': case '9': 199 + case 'l': case 'L': case 'h': 200 + // non-terminal format modifiers 201 + if (dst < end) 202 + *dst++ = ch; 203 + break; 204 + default: 205 + *dst++ = ch; 206 + *dst = '\0'; 207 + fprintf(fp, format_buf, va_arg(args, void_ptr)); 208 + esc = 0; 209 + break; 210 + } 211 + } else if (ch == '%') { 212 + esc = 1; 213 + dst = format_buf; 214 + end = &dst[30]; // leave room for final "s\0" 215 + *dst++ = ch; 216 + } else { 217 + fputc(ch, fp); 218 + } 219 + } 220 + 221 + va_end (args); 222 +} 223 + 224 +#endif /* !defined(__GLIBC__) */ 225 + 226 static void print_directory_item(FILE *fp, reiserfs_filsys_t fs, 227 struct buffer_head *bh, struct item_head *ih) 228 {