Skip to content

Instantly share code, notes, and snippets.

@nanpuyue
Created January 12, 2016 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nanpuyue/8a74be61642071f5ff39 to your computer and use it in GitHub Desktop.
Save nanpuyue/8a74be61642071f5ff39 to your computer and use it in GitHub Desktop.
mtd-utils(1.5.2) patch for cygwin
diff -ruN a/include/cygwin/ioctl.h b/include/cygwin/ioctl.h
--- a/include/cygwin/ioctl.h 1970-01-01 08:00:00.000000000 +0800
+++ b/include/cygwin/ioctl.h 2016-01-12 21:54:55.562295400 +0800
@@ -0,0 +1,38 @@
+#ifndef _CYGIOCTL_H_
+#define _CYGIOCTL_H_
+
+#ifdef __CYGWIN__
+
+#define _IOC_NRBITS 8
+#define _IOC_TYPEBITS 8
+#define _IOC_SIZEBITS 14
+#define _IOC_DIRBITS 2
+
+#define _IOC_NRMASK ((1 << _IOC_NRBITS)-1)
+#define _IOC_TYPEMASK ((1 << _IOC_TYPEBITS)-1)
+#define _IOC_SIZEMASK ((1 << _IOC_SIZEBITS)-1)
+#define _IOC_DIRMASK ((1 << _IOC_DIRBITS)-1)
+
+#define _IOC_NRSHIFT 0
+#define _IOC_TYPESHIFT (_IOC_NRSHIFT+_IOC_NRBITS)
+#define _IOC_SIZESHIFT (_IOC_TYPESHIFT+_IOC_TYPEBITS)
+#define _IOC_DIRSHIFT (_IOC_SIZESHIFT+_IOC_SIZEBITS)
+
+#define _IOC_NONE 0U
+#define _IOC_WRITE 1U
+#define _IOC_READ 2U
+#if 0
+#define _IOC(dir,type,nr,size) \
+ (((dir) << _IOC_DIRSHIFT) | \
+ ((type) << _IOC_TYPESHIFT) | \
+ ((nr) << _IOC_NRSHIFT) | \
+ ((size) << _IOC_SIZESHIFT))
+#endif
+#define _IO(type,nr) _IOC(_IOC_NONE,(type),(nr),0)
+#define _IOR(type,nr,size) _IOC(_IOC_READ,(type),(nr),sizeof(size))
+#define _IOW(type,nr,size) _IOC(_IOC_WRITE,(type),(nr),sizeof(size))
+#define _IOWR(type,nr,size) _IOC(_IOC_READ|_IOC_WRITE,(type),(nr),sizeof(size))
+
+#endif /* __CYGWIN__ */
+
+#endif /* _CYGIOCTL_H_ */
diff -ruN a/lib/libmtd.c b/lib/libmtd.c
--- a/lib/libmtd.c 2016-01-10 21:10:14.000000000 +0800
+++ b/lib/libmtd.c 2016-01-12 21:54:55.565297100 +0800
@@ -32,7 +32,9 @@
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <inttypes.h>
-
+#ifdef __CYGWIN__
+#include <cygwin/ioctl.h>
+#endif
#include <mtd/mtd-user.h>
#include <libmtd.h>
diff -ruN a/lib/libmtd_legacy.c b/lib/libmtd_legacy.c
--- a/lib/libmtd_legacy.c 2016-01-10 21:10:12.000000000 +0800
+++ b/lib/libmtd_legacy.c 2016-01-12 21:54:55.568800000 +0800
@@ -31,6 +31,9 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
+#if __CYGWIN__
+#include <cygwin/ioctl.h>
+#endif
#include <mtd/mtd-user.h>
#include <libmtd.h>
diff -ruN a/mkfs.jffs2.c b/mkfs.jffs2.c
--- a/mkfs.jffs2.c 2016-01-10 21:10:14.000000000 +0800
+++ b/mkfs.jffs2.c 2016-01-12 21:54:55.550787600 +0800
@@ -66,7 +66,9 @@
#include <time.h>
#include <getopt.h>
#ifndef WITHOUT_XATTR
+#ifndef __CYGWIN__
#include <sys/xattr.h>
+#endif
#include <sys/acl.h>
#endif
#include <byteswap.h>
@@ -375,7 +377,7 @@
the following macros use it if available or use a hacky workaround...
*/
-#ifdef __GNUC__
+#if defined __GNUC__ && !defined __CYGWIN__
#define SCANF_PREFIX "a"
#define SCANF_STRING(s) (&s)
#define GETCWD_SIZE 0
@@ -1140,6 +1142,8 @@
if (!enable_xattr)
return;
+#ifndef __CYGWIN__
+
list_sz = llistxattr(e->hostname, xlist, XATTR_BUFFER_SIZE);
if (list_sz < 0) {
if (verbose)
@@ -1201,6 +1205,7 @@
full_write(out_fd, &ref, sizeof(ref));
padword();
}
+#endif
}
#else /* WITHOUT_XATTR */
diff -ruN a/rfddump.c b/rfddump.c
--- a/rfddump.c 2016-01-10 21:10:14.000000000 +0800
+++ b/rfddump.c 2016-01-12 21:54:55.552788600 +0800
@@ -25,7 +25,11 @@
#include <getopt.h>
#include <mtd/mtd-user.h>
+#ifdef __CYGWIN__
+#include <asm/types.h>
+#else
#include <linux/types.h>
+#endif
#include <mtd_swab.h>
/* next is an array of mapping for each corresponding sector */
diff -ruN a/rfdformat.c b/rfdformat.c
--- a/rfdformat.c 2016-01-10 21:10:14.000000000 +0800
+++ b/rfdformat.c 2016-01-12 21:54:55.554790000 +0800
@@ -27,7 +27,11 @@
#include <getopt.h>
#include <mtd/mtd-user.h>
+#ifdef __CYGWIN__
+#include <asm/types.h>
+#else
#include <linux/types.h>
+#endif
void display_help(void)
{
diff -ruN a/ubi-utils/libubi.c b/ubi-utils/libubi.c
--- a/ubi-utils/libubi.c 2016-01-10 21:10:13.000000000 +0800
+++ b/ubi-utils/libubi.c 2016-01-12 21:54:55.572802800 +0800
@@ -32,6 +32,9 @@
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
+#ifdef __CYGWIN__
+#include <cygwin/ioctl.h>
+#endif
#include <libubi.h>
#include "libubi_int.h"
#include "common.h"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment