1 # --- T2-COPYRIGHT-NOTE-BEGIN ---
2 # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
4 # T2 SDE: package/.../yaboot/link_with_new_e2fsprogs.patch
5 # Copyright (C) 2015 The T2 SDE Project
7 # More information can be found in the files COPYING and README.
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
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
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>
31 include/nonstd.h | 48 +++++++++++-
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
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 */
51 +typedef unsigned int uid_t;
53 +typedef unsigned int mode_t;
55 +typedef long long off64_t;
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);
76 +void srand(unsigned int seed);
77 +long int random(void);
78 +void srandom(unsigned int seed);
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);
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 *));
102 diff --git a/lib/malloc.c b/lib/malloc.c
103 index 0121112..b21490c 100644
106 @@ -107,6 +107,13 @@ int posix_memalign(void **memptr, size_t alignment, size_t size)
110 +void *calloc(size_t nmemb, size_t size)
112 + unsigned char *p = malloc(nmemb * size);
113 + memset(p, 0x0, nmemb * size);
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
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;
152 + DEBUG_F("Stub function called");
158 + DEBUG_F("Stub function called");
164 + DEBUG_F("Stub function called");
168 +/* selected by roll of a six sided dice ... that's random right? */
171 + DEBUG_F("Stub function called");
175 +void srand(unsigned int seed __unused)
177 + DEBUG_F("Stub function called");
180 +long int random(void)
182 + DEBUG_F("Stub function called");
186 +void srandom(unsigned int seed __unused)
188 + DEBUG_F("Stub function called");
191 +unsigned int sleep(unsigned int seconds)
193 + prom_sleep(seconds);
197 +int stat(const char *path __unused, struct stat *buf __unused)
199 + DEBUG_F("Stub function called");
203 +int stat64(const char *path __unused, struct stat *buf __unused)
205 + DEBUG_F("Stub function called");
209 +int fstat(int fd __unused, struct stat *buf __unused)
211 + DEBUG_F("Stub function called");
215 +int fstat64(int fd __unused, struct stat *buf __unused)
217 + DEBUG_F("Stub function called");
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");
237 +off64_t lseek64(int fd __unused, off64_t offset __unused, int whence __unused)
239 + DEBUG_F("Stub function called");
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);
254 +int gethostname(char *name __unused, size_t len __unused)
256 + DEBUG_F("Stub function called");
260 +int gettimeofday(struct timeval *tv __unused, struct timezone *tz __unused)
262 + DEBUG_F("Stub function called");
266 int printf(const char *format, ...)
268 @@ -39,7 +170,7 @@ int printf(const char *format, ...)
272 -int fprintf(FILE *stream, const char *format, ...)
273 +int fprintf(FILE *stream __unused, const char *format, ...)
276 va_start (ap, format);
277 @@ -49,19 +180,113 @@ int fprintf(FILE *stream, const char *format, ...)
281 -int fputs(const char *s, FILE *stream)
282 +int fputs(const char *s, FILE *stream __unused)
284 prom_printf("%s", s);
289 -int fflush(FILE *stream)
290 +int fflush(FILE *stream __unused)
292 + DEBUG_F("Stub function called");
296 -char *getenv(const char *name)
297 +char *getenv(const char *name __unused)
299 + DEBUG_F("Stub function called");
303 +int __printf_chk(int flag __unused, const char *format, ...)
306 + va_start (ap, format);
307 + prom_vfprintf (prom_stdout, format, ap);
310 + DEBUG_F("Stub function called");
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");
322 +int __fprintf_chk(FILE *stream __unused, int flag __unused,
323 + const char *format, ...)
326 + va_start (ap, format);
327 + prom_vfprintf (prom_stdout, format, ap);
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");
348 +void exit(int status __unused)
354 +int ioctl(int d __unused, int request __unused, ...)
356 + DEBUG_F("Stub function called");
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()
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);
369 + DEBUG_F("Stub function called on unknown stream");
374 +long sysconf(int name __unused)
376 + DEBUG_F("Stub function called");
380 +int getpagesize(void)
382 + DEBUG_F("Stub function called");
383 + /* I think this is safe to assume */
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? */