summaryrefslogtreecommitdiff
path: root/sys-fs/reiserfsprogs/files/reiserfsprogs-3.6.27-musl.patch
blob: 040914be4f498b2f8319c9b7618b5dba11b06ceb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
https://github.com/void-linux/void-packages/tree/master/srcpkgs/reiserfsprogs/patches

Define _GNU_SOURCE for the declaration of loff_t in fcntl.h
Add missing typedefs for __compar_fn_t and compare_fn_t for
non __GLIBC__ case.

--- a/include/misc.h
+++ b/include/misc.h
@@ -35,6 +35,11 @@

 #define INVAL_PTR	(void *)-1

+#if !defined(__GLIBC__)
+typedef int (*__compar_fn_t) (const void*, const void*);
+typedef __compar_fn_t comparison_fn_t;
+#endif
+
 void check_memory_msg(void);
 void die(const char *fmt, ...) __attribute__ ((format(printf, 1, 2)));
 void *getmem(int size);
See https://www.openwall.com/lists/musl/2013/01/23/6
--- a/include/reiserfs_lib.h
+++ b/include/reiserfs_lib.h
@@ -3,6 +3,10 @@
  *  reiserfsprogs/README
  */

+#if !defined(__GLIBC__)
+#define loff_t off_t
+#endif
+
 #ifndef REISERFSPROGS_LIB_H
 #define REISERFSPROGS_LIB_H

Add definitions for LONG_LONG_MIN and _MAX derived
from the values for int64_t.

--- a/resize_reiserfs/resize_reiserfs.c
+++ b/resize_reiserfs/resize_reiserfs.c
@@ -15,6 +15,13 @@
 #include "resize.h"
 #include <limits.h>

+#if !defined(__GLIBC__)
+/* These are not defined in musl libc */
+#include <stdint.h>
+#define LONG_LONG_MIN INT64_MIN
+#define LONG_LONG_MAX INT64_MAX
+#endif
+
 static int opt_banner = 0;
 static int opt_skipj = 0;
 int opt_force = 0;
--- a/reiserfscore/prints.c
+++ b/reiserfscore/prints.c
@@ -7,8 +7,11 @@

 #include "includes.h"
 #include <stdarg.h>
+#include <stdint.h>
 #include <limits.h>
+#if defined(__GLIBC__)
 #include <printf.h>
+#endif
 #include <limits.h>
 #include <time.h>

@@ -16,6 +19,38 @@
 #  include <uuid/uuid.h>
 #endif

+
+char ftypelet (mode_t mode)
+{
+    if (S_ISBLK (mode))
+      return 'b';
+    if (S_ISCHR (mode))
+      return 'c';
+    if (S_ISDIR (mode))
+      return 'd';
+    if (S_ISREG (mode))
+      return '-';
+    if (S_ISFIFO (mode))
+      return 'p';
+    if (S_ISLNK (mode))
+      return 'l';
+    if (S_ISSOCK (mode))
+      return 's';
+    return '?';
+}
+
+
+static int rwx (FILE * stream, mode_t mode)
+{
+    return fprintf (stream, "%c%c%c",
+                  (mode & S_IRUSR) ? 'r' : '-',
+                  (mode & S_IWUSR) ? 'w' : '-',
+                  (mode & S_IXUSR) ? 'x' : '-');
+}
+
+#if defined(__GLIBC__)
+
+
 #ifndef HAVE_REGISTER_PRINTF_SPECIFIER
 #define register_printf_specifier(x, y, z) register_printf_function(x, y, z)
 static int arginfo_ptr(const struct printf_info *info, size_t n, int *argtypes)
@@ -129,33 +164,6 @@ static int print_disk_child(FILE * stream,
 	FPRINTF;
 }

-char ftypelet(mode_t mode)
-{
-	if (S_ISBLK(mode))
-		return 'b';
-	if (S_ISCHR(mode))
-		return 'c';
-	if (S_ISDIR(mode))
-		return 'd';
-	if (S_ISREG(mode))
-		return '-';
-	if (S_ISFIFO(mode))
-		return 'p';
-	if (S_ISLNK(mode))
-		return 'l';
-	if (S_ISSOCK(mode))
-		return 's';
-	return '?';
-}
-
-static int rwx(FILE * stream, mode_t mode)
-{
-	return fprintf(stream, "%c%c%c",
-		       (mode & S_IRUSR) ? 'r' : '-',
-		       (mode & S_IWUSR) ? 'w' : '-',
-		       (mode & S_IXUSR) ? 'x' : '-');
-}
-
 /* %M */
 static int print_sd_mode(FILE * stream,
 			 const struct printf_info *info,
@@ -211,6 +219,140 @@ void reiserfs_warning(FILE * fp, const char *fmt, ...)
 	va_end(args);
 }

+#else /* defined(__GLIBC__) */
+
+typedef void* void_ptr;
+
+void reiserfs_warning (FILE * fp, const char * fmt, ...)
+{
+      char * buffer;
+      int len;
+      char format_buf[32];
+      char* dst = format_buf;
+      char* end = &dst[30];
+      const struct buffer_head * bh;
+      const struct item_head * ih;
+      const struct disk_child * dc;
+      const struct reiserfs_key * key;
+      uint16_t mode;
+#if defined(HAVE_LIBUUID) && defined(HAVE_UUID_UUID_H)
+      const unsigned char *uuid;
+      char uuid_buf[37];
+#endif
+      va_list args;
+      int esc = 0;
+
+      va_start (args, fmt);
+      while (*fmt) {
+              int ch = *fmt++;
+              if (esc) {
+                      switch (ch) {
+                      case '%':
+                              fputc(ch, fp);
+                              esc = 0;
+                              break;
+                      case 'b':       // block head
+                              bh = (const struct buffer_head *) va_arg(args, void_ptr);
+                              len = asprintf(&buffer, "level=%d, nr_items=%d, free_space=%d rdkey",
+                                      B_LEVEL (bh), B_NR_ITEMS (bh), B_FREE_SPACE (bh));
+                              *dst++ = 's';
+                              *dst = '\0';
+                              fprintf(fp, format_buf, buffer);
+                              esc = 0;
+                              break;
+                      case 'K':       // short key
+                              key = (const struct reiserfs_key *) va_arg(args, void_ptr);
+                              len = asprintf(&buffer, "[%u %u]", get_key_dirid (key),
+                                      get_key_objectid (key));
+                              *dst++ = 's';
+                              *dst = '\0';
+                              fprintf(fp, format_buf, buffer);
+                              esc = 0;
+                              break;
+                      case 'k':       // key
+                              key = (const struct reiserfs_key *) va_arg(args, void_ptr);
+                              len = asprintf(&buffer, "[%u %u 0x%Lx %s (%d)]",
+                                      get_key_dirid (key), get_key_objectid (key),
+                                      (unsigned long long)get_offset (key), key_of_what (key), get_type (key));
+                              *dst++ = 's';
+                              *dst = '\0';
+                              fprintf(fp, format_buf, buffer);
+                              esc = 0;
+                              break;
+                      case 'H':       // item head
+                              ih = (const struct item_head *) va_arg(args, void_ptr);
+                              len = asprintf(&buffer, "%u %u 0x%Lx %s (%d), "
+                                          "len %u, location %u entry count %u, fsck need %u, format %s",
+                                      get_key_dirid (&ih->ih_key), get_key_objectid (&ih->ih_key),
+                                      (unsigned long long)get_offset (&ih->ih_key), key_of_what (&ih->ih_key),
+                                      get_type (&ih->ih_key), get_ih_item_len (ih), get_ih_location (ih),
+                                      get_ih_entry_count (ih), get_ih_flags (ih),
+                                      get_ih_key_format (ih) == KEY_FORMAT_2 ?
+                                              "new" :
+                                              ((get_ih_key_format (ih) == KEY_FORMAT_1) ? "old" : "BAD"));
+                              *dst++ = 's';
+                              *dst = '\0';
+                              fprintf(fp, format_buf, buffer);
+                              esc = 0;
+                              break;
+                      case 'y':       // disk child
+                              dc = (const struct disk_child *) va_arg(args, void_ptr);
+                              len = asprintf(&buffer, "[dc_number=%u, dc_size=%u]", get_dc_child_blocknr (dc),
+                                              get_dc_child_size (dc));
+                              *dst++ = 's';
+                              *dst = '\0';
+                              fprintf(fp, format_buf, buffer);
+                              esc = 0;
+                              break;
+                      case 'M':       // sd mode
+                              mode = (mode_t) va_arg(args, void_ptr);
+                              fputc(ftypelet (mode), fp);
+                              rwx (fp, (mode & 0700) << 0);
+                              rwx (fp, (mode & 0070) << 3);
+                              rwx (fp, (mode & 0007) << 6);
+                              esc = 0;
+                              break;
+                      case 'U':       // UUID
+#if defined(HAVE_LIBUUID) && defined(HAVE_UUID_UUID_H)
+                              uuid = (const unsigned char *) va_arg(args, void_ptr);
+                              uuid_buf[36] = '\0';
+                              uuid_unparse(uuid, uuid_buf);
+                              fprintf(fp, "%s", uuid_buf);
+#else
+                              fprintf(fp, "<no libuuid installed>");
+#endif
+                              esc = 0;
+                              break;
+                      case '-': case '+': case '#': case '.':
+                      case '0': case '1': case '2': case '3': case '4':
+                      case '5': case '6': case '7': case '8': case '9':
+                      case 'l': case 'L': case 'h':
+                              // non-terminal format modifiers
+                              if (dst < end)
+                                      *dst++ = ch;
+                              break;
+                      default:
+                              *dst++ = ch;
+                              *dst = '\0';
+                              fprintf(fp, format_buf, va_arg(args, void_ptr));
+                              esc = 0;
+                              break;
+                      }
+              } else if (ch == '%') {
+                      esc = 1;
+                      dst = format_buf;
+                      end = &dst[30]; // leave room for final "s\0"
+                      *dst++ = ch;
+              } else {
+                      fputc(ch, fp);
+              }
+      }
+
+      va_end (args);
+}
+
+#endif        /* !defined(__GLIBC__) */
+
 static void print_directory_item(FILE *fp, reiserfs_filsys_t fs,
 				 struct buffer_head *bh, struct item_head *ih)
 {