@@ -1,5 +1,11 @@
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.
4+
5+See also https://github.com/plougher/squashfs-tools/pull/69.
6+
17diff --git a/squashfs-tools/action.c b/squashfs-tools/action.c
2−index 4b06ccb..26365e7 100644
8+index 4b06ccb..3cad2ab 100644
39--- a/squashfs-tools/action.c
410+++ b/squashfs-tools/action.c
511@@ -38,6 +38,10 @@
@@ -7,7 +13,7 @@ index 4b06ccb..26365e7 100644
713 #include <errno.h>
814
915+#ifndef FNM_EXTMATCH /* glibc extension */
10−+ #define FNM_EXTMATCH 0
16++ #define FNM_EXTMATCH 0
1117+#endif
1218+
1319 #include "squashfs_fs.h"
@@ -28,7 +34,7 @@ index 4b06ccb..26365e7 100644
2834
2935 /*
3036diff --git a/squashfs-tools/info.c b/squashfs-tools/info.c
31−index fe23d78..8efefe6 100644
37+index fe23d78..5c2f835 100644
3238--- a/squashfs-tools/info.c
3339+++ b/squashfs-tools/info.c
3440@@ -144,31 +144,22 @@ void dump_state()
@@ -37,12 +43,12 @@ index fe23d78..8efefe6 100644
3743 sigset_t sigmask;
3844- struct timespec timespec = { .tv_sec = 1, .tv_nsec = 0 };
3945- int sig, waiting = 0;
40−+ int sig, err, waiting = 0;
46++ int sig, err, waiting = 0;
4147
4248 sigemptyset(&sigmask);
4349 sigaddset(&sigmask, SIGQUIT);
4450 sigaddset(&sigmask, SIGHUP);
45−+ sigaddset(&sigmask, SIGALRM);
51++ sigaddset(&sigmask, SIGALRM);
4652
4753 while(1) {
4854- if(waiting)
@@ -64,7 +70,7 @@ index fe23d78..8efefe6 100644
6470 continue;
6571 default:
6672- BAD_ERROR("sigtimedwait/sigwaitinfo failed "
67−+ BAD_ERROR("sigwaitfailed "
73++ BAD_ERROR("sigwait failed "
6874 "because %s\n", strerror(errno));
6975 }
7076 }
@@ -83,21 +89,35 @@ index fe23d78..8efefe6 100644
8389 }
8490
8591diff --git a/squashfs-tools/mksquashfs.c b/squashfs-tools/mksquashfs.c
86−index a45b77f..6d186ea 100644
92+index a45b77f..3607448 100644
8793--- a/squashfs-tools/mksquashfs.c
8894+++ b/squashfs-tools/mksquashfs.c
89−@@ -52,6 +52,10 @@
95+@@ -35,7 +35,12 @@
96+ #include <stddef.h>
97+ #include <sys/types.h>
98+ #include <sys/stat.h>
99++#ifndef linux
100++#include <sys/sysctl.h>
101++#else
102++#include <sys/sysinfo.h>
103+ #include <sys/sysmacros.h>
104++#endif
105+ #include <fcntl.h>
106+ #include <errno.h>
107+ #include <dirent.h>
108+@@ -50,7 +55,10 @@
109+ #include <sys/wait.h>
110+ #include <limits.h>
90111 #include <ctype.h>
91− #include <sys/sysinfo.h>
92−
112+-#include <sys/sysinfo.h>
113++
93114+#ifndef FNM_EXTMATCH /* glibc extension */
94−+ #define FNM_EXTMATCH 0
115++ #define FNM_EXTMATCH 0
95116+#endif
96−+
117+
97118 #ifndef linux
98119 #define __BYTE_ORDER BYTE_ORDER
99− #define __BIG_ENDIAN BIG_ENDIAN
100−@@ -4348,6 +4352,7 @@ void initialise_threads(int readq, int fragq, int bwriteq, int fwriteq,
120+@@ -4348,6 +4356,7 @@ void initialise_threads(int readq, int fragq, int bwriteq, int fwriteq,
101121 sigemptyset(&sigmask);
102122 sigaddset(&sigmask, SIGQUIT);
103123 sigaddset(&sigmask, SIGHUP);
@@ -105,11 +125,10 @@ index a45b77f..6d186ea 100644
105125 if(pthread_sigmask(SIG_BLOCK, &sigmask, NULL) != 0)
106126 BAD_ERROR("Failed to set signal mask in intialise_threads\n");
107127
108−@@ -5184,6 +5189,36 @@ int parse_mode(char *arg, mode_t *res)
128+@@ -5195,6 +5204,35 @@ int get_physical_memory()
129+ long long page_size = sysconf(_SC_PAGESIZE);
130+ int phys_mem;
109131
110− int get_physical_memory()
111− {
112−+ int phys_mem;
113132+#ifndef linux
114133+ #ifdef HW_MEMSIZE
115134+ #define SYSCTL_PHYSMEM HW_MEMSIZE
@@ -137,20 +156,12 @@ index a45b77f..6d186ea 100644
137156+ ERROR_EXIT(" Defaulting to least viable amount\n");
138157+ phys_mem = SQUASHFS_LOWMEM;
139158+ }
140−+ #undef SYSCTL_PHYSMEM
159++ #undef SYSCTL_PHYSMEM
141160+#else
142− /*
143− * Long longs are used here because with PAE, a 32-bit
144− * machine can have more than 4GB of physical memory
145−@@ -5193,7 +5228,6 @@ int get_physical_memory()
146− */
147− long long num_pages = sysconf(_SC_PHYS_PAGES);
148− long long page_size = sysconf(_SC_PAGESIZE);
149−- int phys_mem;
150−
151161 if(num_pages == -1 || page_size == -1) {
152162 struct sysinfo sys;
153−@@ -5207,6 +5241,7 @@ int get_physical_memory()
163+ int res = sysinfo(&sys);
164+@@ -5207,6 +5245,7 @@ int get_physical_memory()
154165 }
155166
156167 phys_mem = num_pages * page_size >> 20;
@@ -158,30 +169,6 @@ index a45b77f..6d186ea 100644
158169
159170 if(phys_mem < SQUASHFS_LOWMEM)
160171 BAD_ERROR("Mksquashfs requires more physical memory than is "
161−diff --git a/squashfs-tools/mksquashfs.h b/squashfs-tools/mksquashfs.h
162−index 1beefef..88d0b5c 100644
163−--- a/squashfs-tools/mksquashfs.h
164−+++ b/squashfs-tools/mksquashfs.h
165−@@ -24,6 +24,7 @@
166− * mksquashfs.h
167− *
168− */
169−+#include <pthread.h>
170−
171− struct dir_info {
172− char *pathname;
173−diff --git a/squashfs-tools/pseudo.c b/squashfs-tools/pseudo.c
174−index 48e6b27..f8fd529 100644
175−--- a/squashfs-tools/pseudo.c
176−+++ b/squashfs-tools/pseudo.c
177−@@ -30,6 +30,7 @@
178− #include <errno.h>
179− #include <string.h>
180− #include <stdlib.h>
181−+#include <sys/stat.h>
182− #include <sys/types.h>
183− #include <sys/wait.h>
184− #include <sys/stat.h>
185172diff --git a/squashfs-tools/read_xattrs.c b/squashfs-tools/read_xattrs.c
186173index 4debedf..3257c30 100644
187174--- a/squashfs-tools/read_xattrs.c
@@ -203,10 +190,10 @@ index 4debedf..3257c30 100644
203190 extern int read_block(int, long long, long long *, int, void *);
204191
205192diff --git a/squashfs-tools/unsquashfs.c b/squashfs-tools/unsquashfs.c
206−index 727f1d5..00615ce 100644
193+index 727f1d5..c1a6183 100644
207194--- a/squashfs-tools/unsquashfs.c
208195+++ b/squashfs-tools/unsquashfs.c
209−@@ -32,8 +32,13 @@
196+@@ -32,8 +32,12 @@
210197 #include "stdarg.h"
211198 #include "fnmatch_compat.h"
212199
@@ -216,11 +203,29 @@ index 727f1d5..00615ce 100644
216203 #include <sys/sysinfo.h>
217204 #include <sys/sysmacros.h>
218205+#endif
219−+
220206 #include <sys/types.h>
221207 #include <sys/time.h>
222208 #include <sys/resource.h>
223−@@ -2235,6 +2240,7 @@ void initialise_threads(int fragment_buffer_size, int data_buffer_size)
209+@@ -1080,7 +1084,7 @@ int create_inode(char *pathname, struct inode *i)
210+ break;
211+ case SQUASHFS_SYMLINK_TYPE:
212+ case SQUASHFS_LSYMLINK_TYPE: {
213+- struct timespec times[2] = {
214++ struct timeval times[2] = {
215+ { i->time, 0 },
216+ { i->time, 0 }
217+ };
218+@@ -1099,8 +1103,7 @@ int create_inode(char *pathname, struct inode *i)
219+ goto failed;
220+ }
221+
222+- res = utimensat(AT_FDCWD, pathname, times,
223+- AT_SYMLINK_NOFOLLOW);
224++ res = lutimes(pathname, times);
225+ if(res == -1) {
226+ EXIT_UNSQUASH_STRICT("create_inode: failed to set time on "
227+ "%s, because %s\n", pathname,
228+@@ -2235,6 +2238,7 @@ void initialise_threads(int fragment_buffer_size, int data_buffer_size)
224229 sigemptyset(&sigmask);
225230 sigaddset(&sigmask, SIGQUIT);
226231 sigaddset(&sigmask, SIGHUP);
@@ -229,7 +234,7 @@ index 727f1d5..00615ce 100644
229234 EXIT_UNSQUASH("Failed to set signal mask in initialise_threads"
230235 "\n");
231236diff --git a/squashfs-tools/unsquashfs.h b/squashfs-tools/unsquashfs.h
232−index 934618b..329eb9e 100644
237+index 934618b..0e680ab 100644
233238--- a/squashfs-tools/unsquashfs.h
234239+++ b/squashfs-tools/unsquashfs.h
235240@@ -46,6 +46,10 @@
@@ -237,7 +242,7 @@ index 934618b..329eb9e 100644
237242 #include <sys/time.h>
238243
239244+#ifndef FNM_EXTMATCH /* glibc extension */
240−+ #define FNM_EXTMATCH 0
245++ #define FNM_EXTMATCH 0
241246+#endif
242247+
243248 #ifndef linux
@@ -299,7 +304,7 @@ index c8e2b9b..7d4f7af 100644
299304 }
300305
301306diff --git a/squashfs-tools/unsquashfs_xattr.c b/squashfs-tools/unsquashfs_xattr.c
302−index 7742dfe..26ccd39 100644
307+index 7742dfe..f8cd3b6 100644
303308--- a/squashfs-tools/unsquashfs_xattr.c
304309+++ b/squashfs-tools/unsquashfs_xattr.c
305310@@ -27,6 +27,11 @@
@@ -307,15 +312,15 @@ index 7742dfe..26ccd39 100644
307312 #include <sys/xattr.h>
308313
309314+#ifdef XATTR_NOFOLLOW /* Apple's xattrs */
310−+ #define lsetxattr(path_, name_, val_, sz_, flags_) \
311−+ setxattr(path_, name_, val_, sz_, 0, flags_ | XATTR_NOFOLLOW)
315++ #define lsetxattr(path_, name_, val_, sz_, flags_) \
316++ setxattr(path_, name_, val_, sz_, 0, flags_ | XATTR_NOFOLLOW)
312317+#endif
313318+
314319 #define NOSPACE_MAX 10
315320
316321 extern int root_process;
317322diff --git a/squashfs-tools/xattr.c b/squashfs-tools/xattr.c
318−index 64dfd82..9c4532d 100644
323+index 64dfd82..d82d186 100644
319324--- a/squashfs-tools/xattr.c
320325+++ b/squashfs-tools/xattr.c
321326@@ -22,6 +22,14 @@
@@ -338,10 +343,10 @@ index 64dfd82..9c4532d 100644
338343 #include <sys/xattr.h>
339344
340345+#ifdef XATTR_NOFOLLOW /* Apple's xattrs */
341−+ #define llistxattr(path_, buf_, sz_) \
342−+ listxattr(path_, buf_, sz_, XATTR_NOFOLLOW)
343−+ #define lgetxattr(path_, name_, val_, sz_) \
344−+ getxattr(path_, name_, val_, sz_, 0, XATTR_NOFOLLOW)
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)
345350+#endif
346351+
347352 #include "squashfs_fs.h"