Libraries updates and cleanup

* Updating common/lib
 * Updating lib/csu
 * Updating lib/libc
 * Updating libexec/ld.elf_so
 * Corrected test on __minix in featuretest to actually follow the
   meaning of the comment.
 * Cleaned up _REENTRANT-related defintions.
 * Disabled -D_REENTRANT for libfetch
 * Removing some unneeded __NBSD_LIBC defines and tests

Change-Id: Ic1394baef74d11b9f86b312f5ff4bbc3cbf72ce2
This commit is contained in:
2013-01-14 11:36:26 +01:00
parent f6aac1c3b5
commit f14fb60209
1285 changed files with 44244 additions and 14308 deletions
+8 -16
View File
@@ -1,4 +1,4 @@
/* $NetBSD: ansi.h,v 1.24 2010/03/27 22:14:09 tnozaki Exp $ */
/* $NetBSD: ansi.h,v 1.25 2011/07/17 20:54:41 joerg Exp $ */
/*-
* Copyright (c) 1990, 1993
@@ -49,23 +49,15 @@
* #undef _BSD_SIZE_T_
* #endif
*/
#define _BSD_CLOCK_T_ long
#define _BSD_PTRDIFF_T_ int
#define _BSD_SIZE_T_ unsigned int
#define _BSD_SSIZE_T_ int
#define _BSD_TIME_T_ long /* time() */
#if __GNUC_PREREQ__(2, 96)
#define _BSD_VA_LIST_ __builtin_va_list /* GCC built-in type */
#else
#define _BSD_VA_LIST_ char * /* va_list */
#endif
#define _BSD_CLOCK_T_ int /* clock() */
#define _BSD_PTRDIFF_T_ int /* ptr1 - ptr2 */
#define _BSD_SIZE_T_ unsigned int /* sizeof() */
#define _BSD_SSIZE_T_ int /* byte count or error */
#define _BSD_TIME_T_ int /* time() */
#define _BSD_CLOCKID_T_ int /* clockid_t */
#define _BSD_TIMER_T_ int /* timer_t */
#define _BSD_SUSECONDS_T_ long /* suseconds_t */
#define _BSD_USECONDS_T_ long /* useconds_t */
#define _BSD_SUSECONDS_T_ int /* suseconds_t */
#define _BSD_USECONDS_T_ int /* useconds_t */
#define _BSD_WCHAR_T_ int /* wchar_t */
#define _BSD_WINT_T_ int /* wint_t */
+5 -10
View File
@@ -1,22 +1,17 @@
/* $NetBSD: cdefs.h,v 1.8 2011/06/16 13:27:59 joerg Exp $ */
/* $NetBSD: cdefs.h,v 1.9 2012/01/20 14:08:06 joerg Exp $ */
#ifndef _I386_CDEFS_H_
#define _I386_CDEFS_H_
#if defined(_STANDALONE)
#ifdef __PCC__
#define __compactcall
#else
#define __compactcall __attribute__((__regparm__(3)))
#endif
#endif
#ifdef __minix
#define __ALIGNBYTES (sizeof(int) - 1)
#if defined(__minix)
#ifndef __ELF__
#define __LEADING_UNDERSCORE
#endif
#else /* !__minix */
/* No arch-specific cdefs. */
#endif
#endif /* defined(__minix) */
#endif /* !_I386_CDEFS_H_ */
+2
View File
@@ -16,4 +16,6 @@
#define X86_FLAGS_USER (X86_FLAG_C | X86_FLAG_P | X86_FLAG_A | X86_FLAG_Z | \
X86_FLAG_S | X86_FLAG_D | X86_FLAG_O)
#include <x86/cpu.h>
#endif
+2 -5
View File
@@ -1,4 +1,4 @@
/* $NetBSD: limits.h,v 1.22 2010/06/07 13:52:30 tnozaki Exp $ */
/* $NetBSD: limits.h,v 1.23 2012/03/28 17:03:29 christos Exp $ */
/*
* Copyright (c) 1988 The Regents of the University of California.
@@ -38,13 +38,10 @@
#define CHAR_BIT 8 /* number of bits in a char */
#define UCHAR_MAX 0xff /* max value for an unsigned char */
#define SCHAR_MAX 0x7f /* max value for a signed char */
#define SCHAR_MIN (-0x7f-1) /* min value for a signed char */
#define UCHAR_MAX 0xff /* max value for an unsigned char */
#define CHAR_MAX 0x7f /* max value for a char */
#define CHAR_MIN (-0x7f-1) /* min value for a char */
#define USHRT_MAX 0xffff /* max value for an unsigned short */
#define SHRT_MAX 0x7fff /* max value for a short */
#define SHRT_MIN (-0x7fff-1) /* min value for a short */
+208
View File
@@ -1,6 +1,213 @@
/* $NetBSD: multiboot.h,v 1.8 2009/02/22 18:05:42 ahoka Exp $ */
/*-
* Copyright (c) 2005, 2006 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Julio M. Merino Vidal.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __MULTIBOOT_H__
#define __MULTIBOOT_H__
#if !defined(_KERNEL) && defined(_STANDALONE)
/* --------------------------------------------------------------------- */
/*
* Multiboot header structure.
*/
#define MULTIBOOT_HEADER_MAGIC 0x1BADB002
#define MULTIBOOT_HEADER_MODS_ALIGNED 0x00000001
#define MULTIBOOT_HEADER_WANT_MEMORY 0x00000002
#define MULTIBOOT_HEADER_HAS_VBE 0x00000004
#define MULTIBOOT_HEADER_HAS_ADDR 0x00010000
#if !defined(_LOCORE)
struct multiboot_header {
uint32_t mh_magic;
uint32_t mh_flags;
uint32_t mh_checksum;
/* Valid if mh_flags sets MULTIBOOT_HEADER_HAS_ADDR. */
paddr_t mh_header_addr;
paddr_t mh_load_addr;
paddr_t mh_load_end_addr;
paddr_t mh_bss_end_addr;
paddr_t mh_entry_addr;
/* Valid if mh_flags sets MULTIBOOT_HEADER_HAS_VBE. */
uint32_t mh_mode_type;
uint32_t mh_width;
uint32_t mh_height;
uint32_t mh_depth;
};
#endif /* !defined(_LOCORE) */
/*
* Symbols defined in locore.S.
*/
#if !defined(_LOCORE) && defined(_KERNEL)
extern struct multiboot_header *Multiboot_Header;
#endif /* !defined(_LOCORE) && defined(_KERNEL) */
/* --------------------------------------------------------------------- */
/*
* Multiboot information structure.
*/
#define MULTIBOOT_INFO_MAGIC 0x2BADB002
#define MULTIBOOT_INFO_HAS_MEMORY 0x00000001
#define MULTIBOOT_INFO_HAS_BOOT_DEVICE 0x00000002
#define MULTIBOOT_INFO_HAS_CMDLINE 0x00000004
#define MULTIBOOT_INFO_HAS_MODS 0x00000008
#define MULTIBOOT_INFO_HAS_AOUT_SYMS 0x00000010
#define MULTIBOOT_INFO_HAS_ELF_SYMS 0x00000020
#define MULTIBOOT_INFO_HAS_MMAP 0x00000040
#define MULTIBOOT_INFO_HAS_DRIVES 0x00000080
#define MULTIBOOT_INFO_HAS_CONFIG_TABLE 0x00000100
#define MULTIBOOT_INFO_HAS_LOADER_NAME 0x00000200
#define MULTIBOOT_INFO_HAS_APM_TABLE 0x00000400
#define MULTIBOOT_INFO_HAS_VBE 0x00000800
#if !defined(_LOCORE)
struct multiboot_info {
uint32_t mi_flags;
/* Valid if mi_flags sets MULTIBOOT_INFO_HAS_MEMORY. */
uint32_t mi_mem_lower;
uint32_t mi_mem_upper;
/* Valid if mi_flags sets MULTIBOOT_INFO_HAS_BOOT_DEVICE. */
uint8_t mi_boot_device_part3;
uint8_t mi_boot_device_part2;
uint8_t mi_boot_device_part1;
uint8_t mi_boot_device_drive;
/* Valid if mi_flags sets MULTIBOOT_INFO_HAS_CMDLINE. */
char * mi_cmdline;
/* Valid if mi_flags sets MULTIBOOT_INFO_HAS_MODS. */
uint32_t mi_mods_count;
vaddr_t mi_mods_addr;
/* Valid if mi_flags sets MULTIBOOT_INFO_HAS_{AOUT,ELF}_SYMS. */
uint32_t mi_elfshdr_num;
uint32_t mi_elfshdr_size;
vaddr_t mi_elfshdr_addr;
uint32_t mi_elfshdr_shndx;
/* Valid if mi_flags sets MULTIBOOT_INFO_HAS_MMAP. */
uint32_t mi_mmap_length;
vaddr_t mi_mmap_addr;
/* Valid if mi_flags sets MULTIBOOT_INFO_HAS_DRIVES. */
uint32_t mi_drives_length;
vaddr_t mi_drives_addr;
/* Valid if mi_flags sets MULTIBOOT_INFO_HAS_CONFIG_TABLE. */
void * unused_mi_config_table;
/* Valid if mi_flags sets MULTIBOOT_INFO_HAS_LOADER_NAME. */
char * mi_loader_name;
/* Valid if mi_flags sets MULTIBOOT_INFO_HAS_APM. */
void * unused_mi_apm_table;
/* Valid if mi_flags sets MULTIBOOT_INFO_HAS_VBE. */
void * unused_mi_vbe_control_info;
void * unused_mi_vbe_mode_info;
paddr_t unused_mi_vbe_interface_seg;
paddr_t unused_mi_vbe_interface_off;
uint32_t unused_mi_vbe_interface_len;
};
/* --------------------------------------------------------------------- */
/*
* Drive information. This describes an entry in the drives table as
* pointed to by mi_drives_addr.
*/
struct multiboot_drive {
uint32_t md_length;
uint8_t md_number;
uint8_t md_mode;
uint16_t md_cylinders;
uint8_t md_heads;
uint8_t md_sectors;
/* The variable-sized 'ports' field comes here, so this structure
* can be longer. */
};
/* --------------------------------------------------------------------- */
/*
* Memory mapping. This describes an entry in the memory mappings table
* as pointed to by mi_mmap_addr.
*
* Be aware that mm_size specifies the size of all other fields *except*
* for mm_size. In order to jump between two different entries, you
* have to count mm_size + 4 bytes.
*/
struct multiboot_mmap {
uint32_t mm_size;
uint64_t mm_base_addr;
uint64_t mm_length;
uint32_t mm_type;
};
/*
* Modules. This describes an entry in the modules table as pointed
* to by mi_mods_addr.
*/
struct multiboot_module {
uint32_t mmo_start;
uint32_t mmo_end;
char * mmo_string;
uint32_t mmo_reserved;
};
#endif /* !defined(_LOCORE) */
/* --------------------------------------------------------------------- */
/*
* Prototypes for public functions defined in multiboot.c.
*/
#if !defined(_LOCORE) && defined(_KERNEL)
void multiboot_pre_reloc(struct multiboot_info *);
void multiboot_post_reloc(void);
void multiboot_print_info(void);
bool multiboot_ksyms_addsyms_elf(void);
#endif /* !defined(_LOCORE) */
/* --------------------------------------------------------------------- */
#else /* !defined(_KERNEL) && defined(_STANDALONE) */
/* LSC FIXME: OLD MINIX DEFINITION: should be removed and replace with
definition above... */
#define MULTIBOOT_HEADER_MAGIC 0x1BADB002
#define MULTIBOOT_BOOTLOADER_MAGIC 0x2BADB002
@@ -140,4 +347,5 @@ struct multiboot_mmap_entry
typedef struct multiboot_mmap_entry multiboot_memory_map_t;
#endif /* __ASSEMBLY__ */
#endif /* !defined(_KERNEL) && defined(_STANDALONE) */
#endif /* __MULTIBOOT_H__ */
+8 -2
View File
@@ -1,4 +1,4 @@
/* $NetBSD: types.h,v 1.70 2010/12/22 04:15:02 christos Exp $ */
/* $NetBSD: types.h,v 1.74 2011/07/06 18:46:04 dyoung Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
@@ -101,7 +101,7 @@ typedef volatile unsigned char __cpu_simple_lock_t;
/* The x86 does not have strict alignment requirements. */
#define __NO_STRICT_ALIGNMENT
#define __HAVE_DEVICE_REGISTER
#define __HAVE_NEW_STYLE_BUS_H
#define __HAVE_CPU_DATA_FIRST
#define __HAVE_CPU_COUNTER
#define __HAVE_MD_CPU_OFFLINE
@@ -112,6 +112,12 @@ typedef volatile unsigned char __cpu_simple_lock_t;
#define __HAVE_ATOMIC_AS_MEMBAR
#define __HAVE_CPU_LWP_SETPRIVATE
#define __HAVE_INTR_CONTROL
#define __HAVE_MM_MD_OPEN
#define __HAVE___LWP_GETPRIVATE_FAST
#if !defined(__minix)
#define __HAVE_TLS_VARIANT_II
#endif /* !defined(__minix) */
#define __HAVE_COMMON___TLS_GET_ADDR
#if defined(_KERNEL)
#define __HAVE_RAS
+9 -12
View File
@@ -33,11 +33,13 @@ BINMODE=444
.PATH: ${.CURDIR}/.. ${.CURDIR}/../../lib
# MINIX LSC seems to be still needed
#LDFLAGS+= -nostdlib -Wl,-N -Wl,-e,boot_start
LDFLAGS+= -nostdlib -Wl,-N -Wl,-e,boot_start -L${DESTDIR}/${LIBDIR}
LDFLAGS+= -nostdlib -Wl,-N -Wl,-e,boot_start
CPPFLAGS+= -I ${.CURDIR}/.. -I ${.CURDIR}/../../lib -I ${S}/lib/libsa
CPPFLAGS+= -I ${.OBJDIR}
.if defined(__MINIX)
CPPFLAGS+=-isystem ${DESTDIR}/usr/include
CPPFLAGS+= -D_MINIX
.endif # defined(__MINIX)
# Make sure we override any optimization options specified by the user
COPTS= -Os
@@ -57,10 +59,6 @@ COPTS+= -ffreestanding
CFLAGS+= -Wall -Wmissing-prototypes -Wstrict-prototypes
CPPFLAGS+= -nostdinc -D_STANDALONE
CPPFLAGS+= -I$S
.if defined(__MINIX)
CPPFLAGS+= -I${DESTDIR}/usr/include
CPPFLAGS+= -I${.CURDIR}/../../../../../../
.endif
CPPFLAGS+= -DSUPPORT_PS2
CPPFLAGS+= -DDIRECT_SERIAL
@@ -127,8 +125,8 @@ KERN_AS= library
.include "${S}/lib/libkern/Makefile.inc"
LIBKERN= ${KERNLIB}
.else
# MINIX
LIBKERN= # use MINIX minc
# use MINIX minc
LIBKERN= ${DESTDIR}/usr/lib/libminc.a
.endif
### find out what to use for libz
@@ -153,11 +151,10 @@ vers.c: ${VERSIONFILE} ${SOURCES} ${LIBLIST} ${.CURDIR}/../Makefile.boot
# Anything that calls 'real_to_prot' must have a %pc < 0x10000.
# We link the program, find the callers (all in libi386), then
# explicitly pull in the required objects before any other library code.
# MINIX (LSC adding LDADD still needed?)
${PROG}: ${OBJS} ${LIBLIST} ${.CURDIR}/../Makefile.boot
${_MKTARGET_LINK}
bb="$$( ${CC} -o ${PROG}.syms ${LDFLAGS} -Wl,-Ttext,0 -Wl,-cref \
${OBJS} ${LIBLIST} ${LDADD} | ( \
${OBJS} ${LIBLIST} | ( \
while read symbol file; do \
[ -z "$$file" ] && continue; \
[ "$$symbol" = real_to_prot ] && break; \
@@ -173,7 +170,7 @@ ${PROG}: ${OBJS} ${LIBLIST} ${.CURDIR}/../Makefile.boot
done; \
) )"; \
${CC} -o ${PROG}.syms ${LDFLAGS} -Wl,-Ttext,0 \
-Wl,-Map,${PROG}.map -Wl,-cref ${OBJS} $$bb ${LIBLIST} ${LDADD}
-Wl,-Map,${PROG}.map -Wl,-cref ${OBJS} $$bb ${LIBLIST}
${OBJCOPY} -O binary ${PROG}.syms ${PROG}
.ifndef __MINIX
+1 -5
View File
@@ -1,10 +1,6 @@
# $NetBSD: Makefile,v 1.3 2005/12/11 12:17:48 christos Exp $
# MINIX (LSC this still needed?)
# Adding cleaning of specific target? -D_MINIX is not defined at top level ?
# LSC FIXME: Why change the name?
PROG= boot_monitor
CLEANFILES= lib
CPPFLAGS+= -D_MINIX
.include <../Makefile.boot>
+27 -4
View File
@@ -1,4 +1,4 @@
/* $NetBSD: boot2.c,v 1.57 2011/12/25 06:09:09 tsutsui Exp $ */
/* $NetBSD: boot2.c,v 1.58 2012/08/04 03:51:27 riastradh Exp $ */
/*-
* Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -122,7 +122,9 @@ void command_dev(char *);
void command_consdev(char *);
void command_modules(char *);
void command_multiboot(char *);
#ifdef __minix
void command_load_mods(char *);
#endif
const struct bootblk_command commands[] = {
{ "help", command_help },
@@ -134,7 +136,9 @@ const struct bootblk_command commands[] = {
{ "consdev", command_consdev },
{ "modules", command_modules },
{ "load", module_add },
#ifdef __minix
{ "load_mods", command_load_mods },
#endif
{ "multiboot", command_multiboot },
{ "vesa", command_vesa },
{ "splash", splash_add },
@@ -405,7 +409,9 @@ command_help(char *arg)
"vesa {modenum|on|off|enabled|disabled|list}\n"
"modules {on|off|enabled|disabled}\n"
"load {path_to_module}\n"
#ifdef __minix
"load_mods {path_to_modules}, pattern might be used\n"
#endif
"multiboot [xdNx:][filename] [<args>]\n"
"userconf {command}\n"
"rndseed {path_to_rndseed_file}\n"
@@ -419,10 +425,15 @@ command_ls(char *arg)
const char *save = default_filename;
default_filename = "/";
#ifndef __minix
ls(arg);
#else
ls(arg, NULL);
#endif
default_filename = save;
}
#ifdef __minix
void
command_load_mods(char *arg)
{
@@ -432,6 +443,7 @@ command_load_mods(char *arg)
ls(arg, module_add);
default_filename = save;
}
#endif
/* ARGSUSED */
void
@@ -449,10 +461,21 @@ void
command_boot(char *arg)
{
char *filename;
int howto;
int howto, tell;
if (parseboot(arg, &filename, &howto))
bootit(filename, howto, (howto & AB_VERBOSE) != 0);
if (!parseboot(arg, &filename, &howto))
return;
tell = ((howto & AB_VERBOSE) != 0);
if (filename != NULL) {
bootit(filename, howto, tell);
} else {
int i;
for (i = 0; i < NUMNAMES; i++) {
bootit(names[i][0], howto, tell);
bootit(names[i][1], howto, tell);
}
}
}
void
+1 -1
View File
@@ -1,4 +1,4 @@
/* $NetBSD: conf.c,v 1.5 2008/04/05 18:21:34 tsutsui Exp $ */
/* $NetBSD: conf.c,v 1.6 2012/01/16 18:46:20 christos Exp $ */
/*
* Copyright (c) 1997
+7 -11
View File
@@ -1,20 +1,16 @@
# $NetBSD: Makefile,v 1.14 2010/12/29 17:44:03 jakllsch Exp $
SUBDIR=
#SUBDIR= bootxx_ffsv1 .WAIT bootxx_ffsv2 bootxx_lfsv1 bootxx_lfsv2
#SUBDIR+=bootxx_msdos bootxx_ustarfs
.if defined(__MINIX)
SUBDIR= bootxx_minixfs3
.else
SUBDIR= bootxx_ffsv1 .WAIT bootxx_ffsv2 bootxx_lfsv1 bootxx_lfsv2
SUBDIR+=bootxx_msdos bootxx_ustarfs
.endif # defined(__MINIX)
# Ext2fs doesn't have enough free space (it has only 1KB)
# to store this primary bootloader, but we can put it into
# an independent small 'boot' partition as NetBSD/hp300 does.
#
# However MINIX implements a solution using the empty space before subpartition
.if !empty(CC:M*pcc)
# PCC cannot compile bootxx_ext2fs because it lacks regparm aka compactcall
SUBDIR+=bootxx_minixfs3
.else
SUBDIR+=bootxx_ext2fs bootxx_minixfs3
.endif
SUBDIR+=bootxx_ext2fs
LIBOBJ= ${.OBJDIR}
.MAKEOVERRIDES+= LIBOBJ
+11 -15
View File
@@ -38,7 +38,7 @@ BINMODE=444
.PATH: ${.CURDIR}/.. ${.CURDIR}/../../lib
LDFLAGS+= -nostdlib -Wl,-N -Wl,-e,start -L${DESTDIR}/${LIBDIR}
LDFLAGS+= -nostdlib -Wl,-N -Wl,-e,start
CPPFLAGS+= -DBOOTXX
# CPPFLAGS+= -D__daddr_t=int32_t
CPPFLAGS+= -I ${.CURDIR}/../../lib -I ${.OBJDIR}
@@ -50,16 +50,12 @@ CPPFLAGS+= -DXXfs_close=${FS}_close
CPPFLAGS+= -DXXfs_read=${FS}_read
CPPFLAGS+= -DXXfs_stat=${FS}_stat
CPPFLAGS+= -DFS=${FS}
# clang generates too big bootxx_xxx
.if !empty(CC:M*clang)
CPPFLAGS+= -Os
.endif
# CPPFLAGS+= -DBOOT_MSG_COM0
# Make sure we override any optimization options specified by the user
#.include "${.PARSEDIR}/../Makefile.inc"
#COPTS= ${OPT_SIZE.${ACTIVE_CC}}
#DBG=
.include "${.PARSEDIR}/../Makefile.inc"
COPTS= ${OPT_SIZE.${ACTIVE_CC}}
DBG=
CPPFLAGS+= -DNO_LBA_CHECK
@@ -77,10 +73,6 @@ CPUFLAGS= -march=i386 -mtune=i386
CFLAGS+= -Wall -Wmissing-prototypes -Wstrict-prototypes
CPPFLAGS+= -nostdinc -D_STANDALONE
CPPFLAGS+= -I$S
.if defined(__MINIX)
CPPFLAGS+= -I${DESTDIR}/usr/include
CPPFLAGS+= -I${.CURDIR}/../../../../../../
.endif
CPPFLAGS+= -DLIBSA_SINGLE_FILESYSTEM=xxfs \
-DLIBSA_NO_TWIDDLE \
@@ -123,6 +115,9 @@ SA_AS= library
SAMISCMAKEFLAGS+="SA_USE_LOADFILE=yes"
.if defined(__MINIX)
SAMISCMAKEFLAGS+="SA_INCLUDE_NET=no"
CPPFLAGS+= -isystem ${DESTDIR}/usr/include
CPPFLAGS+= -D_MINIX
AFLAGS+= -Wa,--divide
.endif
.include "${S}/lib/libsa/Makefile.inc"
LIBSA= ${SALIB}
@@ -133,10 +128,11 @@ KERN_AS= library
.include "${S}/lib/libkern/Makefile.inc"
LIBKERN= ${KERNLIB}
.else
# MINIX
LIBKERN= # use MINIX minc
# use MINIX minc
LIBKERN= ${DESTDIR}/usr/lib/libminc.a
.endif
cleandir distclean: .WAIT cleanlibdir
cleanlibdir:
@@ -149,7 +145,7 @@ CLEANFILES+= ${PROG}.sym ${PROG}.map
${PROG}: ${OBJS} ${LIBLIST}
${_MKTARGET_LINK}
${CC} -o ${PROG}.sym ${LDFLAGS} -Wl,-Ttext,${PRIMARY_LOAD_ADDRESS} \
-Wl,-Map,${PROG}.map -Wl,-cref ${OBJS} ${LIBLIST} ${LDADD}
-Wl,-Map,${PROG}.map -Wl,-cref ${OBJS} ${LIBLIST}
${OBJCOPY} -O binary ${PROG}.sym ${PROG}
@ sz=$$(${TOOL_STAT} -f '%z' ${PROG}); \
if [ "$$sz" -gt "${BOOTXX_MAXSIZE}" ]; then \
+3 -6
View File
@@ -130,13 +130,12 @@ boot1(uint32_t biosdev, uint64_t *sector)
done:
/* if we fail here, so will fstat, so keep going */
if (fd == -1 || fstat(fd, &sb) == -1) {
if (fd == -1 || fstat(fd, &sb) == -1)
#ifndef __minix
return "Can't open /boot\r\n";
#else
return "Can't open /boot_monitor\r\n";
#endif
}
biosdev = (uint32_t)sb.st_size;
#if 0
@@ -144,21 +143,19 @@ done:
return "/boot too large\r\n";
#endif
if (read(fd, (void *)SECONDARY_LOAD_ADDRESS, biosdev) != biosdev) {
if (read(fd, (void *)SECONDARY_LOAD_ADDRESS, biosdev) != biosdev)
#ifndef __minix
return "/boot load failed\r\n";
#else
return "/boot_monitor load failed\r\n";
#endif
}
if (*(uint32_t *)(SECONDARY_LOAD_ADDRESS + 4) != X86_BOOT_MAGIC_2) {
if (*(uint32_t *)(SECONDARY_LOAD_ADDRESS + 4) != X86_BOOT_MAGIC_2)
#ifndef __minix
return "Invalid /boot file format\r\n";
#else
return "Invalid /boot_monitor file format\r\n";
#endif
}
/* We need to jump to the secondary bootstrap in realmode */
return 0;
+1 -1
View File
@@ -90,7 +90,7 @@ boot_params: /* space for patchable variables */
pop %ecx
movl $boot_params, %esi
orb $X86_BP_FLAGS_LBA64VALID, 4(%esi)
lcall $SECONDARY_LOAD_ADDRESS >> 4, $0
lcall $SECONDARY_LOAD_ADDRESS/16, $0
boot_fail:
push %ax /* error string from boot1 */
@@ -1,8 +1,5 @@
# $NetBSD: Makefile,v 1.1 2010/09/11 13:06:37 tsutsui Exp $
FS=ext2fs
CLEANFILES= lib
CPPFLAGS+= -D_MINIX
CFLAGS+= -Os
.include <../Makefile.bootxx>
@@ -2,7 +2,6 @@
PROG=bootxx_minixfs3
FS=minixfs3
CLEANFILES= lib
MINIX3_FIRST_SUBP_OFFSET=32
+4 -2
View File
@@ -7,6 +7,10 @@ AFLAGS.cdboot.S= ${${ACTIVE_CC} == "clang":?-no-integrated-as:}
NOMAN= # defined
.include <bsd.own.mk>
.if defined(__MINIX)
AFLAGS+= -Wa,--divide
.endif
STRIPFLAG= # nothing
LIBCRT0= # nothing
@@ -41,8 +45,6 @@ BUILDSYMLINKS+= $S/arch/i386/include machine \
DPSRCS+= machine x86
AFLAGS+= -Wa,--divide
CLEANFILES+= ${PROG}.tmp
${PROG}: ${OBJS}
+10 -7
View File
@@ -1,4 +1,4 @@
/* $NetBSD: biosdisk.c,v 1.39 2011/09/21 08:57:12 gsutre Exp $ */
/* $NetBSD: biosdisk.c,v 1.42 2012/07/03 15:24:37 tsutsui Exp $ */
/*
* Copyright (c) 1996, 1998
@@ -316,7 +316,9 @@ read_gpt(struct biosdisk *d)
gptsector[0] = GPT_HDR_BLKNO;
if (set_geometry(&d->ll, &ed) == 0 && d->ll.flags & BIOSDISK_INT13EXT) {
gptsector[1] = ed.totsec - 1;
d->ll.secsize = ed.sbytes;
/* Sanity check values returned from BIOS */
if (ed.sbytes >= 512 && (ed.sbytes & (ed.sbytes - 1)) == 0)
d->ll.secsize = ed.sbytes;
} else {
#ifdef DISK_DEBUG
printf("Unable to determine extended disk geometry - "
@@ -414,7 +416,7 @@ read_minix_subp(struct biosdisk *d, struct disklabel* dflt_lbl,
if (readsects(&d->ll, sector, 1, d->buf, 0)) {
#ifdef DISK_DEBUG
printf("Error reading MFS sector %d\n", sector);
printf("Error reading MFS sector %"PRId64"\n", sector);
#endif
return EIO;
}
@@ -443,10 +445,11 @@ read_label(struct biosdisk *d)
struct disklabel dflt_lbl;
struct mbr_partition mbr[MBR_PART_COUNT];
struct partition *p;
int sector, i;
uint32_t sector;
int i;
int error;
int typ;
int ext_base, this_ext, next_ext;
uint32_t ext_base, this_ext, next_ext;
#ifdef COMPAT_386BSD_MBRPART
int sector_386bsd = -1;
#endif
@@ -471,7 +474,7 @@ read_label(struct biosdisk *d)
next_ext = 0;
if (readsects(&d->ll, this_ext, 1, d->buf, 0)) {
#ifdef DISK_DEBUG
printf("error reading MBR sector %d\n", this_ext);
printf("error reading MBR sector %u\n", this_ext);
#endif
return EIO;
}
@@ -484,7 +487,7 @@ read_label(struct biosdisk *d)
continue;
sector = this_ext + mbr[i].mbrp_start;
#ifdef DISK_DEBUG
printf("ptn type %d in sector %d\n", typ, sector);
printf("ptn type %d in sector %u\n", typ, sector);
#endif
if (typ == MBR_PTYPE_MINIX_14B) {
if (!read_minix_subp(d, &dflt_lbl,
+7 -3
View File
@@ -45,6 +45,7 @@ ENTRY(conputc)
call _C_LABEL(prot_to_real) # enter real mode
.code16
#if defined(__minix)
cmp $0x08, %al # backspace?
jne print_char
@@ -65,10 +66,13 @@ ENTRY(conputc)
jmp do_int
print_char:
#endif /* defined(__minix) */
movw $1,%bx
movb $0x0e,%ah # print character
movb $0x0e,%ah
movb %al, %cl
#if defined(__minix)
do_int:
#endif /* defined(__minix) */
int $0x10
calll _C_LABEL(real_to_prot) # back to protected mode
@@ -89,12 +93,12 @@ ENTRY(congetc)
movb $0x0,%ah
int $0x16
movw %ax,%bx
movb %al,%bl
calll _C_LABEL(real_to_prot) # back to protected mode
.code32
movw %bx, 28(%esp)
movb %bl, 28(%esp)
popa
ret
+4 -2
View File
@@ -1,4 +1,4 @@
/* $NetBSD: exec.c,v 1.49 2011/11/28 07:56:54 tls Exp $ */
/* $NetBSD: exec.c,v 1.50 2012/05/21 21:34:16 dsl Exp $ */
/*-
* Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -297,11 +297,13 @@ common_load_kernel(const char *file, u_long *basemem, u_long *extmem,
close(fd);
/* Now we know the root fs type, load modules for it. */
/* If the root fs type is unusual, load its module. */
if (fsmod != NULL)
module_add(fsmod);
#if defined(__minix)
if (fsmod !=NULL && fsmod2 != NULL && strcmp(fsmod, fsmod2) != 0)
module_add(fsmod2);
#endif /* defined(__minix) */
/*
* Gather some information for the kernel. Do this after the
+5 -1
View File
@@ -91,9 +91,11 @@ struct bootblk_command {
void (*c_fn)(char *);
};
void bootmenu(void);
void prompt(int);
void docommand(char *);
#if defined(__minix)
void editline(char *, size_t, char *);
void prompt(int);
#endif
/* in "user code": */
void command_help(char *);
@@ -116,7 +118,9 @@ int coniskey(void);
__compactcall void conputc(int);
void conclr(void);
#if defined(__minix)
int getchar_ex(void);
#endif
int getextmem2(int *);
__compactcall int getextmemps2(void *);
+1
View File
@@ -69,6 +69,7 @@ prompt(int allowreturn)
for (;;) {
char *c = input;
input[0] = '\0';
printf("> ");
editline(input, sizeof(input), NULL);
+106
View File
@@ -0,0 +1,106 @@
/* $NetBSD: getopt.c,v 1.5 2009/03/14 15:36:08 dsl Exp $ */
/*
* Copyright (c) 1987, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/* from: netbsd:lib/libc/stdlib/getopt.c */
#include <lib/libkern/libkern.h>
#include <lib/libsa/stand.h>
int opterr = 1, /* if error message should be printed */
optind = 1, /* index into parent argv vector */
optopt, /* character checked for validity */
optreset; /* reset getopt */
char *optarg; /* argument associated with option */
#define BADCH (int)'?'
#define BADARG (int)':'
#define EMSG ""
/*
* getopt --
* Parse argc/argv argument vector.
*/
int
getopt(int nargc, char * const *nargv, const char *ostr)
{
static char *place = EMSG; /* option letter processing */
char *oli; /* option letter list index */
if (optreset || !*place) { /* update scanning pointer */
optreset = 0;
if (optind >= nargc || *(place = nargv[optind]) != '-') {
place = EMSG;
return (-1);
}
if (place[1] && *++place == '-') { /* found "--" */
++optind;
place = EMSG;
return (-1);
}
} /* option letter okay? */
if ((optopt = (int)*place++) == (int)':' ||
!(oli = strchr(ostr, optopt))) {
/*
* if the user didn't specify '-' as an option,
* assume it means -1.
*/
if (optopt == (int)'-')
return (-1);
if (!*place)
++optind;
if (opterr && *ostr != ':')
printf("illegal option -- %c\n", optopt);
return (BADCH);
}
if (*++oli != ':') { /* don't need argument */
optarg = NULL;
if (!*place)
++optind;
}
else { /* need an argument */
if (*place) /* no white space */
optarg = place;
else if (nargc <= ++optind) { /* no arg */
place = EMSG;
if (*ostr == ':')
return (BADARG);
if (opterr)
printf("option requires an argument -- %c\n",
optopt);
return (BADCH);
}
else /* white space */
optarg = nargv[optind];
place = EMSG;
++optind;
}
return (optopt); /* dump back option letter */
}
+641
View File
@@ -0,0 +1,641 @@
/* $NetBSD: nfs.c,v 1.19 2011/12/25 06:09:09 tsutsui Exp $ */
/*-
* Copyright (c) 1993 John Brezak
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/param.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <sys/stat.h>
#ifdef _STANDALONE
#include <lib/libkern/libkern.h>
#else
#include <string.h>
#endif
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include "rpcv2.h"
#include "nfsv2.h"
#include <lib/libsa/stand.h>
#include "net.h"
#include "netif.h"
#include "nfs.h"
#include "rpc.h"
/* Define our own NFS attributes. */
struct nfsv2_fattrs {
n_long fa_type;
n_long fa_mode;
n_long fa_nlink;
n_long fa_uid;
n_long fa_gid;
n_long fa_size;
n_long fa_blocksize;
n_long fa_rdev;
n_long fa_blocks;
n_long fa_fsid;
n_long fa_fileid;
struct nfsv2_time fa_atime;
struct nfsv2_time fa_mtime;
struct nfsv2_time fa_ctime;
};
struct nfs_read_args {
u_char fh[NFS_FHSIZE];
n_long off;
n_long len;
n_long xxx; /* XXX what's this for? */
};
/* Data part of nfs rpc reply (also the largest thing we receive) */
#define NFSREAD_SIZE 1024
struct nfs_read_repl {
n_long errno;
struct nfsv2_fattrs fa;
n_long count;
u_char data[NFSREAD_SIZE];
};
#ifndef NFS_NOSYMLINK
struct nfs_readlnk_repl {
n_long errno;
n_long len;
char path[NFS_MAXPATHLEN];
};
#endif
struct nfs_iodesc {
struct iodesc *iodesc;
off_t off;
u_char fh[NFS_FHSIZE];
struct nfsv2_fattrs fa; /* all in network order */
};
int nfs_getrootfh(struct iodesc *, char *, u_char *);
int nfs_lookupfh(struct nfs_iodesc *, const char *, int,
struct nfs_iodesc *);
#ifndef NFS_NOSYMLINK
int nfs_readlink(struct nfs_iodesc *, char *);
#endif
ssize_t nfs_readdata(struct nfs_iodesc *, off_t, void *, size_t);
/*
* Fetch the root file handle (call mount daemon)
* Return zero or error number.
*/
int
nfs_getrootfh(struct iodesc *d, char *path, u_char *fhp)
{
size_t len;
struct args {
n_long len;
char path[FNAME_SIZE];
} *args;
struct repl {
n_long errno;
u_char fh[NFS_FHSIZE];
} *repl;
struct {
n_long h[RPC_HEADER_WORDS];
struct args d;
} sdata;
struct {
n_long h[RPC_HEADER_WORDS];
struct repl d;
} rdata;
ssize_t cc;
#ifdef NFS_DEBUG
if (debug)
printf("nfs_getrootfh: %s\n", path);
#endif
args = &sdata.d;
repl = &rdata.d;
memset(args, 0, sizeof(*args));
len = strlen(path);
if (len > sizeof(args->path))
len = sizeof(args->path);
args->len = htonl(len);
memcpy(args->path, path, len);
len = 4 + roundup(len, 4);
cc = rpc_call(d, RPCPROG_MNT, RPCMNT_VER1, RPCMNT_MOUNT,
args, len, repl, sizeof(*repl));
if (cc == -1) {
/* errno was set by rpc_call */
return (errno);
}
if (cc < 4)
return (EBADRPC);
if (repl->errno)
return (ntohl(repl->errno));
memcpy(fhp, repl->fh, sizeof(repl->fh));
return (0);
}
/*
* Lookup a file. Store handle and attributes.
* Return zero or error number.
*/
int
nfs_lookupfh(struct nfs_iodesc *d, const char *name, int len, struct nfs_iodesc *newfd)
{
int rlen;
struct args {
u_char fh[NFS_FHSIZE];
n_long len;
char name[FNAME_SIZE];
} *args;
struct repl {
n_long errno;
u_char fh[NFS_FHSIZE];
struct nfsv2_fattrs fa;
} *repl;
struct {
n_long h[RPC_HEADER_WORDS];
struct args d;
} sdata;
struct {
n_long h[RPC_HEADER_WORDS];
struct repl d;
} rdata;
ssize_t cc;
#ifdef NFS_DEBUG
if (debug)
printf("lookupfh: called\n");
#endif
args = &sdata.d;
repl = &rdata.d;
memset(args, 0, sizeof(*args));
memcpy(args->fh, d->fh, sizeof(args->fh));
if ((size_t)len > sizeof(args->name))
len = sizeof(args->name);
memcpy(args->name, name, len);
args->len = htonl(len);
len = 4 + roundup(len, 4);
len += NFS_FHSIZE;
rlen = sizeof(*repl);
cc = rpc_call(d->iodesc, NFS_PROG, NFS_VER2, NFSPROC_LOOKUP,
args, len, repl, rlen);
if (cc == -1)
return (errno); /* XXX - from rpc_call */
if (cc < 4)
return (EIO);
if (repl->errno) {
/* saerrno.h now matches NFS error numbers. */
return (ntohl(repl->errno));
}
memcpy(&newfd->fh, repl->fh, sizeof(newfd->fh));
memcpy(&newfd->fa, &repl->fa, sizeof(newfd->fa));
return (0);
}
#ifndef NFS_NOSYMLINK
/*
* Get the destination of a symbolic link.
*/
int
nfs_readlink(struct nfs_iodesc *d, char *buf)
{
struct {
n_long h[RPC_HEADER_WORDS];
u_char fh[NFS_FHSIZE];
} sdata;
struct {
n_long h[RPC_HEADER_WORDS];
struct nfs_readlnk_repl d;
} rdata;
ssize_t cc;
#ifdef NFS_DEBUG
if (debug)
printf("readlink: called\n");
#endif
memcpy(sdata.fh, d->fh, NFS_FHSIZE);
cc = rpc_call(d->iodesc, NFS_PROG, NFS_VER2, NFSPROC_READLINK,
sdata.fh, NFS_FHSIZE,
&rdata.d, sizeof(rdata.d));
if (cc == -1)
return (errno);
if (cc < 4)
return (EIO);
if (rdata.d.errno)
return (ntohl(rdata.d.errno));
rdata.d.len = ntohl(rdata.d.len);
if (rdata.d.len > NFS_MAXPATHLEN)
return (ENAMETOOLONG);
memcpy(buf, rdata.d.path, rdata.d.len);
buf[rdata.d.len] = 0;
return (0);
}
#endif
/*
* Read data from a file.
* Return transfer count or -1 (and set errno)
*/
ssize_t
nfs_readdata(struct nfs_iodesc *d, off_t off, void *addr, size_t len)
{
struct nfs_read_args *args;
struct nfs_read_repl *repl;
struct {
n_long h[RPC_HEADER_WORDS];
struct nfs_read_args d;
} sdata;
struct {
n_long h[RPC_HEADER_WORDS];
struct nfs_read_repl d;
} rdata;
ssize_t cc;
long x;
int hlen, rlen;
args = &sdata.d;
repl = &rdata.d;
memcpy(args->fh, d->fh, NFS_FHSIZE);
args->off = htonl((n_long)off);
if (len > NFSREAD_SIZE)
len = NFSREAD_SIZE;
args->len = htonl((n_long)len);
args->xxx = htonl((n_long)0);
hlen = sizeof(*repl) - NFSREAD_SIZE;
cc = rpc_call(d->iodesc, NFS_PROG, NFS_VER2, NFSPROC_READ,
args, sizeof(*args),
repl, sizeof(*repl));
if (cc == -1) {
/* errno was already set by rpc_call */
return (-1);
}
if (cc < hlen) {
errno = EBADRPC;
return (-1);
}
if (repl->errno) {
errno = ntohl(repl->errno);
return (-1);
}
rlen = cc - hlen;
x = ntohl(repl->count);
if (rlen < x) {
printf("nfsread: short packet, %d < %ld\n", rlen, x);
errno = EBADRPC;
return (-1);
}
memcpy(addr, repl->data, x);
return (x);
}
/*
* Open a file.
* return zero or error number
*/
__compactcall int
nfs_open(const char *path, struct open_file *f)
{
static struct nfs_iodesc nfs_root_node;
struct iodesc *desc;
struct nfs_iodesc *currfd;
const char *cp;
#ifndef NFS_NOSYMLINK
struct nfs_iodesc *newfd;
struct nfsv2_fattrs *fa;
const char *ncp;
int c;
char namebuf[NFS_MAXPATHLEN + 1];
char linkbuf[NFS_MAXPATHLEN + 1];
int nlinks = 0;
#endif
int error;
#ifdef NFS_DEBUG
if (debug)
printf("nfs_open: %s\n", path);
#endif
if (!rootpath[0]) {
printf("no rootpath, no nfs\n");
return (ENXIO);
}
if (!(desc = socktodesc(*(int *)(f->f_devdata))))
return (EINVAL);
/* Bind to a reserved port. */
desc->myport = htons(--rpc_port);
desc->destip = rootip;
if ((error = nfs_getrootfh(desc, rootpath, nfs_root_node.fh)))
return (error);
nfs_root_node.iodesc = desc;
#ifndef NFS_NOSYMLINK
/* Fake up attributes for the root dir. */
fa = &nfs_root_node.fa;
fa->fa_type = htonl(NFDIR);
fa->fa_mode = htonl(0755);
fa->fa_nlink = htonl(2);
currfd = &nfs_root_node;
newfd = 0;
cp = path;
while (*cp) {
/*
* Remove extra separators
*/
while (*cp == '/')
cp++;
if (*cp == '\0')
break;
/*
* Check that current node is a directory.
*/
if (currfd->fa.fa_type != htonl(NFDIR)) {
error = ENOTDIR;
goto out;
}
/* allocate file system specific data structure */
newfd = alloc(sizeof(*newfd));
newfd->iodesc = currfd->iodesc;
newfd->off = 0;
/*
* Get next component of path name.
*/
{
int len = 0;
ncp = cp;
while ((c = *cp) != '\0' && c != '/') {
if (++len > NFS_MAXNAMLEN) {
error = ENOENT;
goto out;
}
cp++;
}
}
/* lookup a file handle */
error = nfs_lookupfh(currfd, ncp, cp - ncp, newfd);
if (error)
goto out;
/*
* Check for symbolic link
*/
if (newfd->fa.fa_type == htonl(NFLNK)) {
int link_len, len;
error = nfs_readlink(newfd, linkbuf);
if (error)
goto out;
link_len = strlen(linkbuf);
len = strlen(cp);
if (link_len + len > MAXPATHLEN
|| ++nlinks > MAXSYMLINKS) {
error = ENOENT;
goto out;
}
memcpy(&namebuf[link_len], cp, len + 1);
memcpy(namebuf, linkbuf, link_len);
/*
* If absolute pathname, restart at root.
* If relative pathname, restart at parent directory.
*/
cp = namebuf;
if (*cp == '/') {
if (currfd != &nfs_root_node)
dealloc(currfd, sizeof(*currfd));
currfd = &nfs_root_node;
}
dealloc(newfd, sizeof(*newfd));
newfd = 0;
continue;
}
if (currfd != &nfs_root_node)
dealloc(currfd, sizeof(*currfd));
currfd = newfd;
newfd = 0;
}
error = 0;
out:
if (newfd)
dealloc(newfd, sizeof(*newfd));
#else
/* allocate file system specific data structure */
currfd = alloc(sizeof(*currfd));
currfd->iodesc = desc;
currfd->off = 0;
cp = path;
/*
* Remove extra separators
*/
while (*cp == '/')
cp++;
/* XXX: Check for empty path here? */
error = nfs_lookupfh(&nfs_root_node, cp, strlen(cp), currfd);
#endif
if (!error) {
f->f_fsdata = (void *)currfd;
fsmod = "nfs";
return (0);
}
#ifdef NFS_DEBUG
if (debug)
printf("nfs_open: %s lookupfh failed: %s\n",
path, strerror(error));
#endif
#ifndef NFS_NOSYMLINK
if (currfd != &nfs_root_node)
#endif
dealloc(currfd, sizeof(*currfd));
return (error);
}
__compactcall int
nfs_close(struct open_file *f)
{
struct nfs_iodesc *fp = (struct nfs_iodesc *)f->f_fsdata;
#ifdef NFS_DEBUG
if (debug)
printf("nfs_close: fp=0x%lx\n", (u_long)fp);
#endif
if (fp)
dealloc(fp, sizeof(struct nfs_iodesc));
f->f_fsdata = (void *)0;
return (0);
}
/*
* read a portion of a file
*/
__compactcall int
nfs_read(struct open_file *f, void *buf, size_t size, size_t *resid)
/* resid: out */
{
struct nfs_iodesc *fp = (struct nfs_iodesc *)f->f_fsdata;
ssize_t cc;
char *addr = buf;
#ifdef NFS_DEBUG
if (debug)
printf("nfs_read: size=%lu off=%d\n", (u_long)size,
(int)fp->off);
#endif
while ((int)size > 0) {
#if !defined(LIBSA_NO_TWIDDLE)
twiddle();
#endif
cc = nfs_readdata(fp, fp->off, (void *)addr, size);
/* XXX maybe should retry on certain errors */
if (cc == -1) {
#ifdef NFS_DEBUG
if (debug)
printf("nfs_read: read: %s", strerror(errno));
#endif
return (errno); /* XXX - from nfs_readdata */
}
if (cc == 0) {
#ifdef NFS_DEBUG
if (debug)
printf("nfs_read: hit EOF unexpectantly");
#endif
goto ret;
}
fp->off += cc;
addr += cc;
size -= cc;
}
ret:
if (resid)
*resid = size;
return (0);
}
/*
* Not implemented.
*/
__compactcall int
nfs_write(struct open_file *f, void *buf, size_t size, size_t *resid)
/* resid: out */
{
return (EROFS);
}
__compactcall off_t
nfs_seek(struct open_file *f, off_t offset, int where)
{
struct nfs_iodesc *d = (struct nfs_iodesc *)f->f_fsdata;
n_long size = ntohl(d->fa.fa_size);
switch (where) {
case SEEK_SET:
d->off = offset;
break;
case SEEK_CUR:
d->off += offset;
break;
case SEEK_END:
d->off = size - offset;
break;
default:
return (-1);
}
return (d->off);
}
/* NFNON=0, NFREG=1, NFDIR=2, NFBLK=3, NFCHR=4, NFLNK=5 */
const int nfs_stat_types[8] = {
0, S_IFREG, S_IFDIR, S_IFBLK, S_IFCHR, S_IFLNK, 0 };
__compactcall int
nfs_stat(struct open_file *f, struct stat *sb)
{
struct nfs_iodesc *fp = (struct nfs_iodesc *)f->f_fsdata;
n_long ftype, mode;
ftype = ntohl(fp->fa.fa_type);
mode = ntohl(fp->fa.fa_mode);
mode |= nfs_stat_types[ftype & 7];
sb->st_mode = mode;
sb->st_nlink = ntohl(fp->fa.fa_nlink);
sb->st_uid = ntohl(fp->fa.fa_uid);
sb->st_gid = ntohl(fp->fa.fa_gid);
sb->st_size = ntohl(fp->fa.fa_size);
return (0);
}
#if defined(LIBSA_ENABLE_LS_OP)
__compactcall void
nfs_ls(struct open_file *f, const char *pattern)
{
printf("Currently ls command is unsupported by nfs\n");
return;
}
#endif
+7 -11
View File
@@ -25,25 +25,21 @@ BINMODE= 444
.PATH: ${.CURDIR}/..
LDFLAGS+= -nostdlib -Wl,-e,start
# MINIX LSC DO we need to remove the includes??
CPPFLAGS+= -I. -I${.CURDIR}/../../lib #-I${S}
CPPFLAGS+= -I. -I${.CURDIR}/../../lib -I${S}
.if defined(__MINIX)
CPPFLAGS+= -DLOADADDR=${LOADADDR}
AFLAGS+= -Wa,--divide
.endif
.if ${MACHINE_ARCH} == "x86_64"
LDFLAGS+= -Wl,-m,elf_i386
AFLAGS+= -m32
.endif
AFLAGS+= "-Wa,--divide"
BUILDSYMLINKS+= $S/arch/i386/include machine \
$S/arch/x86/include x86
# NetBSD can be compiled from a foreign host, MINIX do not. So commented out.
# Make sys/ a local thing for benefit of cross-compilers
#S= ${.CURDIR}/../../../../..
#CPPFLAGS+= -I${S}
# And same for machine/; need a bit more work because of symlink
#BUILDSYMLINKS+= $S/arch/i386/include machine \
# $S/arch/x86/include x86
#DPSRCS+= machine x86
DPSRCS+= machine x86
CLEANFILES+= ${PROG}.tmp