[tools] mtd-utils: do not rely on host kernel headers, redefine the integer types...
[openwrt/svn-archive/archive.git] / tools / mtd-utils / patches / 110-portability.patch
1 --- a/compr_lzo.c
2 +++ b/compr_lzo.c
3 @@ -24,7 +24,6 @@
4 #include <stdint.h>
5 #include <stdio.h>
6 #include <string.h>
7 -#include <asm/types.h>
8 #include <linux/jffs2.h>
9 #include <lzo/lzo1x.h>
10 #include "compr.h"
11 --- a/compr_zlib.c
12 +++ b/compr_zlib.c
13 @@ -35,7 +35,6 @@
14 #include <stdint.h>
15 #include <zlib.h>
16 #include <stdio.h>
17 -#include <asm/types.h>
18 #include <linux/jffs2.h>
19 #include "compr.h"
20
21 --- a/rbtree.h
22 +++ b/rbtree.h
23 @@ -94,8 +94,7 @@ static inline struct page * rb_insert_pa
24 #ifndef _LINUX_RBTREE_H
25 #define _LINUX_RBTREE_H
26
27 -#include <linux/kernel.h>
28 -#include <linux/stddef.h>
29 +#include <stddef.h>
30
31 struct rb_node
32 {
33 @@ -131,7 +130,9 @@ static inline void rb_set_color(struct r
34
35 #define RB_ROOT (struct rb_root) { NULL, }
36
37 +#ifndef offsetof
38 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
39 +#endif
40
41 #define container_of(ptr, type, member) ({ \
42 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
43 --- a/include/mtd/ubi-media.h
44 +++ b/include/mtd/ubi-media.h
45 @@ -30,7 +30,13 @@
46 #ifndef __UBI_MEDIA_H__
47 #define __UBI_MEDIA_H__
48
49 -#include <asm/byteorder.h>
50 +#if !defined(__u8) || !defined(__be16) || !defined(__be32) || !defined(__be64)
51 +#include <stdint.h>
52 +typedef uint8_t __u8;
53 +typedef uint16_t __be16;
54 +typedef uint32_t __be32;
55 +typedef uint64_t __be64;
56 +#endif
57
58 /* The version of UBI images supported by this implementation */
59 #define UBI_VERSION 1
60 --- a/mkfs.ubifs/mkfs.ubifs.h
61 +++ b/mkfs.ubifs/mkfs.ubifs.h
62 @@ -34,7 +34,14 @@
63 #include <endian.h>
64 #include <byteswap.h>
65 #include <linux/types.h>
66 +#ifdef __linux__
67 #include <linux/fs.h>
68 +#else
69 +# ifndef O_LARGEFILE
70 +# define O_LARGEFILE 0
71 +# endif
72 +# define llseek lseek
73 +#endif
74
75 #include <getopt.h>
76 #include <sys/types.h>
77 --- a/mkfs.ubifs/mkfs.ubifs.c
78 +++ b/mkfs.ubifs/mkfs.ubifs.c
79 @@ -773,8 +773,8 @@ int write_leb(int lnum, int len, void *b
80 if (ubi_leb_change_start(ubi, out_fd, lnum, c->leb_size, dtype))
81 return sys_err_msg("ubi_leb_change_start failed");
82
83 - if (lseek64(out_fd, pos, SEEK_SET) != pos)
84 - return sys_err_msg("lseek64 failed seeking %lld",
85 + if (llseek(out_fd, pos, SEEK_SET) != pos)
86 + return sys_err_msg("llseek failed seeking %lld",
87 (long long)pos);
88
89 if (write(out_fd, buf, c->leb_size) != c->leb_size)
90 @@ -1029,6 +1029,7 @@ static int add_inode_with_data(struct st
91
92 if (c->default_compr != UBIFS_COMPR_NONE)
93 use_flags |= UBIFS_COMPR_FL;
94 +#ifndef NO_NATIVE_SUPPORT
95 if (flags & FS_COMPR_FL)
96 use_flags |= UBIFS_COMPR_FL;
97 if (flags & FS_SYNC_FL)
98 @@ -1039,6 +1040,7 @@ static int add_inode_with_data(struct st
99 use_flags |= UBIFS_APPEND_FL;
100 if (flags & FS_DIRSYNC_FL && S_ISDIR(st->st_mode))
101 use_flags |= UBIFS_DIRSYNC_FL;
102 +#endif
103
104 memset(ino, 0, UBIFS_INO_NODE_SZ);
105
106 @@ -1108,7 +1110,9 @@ static int add_dir_inode(DIR *dir, ino_t
107 fd = dirfd(dir);
108 if (fd == -1)
109 return sys_err_msg("dirfd failed");
110 +#ifndef NO_NATIVE_SUPPORT
111 if (ioctl(fd, FS_IOC_GETFLAGS, &flags) == -1)
112 +#endif
113 flags = 0;
114 }
115
116 @@ -1293,10 +1297,12 @@ static int add_file(const char *path_nam
117 key_write(&key, &dn->key);
118 dn->size = cpu_to_le32(bytes_read);
119 out_len = NODE_BUFFER_SIZE - UBIFS_DATA_NODE_SZ;
120 +#ifndef NO_NATIVE_SUPPORT
121 if (c->default_compr == UBIFS_COMPR_NONE &&
122 (flags & FS_COMPR_FL))
123 use_compr = UBIFS_COMPR_LZO;
124 else
125 +#endif
126 use_compr = c->default_compr;
127 compr_type = compress_data(buf, bytes_read, &dn->data,
128 &out_len, use_compr);
129 @@ -1338,7 +1344,9 @@ static int add_non_dir(const char *path_
130 if (fd == -1)
131 return sys_err_msg("failed to open file '%s'",
132 path_name);
133 +#ifndef NO_NATIVE_SUPPORT
134 if (ioctl(fd, FS_IOC_GETFLAGS, &flags) == -1)
135 +#endif
136 flags = 0;
137 if (close(fd) == -1)
138 return sys_err_msg("failed to close file '%s'",
139 --- a/mkfs.ubifs/devtable.c
140 +++ b/mkfs.ubifs/devtable.c
141 @@ -134,6 +134,7 @@ static int interpret_table_entry(const c
142 unsigned int mode = 0755, uid = 0, gid = 0, major = 0, minor = 0;
143 unsigned int start = 0, increment = 0, count = 0;
144
145 + buf[1023] = 0;
146 if (sscanf(line, "%1023s %c %o %u %u %u %u %u %u %u",
147 buf, &type, &mode, &uid, &gid, &major, &minor,
148 &start, &increment, &count) < 0)
149 @@ -144,8 +145,8 @@ static int interpret_table_entry(const c
150 buf, type, mode, uid, gid, major, minor, start,
151 increment, count);
152
153 - len = strnlen(buf, 1024);
154 - if (len == 1024)
155 + len = strlen(buf);
156 + if (len == 1023)
157 return err_msg("too long path");
158
159 if (!strcmp(buf, "/"))