btrfs: Fix booting off a btrfs subvolume.

The subvolume name in path.data is not NUL-terminated, so don't use
strcmp on it.

Before this patch, it would accumulate the following (given
subvolumes with names "ext2_saved", "home", "gentoo" and "boot"):

ext2_saved
home_saved
gentooaved
bootooaved

Signed-off-by: Alexander E. Patrakov <patrakov@gmail.com>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
ldlinux: fixes bug that happens when using fullpath for a COM32 module

When using full path for a com32 module, for example,
/boot/syslinux/ls.c32 it fails without any error message. This patch
fixes it by looking first if the argv[0] is the path to a module before
looking for it at PATH.

Since we're using fopen to open module files (which works for both
absolute paths and paths relative to the current working directory) we
no longer need to include "." in PATH and neither the code to handle it.

Signed-off-by: Andre Ericson <de.ericson@gmail.com>
Signed-off-by: Matt Fleming <matt.fleming@intel.com>
module: Actually use last component of DT_NEEDED pathname

The comment in module_load() claims that we strip everything from the
DT_NEEDED pathnames but the last component. That's not true as we
leave the initial '/', which works fine if the module is in the root
directory, but not so well if we're in a sub-directory. Worse still,
if the DT_NEEDED entry pathname doesn't include a '/' the module is
skipped entirely.

We should also be loading dependencies in reverse order, as modules
loaded because of DT_NEEDED entries may also have dependencies and
their dependencies should be loaded first.

Also, now we need the strrchr() implementation in the core, so move
strrchr.o into $CORELIBOBJS.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
Delete all references to __com32.cs_bounce

The COM32 cs_bounce buffer is not usable with ELF modules, as we're
trying to move to an environment where memory is dynamically
allocated. All users of __com32.cs_bounce have been converted to using
lmalloc() to allocate low memory.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
pxechn: Fix merge botch s/pxe_dns/pxe_dns_resolv/

pxe_dns() was deleted in commit 6aba981cd93 ("pxe: resolve names via
DNS from protected-mode code"), so when pxechn was merged from
'master' we should really have updated pxechn.c to use
pxe_dns_resolv().

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
com32: Add missing DHCP pack/unpack files

These files were left out of the recent merge from master.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
linux.c32: Make errors clearer for users

Signed-off-by: Gene Cumm <gene.cumm@gmail.com>
isohybrid: Fix building with --as-needed

The library link order was wrong.

This patch was picked from Ubuntu.

Reported-and-tested-by: Tim Fletcher <tim@night-shade.org.uk>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Merge remote-tracking branch 'genec/linux-com32-error-message-for-hpa'
elflink: Fix compiler warning

Apply the correct cast to fix the following warning,

chainboot.c: In function ‘chainboot_file’:
chainboot.c:88:7: warning: passing argument 3 of ‘syslinux_add_movelist’ makes integer from pointer without a cast
../../../com32/include/syslinux/movebits.h:57:5: note: expected ‘addr_t’ but argument is of type ‘const void * const’

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
Merge remote-tracking branch 'origin/master' into elflink
extlinux: better methods for finding device matches

1. Support parsing /proc/self/mountinfo for devices;
2. For btrfs, query the device names from btrfs itself.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
fs: Add .copy_super to struct fs_ops

commit c0d18deeee2 ("elflink: Fix boot sector booting") makes
reference to vfat_copy_superblock() which is only implemented for
SYSLINUX, resulting in an undefined symbol when booting ISOLINUX or
PXELINUX. Move the superblock copy operation to struct fs_ops so that
we don't need to add a stub implementation of vfat_copy_superblock()
to ISOLINUX and PXELINUX.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
com32: Per-object file LDFLAGS

Some object files need to link against the ELF libraries. Allow them
to be specified with the following syntax in the Makefiles,

     LDFLAGS_$(object_file) = $(LIBS)

By adding libraries in this way DT_NEEDED entries are created in the
ELF modules and the required library dependencies are automatically
loaded before running the module.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
Revert "pxe: resolve names via DNS from protected-mode code"

This reverts commit 6aba981cd9310bae94587d3e51106261bf0e27b9.

dns_resolv() is only implemented for PXELINUX, meaning that if we try
to execute any module that references it under SYSLINUX, EXTLINUX or
ISOLINUX it fails to run because it cannot resolve the symbol.

We need a way to implement DNS resolution so that it works for
PXELINUX but returns an error for SYSLINUX/EXTLINUX or ISOLINUX,
without introducing undefined symbols. The old COMBOOT API method
worked splendidly for this, so revert until someone provides a better
solution.

Conflicts:

	com32/lib/Makefile
	com32/modules/host.c
	mk/elf.mk

Cc: Paulo Alcantara <pcacjr@zytor.com>
Signed-off-by: Matt Fleming <matt.fleming@intel.com>
ldlinux: Don't lfree() 'kernel' twice

This lead to serious problems where duplicate free blocks would appear
next to each other on the free list, which created an infinite loop in
the following code,

	for ( fp = head->next_free ; fp != head ; fp = fp->next_free ) {
	    if ( ARENA_SIZE_GET(fp->a.attrs) >= size ) {
		/* Found fit -- allocate out of this block */
		p = __malloc_from_block(fp, size, tag);
		break;
	    }
	}

because fp == fp->next_free, resulting in modules hanging forever at
malloc() call sites.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
module: Make list of DT_NEEDED entries per-module

We can't store the DT_NEEDED entries in the bss because 'needed[]'
will be overwritten with recursive calls to module_load(). Make the
list part of struct elf_module instead.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
extlinux: centralize and reuse btrfs validation

We can re-use btrfs device validation now.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
extlinux: add --device option to override device detect

Add a --device option for scripts and expert users to override the
device detection.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
NEWS: document extlinux --device

Signed-off-by: H. Peter Anvin <hpa@zytor.com>