Root/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,15 @@
46 #ifndef __UBI_MEDIA_H__
47 #define __UBI_MEDIA_H__
48 
49+#ifdef __linux__
50 #include <asm/byteorder.h>
51+#else
52+#include <stdint.h>
53+typedef uint8_t __u8;
54+typedef uint16_t __be16;
55+typedef uint32_t __be32;
56+typedef uint64_t __be64;
57+#endif
58 
59 /* The version of UBI images supported by this implementation */
60 #define UBI_VERSION 1
61--- a/mkfs.ubifs/mkfs.ubifs.h
62+++ b/mkfs.ubifs/mkfs.ubifs.h
63@@ -34,7 +34,14 @@
64 #include <endian.h>
65 #include <byteswap.h>
66 #include <linux/types.h>
67+#ifdef __linux__
68 #include <linux/fs.h>
69+#else
70+# ifndef O_LARGEFILE
71+# define O_LARGEFILE 0
72+# endif
73+# define llseek lseek
74+#endif
75 
76 #include <getopt.h>
77 #include <sys/types.h>
78--- a/mkfs.ubifs/mkfs.ubifs.c
79+++ b/mkfs.ubifs/mkfs.ubifs.c
80@@ -773,8 +773,8 @@ int write_leb(int lnum, int len, void *b
81         if (ubi_leb_change_start(ubi, out_fd, lnum, c->leb_size, dtype))
82             return sys_err_msg("ubi_leb_change_start failed");
83 
84- if (lseek64(out_fd, pos, SEEK_SET) != pos)
85- return sys_err_msg("lseek64 failed seeking %lld",
86+ if (llseek(out_fd, pos, SEEK_SET) != pos)
87+ return sys_err_msg("llseek failed seeking %lld",
88                    (long long)pos);
89 
90     if (write(out_fd, buf, c->leb_size) != c->leb_size)
91@@ -1029,6 +1029,7 @@ static int add_inode_with_data(struct st
92 
93     if (c->default_compr != UBIFS_COMPR_NONE)
94         use_flags |= UBIFS_COMPR_FL;
95+#ifndef NO_NATIVE_SUPPORT
96     if (flags & FS_COMPR_FL)
97         use_flags |= UBIFS_COMPR_FL;
98     if (flags & FS_SYNC_FL)
99@@ -1039,6 +1040,7 @@ static int add_inode_with_data(struct st
100         use_flags |= UBIFS_APPEND_FL;
101     if (flags & FS_DIRSYNC_FL && S_ISDIR(st->st_mode))
102         use_flags |= UBIFS_DIRSYNC_FL;
103+#endif
104 
105     memset(ino, 0, UBIFS_INO_NODE_SZ);
106 
107@@ -1108,7 +1110,9 @@ static int add_dir_inode(DIR *dir, ino_t
108         fd = dirfd(dir);
109         if (fd == -1)
110             return sys_err_msg("dirfd failed");
111+#ifndef NO_NATIVE_SUPPORT
112         if (ioctl(fd, FS_IOC_GETFLAGS, &flags) == -1)
113+#endif
114             flags = 0;
115     }
116 
117@@ -1293,10 +1297,12 @@ static int add_file(const char *path_nam
118         key_write(&key, &dn->key);
119         dn->size = cpu_to_le32(bytes_read);
120         out_len = NODE_BUFFER_SIZE - UBIFS_DATA_NODE_SZ;
121+#ifndef NO_NATIVE_SUPPORT
122         if (c->default_compr == UBIFS_COMPR_NONE &&
123             (flags & FS_COMPR_FL))
124             use_compr = UBIFS_COMPR_LZO;
125         else
126+#endif
127             use_compr = c->default_compr;
128         compr_type = compress_data(buf, bytes_read, &dn->data,
129                        &out_len, use_compr);
130@@ -1338,7 +1344,9 @@ static int add_non_dir(const char *path_
131         if (fd == -1)
132             return sys_err_msg("failed to open file '%s'",
133                        path_name);
134+#ifndef NO_NATIVE_SUPPORT
135         if (ioctl(fd, FS_IOC_GETFLAGS, &flags) == -1)
136+#endif
137             flags = 0;
138         if (close(fd) == -1)
139             return sys_err_msg("failed to close file '%s'",
140--- a/mkfs.ubifs/devtable.c
141+++ b/mkfs.ubifs/devtable.c
142@@ -134,6 +134,7 @@ static int interpret_table_entry(const c
143     unsigned int mode = 0755, uid = 0, gid = 0, major = 0, minor = 0;
144     unsigned int start = 0, increment = 0, count = 0;
145 
146+ buf[1023] = 0;
147     if (sscanf(line, "%1023s %c %o %u %u %u %u %u %u %u",
148            buf, &type, &mode, &uid, &gid, &major, &minor,
149            &start, &increment, &count) < 0)
150@@ -144,8 +145,8 @@ static int interpret_table_entry(const c
151         buf, type, mode, uid, gid, major, minor, start,
152         increment, count);
153 
154- len = strnlen(buf, 1024);
155- if (len == 1024)
156+ len = strlen(buf);
157+ if (len == 1023)
158         return err_msg("too long path");
159 
160     if (!strcmp(buf, "/"))
161

Archive Download this file



interactive