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