Thursday, December 25, 2008

SquashFS on Cygwin

It's rather trivial to compile Squashfs-Tools under Cygwin. With this comes a host of benefits for developers, i.e. lay people can make their own modifications, and roll their own images without bothering the developers to run mksquashfs for them under Linux.

I know most people are not going to compile their own (although I don't see the big difficulty), so I have packaged the binaries for Squashfs 3.4, which are available here.

Anyway, this is the patch against squashfs3.4:

Update: I've submitted the patch to the official Sourceforge page:
https://sourceforge.net/tracker/index.php?func=detail&aid=2465952&group_id=63835&atid=505343
Index: squashfs3.4/squashfs-tools/unsquashfs.c
===================================================================
--- squashfs3.4/squashfs-tools/unsquashfs.c (revision 4)
+++ squashfs3.4/squashfs-tools/unsquashfs.c (revision 5)
@@ -49,9 +49,11 @@
#include <sys/time.h>

#ifndef linux
+#ifndef __CYGWIN__
#define __BYTE_ORDER BYTE_ORDER
#define __BIG_ENDIAN BIG_ENDIAN
#define __LITTLE_ENDIAN LITTLE_ENDIAN
+#endif /* __CYGWIN__ */
#else
#include <endian.h>
#endif
@@ -252,6 +254,7 @@

void sigwinch_handler()
{
+#ifndef __CYGWIN__
struct winsize winsize;

if(ioctl(1, TIOCGWINSZ, &winsize) == -1) {
@@ -259,6 +262,9 @@
columns = 80;
} else
columns = winsize.ws_col;
+#else
+ columns = 80;
+#endif
}


@@ -2411,6 +2417,9 @@
if(sigprocmask(SIG_BLOCK, &sigmask, &old_mask) == -1)
EXIT_UNSQUASH("Failed to set signal mask in intialise_threads\n");

+#ifdef __CYGWIN__
+ processors = atoi(getenv("NUMBER_OF_PROCESSORS"));
+#else /* __CYGWIN__ */
if(processors == -1) {
#ifndef linux
int mib[2];
@@ -2431,6 +2440,7 @@
processors = get_nprocs();
#endif
}
+#endif /* __CYGWIN__ */

if((thread = malloc((3 + processors) * sizeof(pthread_t))) == NULL)
EXIT_UNSQUASH("Out of memory allocating thread descriptors\n");
Index: squashfs3.4/squashfs-tools/read_fs.c
===================================================================
--- squashfs3.4/squashfs-tools/read_fs.c (revision 4)
+++ squashfs3.4/squashfs-tools/read_fs.c (revision 5)
@@ -36,9 +36,11 @@
#include <sys/mman.h>

#ifndef linux
+#ifndef __CYGWIN__
#define __BYTE_ORDER BYTE_ORDER
#define __BIG_ENDIAN BIG_ENDIAN
#define __LITTLE_ENDIAN LITTLE_ENDIAN
+#endif /* __CYGWIN__ */
#else
#include <endian.h>
#endif
Index: squashfs3.4/squashfs-tools/global.h
===================================================================
--- squashfs3.4/squashfs-tools/global.h (revision 4)
+++ squashfs3.4/squashfs-tools/global.h (revision 5)
@@ -71,4 +71,9 @@
typedef squashfs_inode_t squashfs_inode;
typedef squashfs_block_t squashfs_block;

+#ifdef __CYGWIN__
+#include <sys/termios.h>
+#define FNM_EXTMATCH (1 << 5)
#endif
+
+#endif
\ No newline at end of file
Index: squashfs3.4/squashfs-tools/mksquashfs.c
===================================================================
--- squashfs3.4/squashfs-tools/mksquashfs.c (revision 4)
+++ squashfs3.4/squashfs-tools/mksquashfs.c (revision 5)
@@ -49,10 +49,12 @@
#include <fnmatch.h>

#ifndef linux
+#ifndef __CYGWIN__
#define __BYTE_ORDER BYTE_ORDER
#define __BIG_ENDIAN BIG_ENDIAN
#define __LITTLE_ENDIAN LITTLE_ENDIAN
#include <sys/sysctl.h>
+#endif /* __CYGWIN__ */
#else
#include <endian.h>
#include <sys/sysinfo.h>
@@ -3161,6 +3163,9 @@

signal(SIGUSR1, sigusr1_handler);

+#ifdef __CYGWIN__
+ processors = atoi(getenv("NUMBER_OF_PROCESSORS"));
+#else
if(processors == -1) {
#ifndef linux
int mib[2];
@@ -3172,7 +3177,6 @@
#else
mib[1] = HW_NCPU;
#endif
-
if(sysctl(mib, 2, &processors, &len, NULL, 0) == -1) {
ERROR("Failed to get number of available processors. Defaulting to 1\n");
processors = 1;
@@ -3181,6 +3185,7 @@
processors = get_nprocs();
#endif
}
+#endif /* __CYGWIN__ */

if((thread = malloc((2 + processors * 2) * sizeof(pthread_t))) == NULL)
BAD_ERROR("Out of memory allocating thread descriptors\n");
@@ -3422,7 +3427,6 @@
return FALSE;
}

-
*new = init_subdir();
if(stickypath)
*new = add_subdir(*new, stickypath);



Here are some links to this topic:



3 comments:

Sherman said...

Here's the patches for 4.0: http://pastebin.com/R9EQcbQY

Unknown said...

Likewise, here is the patch for 4.2: https://gist.github.com/926782.

It is based on chnrxn's 3.4 patch because I didn't see Sherman's 4.0 patch at first.

Unknown said...

There's a better way on Cygwin:

EXTRA_CFLAGS="-Dlinux -DFNM_EXTMATCH=0" make

This simply compiles the same code on Cygwin as on Linux, except that Cygwin doesn't (yet?) implement the GNU extension to fnmatch, FNM_EXTMATCH.