diff options
author | Michal Soltys <soltys@ziu.info> | 2011-08-02 00:00:43 +0200 |
---|---|---|
committer | Michal Soltys <soltys@ziu.info> | 2011-08-02 00:00:43 +0200 |
commit | fde23299f87d6d187d3de2318d7fb82dce8090fd (patch) | |
tree | 312fb4237bb9d8f885d44b9b0999a4b0a0ee7e4f | |
parent | d4347ad445ab417946413dd9fcbf6ea2b1e00747 (diff) | |
parent | c210e571f61eeb898fadbb6f47d4a2c82e5bfbfd (diff) | |
download | syslinux-fde23299f87d6d187d3de2318d7fb82dce8090fd.tar.gz |
Merge remote-tracking branch 'origin/master' into chaindev
Conflicts:
com32/modules/chain.c
27 files changed, 575 insertions, 315 deletions
diff --git a/com32/include/bitsize/stddef.h b/com32/include/bitsize/stddef.h index caa5e726..213e8ab7 100644 --- a/com32/include/bitsize/stddef.h +++ b/com32/include/bitsize/stddef.h @@ -6,13 +6,9 @@ #define _BITSIZE_STDDEF_H #define _SIZE_T -#if defined(__s390__) || defined(__hppa__) || defined(__cris__) -typedef unsigned long size_t; -#else typedef unsigned int size_t; -#endif #define _PTRDIFF_T -typedef signed int ptrdiff_t; +typedef signed long ptrdiff_t; #endif /* _BITSIZE_STDDEF_H */ diff --git a/com32/include/bitsize/stdint.h b/com32/include/bitsize/stdint.h index 8cbfc5dd..8e444b6d 100644 --- a/com32/include/bitsize/stdint.h +++ b/com32/include/bitsize/stdint.h @@ -5,24 +5,24 @@ #ifndef _BITSIZE_STDINT_H #define _BITSIZE_STDINT_H -typedef signed char int8_t; -typedef short int int16_t; -typedef int int32_t; -typedef long long int int64_t; +typedef signed char int8_t; +typedef short int int16_t; +typedef int int32_t; +typedef long long int int64_t; -typedef unsigned char uint8_t; -typedef unsigned short int uint16_t; -typedef unsigned int uint32_t; -typedef unsigned long long int uint64_t; +typedef unsigned char uint8_t; +typedef unsigned short int uint16_t; +typedef unsigned int uint32_t; +typedef unsigned long long int uint64_t; -typedef int int_fast16_t; -typedef int int_fast32_t; +typedef int int_fast16_t; +typedef int int_fast32_t; -typedef unsigned int uint_fast16_t; -typedef unsigned int uint_fast32_t; +typedef unsigned int uint_fast16_t; +typedef unsigned int uint_fast32_t; -typedef int intptr_t; -typedef unsigned int uintptr_t; +typedef int intptr_t; +typedef unsigned int uintptr_t; #define __INT64_C(c) c ## LL #define __UINT64_C(c) c ## ULL @@ -31,4 +31,4 @@ typedef unsigned int uintptr_t; #define __PRIFAST_RANK "" #define __PRIPTR_RANK "" -#endif /* _BITSIZE_STDINT_H */ +#endif /* _BITSIZE_STDINT_H */ diff --git a/com32/include/bitsize/stdintconst.h b/com32/include/bitsize/stdintconst.h index 8157dd06..7db63bdf 100644 --- a/com32/include/bitsize/stdintconst.h +++ b/com32/include/bitsize/stdintconst.h @@ -15,4 +15,4 @@ #define UINTPTR_C(c) UINT32_C(c) #define PTRDIFF_C(c) INT32_C(c) -#endif /* _BITSIZE_STDINTCONST_H */ +#endif /* _BITSIZE_STDINTCONST_H */ diff --git a/com32/include/bitsize/stdintlimits.h b/com32/include/bitsize/stdintlimits.h index b44fe011..d85094d9 100644 --- a/com32/include/bitsize/stdintlimits.h +++ b/com32/include/bitsize/stdintlimits.h @@ -19,4 +19,4 @@ #define PTRDIFF_MIN INT32_MIN #define PTRDIFF_MAX INT32_MAX -#endif /* _BITSIZE_STDINTLIMITS_H */ +#endif /* _BITSIZE_STDINTLIMITS_H */ diff --git a/com32/include/dprintf.h b/com32/include/dprintf.h index 30a21ada..b8a3b84c 100644 --- a/com32/include/dprintf.h +++ b/com32/include/dprintf.h @@ -7,16 +7,30 @@ #ifdef DEBUG -#include <stdio.h> +# include <stdio.h> +# ifdef DEBUG_STDIO +# define dprintf printf +# define vdprintf vprintf +# else void dprintf(const char *, ...); void vdprintf(const char *, va_list); +# endif #else -#define dprintf(fmt, ...) ((void)(0)) -#define vdprintf(fmt, ap) ((void)(0)) +# define dprintf(fmt, ...) ((void)(0)) +# define vdprintf(fmt, ap) ((void)(0)) #endif /* DEBUG */ +# if DEBUG >= 2 +/* Really verbose debugging... */ +# define dprintf2 dprintf +# define vdprintf2 vdprintf +# else +# define dprintf2(fmt, ...) ((void)(0)) +# define vdprintf2(fmt, ap) ((void)(0)) +# endif + #endif /* _DPRINTF_H */ diff --git a/com32/include/stdint.h b/com32/include/stdint.h index a8391bf9..f64f0278 100644 --- a/com32/include/stdint.h +++ b/com32/include/stdint.h @@ -5,138 +5,112 @@ #ifndef _STDINT_H #define _STDINT_H -/* Exact types */ +#include <bitsize/stdint.h> -typedef signed char int8_t; -typedef signed short int16_t; -typedef signed int int32_t; -typedef signed long long int64_t; +typedef int8_t int_least8_t; +typedef int16_t int_least16_t; +typedef int32_t int_least32_t; +typedef int64_t int_least64_t; -typedef unsigned char uint8_t; -typedef unsigned short uint16_t; -typedef unsigned int uint32_t; -typedef unsigned long long uint64_t; +typedef uint8_t uint_least8_t; +typedef uint16_t uint_least16_t; +typedef uint32_t uint_least32_t; +typedef uint64_t uint_least64_t; -/* Small types */ +typedef int8_t int_fast8_t; +typedef int64_t int_fast64_t; -typedef signed char int_least8_t; -typedef signed short int_least16_t; -typedef signed int int_least32_t; -typedef signed long long int_least64_t; +typedef uint8_t uint_fast8_t; +typedef uint64_t uint_fast64_t; -typedef unsigned char uint_least8_t; -typedef unsigned short uint_least16_t; -typedef unsigned int uint_least32_t; -typedef unsigned long long uint_least64_t; +typedef int64_t intmax_t; +typedef uint64_t uintmax_t; -/* Fast types */ - -typedef signed char int_fast8_t; -typedef signed short int_fast16_t; -typedef signed int int_fast32_t; -typedef signed long long int_fast64_t; - -typedef unsigned char uint_fast8_t; -typedef unsigned short uint_fast16_t; -typedef unsigned int uint_fast32_t; -typedef unsigned long long uint_fast64_t; - -/* Pointer types */ - -typedef int32_t intptr_t; -typedef uint32_t uintptr_t; +#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) -/* Maximal types */ +#define INT8_MIN (-128) +#define INT16_MIN (-32768) +#define INT32_MIN (-2147483647-1) +#define INT64_MIN (__INT64_C(-9223372036854775807)-1) -typedef int64_t intmax_t; -typedef uint64_t uintmax_t; +#define INT8_MAX (127) +#define INT16_MAX (32767) +#define INT32_MAX (2147483647) +#define INT64_MAX (__INT64_C(9223372036854775807)) -/* - * To be strictly correct... - */ -#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) +#define UINT8_MAX (255U) +#define UINT16_MAX (65535U) +#define UINT32_MAX (4294967295U) +#define UINT64_MAX (__UINT64_C(18446744073709551615)) -# define INT8_MIN (-128) -# define INT16_MIN (-32767-1) -# define INT32_MIN (-2147483647-1) -# define INT64_MIN (-9223372036854775807LL-1) +#define INT_LEAST8_MIN INT8_MIN +#define INT_LEAST16_MIN INT16_MIN +#define INT_LEAST32_MIN INT32_MIN +#define INT_LEAST64_MIN INT64_MIN -# define INT8_MAX (127) -# define INT16_MAX (32767) -# define INT32_MAX (2147483647) -# define INT64_MAX (9223372036854775807LL) +#define INT_LEAST8_MAX INT8_MAX +#define INT_LEAST16_MAX INT16_MAX +#define INT_LEAST32_MAX INT32_MAX +#define INT_LEAST64_MAX INT64_MAX -# define UINT8_MAX (255U) -# define UINT16_MAX (65535U) -# define UINT32_MAX (4294967295U) -# define UINT64_MAX (18446744073709551615ULL) +#define UINT_LEAST8_MAX UINT8_MAX +#define UINT_LEAST16_MAX UINT16_MAX +#define UINT_LEAST32_MAX UINT32_MAX +#define UINT_LEAST64_MAX UINT64_MAX -# define INT_LEAST8_MIN (-128) -# define INT_LEAST16_MIN (-32767-1) -# define INT_LEAST32_MIN (-2147483647-1) -# define INT_LEAST64_MIN (-9223372036854775807LL-1) +#define INT_FAST8_MIN INT8_MIN +#define INT_FAST64_MIN INT64_MIN -# define INT_LEAST8_MAX (127) -# define INT_LEAST16_MAX (32767) -# define INT_LEAST32_MAX (2147483647) -# define INT_LEAST64_MAX (9223372036854775807LL) +#define INT_FAST8_MAX INT8_MAX +#define INT_FAST64_MAX INT64_MAX -# define UINT_LEAST8_MAX (255U) -# define UINT_LEAST16_MAX (65535U) -# define UINT_LEAST32_MAX (4294967295U) -# define UINT_LEAST64_MAX (18446744073709551615ULL) +#define UINT_FAST8_MAX UINT8_MAX +#define UINT_FAST64_MAX UINT64_MAX -# define INT_FAST8_MIN (-128) -# define INT_FAST16_MIN (-32767-1) -# define INT_FAST32_MIN (-2147483647-1) -# define INT_FAST64_MIN (-9223372036854775807LL-1) +#define INTMAX_MIN INT64_MIN +#define INTMAX_MAX INT64_MAX +#define UINTMAX_MAX UINT64_MAX -# define INT_FAST8_MAX (127) -# define INT_FAST16_MAX (32767) -# define INT_FAST32_MAX (2147483647) -# define INT_FAST64_MAX (9223372036854775807LL) +#include <bitsize/stdintlimits.h> -# define UINT_FAST8_MAX (255U) -# define UINT_FAST16_MAX (65535U) -# define UINT_FAST32_MAX (4294967295U) -# define UINT_FAST64_MAX (18446744073709551615ULL) +#endif -# define INTPTR_MIN (-2147483647-1) -# define INTPTR_MAX (2147483647) -# define UINTPTR_MAX (4294967295U) +#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) -# define INTMAX_MIN (-9223372036854775807LL-1) -# define INTMAX_MAX (9223372036854775807LL) -# define UINTMAX_MAX (18446744073709551615ULL) +#define INT8_C(c) c +#define INT16_C(c) c +#define INT32_C(c) c +#define INT64_C(c) __INT64_C(c) -/* ptrdiff_t limit */ -# define PTRDIFF_MIN (-2147483647-1) -# define PTRDIFF_MAX (2147483647) +#define UINT8_C(c) c ## U +#define UINT16_C(c) c ## U +#define UINT32_C(c) c ## U +#define UINT64_C(c) __UINT64_C(c) -/* sig_atomic_t limit */ -# define SIG_ATOMIC_MIN (-2147483647-1) -# define SIG_ATOMIC_MAX (2147483647) +#define INT_LEAST8_C(c) INT8_C(c) +#define INT_LEAST16_C(c) INT16_C(c) +#define INT_LEAST32_C(c) INT32_C(c) +#define INT_LEAST64_C(c) INT64_C(c) -/* size_t limit */ -# define SIZE_MAX (4294967295U) +#define UINT_LEAST8_C(c) UINT8_C(c) +#define UINT_LEAST16_C(c) UINT16_C(c) +#define UINT_LEAST32_C(c) UINT32_C(c) +#define UINT_LEAST64_C(c) UINT64_C(c) -#endif /* STDC_LIMIT_MACROS */ +#define INT_FAST8_C(c) INT8_C(c) +#define INT_FAST64_C(c) INT64_C(c) -#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) +#define UINT_FAST8_C(c) UINT8_C(c) +#define UINT_FAST64_C(c) UINT64_C(c) -# define INT8_C(n) n -# define INT16_C(n) n -# define INT32_C(n) n -# define INT64_C(n) n ## LL +#define INTMAX_C(c) INT64_C(c) +#define UINTMAX_C(c) UINT64_C(c) -# define UINT8_C(n) n ## U -# define UINT16_C(n) n ## U -# define UINT32_C(n) n ## U -# define UINT64_C(n) n ## ULL +#include <bitsize/stdintconst.h> -# define INTMAX_C(n) n ## LL -# define UINTMAX_C(n) n ## ULL +#endif -#endif /* STDC_CONSTANT_MACROS */ +/* Keep the kernel from trying to define these types... */ +#define __BIT_TYPES_DEFINED__ -#endif /* _STDINT_H */ +#endif /* _STDINT_H */ diff --git a/com32/include/syslinux/movebits.h b/com32/include/syslinux/movebits.h index 54ee7ff9..8bcdf3ed 100644 --- a/com32/include/syslinux/movebits.h +++ b/com32/include/syslinux/movebits.h @@ -83,7 +83,12 @@ int syslinux_memmap_find(struct syslinux_memmap *list, addr_t * start, addr_t * len, addr_t align); /* Debugging functions */ -void syslinux_dump_movelist(FILE * file, struct syslinux_movelist *ml); -void syslinux_dump_memmap(FILE * file, struct syslinux_memmap *memmap); +#ifdef DEBUG +void syslinux_dump_movelist(struct syslinux_movelist *ml); +void syslinux_dump_memmap(struct syslinux_memmap *memmap); +#else +#define syslinux_dump_movelist(x) ((void)0) +#define syslinux_dump_memmap(x) ((void)0) +#endif #endif /* _SYSLINUX_MOVEBITS_H */ diff --git a/com32/lib/dprintf.c b/com32/lib/dprintf.c index 900c0a47..aad11746 100644 --- a/com32/lib/dprintf.c +++ b/com32/lib/dprintf.c @@ -9,6 +9,7 @@ #define DEBUG 1 #include <dprintf.h> +#ifndef dprintf void dprintf(const char *format, ...) { va_list ap; @@ -17,3 +18,4 @@ void dprintf(const char *format, ...) vdprintf(format, ap); va_end(ap); } +#endif diff --git a/com32/lib/pci/scan.c b/com32/lib/pci/scan.c index 4e5635f6..e0974f98 100644 --- a/com32/lib/pci/scan.c +++ b/com32/lib/pci/scan.c @@ -41,12 +41,7 @@ #include <stdbool.h> #include <ctype.h> #include <syslinux/zio.h> - -#ifdef DEBUG -# define dprintf printf -#else -# define dprintf(...) ((void)0) -#endif +#include <dprintf.h> #define MAX_LINE 512 diff --git a/com32/lib/syslinux/dump_mmap.c b/com32/lib/syslinux/dump_mmap.c index 3f1e340b..85638cd9 100644 --- a/com32/lib/syslinux/dump_mmap.c +++ b/com32/lib/syslinux/dump_mmap.c @@ -28,20 +28,22 @@ /* * dump_mmap.c * - * Writes a syslinux_memmap out to a specified file. This is - * intended for debugging. + * Writes a syslinux_memmap out to a dprintf. */ #include <stdio.h> +#include <dprintf.h> #include <syslinux/movebits.h> -void syslinux_dump_memmap(FILE * file, struct syslinux_memmap *memmap) +#ifdef DEBUG +void syslinux_dump_memmap(struct syslinux_memmap *memmap) { - fprintf(file, "%10s %10s %10s\n" + dprintf("%10s %10s %10s\n" "--------------------------------\n", "Start", "Length", "Type"); while (memmap->next) { - fprintf(file, "0x%08x 0x%08x %10d\n", memmap->start, + dprintf("0x%08x 0x%08x %10d\n", memmap->start, memmap->next->start - memmap->start, memmap->type); memmap = memmap->next; } } +#endif diff --git a/com32/lib/syslinux/dump_movelist.c b/com32/lib/syslinux/dump_movelist.c index 282d0068..4042ce96 100644 --- a/com32/lib/syslinux/dump_movelist.c +++ b/com32/lib/syslinux/dump_movelist.c @@ -33,14 +33,17 @@ */ #include <stdio.h> +#include <dprintf.h> #include <syslinux/movebits.h> -void syslinux_dump_movelist(FILE * file, struct syslinux_movelist *ml) +#ifdef DEBUG +void syslinux_dump_movelist(struct syslinux_movelist *ml) { - fprintf(file, "%10s %10s %10s\n" + dprintf("%10s %10s %10s\n" "--------------------------------\n", "Dest", "Src", "Length"); while (ml) { - fprintf(file, "0x%08x 0x%08x 0x%08x\n", ml->dst, ml->src, ml->len); + dprintf("0x%08x 0x%08x 0x%08x\n", ml->dst, ml->src, ml->len); ml = ml->next; } } +#endif diff --git a/com32/lib/syslinux/load_linux.c b/com32/lib/syslinux/load_linux.c index c1ce875c..45cd6965 100644 --- a/com32/lib/syslinux/load_linux.c +++ b/com32/lib/syslinux/load_linux.c @@ -43,16 +43,7 @@ #include <syslinux/linux.h> #include <syslinux/bootrm.h> #include <syslinux/movebits.h> - -#ifndef DEBUG -# define DEBUG 0 -#endif -#if DEBUG -# include <stdio.h> -# define dprintf printf -#else -# define dprintf(f, ...) ((void)0) -#endif +#include <dprintf.h> struct linux_header { uint8_t boot_sector_1[0x0020]; @@ -318,10 +309,8 @@ int syslinux_boot_linux(void *kernel_buf, size_t kernel_size, if (!mmap || !amap) goto bail; -#if DEBUG dprintf("Initial memory map:\n"); - syslinux_dump_memmap(stdout, mmap); -#endif + syslinux_dump_memmap(mmap); /* If the user has specified a memory limit, mark that as unavailable. Question: should we mark this off-limit in the mmap as well (meaning @@ -468,16 +457,14 @@ int syslinux_boot_linux(void *kernel_buf, size_t kernel_size, /* Linux is OK with sp = 0 = 64K, but perhaps other things aren't... */ regs.esp.w[0] = min(cmdline_offset, (size_t) 0xfff0); -#if DEBUG dprintf("Final memory map:\n"); - syslinux_dump_memmap(stdout, mmap); + syslinux_dump_memmap(mmap); dprintf("Final available map:\n"); - syslinux_dump_memmap(stdout, amap); + syslinux_dump_memmap(amap); dprintf("Initial movelist:\n"); - syslinux_dump_movelist(stdout, fraglist); -#endif + syslinux_dump_movelist(fraglist); syslinux_shuffle_boot_rm(fraglist, mmap, 0, ®s); diff --git a/com32/lib/syslinux/movebits.c b/com32/lib/syslinux/movebits.c index bd5ce0e8..7a05f3c1 100644 --- a/com32/lib/syslinux/movebits.c +++ b/com32/lib/syslinux/movebits.c @@ -48,21 +48,7 @@ #include <stdbool.h> #include <syslinux/movebits.h> - -#ifndef DEBUG -# ifdef TEST -# define DEBUG 1 -# else -# define DEBUG 0 -# endif -#endif - -#if DEBUG -# include <stdio.h> -# define dprintf printf -#else -# define dprintf(...) ((void)0) -#endif +#include <dprintf.h> static jmp_buf new_movelist_bail; @@ -242,10 +228,8 @@ static void shuffle_dealias(struct syslinux_movelist **fraglist, addr_t ps, pe, xs, xe, delta; bool advance; -#if DEBUG dprintf("Before alias resolution:\n"); - syslinux_dump_movelist(stdout, *fraglist); -#endif + syslinux_dump_movelist(*fraglist); *postcopy = NULL; @@ -316,12 +300,10 @@ restart: ; } -#if DEBUG dprintf("After alias resolution:\n"); - syslinux_dump_movelist(stdout, *fraglist); + syslinux_dump_movelist(*fraglist); dprintf("Post-shuffle copies:\n"); - syslinux_dump_movelist(stdout, *postcopy); -#endif + syslinux_dump_movelist(*postcopy); } /* @@ -449,12 +431,10 @@ nomem: /* As long as there are unprocessed fragments in the chain... */ while ((fp = &frags, f = *fp)) { -#if DEBUG dprintf("Current free list:\n"); - syslinux_dump_memmap(stdout, mmap); + syslinux_dump_memmap(mmap); dprintf("Current frag list:\n"); - syslinux_dump_movelist(stdout, frags); -#endif + syslinux_dump_movelist(frags); /* Scan for fragments which can be discarded without action. */ if (f->src == f->dst) { @@ -692,16 +672,16 @@ int main(int argc, char *argv[]) *fep = NULL; - printf("Input move list:\n"); - syslinux_dump_movelist(stdout, frags); - printf("Input free list:\n"); - syslinux_dump_memmap(stdout, memmap); + dprintf("Input move list:\n"); + syslinux_dump_movelist(frags); + dprintf("Input free list:\n"); + syslinux_dump_memmap(memmap); if (syslinux_compute_movelist(&moves, frags, memmap)) { printf("Failed to compute a move sequence\n"); return 1; } else { - printf("Final move list:\n"); + dprintf("Final move list:\n"); syslinux_dump_movelist(stdout, moves); return 0; } diff --git a/com32/lib/syslinux/shuffle.c b/com32/lib/syslinux/shuffle.c index 54a7e651..e9ee6aad 100644 --- a/com32/lib/syslinux/shuffle.c +++ b/com32/lib/syslinux/shuffle.c @@ -39,26 +39,10 @@ #include <inttypes.h> #include <com32.h> #include <minmax.h> +#include <dprintf.h> #include <syslinux/movebits.h> #include <klibc/compiler.h> -#ifndef DEBUG -# define DEBUG 0 -#endif - -#define dprintf(f, ...) ((void)0) -#define dprintf2(f, ...) ((void)0) - -#if DEBUG -# include <stdio.h> -# undef dprintf -# define dprintf printf -# if DEBUG > 1 -# undef dprintf2 -# define dprintf2 printf -# endif -#endif - struct shuffle_descriptor { uint32_t dst, src, len; }; diff --git a/com32/lib/syslinux/zonelist.c b/com32/lib/syslinux/zonelist.c index b548211f..7034c4be 100644 --- a/com32/lib/syslinux/zonelist.c +++ b/com32/lib/syslinux/zonelist.c @@ -39,21 +39,7 @@ #include <stdlib.h> #include <syslinux/align.h> #include <syslinux/movebits.h> - -#ifndef DEBUG -# ifdef TEST -# define DEBUG 1 -# else -# define DEBUG 0 -# endif -#endif - -#if DEBUG -# include <stdio.h> -# define dprintf printf -#else -# define dprintf(...) ((void)0) -#endif +#include <dprintf.h> /* * Create an empty syslinux_memmap list. @@ -96,10 +82,8 @@ int syslinux_add_memmap(struct syslinux_memmap **list, struct syslinux_memmap *range; enum syslinux_memmap_types oldtype; -#if DEBUG dprintf("Input memmap:\n"); - syslinux_dump_memmap(stdout, *list); -#endif + syslinux_dump_memmap(*list); /* Remove this to make len == 0 mean all of memory */ if (len == 0) @@ -164,10 +148,8 @@ int syslinux_add_memmap(struct syslinux_memmap **list, } } -#if DEBUG dprintf("After adding (%#x,%#x,%d):\n", start, len, type); - syslinux_dump_memmap(stdout, *list); -#endif + syslinux_dump_memmap(*list); return 0; } diff --git a/com32/lib/vdprintf.c b/com32/lib/vdprintf.c index d74f2782..c1f90a63 100644 --- a/com32/lib/vdprintf.c +++ b/com32/lib/vdprintf.c @@ -14,6 +14,8 @@ #define DEBUG 1 #include <dprintf.h> +#ifndef vdprintf + #define BUFFER_SIZE 4096 enum serial_port_regs { @@ -114,3 +116,5 @@ void vdprintf(const char *format, va_list ap) while (rv--) debug_putc(*p++); } + +#endif /* vdprintf */ diff --git a/com32/libupload/cpio.c b/com32/libupload/cpio.c index b3e1eb78..25b464d4 100644 --- a/com32/libupload/cpio.c +++ b/com32/libupload/cpio.c @@ -31,7 +31,7 @@ int cpio_hdr(struct upload_backend *be, uint32_t mode, size_t datalen, cpio_pad(be); - sprintf(hdr, "%06o%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x", + sprintf(hdr, "%06o%08x%08x%08x%08x%08x%08x%08zx%08x%08x%08x%08x%08x%08x", 070701, /* c_magic */ inode++, /* c_ino */ mode, /* c_mode */ diff --git a/com32/mboot/map.c b/com32/mboot/map.c index 0a71d4c9..99add306 100644 --- a/com32/mboot/map.c +++ b/com32/mboot/map.c @@ -91,10 +91,9 @@ int init_map(void) error("Failed to allocate initial memory map!\n"); return -1; } -#if DEBUG + dprintf("Initial memory map:\n"); - syslinux_dump_memmap(stdout, mmap); -#endif + syslinux_dump_memmap(mmap); return 0; } diff --git a/com32/modules/elf.c b/com32/modules/elf.c index 182afa60..0ac45174 100644 --- a/com32/modules/elf.c +++ b/com32/modules/elf.c @@ -120,10 +120,8 @@ int boot_elf(void *ptr, size_t len, char **argv) if (!mmap || !amap) goto bail; -#if DEBUG dprintf("Initial memory map:\n"); - syslinux_dump_memmap(stdout, mmap); -#endif + syslinux_dump_memmap(mmap); ph = (Elf32_Phdr *) (cptr + eh->e_phoff); @@ -185,10 +183,8 @@ int boot_elf(void *ptr, size_t len, char **argv) if (!stack_frame) goto bail; -#if DEBUG dprintf("Right before syslinux_memmap_largest()...\n"); - syslinux_dump_memmap(stdout, amap); -#endif + syslinux_dump_memmap(amap); if (syslinux_memmap_largest(amap, SMT_FREE, &lstart, &llen)) goto bail; /* NO free memory?! */ @@ -239,16 +235,14 @@ int boot_elf(void *ptr, size_t len, char **argv) regs.eip = eh->e_entry; regs.esp = stack_pointer; -#if DEBUG dprintf("Final memory map:\n"); - syslinux_dump_memmap(stdout, mmap); + syslinux_dump_memmap(mmap); dprintf("Final available map:\n"); - syslinux_dump_memmap(stdout, amap); + syslinux_dump_memmap(amap); dprintf("Movelist:\n"); - syslinux_dump_movelist(stdout, ml); -#endif + syslinux_dump_movelist(ml); /* This should not return... */ fputs("Booting...\n", stdout); diff --git a/com32/modules/ethersel.c b/com32/modules/ethersel.c index 5c3cf02a..28dc62ca 100644 --- a/com32/modules/ethersel.c +++ b/com32/modules/ethersel.c @@ -38,12 +38,7 @@ #include <com32.h> #include <syslinux/boot.h> #include <syslinux/config.h> - -#ifdef DEBUG -# define dprintf printf -#else -# define dprintf(...) ((void)0) -#endif +#include <dprintf.h> #define MAX_LINE 512 diff --git a/com32/modules/pcitest.c b/com32/modules/pcitest.c index 672023ad..9921ee6d 100644 --- a/com32/modules/pcitest.c +++ b/com32/modules/pcitest.c @@ -39,12 +39,7 @@ #include <com32.h> #include <sys/pci.h> #include <stdbool.h> - -#ifdef DEBUG -# define dprintf printf -#else -# define dprintf(...) ((void)0) -#endif +#include <dprintf.h> char display_line = 0; #define moreprintf(...) \ diff --git a/com32/modules/pmload.c b/com32/modules/pmload.c index 3064a94f..4c01db08 100644 --- a/com32/modules/pmload.c +++ b/com32/modules/pmload.c @@ -81,10 +81,8 @@ int boot_raw(void *ptr, size_t len, addr_t where, char **argv) if (!mmap || !amap) goto bail; -#if DEBUG dprintf("Initial memory map:\n"); - syslinux_dump_memmap(stdout, mmap); -#endif + syslinux_dump_memmap(mmap); dprintf("Segment at 0x%08x len 0x%08x\n", where, len); @@ -119,10 +117,8 @@ int boot_raw(void *ptr, size_t len, addr_t where, char **argv) if (!stack_frame) goto bail; -#if DEBUG dprintf("Right before syslinux_memmap_largest()...\n"); - syslinux_dump_memmap(stdout, amap); -#endif + syslinux_dump_memmap(amap); if (syslinux_memmap_largest(amap, SMT_FREE, &lstart, &llen)) goto bail; /* NO free memory?! */ @@ -173,16 +169,14 @@ int boot_raw(void *ptr, size_t len, addr_t where, char **argv) regs.eip = where; regs.esp = stack_pointer; -#if DEBUG dprintf("Final memory map:\n"); - syslinux_dump_memmap(stdout, mmap); + syslinux_dump_memmap(mmap); dprintf("Final available map:\n"); - syslinux_dump_memmap(stdout, amap); + syslinux_dump_memmap(amap); dprintf("Movelist:\n"); - syslinux_dump_movelist(stdout, ml); -#endif + syslinux_dump_movelist(ml); /* This should not return... */ fputs("Booting...\n", stdout); diff --git a/extlinux/btrfs.h b/extlinux/btrfs.h index 39a861a5..be0c24ef 100644 --- a/extlinux/btrfs.h +++ b/extlinux/btrfs.h @@ -1,6 +1,9 @@ #ifndef _BTRFS_H_ #define _BTRFS_H_ +#include <asm/types.h> +#include <linux/ioctl.h> + #define BTRFS_SUPER_MAGIC 0x9123683E #define BTRFS_SUPER_INFO_OFFSET (64 * 1024) #define BTRFS_SUPER_INFO_SIZE 4096 @@ -8,6 +11,40 @@ #define BTRFS_CSUM_SIZE 32 #define BTRFS_FSID_SIZE 16 +typedef __u64 u64; +typedef __u32 u32; +typedef __u16 u16; +typedef __u8 u8; +typedef u64 __le64; +typedef u16 __le16; + +#define BTRFS_ROOT_BACKREF_KEY 144 +#define BTRFS_ROOT_TREE_DIR_OBJECTID 6ULL +#define BTRFS_DIR_ITEM_KEY 84 + +/* + * * this is used for both forward and backward root refs + * */ +struct btrfs_root_ref { + __le64 dirid; + __le64 sequence; + __le16 name_len; +} __attribute__ ((__packed__)); + +struct btrfs_disk_key { + __le64 objectid; + u8 type; + __le64 offset; +} __attribute__ ((__packed__)); + +struct btrfs_dir_item { + struct btrfs_disk_key location; + __le64 transid; + __le16 data_len; + __le16 name_len; + u8 type; +} __attribute__ ((__packed__)); + struct btrfs_super_block { unsigned char csum[BTRFS_CSUM_SIZE]; /* the first 3 fields must match struct btrfs_header */ @@ -19,4 +56,72 @@ struct btrfs_super_block { u64 magic; } __attribute__ ((__packed__)); + +#define BTRFS_IOCTL_MAGIC 0x94 +#define BTRFS_VOL_NAME_MAX 255 +#define BTRFS_PATH_NAME_MAX 4087 + +struct btrfs_ioctl_vol_args { + __s64 fd; + char name[BTRFS_PATH_NAME_MAX + 1]; +}; + +struct btrfs_ioctl_search_key { + /* which root are we searching. 0 is the tree of tree roots */ + __u64 tree_id; + + /* keys returned will be >= min and <= max */ + __u64 min_objectid; + __u64 max_objectid; + + /* keys returned will be >= min and <= max */ + __u64 min_offset; + __u64 max_offset; + + /* max and min transids to search for */ + __u64 min_transid; + __u64 max_transid; + + /* keys returned will be >= min and <= max */ + __u32 min_type; + __u32 max_type; + + /* + * how many items did userland ask for, and how many are we + * returning + */ + __u32 nr_items; + + /* align to 64 bits */ + __u32 unused; + + /* some extra for later */ + __u64 unused1; + __u64 unused2; + __u64 unused3; + __u64 unused4; +}; + +struct btrfs_ioctl_search_header { + __u64 transid; + __u64 objectid; + __u64 offset; + __u32 type; + __u32 len; +} __attribute__((may_alias)); + +#define BTRFS_SEARCH_ARGS_BUFSIZE (4096 - sizeof(struct btrfs_ioctl_search_key)) +/* + * the buf is an array of search headers where + * each header is followed by the actual item + * the type field is expanded to 32 bits for alignment + */ +struct btrfs_ioctl_search_args { + struct btrfs_ioctl_search_key key; + char buf[BTRFS_SEARCH_ARGS_BUFSIZE]; +}; + +#define BTRFS_IOC_TREE_SEARCH _IOWR(BTRFS_IOCTL_MAGIC, 17, \ + struct btrfs_ioctl_search_args) + #endif diff --git a/extlinux/main.c b/extlinux/main.c index e5212a95..e574051b 100755 --- a/extlinux/main.c +++ b/extlinux/main.c @@ -20,12 +20,12 @@ #define _GNU_SOURCE /* Enable everything */ #include <inttypes.h> /* This is needed to deal with the kernel headers imported into glibc 3.3.3. */ -typedef uint64_t u64; #include <alloca.h> #include <errno.h> #include <fcntl.h> #include <stdio.h> #include <unistd.h> +#include <dirent.h> #ifndef __KLIBC__ #include <mntent.h> #endif @@ -65,7 +65,6 @@ typedef uint64_t u64; boot image, the boot sector is from 0~512, the boot image starts after */ #define BTRFS_BOOTSECT_AREA 65536 #define BTRFS_EXTLINUX_OFFSET SECTOR_SIZE -#define BTRFS_SUBVOL_OPT "subvol=" #define BTRFS_SUBVOL_MAX 256 /* By btrfs specification */ static char subvol[BTRFS_SUBVOL_MAX]; @@ -112,7 +111,7 @@ static int sysfs_get_offset(int devfd, unsigned long *start) if ((size_t)snprintf(sysfs_name, sizeof sysfs_name, "/sys/dev/block/%u:%u/start", - major(st.st_dev), minor(st.st_dev)) + major(st.st_rdev), minor(st.st_rdev)) >= sizeof sysfs_name) return -1; @@ -153,7 +152,7 @@ int get_geometry(int devfd, uint64_t totalbytes, struct hd_geometry *geo) memset(geo, 0, sizeof *geo); - if (!ioctl(devfd, HDIO_GETGEO, &geo)) { + if (!ioctl(devfd, HDIO_GETGEO, geo)) { goto ok; } else if (!ioctl(devfd, FDGETPRM, &fd_str)) { geo->heads = fd_str.head; @@ -347,9 +346,7 @@ int install_bootblock(int fd, const char *device) perror("reading fat superblock"); return 1; } - if (sb3.bsResSectors && sb3.bsFATs && - (strstr(sb3.bs16.FileSysType, "FAT") || - strstr(sb3.bs32.FileSysType, "FAT"))) + if (fat_check_sb_fields(&sb3)) ok = true; } if (!ok) { @@ -494,6 +491,267 @@ int btrfs_install_file(const char *path, int devfd, struct stat *rst) return 0; } +/* + * * test if path is a subvolume: + * * this function return + * * 0-> path exists but it is not a subvolume + * * 1-> path exists and it is a subvolume + * * -1 -> path is unaccessible + * */ +static int test_issubvolume(char *path) +{ + + struct stat st; + int res; + + res = stat(path, &st); + if(res < 0 ) + return -1; + + return (st.st_ino == 256) && S_ISDIR(st.st_mode); + +} + +/* + * Get file handle for a file or dir + */ +static int open_file_or_dir(const char *fname) +{ + int ret; + struct stat st; + DIR *dirstream; + int fd; + + ret = stat(fname, &st); + if (ret < 0) { + return -1; + } + if (S_ISDIR(st.st_mode)) { + dirstream = opendir(fname); + if (!dirstream) { + return -2; + } + fd = dirfd(dirstream); + } else { + fd = open(fname, O_RDWR); + } + if (fd < 0) { + return -3; + } + return fd; +} + +/* + * Get the default subvolume of a btrfs filesystem + * rootdir: btrfs root dir + * subvol: this function will save the default subvolume name here + */ +static char * get_default_subvol(char * rootdir, char * subvol) +{ + struct btrfs_ioctl_search_args args; + struct btrfs_ioctl_search_key *sk = &args.key; + struct btrfs_ioctl_search_header *sh; + int ret, i; + int fd; + struct btrfs_root_ref *ref; + struct btrfs_dir_item *dir_item; + unsigned long off = 0; + int name_len; + char *name; + char dirname[4096]; + u64 defaultsubvolid = 0; + + ret = test_issubvolume(rootdir); + if (ret == 1) { + fd = open_file_or_dir(rootdir); + if (fd < 0) { + fprintf(stderr, "ERROR: failed to open %s\n", rootdir); + } + ret = fd; + } + if (ret <= 0) { + subvol[0] = '\0'; + return NULL; + } + + memset(&args, 0, sizeof(args)); + + /* search in the tree of tree roots */ + sk->tree_id = 1; + + /* + * set the min and max to backref keys. The search will + * only send back this type of key now. + */ + sk->max_type = BTRFS_DIR_ITEM_KEY; + sk->min_type = BTRFS_DIR_ITEM_KEY; + + /* + * set all the other params to the max, we'll take any objectid + * and any trans + */ + sk->min_objectid = BTRFS_ROOT_TREE_DIR_OBJECTID; + sk->max_objectid = BTRFS_ROOT_TREE_DIR_OBJECTID; + + sk->max_offset = (u64)-1; + sk->min_offset = 0; + sk->max_transid = (u64)-1; + + /* just a big number, doesn't matter much */ + sk->nr_items = 4096; + + while(1) { + ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, &args); + if (ret < 0) { + fprintf(stderr, "ERROR: can't perform the search\n"); + subvol[0] = '\0'; + return NULL; + } + /* the ioctl returns the number of item it found in nr_items */ + if (sk->nr_items == 0) { + break; + } + + off = 0; + + /* + * for each item, pull the key out of the header and then + * read the root_ref item it contains + */ + for (i = 0; i < sk->nr_items; i++) { + sh = (struct btrfs_ioctl_search_header *)(args.buf + off); + off += sizeof(*sh); + if (sh->type == BTRFS_DIR_ITEM_KEY) { + dir_item = (struct btrfs_dir_item *)(args.buf + off); + name_len = dir_item->name_len; + name = (char *)(dir_item + 1); + + + /*add_root(&root_lookup, sh->objectid, sh->offset, + dir_id, name, name_len);*/ + strncpy(dirname, name, name_len); + dirname[name_len] = '\0'; + if (strcmp(dirname, "default") == 0) { + defaultsubvolid = dir_item->location.objectid; + break; + } + } + off += sh->len; + + /* + * record the mins in sk so we can make sure the + * next search doesn't repeat this root + */ + sk->min_objectid = sh->objectid; + sk->min_type = sh->type; + sk->max_type = sh->type; + sk->min_offset = sh->offset; + } + if (defaultsubvolid != 0) + break; + sk->nr_items = 4096; + /* this iteration is done, step forward one root for the next + * ioctl + */ + if (sk->min_objectid < (u64)-1) { + sk->min_objectid = BTRFS_ROOT_TREE_DIR_OBJECTID; + sk->max_objectid = BTRFS_ROOT_TREE_DIR_OBJECTID; + sk->max_type = BTRFS_ROOT_BACKREF_KEY; + sk->min_type = BTRFS_ROOT_BACKREF_KEY; + sk->min_offset = 0; + } else + break; + } + + if (defaultsubvolid == 0) { + subvol[0] = '\0'; + return NULL; + } + + memset(&args, 0, sizeof(args)); + + /* search in the tree of tree roots */ + sk->tree_id = 1; + + /* + * set the min and max to backref keys. The search will + * only send back this type of key now. + */ + sk->max_type = BTRFS_ROOT_BACKREF_KEY; + sk->min_type = BTRFS_ROOT_BACKREF_KEY; + + /* + * set all the other params to the max, we'll take any objectid + * and any trans + */ + sk->max_objectid = (u64)-1; + sk->max_offset = (u64)-1; + sk->max_transid = (u64)-1; + + /* just a big number, doesn't matter much */ + sk->nr_items = 4096; + + while(1) { + ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, &args); + if (ret < 0) { + fprintf(stderr, "ERROR: can't perform the search\n"); + subvol[0] = '\0'; + return NULL; + } + /* the ioctl returns the number of item it found in nr_items */ + if (sk->nr_items == 0) + break; + + off = 0; + + /* + * for each item, pull the key out of the header and then + * read the root_ref item it contains + */ + for (i = 0; i < sk->nr_items; i++) { + sh = (struct btrfs_ioctl_search_header *)(args.buf + off); + off += sizeof(*sh); + if (sh->type == BTRFS_ROOT_BACKREF_KEY) { + ref = (struct btrfs_root_ref *)(args.buf + off); + name_len = ref->name_len; + name = (char *)(ref + 1); + + if (sh->objectid == defaultsubvolid) { + strncpy(subvol, name, name_len); + subvol[name_len] = '\0'; + dprintf("The default subvolume: %s, ID: %llu\n", + subvol, sh->objectid); + break; + } + + } + + off += sh->len; + + /* + * record the mins in sk so we can make sure the + * next search doesn't repeat this root + */ + sk->min_objectid = sh->objectid; + sk->min_type = sh->type; + sk->min_offset = sh->offset; + } + if (subvol[0] != '\0') + break; + sk->nr_items = 4096; + /* this iteration is done, step forward one root for the next + * ioctl + */ + if (sk->min_objectid < (u64)-1) { + sk->min_objectid++; + sk->min_type = BTRFS_ROOT_BACKREF_KEY; + sk->min_offset = 0; + } else + break; + } + return subvol; +} + int install_file(const char *path, int devfd, struct stat *rst) { if (fs_type == EXT2 || fs_type == VFAT) @@ -548,19 +806,9 @@ static const char *find_device(const char *mtab_file, dev_t dev) if (!strcmp(mnt->mnt_type, "btrfs") && !stat(mnt->mnt_dir, &dst) && dst.st_dev == dev) { - char *opt = strstr(mnt->mnt_opts, BTRFS_SUBVOL_OPT); - - if (opt) { - if (!subvol[0]) { - char *tmp; - - strcpy(subvol, opt + sizeof(BTRFS_SUBVOL_OPT) - 1); - tmp = strchr(subvol, 32); - if (tmp) - *tmp = '\0'; - } - break; /* should break and let upper layer try again */ - } else + if (!subvol[0]) { + get_default_subvol(mnt->mnt_dir, subvol); + } done = true; } break; @@ -625,24 +873,10 @@ static const char *get_devname(const char *path) #else - /* check /etc/mtab first, since btrfs subvol info is only in here */ - devname = find_device("/etc/mtab", st.st_dev); - if (subvol[0] && !devname) { /* we just find it is a btrfs subvol */ - char parent[256]; - char *tmp; - - strcpy(parent, path); - tmp = strrchr(parent, '/'); - if (tmp) { - *tmp = '\0'; - fprintf(stderr, "%s is subvol, try its parent dir %s\n", path, parent); - devname = get_devname(parent); - } else - devname = NULL; - } + devname = find_device("/proc/mounts", st.st_dev); if (!devname) { - /* Didn't find it in /etc/mtab, try /proc/mounts */ - devname = find_device("/proc/mounts", st.st_dev); + /* Didn't find it in /proc/mounts, try /etc/mtab */ + devname = find_device("/etc/mtab", st.st_dev); } if (!devname) { fprintf(stderr, "%s: cannot find device for path %s\n", program, path); diff --git a/libinstaller/syslxint.h b/libinstaller/syslxint.h index 80c40f76..7c9da516 100644 --- a/libinstaller/syslxint.h +++ b/libinstaller/syslxint.h @@ -247,4 +247,13 @@ struct boot_sector { #define bsCodeLen (offsetof(struct boot_sector, bsSignature) - \ offsetof(struct boot_sector, bsCode)) +static inline int fat_check_sb_fields(const struct boot_sector *sb) +{ + return sb->bsResSectors && sb->bsFATs && + (!memcmp(sb->bs16.FileSysType, "FAT12 ", 8) || + !memcmp(sb->bs16.FileSysType, "FAT16 ", 8) || + !memcmp(sb->bs16.FileSysType, "FAT ", 8) || + !memcmp(sb->bs32.FileSysType, "FAT32 ", 8)); +} + #endif /* SYSLXINT_H */ diff --git a/utils/isohybrid.c b/utils/isohybrid.c index 7ee9a7f0..8a605313 100644 --- a/utils/isohybrid.c +++ b/utils/isohybrid.c @@ -108,6 +108,7 @@ printh(void) int check_option(int argc, char *argv[]) { + char *err = NULL; int n = 0, ind = 0; const char optstr[] = ":h:s:e:o:t:i:fcp?vV"; @@ -135,32 +136,38 @@ check_option(int argc, char *argv[]) switch (n) { case 'h': - if (!sscanf(optarg, "%hu", &head) || head < 1 || head > 256) + head = strtoul(optarg, &err, 0); + if (head < 1 || head > 256) errx(1, "invalid head: `%s', 1 <= head <= 256", optarg); break; case 's': - if (!sscanf(optarg, "%hhu", §or) || sector < 1 || sector > 63) + sector = strtoul(optarg, &err, 0); + if (sector < 1 || sector > 63) errx(1, "invalid sector: `%s', 1 <= sector <= 63", optarg); break; case 'e': - if (!sscanf(optarg, "%hhu", &entry) || entry < 1 || entry > 4) + entry = strtoul(optarg, &err, 0); + if (entry < 1 || entry > 4) errx(1, "invalid entry: `%s', 1 <= entry <= 4", optarg); break; case 'o': - if (!sscanf(optarg, "%hhu", &offset) || offset > 64) + offset = strtoul(optarg, &err, 0); + if (*err || offset > 64) errx(1, "invalid offset: `%s', 0 <= offset <= 64", optarg); break; case 't': - if (!sscanf(optarg, "%hu", &type) || type > 255) + type = strtoul(optarg, &err, 0); + if (*err || type > 255) errx(1, "invalid type: `%s', 0 <= type <= 255", optarg); break; case 'i': - if (!sscanf(optarg, "%u", &id)) + id = strtoul(optarg, &err, 0); + if (*err) errx(1, "invalid id: `%s'", optarg); break; diff --git a/utils/isohybrid.h b/utils/isohybrid.h index 826e90c5..eecf1caa 100644 --- a/utils/isohybrid.h +++ b/utils/isohybrid.h @@ -20,7 +20,7 @@ * */ -#define VERSION "0.11" +#define VERSION "0.12" #define BUFSIZE 2048 #define MBRSIZE 432 |