1 Patch based on commits by Dave Vasilevsky <dave@vasilevsky.ca> and
2 Blake Riley <blake.riley@gmail.com>, squashed into a single patch,
3 with BSD-specific changes omitted.
5 See also https://github.com/plougher/squashfs-tools/pull/69.
7 diff --git a/squashfs-tools/action.c b/squashfs-tools/action.c
8 index ea2f604..9c979f8 100644
9 --- a/squashfs-tools/action.c
10 +++ b/squashfs-tools/action.c
15 +#ifndef FNM_EXTMATCH /* glibc extension */
16 + #define FNM_EXTMATCH 0
19 #include "squashfs_fs.h"
20 #include "mksquashfs.h"
22 @@ -2415,9 +2419,12 @@ static char *get_start(char *s, int n)
24 static int subpathname_fn(struct atom *atom, struct action_data *action_data)
26 - return fnmatch(atom->argv[0], get_start(strdupa(action_data->subpath),
27 + char *path = strdup(action_data->subpath);
28 + int is_match = fnmatch(atom->argv[0], get_start(path,
29 count_components(atom->argv[0])),
30 FNM_PATHNAME|FNM_EXTMATCH) == 0;
36 diff --git a/squashfs-tools/info.c b/squashfs-tools/info.c
37 index 216b979..eea2ec9 100644
38 --- a/squashfs-tools/info.c
39 +++ b/squashfs-tools/info.c
40 @@ -144,31 +144,22 @@ void dump_state()
41 void *info_thrd(void *arg)
44 - struct timespec timespec = { .tv_sec = 1, .tv_nsec = 0 };
45 - int sig, waiting = 0;
46 + int sig, err, waiting = 0;
48 sigemptyset(&sigmask);
49 sigaddset(&sigmask, SIGQUIT);
50 sigaddset(&sigmask, SIGHUP);
51 + sigaddset(&sigmask, SIGALRM);
55 - sig = sigtimedwait(&sigmask, NULL, ×pec);
57 - sig = sigwaitinfo(&sigmask, NULL);
58 + err = sigwait(&sigmask, &sig);
64 - /* interval timed out */
68 - /* if waiting, the wait will be longer, but
72 - BAD_ERROR("sigtimedwait/sigwaitinfo failed "
73 + BAD_ERROR("sigwait failed "
74 "because %s\n", strerror(errno));
77 @@ -179,8 +170,12 @@ void *info_thrd(void *arg)
78 /* set one second interval period, if ^\ received
79 within then, dump queue and cache status */
83 + } else if (sig == SIGQUIT) {
85 + } else if (sig == SIGALRM) {
91 diff --git a/squashfs-tools/mksquashfs.c b/squashfs-tools/mksquashfs.c
92 index 843f9f4..ed2c3a6 100644
93 --- a/squashfs-tools/mksquashfs.c
94 +++ b/squashfs-tools/mksquashfs.c
97 #include <sys/types.h>
100 +#include <sys/sysctl.h>
102 +#include <sys/sysinfo.h>
103 #include <sys/sysmacros.h>
109 #include <sys/wait.h>
112 -#include <sys/sysinfo.h>
114 +#ifndef FNM_EXTMATCH /* glibc extension */
115 + #define FNM_EXTMATCH 0
119 #include <sys/sysctl.h>
120 @@ -5064,6 +5072,7 @@ static void initialise_threads(int readq, int fragq, int bwriteq, int fwriteq,
121 sigemptyset(&sigmask);
122 sigaddset(&sigmask, SIGQUIT);
123 sigaddset(&sigmask, SIGHUP);
124 + sigaddset(&sigmask, SIGALRM);
125 if(pthread_sigmask(SIG_BLOCK, &sigmask, NULL) != 0)
126 BAD_ERROR("Failed to set signal mask in intialise_threads\n");
128 @@ -5802,6 +5811,35 @@ static int get_physical_memory()
129 long long page_size = sysconf(_SC_PAGESIZE);
134 + #define SYSCTL_PHYSMEM HW_MEMSIZE
135 + #elif defined(HW_PHYSMEM64)
136 + #define SYSCTL_PHYSMEM HW_PHYSMEM64
138 + #define SYSCTL_PHYSMEM HW_PHYSMEM
142 + uint64_t sysctl_physmem = 0;
143 + size_t sysctl_len = sizeof(sysctl_physmem);
146 + mib[1] = SYSCTL_PHYSMEM;
148 + if(sysctl(mib, 2, &sysctl_physmem, &sysctl_len, NULL, 0) == 0) {
149 + /* some systems use 32-bit values, work with what we're given */
150 + if (sysctl_len == 4)
151 + sysctl_physmem = *(uint32_t*)&sysctl_physmem;
152 + phys_mem = sysctl_physmem >> 20;
154 + ERROR_START("Failed to get amount of available "
156 + ERROR_EXIT(" Defaulting to least viable amount\n");
157 + phys_mem = SQUASHFS_LOWMEM;
159 + #undef SYSCTL_PHYSMEM
161 if(num_pages == -1 || page_size == -1) {
163 int res = sysinfo(&sys);
164 @@ -5814,6 +5852,7 @@ static int get_physical_memory()
167 phys_mem = num_pages * page_size >> 20;
170 if(phys_mem < SQUASHFS_LOWMEM)
171 BAD_ERROR("Mksquashfs requires more physical memory than is "
172 diff --git a/squashfs-tools/read_xattrs.c b/squashfs-tools/read_xattrs.c
173 index 2067f80..ca8b7f4 100644
174 --- a/squashfs-tools/read_xattrs.c
175 +++ b/squashfs-tools/read_xattrs.c
182 #include "squashfs_fs.h"
183 #include "squashfs_swap.h"
189 extern int read_fs_bytes(int, long long, long long, void *);
190 extern int read_block(int, long long, long long *, int, void *);
192 diff --git a/squashfs-tools/unsquashfs.c b/squashfs-tools/unsquashfs.c
193 index d434b42..1208e45 100644
194 --- a/squashfs-tools/unsquashfs.c
195 +++ b/squashfs-tools/unsquashfs.c
198 #include "fnmatch_compat.h"
201 +#include <sys/sysctl.h>
203 #include <sys/sysinfo.h>
204 #include <sys/sysmacros.h>
206 #include <sys/types.h>
207 #include <sys/time.h>
208 #include <sys/resource.h>
209 @@ -1182,7 +1186,7 @@ int create_inode(char *pathname, struct inode *i)
211 case SQUASHFS_SYMLINK_TYPE:
212 case SQUASHFS_LSYMLINK_TYPE: {
213 - struct timespec times[2] = {
214 + struct timeval times[2] = {
218 @@ -1201,8 +1205,7 @@ int create_inode(char *pathname, struct inode *i)
222 - res = utimensat(AT_FDCWD, pathname, times,
223 - AT_SYMLINK_NOFOLLOW);
224 + res = lutimes(pathname, times);
226 EXIT_UNSQUASH_STRICT("create_inode: failed to"
227 " set time on %s, because %s\n",
228 @@ -2687,6 +2690,7 @@ void initialise_threads(int fragment_buffer_size, int data_buffer_size, int cat_
229 sigemptyset(&sigmask);
230 sigaddset(&sigmask, SIGQUIT);
231 sigaddset(&sigmask, SIGHUP);
232 + sigaddset(&sigmask, SIGALRM);
233 if(pthread_sigmask(SIG_BLOCK, &sigmask, NULL) != 0)
234 EXIT_UNSQUASH("Failed to set signal mask in initialise_threads\n");
236 diff --git a/squashfs-tools/unsquashfs.h b/squashfs-tools/unsquashfs.h
237 index 1099678..5b6a038 100644
238 --- a/squashfs-tools/unsquashfs.h
239 +++ b/squashfs-tools/unsquashfs.h
241 #include <sys/ioctl.h>
242 #include <sys/time.h>
244 +#ifndef FNM_EXTMATCH /* glibc extension */
245 + #define FNM_EXTMATCH 0
248 #include "endian_compat.h"
249 #include "squashfs_fs.h"
250 #include "unsquashfs_error.h"
251 diff --git a/squashfs-tools/unsquashfs_info.c b/squashfs-tools/unsquashfs_info.c
252 index e906eaf..f1e68c2 100644
253 --- a/squashfs-tools/unsquashfs_info.c
254 +++ b/squashfs-tools/unsquashfs_info.c
255 @@ -96,31 +96,22 @@ void dump_state()
256 void *info_thrd(void *arg)
259 - struct timespec timespec = { .tv_sec = 1, .tv_nsec = 0 };
260 - int sig, waiting = 0;
261 + int sig, err, waiting = 0;
263 sigemptyset(&sigmask);
264 sigaddset(&sigmask, SIGQUIT);
265 sigaddset(&sigmask, SIGHUP);
266 + sigaddset(&sigmask, SIGALRM);
270 - sig = sigtimedwait(&sigmask, NULL, ×pec);
272 - sig = sigwaitinfo(&sigmask, NULL);
273 + err = sigwait(&sigmask, &sig);
279 - /* interval timed out */
283 - /* if waiting, the wait will be longer, but
287 - BAD_ERROR("sigtimedwait/sigwaitinfo failed "
288 + BAD_ERROR("sigwait failed "
289 "because %s\n", strerror(errno));
292 @@ -132,8 +123,12 @@ void *info_thrd(void *arg)
293 /* set one second interval period, if ^\ received
294 within then, dump queue and cache status */
298 + } else if (sig == SIGQUIT) {
300 + } else if (sig == SIGALRM) {
306 diff --git a/squashfs-tools/unsquashfs_xattr.c b/squashfs-tools/unsquashfs_xattr.c
307 index 61910e1..73e0090 100644
308 --- a/squashfs-tools/unsquashfs_xattr.c
309 +++ b/squashfs-tools/unsquashfs_xattr.c
312 #include <sys/xattr.h>
314 +#ifdef XATTR_NOFOLLOW /* Apple's xattrs */
315 + #define lsetxattr(path_, name_, val_, sz_, flags_) \
316 + setxattr(path_, name_, val_, sz_, 0, flags_ | XATTR_NOFOLLOW)
319 #define NOSPACE_MAX 10
321 extern int root_process;
322 diff --git a/squashfs-tools/xattr.c b/squashfs-tools/xattr.c
323 index b1c0089..6d7ed98 100644
324 --- a/squashfs-tools/xattr.c
325 +++ b/squashfs-tools/xattr.c
331 +#define __BYTE_ORDER BYTE_ORDER
332 +#define __BIG_ENDIAN BIG_ENDIAN
333 +#define __LITTLE_ENDIAN LITTLE_ENDIAN
343 #include <sys/xattr.h>
345 +#ifdef XATTR_NOFOLLOW /* Apple's xattrs */
346 + #define llistxattr(path_, buf_, sz_) \
347 + listxattr(path_, buf_, sz_, XATTR_NOFOLLOW)
348 + #define lgetxattr(path_, name_, val_, sz_) \
349 + getxattr(path_, name_, val_, sz_, 0, XATTR_NOFOLLOW)
352 #include "squashfs_fs.h"
353 #include "squashfs_swap.h"
354 #include "mksquashfs.h"