Dash:
[t2.git] / package / boot / yaboot / link_with_new_e2fsprogs.patch
blob4465609d19b11108527c96fffe60926f270175da
1 # --- T2-COPYRIGHT-NOTE-BEGIN ---
2 # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
3 #
4 # T2 SDE: package/.../yaboot/link_with_new_e2fsprogs.patch
5 # Copyright (C) 2015 The T2 SDE Project
6 #
7 # More information can be found in the files COPYING and README.
8 #
9 # This patch file is dual-licensed. It is available under the license the
10 # patched project is licensed under, as long as it is an OpenSource license
11 # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
12 # of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
14 # version.
15 # --- T2-COPYRIGHT-NOTE-END ---
17 From cf53e4804fb8862bf6ac6564ba5fa458bf3c0600 Mon Sep 17 00:00:00 2001
18 From: Tony Breeds <tony@bakeyournoodle.com>
19 Date: Tue, 12 Jun 2012 15:19:02 +1000
20 Subject: [PATCH] Add more libc helper functions for e2fsprogs.
22 I've added debug() statements for all of the stub functions. So if
23 things get "strange" we at least know we've been playing around in this
24 backwater.
26 Portions of this patch are based on the work by Joseph Jezak <josejx@gentoo.org>
27 specifically the *_chk() functions.
29 Signed-off-by: Tony Breeds <tony@bakeyournoodle.com>
30 ---
31 include/nonstd.h | 48 +++++++++++-
32 lib/malloc.c | 7 ++
33 lib/nonstd.c | 235 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
34 3 files changed, 284 insertions(+), 6 deletions(-)
36 diff --git a/include/nonstd.h b/include/nonstd.h
37 index bad5f48..a967380 100644
38 --- a/include/nonstd.h
39 +++ b/include/nonstd.h
40 @@ -22,14 +22,60 @@
41 #ifndef NONSTD_H
42 #define NONSTD_H
44 +/* Copied from asm-generic/errno-base.h */
45 +#define EPERM 1 /* Operation not permitted */
46 +#define EBADF 9 /* Bad file number */
47 +#define EACCES 13 /* Permission denied */
49 typedef int FILE;
51 +typedef unsigned int uid_t;
52 +typedef int pid_t;
53 +typedef unsigned int mode_t;
54 +typedef int ssize_t;
55 +typedef long long off64_t;
56 +typedef long off_t;
58 +struct stat;
59 +struct timezone;
60 +struct timeval;
62 extern FILE *stdout;
63 +extern FILE *stderr;
65 int printf(const char *format, ...);
66 int fprintf(FILE *stream, const char *format, ...);
67 int fputs(const char *s, FILE *stream);
68 int fflush(FILE *stream);
69 char *getenv(const char *name);
71 +int gethostname(char *name, size_t len);
72 +int gettimeofday(struct timeval *tv, struct timezone *tz);
73 +int * __errno_location(void);
74 +unsigned int sleep(unsigned int seconds);
75 +int rand(void);
76 +void srand(unsigned int seed);
77 +long int random(void);
78 +void srandom(unsigned int seed);
79 +uid_t geteuid(void);
80 +uid_t getuid(void);
81 +pid_t getpid(void);
82 +int stat(const char *path, struct stat *buf);
83 +int stat64(const char *path, struct stat *buf);
84 +int fstat(int fd, struct stat *buf);
85 +int fstat64(int fd, struct stat *buf);
86 +int open(const char *pathname, int flags, mode_t mode);
87 +int open64(const char *pathname, int flags, mode_t mode);
88 +off_t lseek(int fd, off_t offset, int whence);
89 +off64_t lseek64(int fd, off64_t offset, int whence);
90 +ssize_t read(int fildes, void *buf, size_t nbyte);
91 +int close(int fd);
92 +void *calloc(size_t nmemb, size_t size);
93 +void perror(const char *s);
94 +void exit(int status);
95 +int ioctl(int d, int request, ...);
96 +size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
97 +long sysconf(int name);
98 +int getpagesize(void);
99 +void qsort(void *base, size_t nmemb, size_t size,
100 + int(*compar)(const void *, const void *));
101 #endif
102 diff --git a/lib/malloc.c b/lib/malloc.c
103 index 0121112..b21490c 100644
104 --- a/lib/malloc.c
105 +++ b/lib/malloc.c
106 @@ -107,6 +107,13 @@ int posix_memalign(void **memptr, size_t alignment, size_t size)
107 return 0;
110 +void *calloc(size_t nmemb, size_t size)
112 + unsigned char *p = malloc(nmemb * size);
113 + memset(p, 0x0, nmemb * size);
114 + return p;
117 void *realloc(void *ptr, unsigned int size)
119 char *caddr, *oaddr = ptr;
120 diff --git a/lib/nonstd.c b/lib/nonstd.c
121 index 5aeb0cb..6549283 100644
122 --- a/lib/nonstd.c
123 +++ b/lib/nonstd.c
124 @@ -23,11 +23,142 @@
125 #include "types.h"
126 #include "stddef.h"
127 #include "stdlib.h"
128 +#include "string.h"
129 #include "ctype.h"
130 #include "prom.h"
131 #include "nonstd.h"
132 +#include "debug.h"
134 -FILE *stdout;
135 +#define __unused __attribute__((unused))
137 +static FILE _stdout;
138 +static FILE _stderr;
139 +FILE *stdout = &_stdout;
140 +FILE *stderr = &_stderr;
142 +static int fake_errno;
144 +int * __errno_location(void)
146 + DEBUG_F("Stub function called");
147 + return &fake_errno;
150 +uid_t geteuid(void)
152 + DEBUG_F("Stub function called");
153 + return 0;
156 +uid_t getuid(void)
158 + DEBUG_F("Stub function called");
159 + return 0;
162 +pid_t getpid(void)
164 + DEBUG_F("Stub function called");
165 + return 1;
168 +/* selected by roll of a six sided dice ... that's random right? */
169 +int rand(void)
171 + DEBUG_F("Stub function called");
172 + return 4;
175 +void srand(unsigned int seed __unused)
177 + DEBUG_F("Stub function called");
180 +long int random(void)
182 + DEBUG_F("Stub function called");
183 + return 4;
186 +void srandom(unsigned int seed __unused)
188 + DEBUG_F("Stub function called");
191 +unsigned int sleep(unsigned int seconds)
193 + prom_sleep(seconds);
194 + return 0;
197 +int stat(const char *path __unused, struct stat *buf __unused)
199 + DEBUG_F("Stub function called");
200 + return EACCES;
203 +int stat64(const char *path __unused, struct stat *buf __unused)
205 + DEBUG_F("Stub function called");
206 + return EACCES;
209 +int fstat(int fd __unused, struct stat *buf __unused)
211 + DEBUG_F("Stub function called");
212 + return EBADF;
215 +int fstat64(int fd __unused, struct stat *buf __unused)
217 + DEBUG_F("Stub function called");
218 + return EBADF;
221 +int open(const char *pathname, int flags __unused, mode_t mode __unused)
223 + return (int) prom_open((char *)pathname);
226 +int open64(const char *pathname, int flags __unused, mode_t mode __unused)
228 + return (int) prom_open((char *)pathname);
231 +off_t lseek(int fd __unused, off_t offset __unused, int whence __unused)
233 + DEBUG_F("Stub function called");
234 + return EBADF;
237 +off64_t lseek64(int fd __unused, off64_t offset __unused, int whence __unused)
239 + DEBUG_F("Stub function called");
240 + return EBADF;
243 +ssize_t read(int filedes, void *buf, size_t nbyte)
245 + return prom_read((void *)filedes, buf, nbyte);
248 +int close(int fd __unused)
250 + prom_close((void *)fd);
251 + return 0;
254 +int gethostname(char *name __unused, size_t len __unused)
256 + DEBUG_F("Stub function called");
257 + return EPERM;
260 +int gettimeofday(struct timeval *tv __unused, struct timezone *tz __unused)
262 + DEBUG_F("Stub function called");
263 + return EPERM;
266 int printf(const char *format, ...)
268 @@ -39,7 +170,7 @@ int printf(const char *format, ...)
269 return 0;
272 -int fprintf(FILE *stream, const char *format, ...)
273 +int fprintf(FILE *stream __unused, const char *format, ...)
275 va_list ap;
276 va_start (ap, format);
277 @@ -49,19 +180,113 @@ int fprintf(FILE *stream, const char *format, ...)
278 return 0;
281 -int fputs(const char *s, FILE *stream)
282 +int fputs(const char *s, FILE *stream __unused)
284 prom_printf("%s", s);
286 return 0;
289 -int fflush(FILE *stream)
290 +int fflush(FILE *stream __unused)
292 + DEBUG_F("Stub function called");
293 return 0;
296 -char *getenv(const char *name)
297 +char *getenv(const char *name __unused)
299 + DEBUG_F("Stub function called");
300 return NULL;
303 +int __printf_chk(int flag __unused, const char *format, ...)
305 + va_list ap;
306 + va_start (ap, format);
307 + prom_vfprintf (prom_stdout, format, ap);
308 + va_end (ap);
310 + DEBUG_F("Stub function called");
311 + return 0;
314 +int __sprintf_chk(char *str __unused, int flag __unused,
315 + size_t strlen __unused, const char * format __unused, ...)
317 + DEBUG_F("Stub function called");
318 + return 0;
322 +int __fprintf_chk(FILE *stream __unused, int flag __unused,
323 + const char *format, ...)
325 + va_list ap;
326 + va_start (ap, format);
327 + prom_vfprintf (prom_stdout, format, ap);
328 + va_end (ap);
330 + return 0;
333 +void *__memcpy_chk(void *dest, const void *src, size_t n,
334 + size_t destlen __unused)
336 + DEBUG_F("Stub function called");
337 + /* FIXME: We really could check that dest+destlen < src, to ensure
338 + * we're not overwriting the src */
339 + return memcpy(dest, src, n);
342 +void perror(const char *s)
344 + DEBUG_F("Stub function called");
345 + prom_printf(s);
348 +void exit(int status __unused)
350 + prom_exit();
351 + for(;;);
354 +int ioctl(int d __unused, int request __unused, ...)
356 + DEBUG_F("Stub function called");
357 + return 0;
360 +/* As we do not implement fopen() I think we're only going to get called
361 + * with stdout and stderr. If that's the case we degenerate to prom_write()
362 + * on stdout */
363 +size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
365 + if ((stream == stdout) || (stream == stderr)) {
366 + DEBUG_F("Stub function called on known stream");
367 + prom_write(prom_stdout, (void *)ptr, size * nmemb);
368 + } else {
369 + DEBUG_F("Stub function called on unknown stream");
371 + return nmemb;
374 +long sysconf(int name __unused)
376 + DEBUG_F("Stub function called");
377 + return -1;
380 +int getpagesize(void)
382 + DEBUG_F("Stub function called");
383 + /* I think this is safe to assume */
384 + return 4096;
387 +void qsort(void *base __unused, size_t nmemb __unused, size_t size __unused,
388 + int(*compar)(const void *, const void *))
390 + DEBUG_F("Stub function called");
391 + /* I'm quite nervous about not implementing this. Could we end up with
392 + * disk corruption. Couldn't we? */
395 1.7.7.6