@@ -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,21 +34,21 @@ index 4b06ccb..26365e7 100644
2834
2935 /*
3036diff --git a/squashfs-tools/info.c b/squashfs-tools/info.c
31−index 7968c77..c8e4c52 100644
37+index fe23d78..5c2f835 100644
3238--- a/squashfs-tools/info.c
3339+++ b/squashfs-tools/info.c
34−@@ -134,31 +134,22 @@ void dump_state()
40+@@ -144,31 +144,22 @@ void dump_state()
3541 void *info_thrd(void *arg)
3642 {
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,11 +70,11 @@ index 7968c77..c8e4c52 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 }
71−@@ -169,8 +160,12 @@ void *info_thrd(void *arg)
77+@@ -179,8 +170,12 @@ void *info_thrd(void *arg)
7278 /* set one second interval period, if ^\ received
7379 within then, dump queue and cache status */
7480 waiting = 1;
@@ -83,119 +89,46 @@ index 7968c77..c8e4c52 100644
8389 }
8490
8591diff --git a/squashfs-tools/mksquashfs.c b/squashfs-tools/mksquashfs.c
86−index d696a51..c86d1b3 100644
92+index a45b77f..3607448 100644
8793--- a/squashfs-tools/mksquashfs.c
8894+++ b/squashfs-tools/mksquashfs.c
89−@@ -50,6 +50,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>
90110 #include <limits.h>
91111 #include <ctype.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−@@ -831,13 +835,13 @@ char *subpathname(struct dir_ent *dir_ent)
101− }
102−
103−
104−-inline unsigned int get_inode_no(struct inode_info *inode)
105−+static inline unsigned int get_inode_no(struct inode_info *inode)
106− {
107− return inode->inode_number;
108− }
109−
110−
111−-inline unsigned int get_parent_no(struct dir_info *dir)
112−+static inline unsigned int get_parent_no(struct dir_info *dir)
113− {
114− return dir->depth ? get_inode_no(dir->dir_ent->inode) : inode_no;
115− }
116−@@ -2030,7 +2034,7 @@ struct file_info *duplicate(long long file_size, long long bytes,
117− }
118−
119−
120−-inline int is_fragment(struct inode_info *inode)
121−+static inline int is_fragment(struct inode_info *inode)
122− {
123− off_t file_size = inode->buf.st_size;
124−
125−@@ -2999,13 +3003,13 @@ struct inode_info *lookup_inode2(struct stat *buf, int pseudo, int id)
126− }
127−
128−
129−-inline struct inode_info *lookup_inode(struct stat *buf)
130−+static inline struct inode_info *lookup_inode(struct stat *buf)
131− {
132− return lookup_inode2(buf, 0, 0);
133− }
134−
135−
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)
138− {
139− if (inode->inode_number == 0) {
140− inode->inode_number = use_this ? : inode_no ++;
141−@@ -3016,7 +3020,7 @@ inline void alloc_inode_no(struct inode_info *inode, unsigned int use_this)
142− }
143−
144−
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)
148− {
149− struct dir_ent *dir_ent = malloc(sizeof(struct dir_ent));
150−@@ -3034,7 +3038,7 @@ inline struct dir_ent *create_dir_entry(char *name, char *source_name,
151− }
152−
153−
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)
157− {
158− struct dir_info *dir = dir_ent->our_dir;
159−@@ -3050,7 +3054,7 @@ inline void add_dir_entry(struct dir_ent *dir_ent, struct dir_info *sub_dir,
160− }
161−
162−
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)
167− {
168−@@ -3062,7 +3066,7 @@ inline void add_dir_entry2(char *name, char *source_name,
169− }
170−
171−
172−-inline void free_dir_entry(struct dir_ent *dir_ent)
173−+static inline void free_dir_entry(struct dir_ent *dir_ent)
174− {
175− if(dir_ent->name)
176− free(dir_ent->name);
177−@@ -3083,7 +3087,7 @@ inline void free_dir_entry(struct dir_ent *dir_ent)
178− }
179−
180−
181−-inline void add_excluded(struct dir_info *dir)
182−+static inline void add_excluded(struct dir_info *dir)
183− {
184− dir->excluded ++;
185− }
186−@@ -4200,6 +4204,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,
187121 sigemptyset(&sigmask);
188122 sigaddset(&sigmask, SIGQUIT);
189123 sigaddset(&sigmask, SIGHUP);
190124+ sigaddset(&sigmask, SIGALRM);
191− if(pthread_sigmask(SIG_BLOCK, &sigmask, NULL) == -1)
125+ if(pthread_sigmask(SIG_BLOCK, &sigmask, NULL) != 0)
192126 BAD_ERROR("Failed to set signal mask in intialise_threads\n");
193127
194−@@ -4987,6 +4992,36 @@ int parse_num(char *arg, int *res)
128+@@ -5195,6 +5204,35 @@ int get_physical_memory()
129+ long long page_size = sysconf(_SC_PAGESIZE);
130+ int phys_mem;
195131
196− int get_physical_memory()
197− {
198−+ int phys_mem;
199132+#ifndef linux
200133+ #ifdef HW_MEMSIZE
201134+ #define SYSCTL_PHYSMEM HW_MEMSIZE
@@ -223,50 +156,21 @@ index d696a51..c86d1b3 100644
223156+ ERROR_EXIT(" Defaulting to least viable amount\n");
224157+ phys_mem = SQUASHFS_LOWMEM;
225158+ }
226−+ #undef SYSCTL_PHYSMEM
159++ #undef SYSCTL_PHYSMEM
227160+#else
228− /*
229− * Long longs are used here because with PAE, a 32-bit
230− * machine can have more than 4GB of physical memory
231−@@ -4996,10 +5031,11 @@ int get_physical_memory()
232− */
233− long long num_pages = sysconf(_SC_PHYS_PAGES);
234− long long page_size = sysconf(_SC_PAGESIZE);
235−- int phys_mem = num_pages * page_size >> 20;
236−+ phys_mem = num_pages * page_size >> 20;
161+ if(num_pages == -1 || page_size == -1) {
162+ struct sysinfo sys;
163+ int res = sysinfo(&sys);
164+@@ -5207,6 +5245,7 @@ int get_physical_memory()
165+ }
237166
238− if(num_pages == -1 || page_size == -1)
239− return 0;
167+ phys_mem = num_pages * page_size >> 20;
240168+#endif
241169
242170 if(phys_mem < SQUASHFS_LOWMEM)
243171 BAD_ERROR("Mksquashfs requires more physical memory than is "
244−diff --git a/squashfs-tools/mksquashfs.h b/squashfs-tools/mksquashfs.h
245−index 55708a3..d44d1fd 100644
246−--- a/squashfs-tools/mksquashfs.h
247−+++ b/squashfs-tools/mksquashfs.h
248−@@ -24,6 +24,7 @@
249− * mksquashfs.h
250− *
251− */
252−+#include <pthread.h>
253−
254− struct dir_info {
255− char *pathname;
256−diff --git a/squashfs-tools/pseudo.c b/squashfs-tools/pseudo.c
257−index cb74cf6..fe2b4bc 100644
258−--- a/squashfs-tools/pseudo.c
259−+++ b/squashfs-tools/pseudo.c
260−@@ -30,6 +30,7 @@
261− #include <errno.h>
262− #include <string.h>
263− #include <stdlib.h>
264−+#include <sys/stat.h>
265− #include <sys/types.h>
266− #include <sys/wait.h>
267− #include <sys/stat.h>
268172diff --git a/squashfs-tools/read_xattrs.c b/squashfs-tools/read_xattrs.c
269−index 42106f5..837d3fb 100644
173+index 4debedf..3257c30 100644
270174--- a/squashfs-tools/read_xattrs.c
271175+++ b/squashfs-tools/read_xattrs.c
272176@@ -39,13 +39,13 @@
@@ -286,10 +190,10 @@ index 42106f5..837d3fb 100644
286190 extern int read_block(int, long long, long long *, int, void *);
287191
288192diff --git a/squashfs-tools/unsquashfs.c b/squashfs-tools/unsquashfs.c
289−index f190e96..927e441 100644
193+index 727f1d5..c1a6183 100644
290194--- a/squashfs-tools/unsquashfs.c
291195+++ b/squashfs-tools/unsquashfs.c
292−@@ -32,7 +32,12 @@
196+@@ -32,8 +32,12 @@
293197 #include "stdarg.h"
294198 #include "fnmatch_compat.h"
295199
@@ -297,21 +201,40 @@ index f190e96..927e441 100644
297201+#include <sys/sysctl.h>
298202+#else
299203 #include <sys/sysinfo.h>
204+ #include <sys/sysmacros.h>
300205+#endif
301−+
302206 #include <sys/types.h>
303207 #include <sys/time.h>
304208 #include <sys/resource.h>
305−@@ -2185,6 +2190,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)
306229 sigemptyset(&sigmask);
307230 sigaddset(&sigmask, SIGQUIT);
308231 sigaddset(&sigmask, SIGHUP);
309232+ sigaddset(&sigmask, SIGALRM);
310− if(pthread_sigmask(SIG_BLOCK, &sigmask, NULL) == -1)
233+ if(pthread_sigmask(SIG_BLOCK, &sigmask, NULL) != 0)
311234 EXIT_UNSQUASH("Failed to set signal mask in initialise_threads"
312235 "\n");
313236diff --git a/squashfs-tools/unsquashfs.h b/squashfs-tools/unsquashfs.h
314−index 0edbd25..cea9caa 100644
237+index 934618b..0e680ab 100644
315238--- a/squashfs-tools/unsquashfs.h
316239+++ b/squashfs-tools/unsquashfs.h
317240@@ -46,6 +46,10 @@
@@ -319,7 +242,7 @@ index 0edbd25..cea9caa 100644
319242 #include <sys/time.h>
320243
321244+#ifndef FNM_EXTMATCH /* glibc extension */
322−+ #define FNM_EXTMATCH 0
245++ #define FNM_EXTMATCH 0
323246+#endif
324247+
325248 #ifndef linux
@@ -381,7 +304,7 @@ index c8e2b9b..7d4f7af 100644
381304 }
382305
383306diff --git a/squashfs-tools/unsquashfs_xattr.c b/squashfs-tools/unsquashfs_xattr.c
384−index 59f4aae..13f0e35 100644
307+index 7742dfe..f8cd3b6 100644
385308--- a/squashfs-tools/unsquashfs_xattr.c
386309+++ b/squashfs-tools/unsquashfs_xattr.c
387310@@ -27,6 +27,11 @@
@@ -389,15 +312,15 @@ index 59f4aae..13f0e35 100644
389312 #include <sys/xattr.h>
390313
391314+#ifdef XATTR_NOFOLLOW /* Apple's xattrs */
392−+ #define lsetxattr(path_, name_, val_, sz_, flags_) \
393−+ 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)
394317+#endif
395318+
396319 #define NOSPACE_MAX 10
397320
398321 extern int root_process;
399322diff --git a/squashfs-tools/xattr.c b/squashfs-tools/xattr.c
400−index b46550c..5b32eca 100644
323+index 64dfd82..d82d186 100644
401324--- a/squashfs-tools/xattr.c
402325+++ b/squashfs-tools/xattr.c
403326@@ -22,6 +22,14 @@
@@ -420,12 +343,15 @@ index b46550c..5b32eca 100644
420343 #include <sys/xattr.h>
421344
422345+#ifdef XATTR_NOFOLLOW /* Apple's xattrs */
423−+ #define llistxattr(path_, buf_, sz_) \
424−+ listxattr(path_, buf_, sz_, XATTR_NOFOLLOW)
425−+ #define lgetxattr(path_, name_, val_, sz_) \
426−+ 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)
427350+#endif
428351+
429352 #include "squashfs_fs.h"
430353 #include "squashfs_swap.h"
431354 #include "mksquashfs.h"
355+--
356+2.23.0
357+