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
9 +#ifndef FNM_EXTMATCH /* glibc extension */
10 + #define FNM_EXTMATCH 0
13 #include "squashfs_fs.h"
14 #include "mksquashfs.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;
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)
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);
49 - sig = sigtimedwait(&sigmask, NULL, ×pec);
51 - sig = sigwaitinfo(&sigmask, NULL);
52 + err = sigwait(&sigmask, &sig);
58 - /* interval timed out */
62 - /* if waiting, the wait will be longer, but
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 */
77 + } else if (sig == SIGQUIT) {
79 + } else if (sig == SIGALRM) {
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
93 +#ifndef FNM_EXTMATCH /* glibc extension */
94 + #define FNM_EXTMATCH 0
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)
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)
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()
201 + #define SYSCTL_PHYSMEM HW_MEMSIZE
202 + #elif defined(HW_PHYSMEM64)
203 + #define SYSCTL_PHYSMEM HW_PHYSMEM64
205 + #define SYSCTL_PHYSMEM HW_PHYSMEM
209 + uint64_t sysctl_physmem = 0;
210 + size_t sysctl_len = sizeof(sysctl_physmem);
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;
221 + ERROR_START("Failed to get amount of available "
223 + ERROR_EXIT(" Defaulting to least viable amount\n");
224 + phys_mem = SQUASHFS_LOWMEM;
226 + #undef SYSCTL_PHYSMEM
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.
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;
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)
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
253 +#include <pthread.h>
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
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
279 #include "squashfs_fs.h"
280 #include "squashfs_swap.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
295 #include "fnmatch_compat.h"
298 +#include <sys/sysctl.h>
300 #include <sys/sysinfo.h>
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"
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
319 #include <sys/ioctl.h>
320 #include <sys/time.h>
322 +#ifndef FNM_EXTMATCH /* glibc extension */
323 + #define FNM_EXTMATCH 0
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)
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);
348 - sig = sigtimedwait(&sigmask, NULL, ×pec);
350 - sig = sigwaitinfo(&sigmask, NULL);
355 - /* interval timed out */
358 + err = sigwait(&sigmask, &sig);
362 - /* if waiting, the wait will be longer, but
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 */
378 + } else if (sig == SIGQUIT) {
380 + } else if (sig == SIGALRM) {
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
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)
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
411 +#define __BYTE_ORDER BYTE_ORDER
412 +#define __BIG_ENDIAN BIG_ENDIAN
413 +#define __LITTLE_ENDIAN LITTLE_ENDIAN
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)
432 #include "squashfs_fs.h"
433 #include "squashfs_swap.h"
434 #include "mksquashfs.h"