120-cygwin_fixes.patch 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. --- a/Makefile
  2. +++ b/Makefile
  3. @@ -12,6 +12,11 @@ else
  4. LZOLDLIBS = -llzo2
  5. endif
  6. +ifeq ($(shell uname -o),Cygwin)
  7. +CPPFLAGS += -I./include/cygwin
  8. +endif
  9. +
  10. +ifneq ($(shell uname -o),Cygwin)
  11. SUBDIRS = lib ubi-utils mkfs.ubifs
  12. TESTS = tests
  13. @@ -23,6 +28,10 @@ TARGETS = ftl_format flash_erase nanddum
  14. rfddump rfdformat \
  15. serve_image recv_image \
  16. sumtool #jffs2reader
  17. +else
  18. +SUBDIRS =
  19. +TARGETS = mkfs.jffs2
  20. +endif
  21. SCRIPTS = flash_eraseall
  22. SYMLINKS =
  23. --- /dev/null
  24. +++ b/include/cygwin/bits-byteswap.h
  25. @@ -0,0 +1,132 @@
  26. +/* Macros to swap the order of bytes in integer values.
  27. + Copyright (C) 1997, 1998, 2000, 2002 Free Software Foundation, Inc.
  28. + This file is part of the GNU C Library.
  29. +
  30. + The GNU C Library is free software; you can redistribute it and/or
  31. + modify it under the terms of the GNU Lesser General Public
  32. + License as published by the Free Software Foundation; either
  33. + version 2.1 of the License, or (at your option) any later version.
  34. +
  35. + The GNU C Library is distributed in the hope that it will be useful,
  36. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  37. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  38. + Lesser General Public License for more details.
  39. +
  40. + You should have received a copy of the GNU Lesser General Public
  41. + License along with the GNU C Library; if not, write to the Free
  42. + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  43. + 02111-1307 USA. */
  44. +
  45. +#if !defined _BYTESWAP_H && !defined _NETINET_IN_H
  46. +# error "Never use <bits/byteswap.h> directly; include <byteswap.h> instead."
  47. +#endif
  48. +
  49. +#ifndef _BITS_BYTESWAP_H
  50. +#define _BITS_BYTESWAP_H 1
  51. +
  52. +/* Swap bytes in 16 bit value. */
  53. +#define __bswap_constant_16(x) \
  54. + ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8))
  55. +
  56. +#ifdef __GNUC__
  57. +# if __GNUC__ >= 2
  58. +# define __bswap_16(x) \
  59. + (__extension__ \
  60. + ({ register unsigned short int __v, __x = (x); \
  61. + if (__builtin_constant_p (__x)) \
  62. + __v = __bswap_constant_16 (__x); \
  63. + else \
  64. + __asm__ ("rorw $8, %w0" \
  65. + : "=r" (__v) \
  66. + : "0" (__x) \
  67. + : "cc"); \
  68. + __v; }))
  69. +# else
  70. +/* This is better than nothing. */
  71. +# define __bswap_16(x) \
  72. + (__extension__ \
  73. + ({ register unsigned short int __x = (x); __bswap_constant_16 (__x); }))
  74. +# endif
  75. +#else
  76. +static __inline unsigned short int
  77. +__bswap_16 (unsigned short int __bsx)
  78. +{
  79. + return __bswap_constant_16 (__bsx);
  80. +}
  81. +#endif
  82. +
  83. +/* Swap bytes in 32 bit value. */
  84. +#define __bswap_constant_32(x) \
  85. + ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
  86. + (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
  87. +
  88. +#ifdef __GNUC__
  89. +# if __GNUC__ >= 2
  90. +/* To swap the bytes in a word the i486 processors and up provide the
  91. + `bswap' opcode. On i386 we have to use three instructions. */
  92. +# if !defined __i486__ && !defined __pentium__ && !defined __pentiumpro__
  93. +# define __bswap_32(x) \
  94. + (__extension__ \
  95. + ({ register unsigned int __v, __x = (x); \
  96. + if (__builtin_constant_p (__x)) \
  97. + __v = __bswap_constant_32 (__x); \
  98. + else \
  99. + __asm__ ("rorw $8, %w0;" \
  100. + "rorl $16, %0;" \
  101. + "rorw $8, %w0" \
  102. + : "=r" (__v) \
  103. + : "0" (__x) \
  104. + : "cc"); \
  105. + __v; }))
  106. +# else
  107. +# define __bswap_32(x) \
  108. + (__extension__ \
  109. + ({ register unsigned int __v, __x = (x); \
  110. + if (__builtin_constant_p (__x)) \
  111. + __v = __bswap_constant_32 (__x); \
  112. + else \
  113. + __asm__ ("bswap %0" : "=r" (__v) : "0" (__x)); \
  114. + __v; }))
  115. +# endif
  116. +# else
  117. +# define __bswap_32(x) \
  118. + (__extension__ \
  119. + ({ register unsigned int __x = (x); __bswap_constant_32 (__x); }))
  120. +# endif
  121. +#else
  122. +static __inline unsigned int
  123. +__bswap_32 (unsigned int __bsx)
  124. +{
  125. + return __bswap_constant_32 (__bsx);
  126. +}
  127. +#endif
  128. +
  129. +
  130. +#if defined __GNUC__ && __GNUC__ >= 2
  131. +/* Swap bytes in 64 bit value. */
  132. +#define __bswap_constant_64(x) \
  133. + ((((x) & 0xff00000000000000ull) >> 56) \
  134. + | (((x) & 0x00ff000000000000ull) >> 40) \
  135. + | (((x) & 0x0000ff0000000000ull) >> 24) \
  136. + | (((x) & 0x000000ff00000000ull) >> 8) \
  137. + | (((x) & 0x00000000ff000000ull) << 8) \
  138. + | (((x) & 0x0000000000ff0000ull) << 24) \
  139. + | (((x) & 0x000000000000ff00ull) << 40) \
  140. + | (((x) & 0x00000000000000ffull) << 56))
  141. +
  142. +# define __bswap_64(x) \
  143. + (__extension__ \
  144. + ({ union { __extension__ unsigned long long int __ll; \
  145. + unsigned long int __l[2]; } __w, __r; \
  146. + if (__builtin_constant_p (x)) \
  147. + __r.__ll = __bswap_constant_64 (x); \
  148. + else \
  149. + { \
  150. + __w.__ll = (x); \
  151. + __r.__l[0] = __bswap_32 (__w.__l[1]); \
  152. + __r.__l[1] = __bswap_32 (__w.__l[0]); \
  153. + } \
  154. + __r.__ll; }))
  155. +#endif
  156. +
  157. +#endif /* _BITS_BYTESWAP_H */
  158. --- /dev/null
  159. +++ b/include/cygwin/byteswap.h
  160. @@ -0,0 +1,40 @@
  161. +/* Copyright (C) 1997 Free Software Foundation, Inc.
  162. + This file is part of the GNU C Library.
  163. +
  164. + The GNU C Library is free software; you can redistribute it and/or
  165. + modify it under the terms of the GNU Lesser General Public
  166. + License as published by the Free Software Foundation; either
  167. + version 2.1 of the License, or (at your option) any later version.
  168. +
  169. + The GNU C Library is distributed in the hope that it will be useful,
  170. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  171. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  172. + Lesser General Public License for more details.
  173. +
  174. + You should have received a copy of the GNU Lesser General Public
  175. + License along with the GNU C Library; if not, write to the Free
  176. + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  177. + 02111-1307 USA. */
  178. +
  179. +#ifndef _BYTESWAP_H
  180. +#define _BYTESWAP_H 1
  181. +
  182. +/* Get the machine specific, optimized definitions. */
  183. +#include "bits-byteswap.h"
  184. +
  185. +
  186. +/* The following definitions must all be macros since otherwise some
  187. + of the possible optimizations are not possible. */
  188. +
  189. +/* Return a value with all bytes in the 16 bit argument swapped. */
  190. +#define bswap_16(x) __bswap_16 (x)
  191. +
  192. +/* Return a value with all bytes in the 32 bit argument swapped. */
  193. +#define bswap_32(x) __bswap_32 (x)
  194. +
  195. +#if defined __GNUC__ && __GNUC__ >= 2
  196. +/* Return a value with all bytes in the 64 bit argument swapped. */
  197. +# define bswap_64(x) __bswap_64 (x)
  198. +#endif
  199. +
  200. +#endif /* byteswap.h */
  201. --- /dev/null
  202. +++ b/include/cygwin/endian.h
  203. @@ -0,0 +1,26 @@
  204. +#ifndef _CYGENDIAN_H_
  205. +#define _CYGENDIAN_H_
  206. +
  207. +#ifdef __CYGWIN__
  208. +
  209. +#include <sys/param.h>
  210. +
  211. +#ifndef __BIG_ENDIAN
  212. +#define __BIG_ENDIAN 4321
  213. +#endif
  214. +
  215. +#ifndef __LITTLE_ENDIAN
  216. +#define __LITTLE_ENDIAN 1234
  217. +#endif
  218. +
  219. +#ifndef __BYTE_ORDER
  220. +#define __BYTE_ORDER __LITTLE_ENDIAN
  221. +#endif
  222. +
  223. +#ifndef BYTE_ORDER
  224. +#define BYTE_ORDER __LITTLE_ENDIAN
  225. +#endif
  226. +
  227. +#endif /* __CYGWIN__ */
  228. +
  229. +#endif /* _CYGENDIAN_H_ */
  230. --- /dev/null
  231. +++ b/include/cygwin/ioctl.h
  232. @@ -0,0 +1,38 @@
  233. +#ifndef _CYGIOCTL_H_
  234. +#define _CYGIOCTL_H_
  235. +
  236. +#ifdef __CYGWIN__
  237. +
  238. +#define _IOC_NRBITS 8
  239. +#define _IOC_TYPEBITS 8
  240. +#define _IOC_SIZEBITS 14
  241. +#define _IOC_DIRBITS 2
  242. +
  243. +#define _IOC_NRMASK ((1 << _IOC_NRBITS)-1)
  244. +#define _IOC_TYPEMASK ((1 << _IOC_TYPEBITS)-1)
  245. +#define _IOC_SIZEMASK ((1 << _IOC_SIZEBITS)-1)
  246. +#define _IOC_DIRMASK ((1 << _IOC_DIRBITS)-1)
  247. +
  248. +#define _IOC_NRSHIFT 0
  249. +#define _IOC_TYPESHIFT (_IOC_NRSHIFT+_IOC_NRBITS)
  250. +#define _IOC_SIZESHIFT (_IOC_TYPESHIFT+_IOC_TYPEBITS)
  251. +#define _IOC_DIRSHIFT (_IOC_SIZESHIFT+_IOC_SIZEBITS)
  252. +
  253. +#define _IOC_NONE 0U
  254. +#define _IOC_WRITE 1U
  255. +#define _IOC_READ 2U
  256. +
  257. +#define _IOC(dir,type,nr,size) \
  258. + (((dir) << _IOC_DIRSHIFT) | \
  259. + ((type) << _IOC_TYPESHIFT) | \
  260. + ((nr) << _IOC_NRSHIFT) | \
  261. + ((size) << _IOC_SIZESHIFT))
  262. +
  263. +#define _IO(type,nr) _IOC(_IOC_NONE,(type),(nr),0)
  264. +#define _IOR(type,nr,size) _IOC(_IOC_READ,(type),(nr),sizeof(size))
  265. +#define _IOW(type,nr,size) _IOC(_IOC_WRITE,(type),(nr),sizeof(size))
  266. +#define _IOWR(type,nr,size) _IOC(_IOC_READ|_IOC_WRITE,(type),(nr),sizeof(size))
  267. +
  268. +#endif /* __CYGWIN__ */
  269. +
  270. +#endif /* _CYGIOCTL_H_ */
  271. --- /dev/null
  272. +++ b/include/cygwin/pread.c
  273. @@ -0,0 +1,41 @@
  274. +#ifdef __CYGWIN__
  275. +
  276. +#include <errno.h>
  277. +
  278. +ssize_t
  279. +pread(int fd, void *p, size_t n, off_t off)
  280. +{
  281. + off_t ooff;
  282. + int oerrno;
  283. +
  284. + if ((ooff = lseek(fd, off, SEEK_SET)) == -1)
  285. + return -1;
  286. +
  287. + n = read(fd, p, n);
  288. +
  289. + oerrno = errno;
  290. + lseek(fd, ooff, SEEK_SET);
  291. + errno = oerrno;
  292. +
  293. + return n;
  294. +}
  295. +
  296. +ssize_t
  297. +pwrite(int fd, const void *p, size_t n, off_t off)
  298. +{
  299. + off_t ooff;
  300. + int oerrno;
  301. +
  302. + if ((ooff = lseek(fd, off, SEEK_SET)) == -1)
  303. + return -1;
  304. +
  305. + n = write(fd, p, n);
  306. +
  307. + oerrno = errno;
  308. + lseek(fd, ooff, SEEK_SET);
  309. + errno = oerrno;
  310. +
  311. + return n;
  312. +}
  313. +
  314. +#endif /* __CYGWIN__ */
  315. --- /dev/null
  316. +++ b/lnconf.sh
  317. @@ -0,0 +1,53 @@
  318. +#!/bin/sh
  319. +#
  320. +# Generic configure replacement.
  321. +#
  322. +# $Id: lnconf.sh,v 1.1 2004/04/05 21:55:59 igor Exp $
  323. +#
  324. +# Copies all files from the script directory to the current one.
  325. +# Intended to replace 'configure' for packages that don't have one, to
  326. +# allow building outside of the source tree.
  327. +#
  328. +# Note: this does not do any fancy things with detecting shells and
  329. +# supporting other platforms. But it should work on Cygwin.
  330. +
  331. +# find out where the script is located
  332. +tdir=`echo "$0" | sed 's%[\\/][^\\/][^\\/]*$%%'`
  333. +test "x$tdir" = "x$0" && tdir=.
  334. +
  335. +a_srcdir=`cd $tdir; pwd`
  336. +a_destdir=`pwd`
  337. +
  338. +# sanity checks:
  339. +# are we in the script directory?
  340. +test "x$a_srcdir" = "x$a_destdir" && exit 0
  341. +# is there any chance that this is the script directory?
  342. +test "x`cd "$a_srcdir" && /bin/ls -id`" = "x`/bin/ls -id`" && exit 0
  343. +
  344. +# try to find lndir and use it if it's available
  345. +LNDIR="`which lndir 2>/dev/null`"
  346. +if [ "x$LNDIR" = "x" ]; then
  347. + lndir() {
  348. + test "x$1" = "x" && return 1
  349. + # be careful of the current directory
  350. + DINODE=`find . -maxdepth 0 -ls | sed 's/ .*$//'`
  351. + case "`pwd`" in
  352. + "`cd "$1" && pwd`"/*) CUR="-type d -inum $DINODE -prune -o";;
  353. + esac
  354. + # duplicate the directory structure
  355. + (cd "$1" && find . $CUR -type d -mindepth 1 -print) | xargs -tr mkdir -p
  356. + # copy all symbolic links
  357. + (cd "$1" && find . $CUR -type l -mindepth 1 -print) | xargs -ri sh -c "ln -s \"\`readlink "$1/{}"\`\" \"{}\""
  358. + # or simply
  359. + #(cd "$1" && find . $CUR -type l -mindepth 1 -print) | xargs -ri ln -s "$1"/{} {}
  360. + # link all files
  361. + (cd "$1" && find . $CUR -type f -mindepth 1 -print) | xargs -ri ln -s "$1"/{} {}
  362. + }
  363. +else
  364. + lndir() {
  365. + "$LNDIR" "$@"
  366. + }
  367. +fi
  368. +
  369. +lndir "$tdir"
  370. +
  371. --- a/mkfs.jffs2.c
  372. +++ b/mkfs.jffs2.c
  373. @@ -77,6 +77,14 @@
  374. #include "rbtree.h"
  375. #include "common.h"
  376. +#ifdef __CYGWIN__
  377. +#include <cygwin/ioctl.h>
  378. +#include <cygwin/endian.h>
  379. +#include <cygwin/pread.c>
  380. +# define IFTODT(mode) (((mode) & 0170000) >> 12)
  381. +# define DTTOIF(dirtype) ((dirtype) << 12)
  382. +#endif /* __CYGWIN__ */
  383. +
  384. /* Do not use the weird XPG version of basename */
  385. #undef basename
  386. @@ -376,7 +384,7 @@ static struct filesystem_entry *recursiv
  387. the following macros use it if available or use a hacky workaround...
  388. */
  389. -#ifdef __GNUC__
  390. +#if defined __GNUC__ && !defined __CYGWIN__
  391. #define SCANF_PREFIX "a"
  392. #define SCANF_STRING(s) (&s)
  393. #define GETCWD_SIZE 0
  394. @@ -459,6 +467,14 @@ static int interpret_table_entry(struct
  395. }
  396. entry = find_filesystem_entry(root, name, mode);
  397. if (entry && !(count > 0 && (type == 'c' || type == 'b'))) {
  398. + /* Check the type */
  399. + if ((mode & S_IFMT) != (entry->sb.st_mode & S_IFMT)) {
  400. + error_msg ("skipping device_table entry '%s': type mismatch!", name);
  401. + free(name);
  402. + free(hostpath);
  403. + return 1;
  404. + }
  405. +
  406. /* Ok, we just need to fixup the existing entry
  407. * and we will be all done... */
  408. entry->sb.st_uid = uid;
  409. @@ -468,11 +484,21 @@ static int interpret_table_entry(struct
  410. entry->sb.st_rdev = makedev(major, minor);
  411. }
  412. } else {
  413. + if (type == 'f' || type == 'l') {
  414. + error_msg ("skipping device_table entry '%s': file does not exist!", name);
  415. + free(name);
  416. + free(hostpath);
  417. + return 1;
  418. + }
  419. /* If parent is NULL (happens with device table entries),
  420. * try and find our parent now) */
  421. tmp = strdup(name);
  422. dir = dirname(tmp);
  423. - parent = find_filesystem_entry(root, dir, S_IFDIR);
  424. + if (!strcmp(dir, "/")) {
  425. + parent = root;
  426. + } else {
  427. + parent = find_filesystem_entry(root, dir, S_IFDIR);
  428. + }
  429. free(tmp);
  430. if (parent == NULL) {
  431. errmsg ("skipping device_table entry '%s': no parent directory!", name);
  432. @@ -486,6 +512,7 @@ static int interpret_table_entry(struct
  433. add_host_filesystem_entry(name, hostpath, uid, gid, mode, 0, parent);
  434. break;
  435. case 'f':
  436. + case 'l':
  437. add_host_filesystem_entry(name, hostpath, uid, gid, mode, 0, parent);
  438. break;
  439. case 'p':
  440. --- a/ubi-utils/src/libubi.c
  441. +++ b/ubi-utils/src/libubi.c
  442. @@ -32,6 +32,9 @@
  443. #include <sys/ioctl.h>
  444. #include <sys/stat.h>
  445. #include <sys/types.h>
  446. +#ifdef __CYGWIN__
  447. +#include <cygwin/ioctl.h>
  448. +#endif
  449. #include <libubi.h>
  450. #include "libubi_int.h"
  451. #include "common.h"