forked from whitemike889/AppImageKit
-
Notifications
You must be signed in to change notification settings - Fork 1
/
squashfs_osx.patch
434 lines (386 loc) · 11.8 KB
/
squashfs_osx.patch
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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
diff --git a/squashfs-tools/action.c b/squashfs-tools/action.c
index 4b06ccb..40780ae 100644
--- a/squashfs-tools/action.c
+++ b/squashfs-tools/action.c
@@ -38,6 +38,10 @@
#include <limits.h>
#include <errno.h>
+#ifndef FNM_EXTMATCH /* glibc extension */
+ #define FNM_EXTMATCH 0
+#endif
+
#include "squashfs_fs.h"
#include "mksquashfs.h"
#include "action.h"
@@ -2284,9 +2288,12 @@ static char *get_start(char *s, int n)
static int subpathname_fn(struct atom *atom, struct action_data *action_data)
{
- return fnmatch(atom->argv[0], get_start(strdupa(action_data->subpath),
+ char *path = strdup(action_data->subpath);
+ int is_match = fnmatch(atom->argv[0], get_start(path,
count_components(atom->argv[0])),
FNM_PATHNAME|FNM_PERIOD|FNM_EXTMATCH) == 0;
+ free(path);
+ return is_match;
}
/*
diff --git a/squashfs-tools/info.c b/squashfs-tools/info.c
index 7968c77..56f26dc 100644
--- a/squashfs-tools/info.c
+++ b/squashfs-tools/info.c
@@ -134,31 +134,22 @@ void dump_state()
void *info_thrd(void *arg)
{
sigset_t sigmask;
- struct timespec timespec = { .tv_sec = 1, .tv_nsec = 0 };
- int sig, waiting = 0;
+ int sig, err, waiting = 0;
sigemptyset(&sigmask);
sigaddset(&sigmask, SIGQUIT);
sigaddset(&sigmask, SIGHUP);
+ sigaddset(&sigmask, SIGALRM);
while(1) {
- if(waiting)
- sig = sigtimedwait(&sigmask, NULL, ×pec);
- else
- sig = sigwaitinfo(&sigmask, NULL);
+ err = sigwait(&sigmask, &sig);
- if(sig == -1) {
+ if(err == -1) {
switch(errno) {
- case EAGAIN:
- /* interval timed out */
- waiting = 0;
- /* FALLTHROUGH */
case EINTR:
- /* if waiting, the wait will be longer, but
- that's OK */
continue;
default:
- BAD_ERROR("sigtimedwait/sigwaitinfo failed "
+ BAD_ERROR("sigwait failed "
"because %s\n", strerror(errno));
}
}
@@ -169,8 +160,12 @@ void *info_thrd(void *arg)
/* set one second interval period, if ^\ received
within then, dump queue and cache status */
waiting = 1;
- } else
+ alarm(1);
+ } else if (sig == SIGQUIT) {
dump_state();
+ } else if (sig == SIGALRM) {
+ waiting = 0;
+ }
}
}
diff --git a/squashfs-tools/mksquashfs.c b/squashfs-tools/mksquashfs.c
index e7965c4..44d62ce 100644
--- a/squashfs-tools/mksquashfs.c
+++ b/squashfs-tools/mksquashfs.c
@@ -50,6 +50,10 @@
#include <limits.h>
#include <ctype.h>
+#ifndef FNM_EXTMATCH /* glibc extension */
+ #define FNM_EXTMATCH 0
+#endif
+
#ifndef linux
#define __BYTE_ORDER BYTE_ORDER
#define __BIG_ENDIAN BIG_ENDIAN
@@ -830,13 +834,13 @@ char *subpathname(struct dir_ent *dir_ent)
}
-inline unsigned int get_inode_no(struct inode_info *inode)
+static inline unsigned int get_inode_no(struct inode_info *inode)
{
return inode->inode_number;
}
-inline unsigned int get_parent_no(struct dir_info *dir)
+static inline unsigned int get_parent_no(struct dir_info *dir)
{
return dir->depth ? get_inode_no(dir->dir_ent->inode) : inode_no;
}
@@ -2029,7 +2033,7 @@ struct file_info *duplicate(long long file_size, long long bytes,
}
-inline int is_fragment(struct inode_info *inode)
+static inline int is_fragment(struct inode_info *inode)
{
off_t file_size = inode->buf.st_size;
@@ -2998,13 +3002,13 @@ struct inode_info *lookup_inode2(struct stat *buf, int pseudo, int id)
}
-inline struct inode_info *lookup_inode(struct stat *buf)
+static inline struct inode_info *lookup_inode(struct stat *buf)
{
return lookup_inode2(buf, 0, 0);
}
-inline void alloc_inode_no(struct inode_info *inode, unsigned int use_this)
+static inline void alloc_inode_no(struct inode_info *inode, unsigned int use_this)
{
if (inode->inode_number == 0) {
inode->inode_number = use_this ? : inode_no ++;
@@ -3015,7 +3019,7 @@ inline void alloc_inode_no(struct inode_info *inode, unsigned int use_this)
}
-inline struct dir_ent *create_dir_entry(char *name, char *source_name,
+static inline struct dir_ent *create_dir_entry(char *name, char *source_name,
char *nonstandard_pathname, struct dir_info *dir)
{
struct dir_ent *dir_ent = malloc(sizeof(struct dir_ent));
@@ -3033,7 +3037,7 @@ inline struct dir_ent *create_dir_entry(char *name, char *source_name,
}
-inline void add_dir_entry(struct dir_ent *dir_ent, struct dir_info *sub_dir,
+static inline void add_dir_entry(struct dir_ent *dir_ent, struct dir_info *sub_dir,
struct inode_info *inode_info)
{
struct dir_info *dir = dir_ent->our_dir;
@@ -3049,7 +3053,7 @@ inline void add_dir_entry(struct dir_ent *dir_ent, struct dir_info *sub_dir,
}
-inline void add_dir_entry2(char *name, char *source_name,
+static inline void add_dir_entry2(char *name, char *source_name,
char *nonstandard_pathname, struct dir_info *sub_dir,
struct inode_info *inode_info, struct dir_info *dir)
{
@@ -3061,7 +3065,7 @@ inline void add_dir_entry2(char *name, char *source_name,
}
-inline void free_dir_entry(struct dir_ent *dir_ent)
+static inline void free_dir_entry(struct dir_ent *dir_ent)
{
if(dir_ent->name)
free(dir_ent->name);
@@ -3082,7 +3086,7 @@ inline void free_dir_entry(struct dir_ent *dir_ent)
}
-inline void add_excluded(struct dir_info *dir)
+static inline void add_excluded(struct dir_info *dir)
{
dir->excluded ++;
}
@@ -4199,6 +4203,7 @@ void initialise_threads(int readq, int fragq, int bwriteq, int fwriteq,
sigemptyset(&sigmask);
sigaddset(&sigmask, SIGQUIT);
sigaddset(&sigmask, SIGHUP);
+ sigaddset(&sigmask, SIGALRM);
if(pthread_sigmask(SIG_BLOCK, &sigmask, NULL) == -1)
BAD_ERROR("Failed to set signal mask in intialise_threads\n");
@@ -4986,6 +4991,36 @@ int parse_num(char *arg, int *res)
int get_physical_memory()
{
+ int phys_mem;
+#ifndef linux
+ #ifdef HW_MEMSIZE
+ #define SYSCTL_PHYSMEM HW_MEMSIZE
+ #elif defined(HW_PHYSMEM64)
+ #define SYSCTL_PHYSMEM HW_PHYSMEM64
+ #else
+ #define SYSCTL_PHYSMEM HW_PHYSMEM
+ #endif
+
+ int mib[2];
+ uint64_t sysctl_physmem = 0;
+ size_t sysctl_len = sizeof(sysctl_physmem);
+
+ mib[0] = CTL_HW;
+ mib[1] = SYSCTL_PHYSMEM;
+
+ if(sysctl(mib, 2, &sysctl_physmem, &sysctl_len, NULL, 0) == 0) {
+ /* some systems use 32-bit values, work with what we're given */
+ if (sysctl_len == 4)
+ sysctl_physmem = *(uint32_t*)&sysctl_physmem;
+ phys_mem = sysctl_physmem >> 20;
+ } else {
+ ERROR_START("Failed to get amount of available "
+ "memory.");
+ ERROR_EXIT(" Defaulting to least viable amount\n");
+ phys_mem = SQUASHFS_LOWMEM;
+ }
+ #undef SYSCTL_PHYSMEM
+#else
/*
* Long longs are used here because with PAE, a 32-bit
* machine can have more than 4GB of physical memory
@@ -4993,10 +5028,11 @@ int get_physical_memory()
* sysconf(_SC_PHYS_PAGES) relies on /proc being mounted.
* If it isn't fail.
*/
- long long num_pages = sysconf(_SC_PHYS_PAGES);
- long long page_size = sysconf(_SC_PAGESIZE);
int phys_mem = num_pages * page_size >> 20;
+#endif
+ long long num_pages = sysconf(_SC_PHYS_PAGES);
+ long long page_size = sysconf(_SC_PAGESIZE);
if(num_pages == -1 || page_size == -1)
return 0;
diff --git a/squashfs-tools/mksquashfs.h b/squashfs-tools/mksquashfs.h
index 55708a3..d44d1fd 100644
--- a/squashfs-tools/mksquashfs.h
+++ b/squashfs-tools/mksquashfs.h
@@ -24,6 +24,7 @@
* mksquashfs.h
*
*/
+#include <pthread.h>
struct dir_info {
char *pathname;
diff --git a/squashfs-tools/pseudo.c b/squashfs-tools/pseudo.c
index cb74cf6..fe2b4bc 100644
--- a/squashfs-tools/pseudo.c
+++ b/squashfs-tools/pseudo.c
@@ -30,6 +30,7 @@
#include <errno.h>
#include <string.h>
#include <stdlib.h>
+#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>
diff --git a/squashfs-tools/read_xattrs.c b/squashfs-tools/read_xattrs.c
index 42106f5..837d3fb 100644
--- a/squashfs-tools/read_xattrs.c
+++ b/squashfs-tools/read_xattrs.c
@@ -39,13 +39,13 @@
#include <endian.h>
#endif
+#include <stdlib.h>
+
#include "squashfs_fs.h"
#include "squashfs_swap.h"
#include "xattr.h"
#include "error.h"
-#include <stdlib.h>
-
extern int read_fs_bytes(int, long long, int, void *);
extern int read_block(int, long long, long long *, int, void *);
diff --git a/squashfs-tools/unsquashfs.c b/squashfs-tools/unsquashfs.c
index c5e0876..e5566ff 100644
--- a/squashfs-tools/unsquashfs.c
+++ b/squashfs-tools/unsquashfs.c
@@ -32,7 +32,12 @@
#include "stdarg.h"
#include "fnmatch_compat.h"
+#ifndef linux
+#include <sys/sysctl.h>
+#else
#include <sys/sysinfo.h>
+#endif
+
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
@@ -2180,6 +2185,7 @@ void initialise_threads(int fragment_buffer_size, int data_buffer_size)
sigemptyset(&sigmask);
sigaddset(&sigmask, SIGQUIT);
sigaddset(&sigmask, SIGHUP);
+ sigaddset(&sigmask, SIGALRM);
if(pthread_sigmask(SIG_BLOCK, &sigmask, NULL) == -1)
EXIT_UNSQUASH("Failed to set signal mask in initialise_threads"
"\n");
diff --git a/squashfs-tools/unsquashfs.h b/squashfs-tools/unsquashfs.h
index 0edbd25..cea9caa 100644
--- a/squashfs-tools/unsquashfs.h
+++ b/squashfs-tools/unsquashfs.h
@@ -46,6 +46,10 @@
#include <sys/ioctl.h>
#include <sys/time.h>
+#ifndef FNM_EXTMATCH /* glibc extension */
+ #define FNM_EXTMATCH 0
+#endif
+
#ifndef linux
#define __BYTE_ORDER BYTE_ORDER
#define __BIG_ENDIAN BIG_ENDIAN
diff --git a/squashfs-tools/unsquashfs_info.c b/squashfs-tools/unsquashfs_info.c
index c8e2b9b..e26f0de 100644
--- a/squashfs-tools/unsquashfs_info.c
+++ b/squashfs-tools/unsquashfs_info.c
@@ -97,31 +97,21 @@ void dump_state()
void *info_thrd(void *arg)
{
sigset_t sigmask;
- struct timespec timespec = { .tv_sec = 1, .tv_nsec = 0 };
- int sig, waiting = 0;
+ int sig, err, waiting = 0;
sigemptyset(&sigmask);
sigaddset(&sigmask, SIGQUIT);
sigaddset(&sigmask, SIGHUP);
+ sigaddset(&sigmask, SIGALRM);
while(1) {
- if(waiting)
- sig = sigtimedwait(&sigmask, NULL, ×pec);
- else
- sig = sigwaitinfo(&sigmask, NULL);
-
- if(sig == -1) {
- switch(errno) {
- case EAGAIN:
- /* interval timed out */
- waiting = 0;
- /* FALLTHROUGH */
+ err = sigwait(&sigmask, &sig);
+
+ if(err == -1) {
case EINTR:
- /* if waiting, the wait will be longer, but
- that's OK */
continue;
default:
- BAD_ERROR("sigtimedwait/sigwaitinfo failed "
+ BAD_ERROR("sigwait failed "
"because %s\n", strerror(errno));
}
}
@@ -133,8 +123,12 @@ void *info_thrd(void *arg)
/* set one second interval period, if ^\ received
within then, dump queue and cache status */
waiting = 1;
- } else
- dump_state();
+ alarm(1);
+ } else if (sig == SIGQUIT) {
+ dump_state();
+ } else if (sig == SIGALRM) {
+ waiting = 0;
+ }
}
}
diff --git a/squashfs-tools/unsquashfs_xattr.c b/squashfs-tools/unsquashfs_xattr.c
index 59f4aae..13f0e35 100644
--- a/squashfs-tools/unsquashfs_xattr.c
+++ b/squashfs-tools/unsquashfs_xattr.c
@@ -27,6 +27,11 @@
#include <sys/xattr.h>
+#ifdef XATTR_NOFOLLOW /* Apple's xattrs */
+ #define lsetxattr(path_, name_, val_, sz_, flags_) \
+ setxattr(path_, name_, val_, sz_, 0, flags_ | XATTR_NOFOLLOW)
+#endif
+
#define NOSPACE_MAX 10
extern int root_process;
diff --git a/squashfs-tools/xattr.c b/squashfs-tools/xattr.c
index b46550c..5b32eca 100644
--- a/squashfs-tools/xattr.c
+++ b/squashfs-tools/xattr.c
@@ -22,6 +22,14 @@
* xattr.c
*/
+#ifndef linux
+#define __BYTE_ORDER BYTE_ORDER
+#define __BIG_ENDIAN BIG_ENDIAN
+#define __LITTLE_ENDIAN LITTLE_ENDIAN
+#else
+#include <endian.h>
+#endif
+
#define TRUE 1
#define FALSE 0
@@ -36,6 +44,13 @@
#include <stdlib.h>
#include <sys/xattr.h>
+#ifdef XATTR_NOFOLLOW /* Apple's xattrs */
+ #define llistxattr(path_, buf_, sz_) \
+ listxattr(path_, buf_, sz_, XATTR_NOFOLLOW)
+ #define lgetxattr(path_, name_, val_, sz_) \
+ getxattr(path_, name_, val_, sz_, 0, XATTR_NOFOLLOW)
+#endif
+
#include "squashfs_fs.h"
#include "squashfs_swap.h"
#include "mksquashfs.h"