Add downloads badge
[appimagekit/gsi.git] / squashfs_osx.patch
blobb08351b10a6906ef0957935573868b64ceece067
1 diff --git a/squashfs-tools/action.c b/squashfs-tools/action.c
2 index 4b06ccb..40780ae 100644
3 --- a/squashfs-tools/action.c
4 +++ b/squashfs-tools/action.c
5 @@ -38,6 +38,10 @@
6 #include <limits.h>
7 #include <errno.h>
9 +#ifndef FNM_EXTMATCH /* glibc extension */
10 + #define FNM_EXTMATCH 0
11 +#endif
13 #include "squashfs_fs.h"
14 #include "mksquashfs.h"
15 #include "action.h"
16 @@ -2284,9 +2288,12 @@ static char *get_start(char *s, int n)
18 static int subpathname_fn(struct atom *atom, struct action_data *action_data)
20 - return fnmatch(atom->argv[0], get_start(strdupa(action_data->subpath),
21 + char *path = strdup(action_data->subpath);
22 + int is_match = fnmatch(atom->argv[0], get_start(path,
23 count_components(atom->argv[0])),
24 FNM_PATHNAME|FNM_PERIOD|FNM_EXTMATCH) == 0;
25 + free(path);
26 + return is_match;
30 diff --git a/squashfs-tools/info.c b/squashfs-tools/info.c
31 index 7968c77..56f26dc 100644
32 --- a/squashfs-tools/info.c
33 +++ b/squashfs-tools/info.c
34 @@ -134,31 +134,22 @@ void dump_state()
35 void *info_thrd(void *arg)
37 sigset_t sigmask;
38 - struct timespec timespec = { .tv_sec = 1, .tv_nsec = 0 };
39 - int sig, waiting = 0;
40 + int sig, err, waiting = 0;
42 sigemptyset(&sigmask);
43 sigaddset(&sigmask, SIGQUIT);
44 sigaddset(&sigmask, SIGHUP);
45 + sigaddset(&sigmask, SIGALRM);
47 while(1) {
48 - if(waiting)
49 - sig = sigtimedwait(&sigmask, NULL, &timespec);
50 - else
51 - sig = sigwaitinfo(&sigmask, NULL);
52 + err = sigwait(&sigmask, &sig);
54 - if(sig == -1) {
55 + if(err == -1) {
56 switch(errno) {
57 - case EAGAIN:
58 - /* interval timed out */
59 - waiting = 0;
60 - /* FALLTHROUGH */
61 case EINTR:
62 - /* if waiting, the wait will be longer, but
63 - that's OK */
64 continue;
65 default:
66 - BAD_ERROR("sigtimedwait/sigwaitinfo failed "
67 + BAD_ERROR("sigwait failed "
68 "because %s\n", strerror(errno));
71 @@ -169,8 +160,12 @@ void *info_thrd(void *arg)
72 /* set one second interval period, if ^\ received
73 within then, dump queue and cache status */
74 waiting = 1;
75 - } else
76 + alarm(1);
77 + } else if (sig == SIGQUIT) {
78 dump_state();
79 + } else if (sig == SIGALRM) {
80 + waiting = 0;
81 + }
85 diff --git a/squashfs-tools/mksquashfs.c b/squashfs-tools/mksquashfs.c
86 index e7965c4..44d62ce 100644
87 --- a/squashfs-tools/mksquashfs.c
88 +++ b/squashfs-tools/mksquashfs.c
89 @@ -50,6 +50,10 @@
90 #include <limits.h>
91 #include <ctype.h>
93 +#ifndef FNM_EXTMATCH /* glibc extension */
94 + #define FNM_EXTMATCH 0
95 +#endif
97 #ifndef linux
98 #define __BYTE_ORDER BYTE_ORDER
99 #define __BIG_ENDIAN BIG_ENDIAN
100 @@ -830,13 +834,13 @@ char *subpathname(struct dir_ent *dir_ent)
104 -inline unsigned int get_inode_no(struct inode_info *inode)
105 +static inline unsigned int get_inode_no(struct inode_info *inode)
107 return inode->inode_number;
111 -inline unsigned int get_parent_no(struct dir_info *dir)
112 +static inline unsigned int get_parent_no(struct dir_info *dir)
114 return dir->depth ? get_inode_no(dir->dir_ent->inode) : inode_no;
116 @@ -2029,7 +2033,7 @@ struct file_info *duplicate(long long file_size, long long bytes,
120 -inline int is_fragment(struct inode_info *inode)
121 +static inline int is_fragment(struct inode_info *inode)
123 off_t file_size = inode->buf.st_size;
125 @@ -2998,13 +3002,13 @@ struct inode_info *lookup_inode2(struct stat *buf, int pseudo, int id)
129 -inline struct inode_info *lookup_inode(struct stat *buf)
130 +static inline struct inode_info *lookup_inode(struct stat *buf)
132 return lookup_inode2(buf, 0, 0);
136 -inline void alloc_inode_no(struct inode_info *inode, unsigned int use_this)
137 +static inline void alloc_inode_no(struct inode_info *inode, unsigned int use_this)
139 if (inode->inode_number == 0) {
140 inode->inode_number = use_this ? : inode_no ++;
141 @@ -3015,7 +3019,7 @@ inline void alloc_inode_no(struct inode_info *inode, unsigned int use_this)
145 -inline struct dir_ent *create_dir_entry(char *name, char *source_name,
146 +static inline struct dir_ent *create_dir_entry(char *name, char *source_name,
147 char *nonstandard_pathname, struct dir_info *dir)
149 struct dir_ent *dir_ent = malloc(sizeof(struct dir_ent));
150 @@ -3033,7 +3037,7 @@ inline struct dir_ent *create_dir_entry(char *name, char *source_name,
154 -inline void add_dir_entry(struct dir_ent *dir_ent, struct dir_info *sub_dir,
155 +static inline void add_dir_entry(struct dir_ent *dir_ent, struct dir_info *sub_dir,
156 struct inode_info *inode_info)
158 struct dir_info *dir = dir_ent->our_dir;
159 @@ -3049,7 +3053,7 @@ inline void add_dir_entry(struct dir_ent *dir_ent, struct dir_info *sub_dir,
163 -inline void add_dir_entry2(char *name, char *source_name,
164 +static inline void add_dir_entry2(char *name, char *source_name,
165 char *nonstandard_pathname, struct dir_info *sub_dir,
166 struct inode_info *inode_info, struct dir_info *dir)
168 @@ -3061,7 +3065,7 @@ inline void add_dir_entry2(char *name, char *source_name,
172 -inline void free_dir_entry(struct dir_ent *dir_ent)
173 +static inline void free_dir_entry(struct dir_ent *dir_ent)
175 if(dir_ent->name)
176 free(dir_ent->name);
177 @@ -3082,7 +3086,7 @@ inline void free_dir_entry(struct dir_ent *dir_ent)
181 -inline void add_excluded(struct dir_info *dir)
182 +static inline void add_excluded(struct dir_info *dir)
184 dir->excluded ++;
186 @@ -4199,6 +4203,7 @@ void initialise_threads(int readq, int fragq, int bwriteq, int fwriteq,
187 sigemptyset(&sigmask);
188 sigaddset(&sigmask, SIGQUIT);
189 sigaddset(&sigmask, SIGHUP);
190 + sigaddset(&sigmask, SIGALRM);
191 if(pthread_sigmask(SIG_BLOCK, &sigmask, NULL) == -1)
192 BAD_ERROR("Failed to set signal mask in intialise_threads\n");
194 @@ -4986,6 +4991,36 @@ int parse_num(char *arg, int *res)
196 int get_physical_memory()
198 + int phys_mem;
199 +#ifndef linux
200 + #ifdef HW_MEMSIZE
201 + #define SYSCTL_PHYSMEM HW_MEMSIZE
202 + #elif defined(HW_PHYSMEM64)
203 + #define SYSCTL_PHYSMEM HW_PHYSMEM64
204 + #else
205 + #define SYSCTL_PHYSMEM HW_PHYSMEM
206 + #endif
208 + int mib[2];
209 + uint64_t sysctl_physmem = 0;
210 + size_t sysctl_len = sizeof(sysctl_physmem);
212 + mib[0] = CTL_HW;
213 + mib[1] = SYSCTL_PHYSMEM;
215 + if(sysctl(mib, 2, &sysctl_physmem, &sysctl_len, NULL, 0) == 0) {
216 + /* some systems use 32-bit values, work with what we're given */
217 + if (sysctl_len == 4)
218 + sysctl_physmem = *(uint32_t*)&sysctl_physmem;
219 + phys_mem = sysctl_physmem >> 20;
220 + } else {
221 + ERROR_START("Failed to get amount of available "
222 + "memory.");
223 + ERROR_EXIT(" Defaulting to least viable amount\n");
224 + phys_mem = SQUASHFS_LOWMEM;
226 + #undef SYSCTL_PHYSMEM
227 +#else
229 * Long longs are used here because with PAE, a 32-bit
230 * machine can have more than 4GB of physical memory
231 @@ -4993,10 +5028,11 @@ int get_physical_memory()
232 * sysconf(_SC_PHYS_PAGES) relies on /proc being mounted.
233 * If it isn't fail.
235 - long long num_pages = sysconf(_SC_PHYS_PAGES);
236 - long long page_size = sysconf(_SC_PAGESIZE);
237 int phys_mem = num_pages * page_size >> 20;
238 +#endif
240 + long long num_pages = sysconf(_SC_PHYS_PAGES);
241 + long long page_size = sysconf(_SC_PAGESIZE);
242 if(num_pages == -1 || page_size == -1)
243 return 0;
245 diff --git a/squashfs-tools/mksquashfs.h b/squashfs-tools/mksquashfs.h
246 index 55708a3..d44d1fd 100644
247 --- a/squashfs-tools/mksquashfs.h
248 +++ b/squashfs-tools/mksquashfs.h
249 @@ -24,6 +24,7 @@
250 * mksquashfs.h
253 +#include <pthread.h>
255 struct dir_info {
256 char *pathname;
257 diff --git a/squashfs-tools/pseudo.c b/squashfs-tools/pseudo.c
258 index cb74cf6..fe2b4bc 100644
259 --- a/squashfs-tools/pseudo.c
260 +++ b/squashfs-tools/pseudo.c
261 @@ -30,6 +30,7 @@
262 #include <errno.h>
263 #include <string.h>
264 #include <stdlib.h>
265 +#include <sys/stat.h>
266 #include <sys/types.h>
267 #include <sys/wait.h>
268 #include <sys/stat.h>
269 diff --git a/squashfs-tools/read_xattrs.c b/squashfs-tools/read_xattrs.c
270 index 42106f5..837d3fb 100644
271 --- a/squashfs-tools/read_xattrs.c
272 +++ b/squashfs-tools/read_xattrs.c
273 @@ -39,13 +39,13 @@
274 #include <endian.h>
275 #endif
277 +#include <stdlib.h>
279 #include "squashfs_fs.h"
280 #include "squashfs_swap.h"
281 #include "xattr.h"
282 #include "error.h"
284 -#include <stdlib.h>
286 extern int read_fs_bytes(int, long long, int, void *);
287 extern int read_block(int, long long, long long *, int, void *);
289 diff --git a/squashfs-tools/unsquashfs.c b/squashfs-tools/unsquashfs.c
290 index c5e0876..e5566ff 100644
291 --- a/squashfs-tools/unsquashfs.c
292 +++ b/squashfs-tools/unsquashfs.c
293 @@ -32,7 +32,12 @@
294 #include "stdarg.h"
295 #include "fnmatch_compat.h"
297 +#ifndef linux
298 +#include <sys/sysctl.h>
299 +#else
300 #include <sys/sysinfo.h>
301 +#endif
303 #include <sys/types.h>
304 #include <sys/time.h>
305 #include <sys/resource.h>
306 @@ -2180,6 +2185,7 @@ void initialise_threads(int fragment_buffer_size, int data_buffer_size)
307 sigemptyset(&sigmask);
308 sigaddset(&sigmask, SIGQUIT);
309 sigaddset(&sigmask, SIGHUP);
310 + sigaddset(&sigmask, SIGALRM);
311 if(pthread_sigmask(SIG_BLOCK, &sigmask, NULL) == -1)
312 EXIT_UNSQUASH("Failed to set signal mask in initialise_threads"
313 "\n");
314 diff --git a/squashfs-tools/unsquashfs.h b/squashfs-tools/unsquashfs.h
315 index 0edbd25..cea9caa 100644
316 --- a/squashfs-tools/unsquashfs.h
317 +++ b/squashfs-tools/unsquashfs.h
318 @@ -46,6 +46,10 @@
319 #include <sys/ioctl.h>
320 #include <sys/time.h>
322 +#ifndef FNM_EXTMATCH /* glibc extension */
323 + #define FNM_EXTMATCH 0
324 +#endif
326 #ifndef linux
327 #define __BYTE_ORDER BYTE_ORDER
328 #define __BIG_ENDIAN BIG_ENDIAN
329 diff --git a/squashfs-tools/unsquashfs_info.c b/squashfs-tools/unsquashfs_info.c
330 index c8e2b9b..e26f0de 100644
331 --- a/squashfs-tools/unsquashfs_info.c
332 +++ b/squashfs-tools/unsquashfs_info.c
333 @@ -97,31 +97,21 @@ void dump_state()
334 void *info_thrd(void *arg)
336 sigset_t sigmask;
337 - struct timespec timespec = { .tv_sec = 1, .tv_nsec = 0 };
338 - int sig, waiting = 0;
339 + int sig, err, waiting = 0;
341 sigemptyset(&sigmask);
342 sigaddset(&sigmask, SIGQUIT);
343 sigaddset(&sigmask, SIGHUP);
344 + sigaddset(&sigmask, SIGALRM);
346 while(1) {
347 - if(waiting)
348 - sig = sigtimedwait(&sigmask, NULL, &timespec);
349 - else
350 - sig = sigwaitinfo(&sigmask, NULL);
352 - if(sig == -1) {
353 - switch(errno) {
354 - case EAGAIN:
355 - /* interval timed out */
356 - waiting = 0;
357 - /* FALLTHROUGH */
358 + err = sigwait(&sigmask, &sig);
360 + if(err == -1) {
361 case EINTR:
362 - /* if waiting, the wait will be longer, but
363 - that's OK */
364 continue;
365 default:
366 - BAD_ERROR("sigtimedwait/sigwaitinfo failed "
367 + BAD_ERROR("sigwait failed "
368 "because %s\n", strerror(errno));
371 @@ -133,8 +123,12 @@ void *info_thrd(void *arg)
372 /* set one second interval period, if ^\ received
373 within then, dump queue and cache status */
374 waiting = 1;
375 - } else
376 - dump_state();
377 + alarm(1);
378 + } else if (sig == SIGQUIT) {
379 + dump_state();
380 + } else if (sig == SIGALRM) {
381 + waiting = 0;
386 diff --git a/squashfs-tools/unsquashfs_xattr.c b/squashfs-tools/unsquashfs_xattr.c
387 index 59f4aae..13f0e35 100644
388 --- a/squashfs-tools/unsquashfs_xattr.c
389 +++ b/squashfs-tools/unsquashfs_xattr.c
390 @@ -27,6 +27,11 @@
392 #include <sys/xattr.h>
394 +#ifdef XATTR_NOFOLLOW /* Apple's xattrs */
395 + #define lsetxattr(path_, name_, val_, sz_, flags_) \
396 + setxattr(path_, name_, val_, sz_, 0, flags_ | XATTR_NOFOLLOW)
397 +#endif
399 #define NOSPACE_MAX 10
401 extern int root_process;
402 diff --git a/squashfs-tools/xattr.c b/squashfs-tools/xattr.c
403 index b46550c..5b32eca 100644
404 --- a/squashfs-tools/xattr.c
405 +++ b/squashfs-tools/xattr.c
406 @@ -22,6 +22,14 @@
407 * xattr.c
410 +#ifndef linux
411 +#define __BYTE_ORDER BYTE_ORDER
412 +#define __BIG_ENDIAN BIG_ENDIAN
413 +#define __LITTLE_ENDIAN LITTLE_ENDIAN
414 +#else
415 +#include <endian.h>
416 +#endif
418 #define TRUE 1
419 #define FALSE 0
421 @@ -36,6 +44,13 @@
422 #include <stdlib.h>
423 #include <sys/xattr.h>
425 +#ifdef XATTR_NOFOLLOW /* Apple's xattrs */
426 + #define llistxattr(path_, buf_, sz_) \
427 + listxattr(path_, buf_, sz_, XATTR_NOFOLLOW)
428 + #define lgetxattr(path_, name_, val_, sz_) \
429 + getxattr(path_, name_, val_, sz_, 0, XATTR_NOFOLLOW)
430 +#endif
432 #include "squashfs_fs.h"
433 #include "squashfs_swap.h"
434 #include "mksquashfs.h"