diff options
author | Ludovic Courtès <ludo@gnu.org> | 2010-07-17 16:24:39 +0200 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2011-04-03 15:47:34 +0000 |
commit | a8744157214a302d84c8959b1ae99abe3ae2d7d2 (patch) | |
tree | 1cfebbd27e311beee3a6a1660ff7d08624ca20d8 | |
parent | bebc64a9a0f064a0e5f8a3549aa01aa9ac79a2e9 (diff) |
Remove `serverboot'; fix "make dist" in `mach-defpager'.
* serverboot/default_pager.c, serverboot/kalloc.c, serverboot/queue.h,
serverboot/wiring.c, serverboot/wiring.h: Move to `mach-defpager/'.
* serverboot/Makefile, serverboot/assert.h, serverboot/bootstrap.c,
serverboot/bunzip2.c, serverboot/def_pager_setup.c, serverboot/defs.h,
serverboot/dir.h, serverboot/disk_inode.h,
serverboot/disk_inode_ffs.h, serverboot/elf-load.c, serverboot/exec.c,
serverboot/ext2_file_io.c, serverboot/ffs_compat.c,
serverboot/ffs_compat.h, serverboot/ffs_file_io.c,
serverboot/file_io.c, serverboot/file_io.h, serverboot/fs.h,
serverboot/gets.c, serverboot/gunzip.c, serverboot/load.c,
serverboot/mach-exec.h, serverboot/minix_ffs_compat.c,
serverboot/minix_ffs_compat.h, serverboot/minix_file_io.c,
serverboot/minix_fs.h, serverboot/minix_super.h, serverboot/panic.c,
serverboot/strfcns.c: Remove.
* mach-defpager/Makefile (LCLHDRS): New variable.
(vpath): Remove.
(CPPFLAGS): Remove `-I$(srcdir)/../serverboot'.
* mach-defpager/setup.c (page_aligned): Make public.
36 files changed, 3 insertions, 6844 deletions
diff --git a/mach-defpager/Makefile b/mach-defpager/Makefile index 5ed8f11f..51476552 100644 --- a/mach-defpager/Makefile +++ b/mach-defpager/Makefile @@ -1,6 +1,6 @@ # Makefile for mach-defpager subdirectory of hurd sources # -# Copyright (C) 1999, 2000, 2002, 2007 Free Software Foundation, Inc. +# Copyright (C) 1999, 2000, 2002, 2007, 2010 Free Software Foundation, Inc. # # This file is part of the GNU Hurd. # @@ -27,15 +27,13 @@ OBJS := $(SRCS:.c=.o) \ $(addsuffix Server.o,\ memory_object default_pager memory_object_default exc) \ default_pager_replyUser.o +LCLHDRS := file_io.h queue.h wiring.h HURDLIBS:= threads LDFLAGS += -static include ../Makeconf -vpath %.c $(srcdir)/../serverboot -CPPFLAGS += -I$(srcdir)/../serverboot - MIGSFLAGS = -DSEQNOS # Don't even bother. diff --git a/serverboot/default_pager.c b/mach-defpager/default_pager.c index 41c2768d..41c2768d 100644 --- a/serverboot/default_pager.c +++ b/mach-defpager/default_pager.c diff --git a/serverboot/kalloc.c b/mach-defpager/kalloc.c index 28c0b55e..28c0b55e 100644 --- a/serverboot/kalloc.c +++ b/mach-defpager/kalloc.c diff --git a/serverboot/queue.h b/mach-defpager/queue.h index 00619174..00619174 100644 --- a/serverboot/queue.h +++ b/mach-defpager/queue.h diff --git a/mach-defpager/setup.c b/mach-defpager/setup.c index e7e89299..05c19f33 100644 --- a/mach-defpager/setup.c +++ b/mach-defpager/setup.c @@ -27,7 +27,7 @@ #include "default_pager_S.h" /* This should be in some system header... XXX */ -static inline int page_aligned (vm_offset_t num) +int page_aligned (vm_offset_t num) { return trunc_page (num) == num; } diff --git a/serverboot/wiring.c b/mach-defpager/wiring.c index 585a3075..585a3075 100644 --- a/serverboot/wiring.c +++ b/mach-defpager/wiring.c diff --git a/serverboot/wiring.h b/mach-defpager/wiring.h index b5f8e53f..b5f8e53f 100644 --- a/serverboot/wiring.h +++ b/mach-defpager/wiring.h diff --git a/serverboot/Makefile b/serverboot/Makefile deleted file mode 100644 index 653d5963..00000000 --- a/serverboot/Makefile +++ /dev/null @@ -1,53 +0,0 @@ -# Copyright (C) 1997,99,2001,02 Free Software Foundation, Inc. -# This file is part of the GNU Hurd. -# -# The GNU Hurd is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2, or (at your option) -# any later version. -# -# The GNU Hurd is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with the GNU Hurd; see the file COPYING. If not, write to -# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. - -dir := serverboot -makemode := utility - -SRCS = bootstrap.c ffs_compat.c load.c wiring.c \ - ffs_file_io.c minix_ffs_compat.c file_io.c \ - minix_file_io.c ext2_file_io.c strfcns.c exec.c \ - panic.c elf-load.c gunzip.c bunzip2.c -LCLHDRS = assert.h disk_inode_ffs.h fs.h queue.h defs.h \ - minix_ffs_compat.h wiring.h dir.h ffs_compat.h minix_fs.h \ - disk_inode.h file_io.h minix_super.h mach-exec.h -EXTRA_DIST = def_pager_setup.c default_pager.c kalloc.c -target = serverboot -HURDLIBS = threads -installationdir = $(bootdir) - -UNZIP_OBJS = unzip.o inflate.o util.o do-bunzip2.o -OBJS = $(subst .c,.o,$(SRCS)) \ - boot_script.o userland-boot.o \ - $(UNZIP_OBJS) - -include ../Makeconf - -vpath boot_script.c $(srcdir)/../boot -vpath userland-boot.c $(srcdir)/../boot - -# Look for zip stuff -vpath %.c $(srcdir) $(srcdir)/../exec - -# If SMALL_BZIP2 is defined, use relatively small memory. -# It's crucial for serverboot, because swap is not enabled yet. -CPPFLAGS += -I$(srcdir)/../exec -DGZIP -DBZIP2 -DSMALL_BZIP2 - -LDFLAGS += -static - -# Don't even bother. -CFLAGS := $(filter-out -Wall,$(CFLAGS)) diff --git a/serverboot/assert.h b/serverboot/assert.h deleted file mode 100644 index 9f70aec3..00000000 --- a/serverboot/assert.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Mach Operating System - * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University - * All Rights Reserved. - * - * Permission to use, copy, modify and distribute this software and its - * documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" - * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR - * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to - * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 - * - * any improvements or extensions that they make and grant Carnegie Mellon - * the rights to redistribute these changes. - */ - -#ifndef _ASSERT_H_ -#define _ASSERT_H_ - -#ifdef ASSERTIONS -extern void Assert(); - -#define assert(ex) \ - do { \ - if (!(ex)) \ - Assert(__FILE__, __LINE__); \ - } while (0) - -#ifdef lint -#define assert_static(x) -#else /* lint */ -#define assert_static(x) assert(x) -#endif /* lint */ - -#else /* ASSERTIONS */ -#define assert(ex) -#define assert_static(ex) -#endif /* ASSERTIONS */ - -#endif /* _ASSERT_H_ */ diff --git a/serverboot/bootstrap.c b/serverboot/bootstrap.c deleted file mode 100644 index 64f7c5eb..00000000 --- a/serverboot/bootstrap.c +++ /dev/null @@ -1,438 +0,0 @@ -/* - * Mach Operating System - * Copyright (c) 1992,1991,1990,1989 Carnegie Mellon University - * All Rights Reserved. - * - * Permission to use, copy, modify and distribute this software and its - * documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS - * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR - * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to - * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 - * - * any improvements or extensions that they make and grant Carnegie the - * rights to redistribute these changes. - */ -/* - * Bootstrap the various built-in servers. - */ - -#include <mach.h> -#include <mach/message.h> -#include <sys/reboot.h> - -#include <file_io.h> - -#include <stdio.h> -#include <string.h> - -#include "../boot/boot_script.h" - -#if 0 -/* - * Use 8 Kbyte stacks instead of the default 64K. - * Use 4 Kbyte waiting stacks instead of the default 8K. - */ -#if defined(alpha) -vm_size_t cthread_stack_size = 16 * 1024; -#else -vm_size_t cthread_stack_size = 8 * 1024; -#endif -#endif - -extern -vm_size_t cthread_wait_stack_size; - -mach_port_t bootstrap_master_device_port; /* local name */ -mach_port_t bootstrap_master_host_port; /* local name */ - -int boot_load_program(); - -char *root_name; -char boot_script_name[MAXPATHLEN]; - -extern void default_pager(); -extern void default_pager_initialize(); -extern void default_pager_setup(); - -/* - * Convert ASCII to integer. - */ -int atoi(str) - register const char *str; -{ - register int n; - register int c; - int is_negative = 0; - - n = 0; - while (*str == ' ') - str++; - if (*str == '-') { - is_negative = 1; - str++; - } - while ((c = *str++) >= '0' && c <= '9') { - n = n * 10 + (c - '0'); - } - if (is_negative) - n = -n; - return (n); -} - -__main () -{ -} - -static void -boot_panic (kern_return_t err) -{ -#define PFX "bootstrap: " - char *err_string = boot_script_error_string (err); - char panic_string[strlen (err_string) + sizeof (PFX)]; - strcpy (panic_string, PFX); - strcat (panic_string, err_string); - panic (panic_string); -#undef PFX -} - -void -safe_gets (char *str, int maxlen) -{ - char *c = fgets (str, maxlen, stdin); - if (c == 0) { - perror ("fgets"); - panic ("cannot read from console"); - } - c = strchr (c, '\n'); - if (c) - *c = '\0'; - printf ("\r\n"); -} - -printf_init (device_t master) -{ - mach_port_t cons; - kern_return_t rc; - rc = device_open (master, D_READ|D_WRITE, "console", &cons); - if (rc) - while (1) { - volatile int x = 0; - (void) host_reboot(bootstrap_master_host_port, RB_DEBUGGER); - x = x / x; - } - stdin = mach_open_devstream (cons, "r"); - stdout = stderr = mach_open_devstream (cons, "w"); - mach_port_deallocate (mach_task_self (), cons); - setbuf (stdout, 0); -} - -/* - * Bootstrap task. - * Runs in user spacep. - * - * Called as 'boot -switches host_port device_port root_name' - * - */ -main(argc, argv) - int argc; - char **argv; -{ - int die = 0; - int script_paging_file (const struct cmd *cmd, integer_t *val) - { - printf ("*** paging files no longer supported in boot scripts ***\n\a" - "*** use swapon %s and/or /etc/fstab instead ***\n", - cmd->path); - return 0; - } - int script_serverboot_ctl (const struct cmd *cmd, integer_t *val) - { - const char *const ctl = cmd->path; - if (!strcmp (ctl, "die")) - die = 1; - else - printf ("(serverboot): Unknown control word `%s' ignored\n", ctl); - return 0; - } - - void prompt_for_root () - { - static char new_root[MAXPATHLEN/2]; - - if (!root_name) - root_name = "UNKNOWN"; - printf ("Root device name? [%s] ", root_name); - safe_gets(new_root, sizeof(new_root)); - - if (new_root[0] != '\0') { - root_name = new_root; - (void) strbuild(boot_script_name, - "/dev/", - root_name, - "/boot/servers.boot", - (char *)0); - } - } - - register kern_return_t result; - struct file scriptf; - - task_t my_task = mach_task_self(); - - char *flag_string; - - boolean_t ask_boot_script = 0; - boolean_t ask_root_name = 0; - - /* - * Use 4Kbyte cthread wait stacks. - */ - cthread_wait_stack_size = 4 * 1024; - - /* - * Arg 1 is flags - */ - if (argv[1][0] != '-') - panic("bootstrap: no flags"); - - flag_string = argv[1]; - - /* - * Parse the arguments. - */ - if (argc >= 5) - { - /* - * Arg 0 is program name - */ - - /* - * Arg 2 is host port number - */ - bootstrap_master_host_port = atoi(argv[2]); - - /* - * Arg 3 is device port number - */ - bootstrap_master_device_port = atoi(argv[3]); - - /* - * Arg 4 is root name - */ - root_name = argv[4]; - } - else if (argc == 3) - { - root_name = argv[2]; - - get_privileged_ports (&bootstrap_master_host_port, - &bootstrap_master_device_port); - } - - printf_init(bootstrap_master_device_port); -#ifdef pleasenoXXX - panic_init(bootstrap_master_host_port); -#endif - - - /* - * If the '-a' (ask) switch was specified, or if no - * root device was specificed, ask for the root device. - */ - - if (!root_name || root_name [0] == '\0' || index(flag_string, 'a')) - prompt_for_root (); - - (void) strbuild(boot_script_name, - "/dev/", - root_name, - "/boot/servers.boot", - (char *)0); - /* - * If the '-q' (query) switch was specified, ask for the - * server boot script. - */ - - if (index(flag_string, 'q')) - ask_boot_script = TRUE; - - while (TRUE) { - if (ask_root_name) - prompt_for_root (); - - if (ask_boot_script) { - char new_boot_script[MAXPATHLEN]; - - printf("Server boot script? [%s] ", boot_script_name); - safe_gets(new_boot_script, sizeof(new_boot_script)); - if (new_boot_script[0] != '\0') - strcpy(boot_script_name, new_boot_script); - } - - result = open_file(bootstrap_master_device_port, - boot_script_name, - &scriptf); - if (result == D_NO_SUCH_DEVICE) - { - printf ("Root device `%s' does not exist!\n", root_name); - ask_root_name = ask_boot_script = TRUE; - continue; - } - else - ask_root_name = FALSE; - if (result != 0) { - printf("Can't open server boot script %s: %s\n", - boot_script_name, - strerror (result)); - ask_boot_script = TRUE; - continue; - } - break; - } - - /* - * If the server boot script name was changed, - * then use the new device name as the root device. - */ - { - char *dev, *end; - int len; - - dev = boot_script_name; - if (strncmp(dev, "/dev/", 5) == 0) - dev += 5; - end = strchr(dev, '/'); - len = end ? end-dev : strlen(dev); - memcpy(root_name, dev, len); - root_name[len] = 0; - } - - { - char *cmdline; - - /* Initialize boot script variables. */ - if (boot_script_set_variable ("host-port", VAL_PORT, - (integer_t) bootstrap_master_host_port) - || boot_script_set_variable ("device-port", VAL_PORT, - (integer_t) bootstrap_master_device_port) - || boot_script_set_variable ("root-device", VAL_STR, - (integer_t) root_name) - || boot_script_set_variable ("boot-args", VAL_STR, - (integer_t) flag_string) - || boot_script_define_function ("add-paging-file", VAL_NONE, - &script_paging_file) - || boot_script_define_function ("add-raw-paging-file", VAL_NONE, - &script_paging_file) - || boot_script_define_function ("add-linux-paging-file", - VAL_NONE, - &script_paging_file) - || boot_script_define_function ("serverboot", - VAL_NONE, - &script_serverboot_ctl) - ) - panic ("bootstrap: error setting boot script variables"); - - cmdline = getenv ("MULTIBOOT_CMDLINE"); - if (cmdline != NULL - && boot_script_set_variable ("kernel-command-line", - VAL_STR, - (integer_t) cmdline)) - panic ("bootstrap: error setting boot script variables"); - - parse_script (&scriptf); - close_file (&scriptf); - } - - if (index (flag_string, 'd')) - { - char xx[5]; - printf ("Hit return to boot..."); - safe_gets (xx, sizeof xx); - } - - result = boot_script_exec (); - - if (result) - boot_panic (result); - -#if 0 - { - /* - * Delete the old stack (containing only the arguments). - */ - vm_offset_t addr = (vm_offset_t) argv; - - vm_offset_t r_addr; - vm_size_t r_size; - vm_prot_t r_protection, r_max_protection; - vm_inherit_t r_inheritance; - boolean_t r_is_shared; - memory_object_name_t r_object_name; - vm_offset_t r_offset; - kern_return_t kr; - - r_addr = addr; - - kr = vm_region(my_task, - &r_addr, - &r_size, - &r_protection, - &r_max_protection, - &r_inheritance, - &r_is_shared, - &r_object_name, - &r_offset); - if ((kr == KERN_SUCCESS) && MACH_PORT_VALID(r_object_name)) - (void) mach_port_deallocate(my_task, r_object_name); - if ((kr == KERN_SUCCESS) && - (r_addr <= addr) && - ((r_protection & (VM_PROT_READ|VM_PROT_WRITE)) == - (VM_PROT_READ|VM_PROT_WRITE))) - (void) vm_deallocate(my_task, r_addr, r_size); - } -#endif - - printf ("(serverboot): terminating\n"); - while (1) - task_terminate (mach_task_self ()); - /*NOTREACHED*/ -} - -/* Parse the boot script. */ -parse_script (struct file *f) -{ - char *p, *line, *buf; - int amt, fd, err; - int n = 0; - - buf = malloc (f->f_size + 1); /* add one for null terminator we will write */ - err = read_file (f, 0, buf, f->f_size, 0); - if (err) - panic ("bootstrap: error reading boot script file: %s", strerror (err)); - - line = p = buf; - while (1) - { - while (p < buf + f->f_size && *p != '\n') - p++; - *p = '\0'; - err = boot_script_parse_line (0, line); - if (err) - boot_panic (err); - if (p == buf + f->f_size) - break; - line = ++p; - } - free (buf); -} diff --git a/serverboot/bunzip2.c b/serverboot/bunzip2.c deleted file mode 100644 index 9f79ade5..00000000 --- a/serverboot/bunzip2.c +++ /dev/null @@ -1,169 +0,0 @@ -/* Modified by okuji@kuicr.kyoto-u.ac.jp for use in serverboot. */ -/* Decompressing store backend - - Copyright (C) 1997 Free Software Foundation, Inc. - Written by Miles Bader <miles@gnu.ai.mit.edu> - This file is part of the GNU Hurd. - - The GNU Hurd is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2, or (at - your option) any later version. - - The GNU Hurd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ - -#include <stdio.h> -#include <string.h> -#include <setjmp.h> -#include <cthreads.h> -#include <errno.h> - -#include <file_io.h> - -#define IN_BUFFERING (256*1024) -#define OUT_BUFFERING (512*1024) - -static struct mutex bunzip2_lock = MUTEX_INITIALIZER; - -/* Uncompress the contents of FROM, which should contain a valid bzip2 file, - into memory, returning the result buffer in BUF & BUF_LEN. */ -int -serverboot_bunzip2 (struct file *from, void **buf, size_t *buf_len) -{ - /* Callbacks from do_bunzip2 for I/O and error interface. */ - extern int (*unzip_read) (char *buf, size_t maxread); - extern void (*unzip_write) (const char *buf, size_t nwrite); - extern void (*unzip_read_error) (void); - extern void (*unzip_error) (const char *msg); - - /* How we return errors from our hook functions. */ - jmp_buf zerr_jmp_buf; - int zerr; - - size_t offset = 0; /* Offset of read point in FROM. */ - - /* Read at most MAXREAD (or 0 if eof) bytes into BUF from our current - position in FROM. */ - int zread (char *buf, size_t maxread) - { - vm_size_t resid; - size_t did_read; - - if (from->f_size - offset < maxread) - did_read = from->f_size - offset; - else - did_read = maxread; - - zerr = read_file (from, offset, buf, did_read, &resid); - if (zerr) - longjmp (zerr_jmp_buf, 1); - - did_read -= resid; - offset += did_read; - - return did_read; - } - - size_t out_buf_offs = 0; /* Position in the output buffer. */ - - /* Write uncompress data to our output buffer. */ - void zwrite (const char *wbuf, size_t nwrite) - { - size_t old_buf_len = *buf_len; - - if (out_buf_offs + nwrite > old_buf_len) - /* Have to grow the output buffer. */ - { - void *old_buf = *buf; - void *new_buf = old_buf + old_buf_len; /* First try. */ - size_t new_buf_len = round_page (old_buf_len + old_buf_len + nwrite); - - /* Try to grow the buffer. */ - zerr = - vm_allocate (mach_task_self (), - (vm_address_t *)&new_buf, new_buf_len - old_buf_len, - 0); - if (zerr) - /* Can't do that, try to make a bigger buffer elsewhere. */ - { - new_buf = old_buf; - zerr = - vm_allocate (mach_task_self (), - (vm_address_t *)&new_buf, new_buf_len, 1); - if (zerr) - longjmp (zerr_jmp_buf, 1); - - if (out_buf_offs > 0) - /* Copy the old buffer into the start of the new & free it. */ - bcopy (old_buf, new_buf, out_buf_offs); - - vm_deallocate (mach_task_self (), - (vm_address_t)old_buf, old_buf_len); - - *buf = new_buf; - } - - *buf_len = new_buf_len; - } - - bcopy (wbuf, *buf + out_buf_offs, nwrite); - out_buf_offs += nwrite; - } - - void zreaderr (void) - { - zerr = EIO; - longjmp (zerr_jmp_buf, 1); - } - void zerror (const char *msg) - { - zerr = EINVAL; - longjmp (zerr_jmp_buf, 2); - } - - /* Try to guess a reasonable output buffer size. */ - *buf_len = round_page (from->f_size * 2); - zerr = vm_allocate (mach_task_self (), (vm_address_t *)buf, *buf_len, 1); - if (zerr) - return zerr; - - mutex_lock (&bunzip2_lock); - - unzip_read = zread; - unzip_write = zwrite; - unzip_read_error = zreaderr; - unzip_error = zerror; - - if (! setjmp (zerr_jmp_buf)) - { - /* Call the bunzip2 engine. */ - do_bunzip2 (); - zerr = 0; - } - - mutex_unlock (&bunzip2_lock); - - if (zerr) - { - if (*buf_len > 0) - vm_deallocate (mach_task_self (), (vm_address_t)*buf, *buf_len); - } - else if (out_buf_offs < *buf_len) - /* Trim the output buffer to be the right length. */ - { - size_t end = round_page (out_buf_offs); - if (end < *buf_len) - vm_deallocate (mach_task_self (), - (vm_address_t)(*buf + end), *buf_len - end); - *buf_len = out_buf_offs; - } - - return zerr; -} diff --git a/serverboot/def_pager_setup.c b/serverboot/def_pager_setup.c deleted file mode 100644 index 5e2073ec..00000000 --- a/serverboot/def_pager_setup.c +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Mach Operating System - * Copyright (c) 1992-1989 Carnegie Mellon University - * All Rights Reserved. - * - * Permission to use, copy, modify and distribute this software and its - * documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" - * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR - * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to - * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 - * - * any improvements or extensions that they make and grant Carnegie Mellon - * the rights to redistribute these changes. - */ -#include <mach.h> -#include <mach/mig_errors.h> -#include <mach/default_pager_types.h> - -#include <file_io.h> - -extern void *kalloc(); - -/* - * Create a paging partition given a file name - */ -extern void create_paging_partition(); - -kern_return_t -add_paging_file(master_device_port, file_name, linux_signature) - mach_port_t master_device_port; - char *file_name; - int linux_signature; -{ - register struct file_direct *fdp; - register kern_return_t result; - struct file pfile; - boolean_t isa_file; - - bzero((char *) &pfile, sizeof(struct file)); - - result = open_file(master_device_port, file_name, &pfile); - if (result != KERN_SUCCESS) - return result; - - fdp = (struct file_direct *) kalloc(sizeof *fdp); - bzero((char *) fdp, sizeof *fdp); - - isa_file = file_is_structured(&pfile); - - result = open_file_direct(pfile.f_dev, fdp, isa_file); - if (result) - panic("Can't open paging file %s: %s\n", - file_name, strerror (result)); - - result = add_file_direct(fdp, &pfile); - if (result) - panic("Can't read disk addresses: %s\n", strerror (result)); - - close_file(&pfile); - - /* - * Set up the default paging partition - */ - create_paging_partition(file_name, fdp, isa_file, linux_signature); - - return result; -} - -/* - * Destroy a paging_partition given a file name - */ -kern_return_t -remove_paging_file(file_name) - char *file_name; -{ - struct file_direct *fdp = 0; - kern_return_t kr; - - kr = destroy_paging_partition(file_name, &fdp); - if (kr == KERN_SUCCESS) { - remove_file_direct(fdp); - kfree(fdp, sizeof(*fdp)); - } - return kr; -} - -kern_return_t -default_pager_paging_storage (mach_port_t pager, - mach_port_t device, - recnum_t *runs, mach_msg_type_number_t nrun, - default_pager_filename_t name, - boolean_t add) -{ - return MIG_BAD_ID; -} - -#if 0 /* no longer used */ -/* - * Set up default pager - */ -extern char *strbuild(); - -boolean_t -default_pager_setup(master_device_port, server_dir_name) - mach_port_t master_device_port; - char *server_dir_name; -{ - register kern_return_t result; - - char paging_file_name[MAXPATHLEN+1]; - - (void) strbuild(paging_file_name, - server_dir_name, - "/paging_file", - (char *)0); - - while (TRUE) { - result = add_paging_file(master_device_port, paging_file_name); - if (result == KERN_SUCCESS) - break; - printf("Can't open paging file %s: %d\n", - paging_file_name, - result); - - bzero(paging_file_name, sizeof(paging_file_name)); - printf("Paging file name ? "); - safe_gets(paging_file_name, sizeof(paging_file_name)); - - if (paging_file_name[0] == 0) { - printf("*** WARNING: running without paging area!\n"); - return FALSE; - } - } - - /* - * Our caller will become the default pager - later - */ - - return TRUE; -} -#endif diff --git a/serverboot/defs.h b/serverboot/defs.h deleted file mode 100644 index 7b872fd6..00000000 --- a/serverboot/defs.h +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Mach Operating System - * Copyright (c) 1991,1990 Carnegie Mellon University - * All Rights Reserved. - * - * Permission to use, copy, modify and distribute this software and its - * documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" - * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR - * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to - * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 - * - * any improvements or extensions that they make and grant Carnegie Mellon - * the rights to redistribute these changes. - */ -/* - * Common definitions for Berkeley Fast File System. - */ - -/* - * Compatibility definitions for disk IO. - */ - -/* - * Disk devices do all IO in 512-byte blocks. - */ -#define DEV_BSIZE 512 - -/* - * Conversion between bytes and disk blocks. - */ -#define btodb(byte_offset) ((byte_offset) >> 9) -#define dbtob(block_number) ((block_number) << 9) - -/* - * Compatibility definitions for old type names. - */ - -typedef struct _quad_ { - unsigned int val[2]; /* 2 int values make... */ -} quad; /* an 8-byte item */ - -#if 0 -typedef unsigned char u_char; /* unsigned char */ -typedef unsigned short u_short; /* unsigned short */ -typedef unsigned int u_int; /* unsigned int */ - -typedef unsigned int time_t; /* an unsigned int */ -typedef unsigned int daddr_t; /* an unsigned int */ -typedef unsigned int off_t; /* another unsigned int */ - -typedef unsigned short uid_t; -typedef unsigned short gid_t; -typedef unsigned int ino_t; -#endif - -#define NBBY 8 - -/* - * The file system is made out of blocks of at most MAXBSIZE units, - * with smaller units (fragments) only in the last direct block. - * MAXBSIZE primarily determines the size of buffers in the buffer - * pool. It may be made larger without any effect on existing - * file systems; however, making it smaller may make some file - * systems unmountable. - * - * Note that the disk devices are assumed to have DEV_BSIZE "sectors" - * and that fragments must be some multiple of this size. - */ -#define MAXBSIZE 8192 -#define MAXFRAG 8 - -/* - * MAXPATHLEN defines the longest permissible path length - * after expanding symbolic links. - * - * MAXSYMLINKS defines the maximum number of symbolic links - * that may be expanded in a path name. It should be set - * high enough to allow all legitimate uses, but halt infinite - * loops reasonably quickly. - */ - -#define MAXPATHLEN 1024 -#define MAXSYMLINKS 8 - diff --git a/serverboot/dir.h b/serverboot/dir.h deleted file mode 100644 index 208df5ce..00000000 --- a/serverboot/dir.h +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Mach Operating System - * Copyright (c) 1991,1990 Carnegie Mellon University - * All Rights Reserved. - * - * Permission to use, copy, modify and distribute this software and its - * documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" - * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR - * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to - * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 - * - * any improvements or extensions that they make and grant Carnegie Mellon - * the rights to redistribute these changes. - */ -/* - * Copyright (c) 1982, 1986, 1989 The Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms are permitted - * provided that the above copyright notice and this paragraph are - * duplicated in all such forms and that any documentation, - * advertising materials, and other materials related to such - * distribution and use acknowledge that the software was developed - * by the University of California, Berkeley. The name of the - * University may not be used to endorse or promote products derived - * from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. - * - * @(#)dir.h 7.6 (Berkeley) 5/9/89 - */ - -#ifndef _BOOT_UFS_DIR_H_ -#define _BOOT_UFS_DIR_H_ - -/* - * A directory consists of some number of blocks of DIRBLKSIZ - * bytes, where DIRBLKSIZ is chosen such that it can be transferred - * to disk in a single atomic operation (e.g. 512 bytes on most machines). - * - * Each DIRBLKSIZ byte block contains some number of directory entry - * structures, which are of variable length. Each directory entry has - * a struct direct at the front of it, containing its inode number, - * the length of the entry, and the length of the name contained in - * the entry. These are followed by the name padded to a 4 byte boundary - * with null bytes. All names are guaranteed null terminated. - * The maximum length of a name in a directory is MAXNAMLEN. - * - * The macro DIRSIZ(dp) gives the amount of space required to represent - * a directory entry. Free space in a directory is represented by - * entries which have dp->d_reclen > DIRSIZ(dp). All DIRBLKSIZ bytes - * in a directory block are claimed by the directory entries. This - * usually results in the last entry in a directory having a large - * dp->d_reclen. When entries are deleted from a directory, the - * space is returned to the previous entry in the same directory - * block by increasing its dp->d_reclen. If the first entry of - * a directory block is free, then its dp->d_ino is set to 0. - * Entries other than the first in a directory do not normally have - * dp->d_ino set to 0. - */ -#define DIRBLKSIZ DEV_BSIZE -#define MAXNAMLEN 255 - -struct direct { - u_int d_ino; /* inode number of entry */ - u_short d_reclen; /* length of this record */ - u_short d_namlen; /* length of string in d_name */ - char d_name[MAXNAMLEN + 1]; /* name with length <= MAXNAMLEN */ -}; - -/* - * The DIRSIZ macro gives the minimum record length which will hold - * the directory entry. This requires the amount of space in struct direct - * without the d_name field, plus enough space for the name with a terminating - * null byte (dp->d_namlen+1), rounded up to a 4 byte boundary. - */ -#undef DIRSIZ -#define DIRSIZ(dp) \ - ((sizeof (struct direct) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3)) - -#ifdef KERNEL -/* - * Template for manipulating directories. - * Should use struct direct's, but the name field - * is MAXNAMLEN - 1, and this just won't do. - */ -struct dirtemplate { - u_int dot_ino; - short dot_reclen; - short dot_namlen; - char dot_name[4]; /* must be multiple of 4 */ - u_int dotdot_ino; - short dotdot_reclen; - short dotdot_namlen; - char dotdot_name[4]; /* ditto */ -}; -#endif - -/* - * The following information should be obtained from <dirent.h> - * and is provided solely (and temporarily) for backward compatibility. - */ -#ifndef KERNEL -#define d_fileno d_ino /* compatibility with POSIX */ -#ifndef DEV_BSIZE -#define DEV_BSIZE 512 -#endif -/* - * Definitions for library routines operating on directories. - */ -typedef struct _dirdesc { - int dd_fd; - int dd_loc; - int dd_size; - char dd_buf[DIRBLKSIZ]; -} DIR; - -#define dirfd(dirp) ((dirp)->dd_fd) - -#ifndef NULL -#define NULL 0 -#endif -extern DIR *opendir(); -extern struct direct *readdir(); -extern int telldir(); -extern void seekdir(); -#define rewinddir(dirp) seekdir((dirp), (long)0) -extern void closedir(); -#endif /* not KERNEL */ -#endif /* _BOOT_UFS_DIR_H_ */ diff --git a/serverboot/disk_inode.h b/serverboot/disk_inode.h deleted file mode 100644 index 6eed9104..00000000 --- a/serverboot/disk_inode.h +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Mach Operating System - * Copyright (c) 1991,1990 Carnegie Mellon University - * All Rights Reserved. - * - * Permission to use, copy, modify and distribute this software and its - * documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" - * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR - * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to - * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 - * - * any improvements or extensions that they make and grant Carnegie Mellon - * the rights to redistribute these changes. - */ -/* - * Copyright (c) 1982, 1989 The Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms are permitted - * provided that the above copyright notice and this paragraph are - * duplicated in all such forms and that any documentation, - * advertising materials, and other materials related to such - * distribution and use acknowledge that the software was developed - * by the University of California, Berkeley. The name of the - * University may not be used to endorse or promote products derived - * from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. - * - * @(#)inode.h 7.5 (Berkeley) 7/3/89 - */ - -#ifndef _BOOT_UFS_DISK_INODE_H_ -#define _BOOT_UFS_DISK_INODE_H_ - -/* - * The I node is the focus of all file activity in the BSD Fast File System. - * There is a unique inode allocated for each active file, - * each current directory, each mounted-on file, text file, and the root. - * An inode is 'named' by its dev/inumber pair. (iget/iget.c) - * Data in icommon is read in from permanent inode on volume. - */ - -#define FFS_NDADDR 12 /* direct addresses in inode */ -#define FFS_NIADDR 3 /* indirect addresses in inode */ - -#define FFS_MAX_FASTLINK_SIZE ((FFS_NDADDR + FFS_NIADDR) * sizeof(daddr_t)) - -struct icommon { - u_short ic_mode; /* 0: mode and type of file */ - short ic_nlink; /* 2: number of links to file */ - short ic_uid; /* 4: owner's user id */ - short ic_gid; /* 6: owner's group id */ - quad ic_size; /* 8: number of bytes in file */ - time_t ic_atime; /* 16: time last accessed */ - int ic_atspare; - time_t ic_mtime; /* 24: time last modified */ - int ic_mtspare; - time_t ic_ctime; /* 32: last time inode changed */ - int ic_ctspare; - union { - struct { - daddr_t Mb_db[FFS_NDADDR]; /* 40: disk block addresses */ - daddr_t Mb_ib[FFS_NIADDR]; /* 88: indirect blocks */ - } ic_Mb; - char ic_Msymlink[FFS_MAX_FASTLINK_SIZE]; - /* 40: symbolic link name */ - } ic_Mun; -#define ic_db ic_Mun.ic_Mb.Mb_db -#define ic_ib ic_Mun.ic_Mb.Mb_ib -#define ic_symlink ic_Mun.ic_Msymlink - int ic_flags; /* 100: status, currently unused */ - int ic_blocks; /* 104: blocks actually held */ - int ic_gen; /* 108: generation number */ - int ic_spare[4]; /* 112: reserved, currently unused */ -} i_ic; - -/* - * Same structure, but on disk. - */ -struct dinode { - union { - struct icommon di_com; - char di_char[128]; - } di_un; -}; -#define di_ic di_un.di_com - -#endif /* _BOOT_UFS_DISK_INODE_H_ */ diff --git a/serverboot/disk_inode_ffs.h b/serverboot/disk_inode_ffs.h deleted file mode 100644 index ab352f84..00000000 --- a/serverboot/disk_inode_ffs.h +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Mach Operating System - * Copyright (c) 1991,1990 Carnegie Mellon University - * All Rights Reserved. - * - * Permission to use, copy, modify and distribute this software and its - * documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" - * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR - * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to - * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 - * - * any improvements or extensions that they make and grant Carnegie Mellon - * the rights to redistribute these changes. - */ -/* - * Copyright (c) 1982, 1989 The Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms are permitted - * provided that the above copyright notice and this paragraph are - * duplicated in all such forms and that any documentation, - * advertising materials, and other materials related to such - * distribution and use acknowledge that the software was developed - * by the University of California, Berkeley. The name of the - * University may not be used to endorse or promote products derived - * from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. - * - * @(#)inode.h 7.5 (Berkeley) 7/3/89 - */ - -#ifndef _BOOT_UFS_DISK_INODE_FFS_H_ -#define _BOOT_UFS_DISK_INODE_FFS_H_ - -#define NDADDR FFS_NDADDR -#define NIADDR FFS_NIADDR - -#define MAX_FASTLINK_SIZE FFS_MAX_FASTLINK_SIZE - -#define IC_FASTLINK 0x0001 /* Symbolic link in inode */ - -#define i_mode i_ic.ic_mode -#define i_nlink i_ic.ic_nlink -#define i_uid i_ic.ic_uid -#define i_gid i_ic.ic_gid -#if BYTE_MSF -#define i_size i_ic.ic_size.val[1] -#else /* BYTE_LSF */ -#define i_size i_ic.ic_size.val[0] -#endif -#define i_db i_ic.ic_db -#define i_ib i_ic.ic_ib -#define i_atime i_ic.ic_atime -#define i_mtime i_ic.ic_mtime -#define i_ctime i_ic.ic_ctime -#define i_blocks i_ic.ic_blocks -#define i_rdev i_ic.ic_db[0] -#define i_symlink i_ic.ic_symlink -#define i_flags i_ic.ic_flags -#define i_gen i_ic.ic_gen - -/* modes */ -#define IFMT 0xf000 /* type of file */ -#define IFCHR 0x2000 /* character special */ -#define IFDIR 0x4000 /* directory */ -#define IFBLK 0x6000 /* block special */ -#define IFREG 0x8000 /* regular */ -#define IFLNK 0xa000 /* symbolic link */ -#define IFSOCK 0xc000 /* socket */ - - -#define ISUID 0x0800 /* set user id on execution */ -#define ISGID 0x0400 /* set group id on execution */ -#define ISVTX 0x0200 /* save swapped text even after use */ -#define IREAD 0x0100 /* read, write, execute permissions */ -#define IWRITE 0x0080 -#define IEXEC 0x0040 - -#define f_fs u.ffs.ffs_fs -#define i_ic u.ffs.ffs_ic -#define f_nindir u.ffs.ffs_nindir -#define f_blk u.ffs.ffs_blk -#define f_blksize u.ffs.ffs_blksize -#define f_blkno u.ffs.ffs_blkno - -#endif /* _BOOT_UFS_DISK_INODE_FFS_H_ */ diff --git a/serverboot/elf-load.c b/serverboot/elf-load.c deleted file mode 100644 index 603eadf0..00000000 --- a/serverboot/elf-load.c +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright (c) 1995, 1994, 1993, 1992, 1991, 1990 - * Open Software Foundation, Inc. - * - * Permission to use, copy, modify, and distribute this software and - * its documentation for any purpose and without fee is hereby granted, - * provided that the above copyright notice appears in all copies and - * that both the copyright notice and this permission notice appear in - * supporting documentation, and that the name of ("OSF") or Open Software - * Foundation not be used in advertising or publicity pertaining to - * distribution of the software without specific, written prior permission. - * - * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL OSF BE LIABLE FOR ANY - * SPECIAL, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN - * ACTION OF CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING - * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE - */ -/* - * OSF Research Institute MK6.1 (unencumbered) 1/31/1995 - */ - -#include <alloca.h> -#include <mach/machine/vm_types.h> -#include <elf.h> -#include "mach-exec.h" - -int exec_load(exec_read_func_t *read, exec_read_exec_func_t *read_exec, - void *handle, exec_info_t *out_info) -{ - vm_size_t actual; - union { Elf32_Ehdr h; Elf64_Ehdr h64; } x; - int i; - int result; - - /* Read the ELF header. */ - if ((result = (*read)(handle, 0, &x, sizeof(x), &actual)) != 0) - return result; - if (actual < sizeof(x)) - return EX_NOT_EXECUTABLE; - - if ((x.h.e_ident[EI_MAG0] != ELFMAG0) || - (x.h.e_ident[EI_MAG1] != ELFMAG1) || - (x.h.e_ident[EI_MAG2] != ELFMAG2) || - (x.h.e_ident[EI_MAG3] != ELFMAG3)) - return EX_NOT_EXECUTABLE; - - /* Make sure the file is of the right architecture. */ -#ifdef i386 -# define MY_CLASS ELFCLASS32 -# define MY_DATA ELFDATA2LSB -# define MY_MACHINE EM_386 -#elif defined __alpha__ -# define MY_CLASS ELFCLASS64 -# define MY_DATA ELFDATA2LSB -# define MY_MACHINE EM_ALPHA -#else -#error Not ported to this architecture! -#endif - - if ((x.h.e_ident[EI_CLASS] != MY_CLASS) || - (x.h.e_ident[EI_DATA] != MY_DATA)) - return EX_WRONG_ARCH; - - if (MY_CLASS == ELFCLASS64) - { - Elf64_Phdr *phdr, *ph; - vm_size_t phsize; - - if (x.h64.e_machine != MY_MACHINE) - return EX_WRONG_ARCH; - - /* XXX others */ - out_info->entry = (vm_offset_t) x.h64.e_entry; - out_info->init_dp = 0; /* ? */ - - phsize = x.h64.e_phnum * x.h64.e_phentsize; - phdr = (Elf64_Phdr *)alloca(phsize); - - result = (*read)(handle, x.h64.e_phoff, phdr, phsize, &actual); - if (result) - return result; - if (actual < phsize) - return EX_CORRUPT; - - for (i = 0; i < x.h64.e_phnum; i++) - { - ph = (Elf64_Phdr *)((vm_offset_t)phdr + i * x.h64.e_phentsize); - if (ph->p_type == PT_LOAD) - { - exec_sectype_t type = EXEC_SECTYPE_ALLOC | - EXEC_SECTYPE_LOAD; - if (ph->p_flags & PF_R) type |= EXEC_SECTYPE_READ; - if (ph->p_flags & PF_W) type |= EXEC_SECTYPE_WRITE; - if (ph->p_flags & PF_X) type |= EXEC_SECTYPE_EXECUTE; - result = (*read_exec)(handle, - ph->p_offset, ph->p_filesz, - ph->p_vaddr, ph->p_memsz, type); - } - } - } - else - { - Elf32_Phdr *phdr, *ph; - vm_size_t phsize; - - if (x.h.e_machine != MY_MACHINE) - return EX_WRONG_ARCH; - - /* XXX others */ - out_info->entry = (vm_offset_t) x.h.e_entry; - out_info->init_dp = 0; /* ? */ - - phsize = x.h.e_phnum * x.h.e_phentsize; - phdr = (Elf32_Phdr *)alloca(phsize); - - result = (*read)(handle, x.h.e_phoff, phdr, phsize, &actual); - if (result) - return result; - if (actual < phsize) - return EX_CORRUPT; - - for (i = 0; i < x.h.e_phnum; i++) - { - ph = (Elf32_Phdr *)((vm_offset_t)phdr + i * x.h.e_phentsize); - if (ph->p_type == PT_LOAD) - { - exec_sectype_t type = EXEC_SECTYPE_ALLOC | - EXEC_SECTYPE_LOAD; - if (ph->p_flags & PF_R) type |= EXEC_SECTYPE_READ; - if (ph->p_flags & PF_W) type |= EXEC_SECTYPE_WRITE; - if (ph->p_flags & PF_X) type |= EXEC_SECTYPE_EXECUTE; - result = (*read_exec)(handle, - ph->p_offset, ph->p_filesz, - ph->p_vaddr, ph->p_memsz, type); - } - } - } - - return 0; -} diff --git a/serverboot/exec.c b/serverboot/exec.c deleted file mode 100644 index a487fb5d..00000000 --- a/serverboot/exec.c +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Mach Operating System - * Copyright (c) 1993-1989 Carnegie Mellon University - * All Rights Reserved. - * - * Permission to use, copy, modify and distribute this software and its - * documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" - * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR - * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to - * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 - * - * any improvements or extensions that they make and grant Carnegie Mellon - * the rights to redistribute these changes. - */ -/* - * i386-specific routines for loading a.out files. - */ - -#include <mach.h> -#include <mach/machine/vm_param.h> -#include "mach-exec.h" - -#include <file_io.h> - -#ifdef i386 - -#include <mach/machine/eflags.h> - -/* - * Machine-dependent portions of execve() for the i386. - */ - -#define STACK_SIZE (64*1024) - -char *set_regs( - mach_port_t user_task, - mach_port_t user_thread, - struct exec_info *info, - int arg_size) -{ - vm_offset_t stack_start; - vm_offset_t stack_end; - struct i386_thread_state regs; - unsigned int reg_size; - - /* - * Add space for 5 ints to arguments, for - * PS program. XXX - */ - arg_size += 5 * sizeof(int); - - /* - * Allocate stack. - */ - stack_end = VM_MAX_ADDRESS; - stack_start = VM_MAX_ADDRESS - STACK_SIZE; - (void)vm_allocate(user_task, - &stack_start, - (vm_size_t)(stack_end - stack_start), - FALSE); - - reg_size = i386_THREAD_STATE_COUNT; - (void)thread_get_state(user_thread, - i386_THREAD_STATE, - (thread_state_t)®s, - ®_size); - - regs.eip = info->entry; - regs.uesp = (int)((stack_end - arg_size) & ~(sizeof(int)-1)); - - /* regs.efl |= EFL_TF; trace flag*/ - - (void)thread_set_state(user_thread, - i386_THREAD_STATE, - (thread_state_t)®s, - reg_size); - - return (char *)regs.uesp; -} - -#elif defined __alpha__ - - -/* - * Object: - * set_regs EXPORTED function - * - * Initialize enough state for a thread to run, including - * stack memory and stack pointer, and program counter. - * - */ -#define STACK_SIZE (vm_size_t)(128*1024) - -char *set_regs( - mach_port_t user_task, - mach_port_t user_thread, - struct exec_info *info, - int arg_size) -{ - vm_offset_t stack_start; - vm_offset_t stack_end; - struct alpha_thread_state regs; - - natural_t reg_size; - - /* - * Allocate stack. - */ - stack_end = VM_MAX_ADDRESS; - stack_start = stack_end - STACK_SIZE; - (void)vm_allocate(user_task, - &stack_start, - (vm_size_t)(STACK_SIZE), - FALSE); - - reg_size = ALPHA_THREAD_STATE_COUNT; - (void)thread_get_state(user_thread, - ALPHA_THREAD_STATE, - (thread_state_t)®s, - ®_size); - - regs.pc = info->entry; - regs.r29 = info->init_dp; - regs.r30 = (integer_t)((stack_end - arg_size) & ~(sizeof(integer_t)-1)); - - (void)thread_set_state(user_thread, - ALPHA_THREAD_STATE, - (thread_state_t)®s, - reg_size); - - return (char *)regs.r30; -} - -#else -# error "Not ported to this architecture!" -#endif diff --git a/serverboot/ext2_file_io.c b/serverboot/ext2_file_io.c deleted file mode 100644 index cb915c4a..00000000 --- a/serverboot/ext2_file_io.c +++ /dev/null @@ -1,983 +0,0 @@ -/* - * Mach Operating System - * Copyright (c) 1991,1990 Carnegie Mellon University - * All Rights Reserved. - * - * Permission to use, copy, modify and distribute this software and its - * documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" - * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR - * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to - * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 - * - * any improvements or extensions that they make and grant Carnegie Mellon - * the rights to redistribute these changes. - */ -/* - * Stand-alone file reading package. - */ - -#include <device/device_types.h> -#include <device/device.h> - -#include <mach/mach_traps.h> -#include <mach/mach_interface.h> - -#include "file_io.h" -#include "ffs_compat.h" - -void ext2_close_file(); /* forward */ - -/* - * Free file buffers, but don't close file. - */ -static void -free_file_buffers(fp) - register struct file *fp; -{ - register int level; - - /* - * Free the indirect blocks - */ - for (level = 0; level < NIADDR; level++) { - if (fp->f_blk[level] != 0) { - (void) vm_deallocate(mach_task_self(), - fp->f_blk[level], - fp->f_blksize[level]); - fp->f_blk[level] = 0; - } - fp->f_blkno[level] = -1; - } - - /* - * Free the data block - */ - if (fp->f_buf != 0) { - (void) vm_deallocate(mach_task_self(), - fp->f_buf, - fp->f_buf_size); - fp->f_buf = 0; - } - fp->f_buf_blkno = -1; -} - -/* - * Read a new inode into a file structure. - */ -static int -read_inode(inumber, fp) - ino_t inumber; - register struct file *fp; -{ - vm_offset_t buf; - mach_msg_type_number_t buf_size; - register - struct ext2_super_block *fs; - daddr_t disk_block; - kern_return_t rc; - - fs = fp->f_fs; - disk_block = ino2blk(fs, fp->f_gd, inumber); - - rc = device_read(fp->f_dev, - 0, - (recnum_t) fsbtodb(fp->f_fs, disk_block), - (int) EXT2_BLOCK_SIZE(fs), - (char **)&buf, - &buf_size); - if (rc != KERN_SUCCESS) - return (rc); - - { - register struct ext2_inode *dp; - - dp = (struct ext2_inode *)buf; - dp += itoo(fs, inumber); - fp->i_ic = *dp; - fp->f_size = dp->i_size; - } - - (void) vm_deallocate(mach_task_self(), buf, buf_size); - - /* - * Clear out the old buffers - */ - free_file_buffers(fp); - - return (0); -} - -/* - * Given an offset in a file, find the disk block number that - * contains that block. - */ -static int -block_map(fp, file_block, disk_block_p) - struct file *fp; - daddr_t file_block; - daddr_t *disk_block_p; /* out */ -{ - int level; - int idx; - daddr_t ind_block_num; - kern_return_t rc; - - vm_offset_t olddata[NIADDR+1]; - vm_size_t oldsize[NIADDR+1]; - - /* - * Index structure of an inode: - * - * i_db[0..NDADDR-1] hold block numbers for blocks - * 0..NDADDR-1 - * - * i_ib[0] index block 0 is the single indirect - * block - * holds block numbers for blocks - * NDADDR .. NDADDR + NINDIR(fs)-1 - * - * i_ib[1] index block 1 is the double indirect - * block - * holds block numbers for INDEX blocks - * for blocks - * NDADDR + NINDIR(fs) .. - * NDADDR + NINDIR(fs) + NINDIR(fs)**2 - 1 - * - * i_ib[2] index block 2 is the triple indirect - * block - * holds block numbers for double-indirect - * blocks for blocks - * NDADDR + NINDIR(fs) + NINDIR(fs)**2 .. - * NDADDR + NINDIR(fs) + NINDIR(fs)**2 - * + NINDIR(fs)**3 - 1 - */ - - mutex_lock(&fp->f_lock); - - if (file_block < NDADDR) { - /* Direct block. */ - *disk_block_p = fp->i_ic.i_block[file_block]; - mutex_unlock(&fp->f_lock); - return (0); - } - - file_block -= NDADDR; - - /* - * nindir[0] = NINDIR - * nindir[1] = NINDIR**2 - * nindir[2] = NINDIR**3 - * etc - */ - for (level = 0; level < NIADDR; level++) { - if (file_block < fp->f_nindir[level]) - break; - file_block -= fp->f_nindir[level]; - } - if (level == NIADDR) { - /* Block number too high */ - mutex_unlock(&fp->f_lock); - return (FS_NOT_IN_FILE); - } - - ind_block_num = fp->i_ic.i_block[level + NDADDR]; - - /* - * Initialize array of blocks to free. - */ - for (idx = 0; idx < NIADDR; idx++) - oldsize[idx] = 0; - - for (; level >= 0; level--) { - - vm_offset_t data; - mach_msg_type_number_t size; - - if (ind_block_num == 0) - break; - - if (fp->f_blkno[level] == ind_block_num) { - /* - * Cache hit. Just pick up the data. - */ - - data = fp->f_blk[level]; - } - else { - /* - * Drop our lock while doing the read. - * (The f_dev and f_fs fields don`t change.) - */ - mutex_unlock(&fp->f_lock); - - rc = device_read(fp->f_dev, - 0, - (recnum_t) fsbtodb(fp->f_fs, ind_block_num), - EXT2_BLOCK_SIZE(fp->f_fs), - (char **)&data, - &size); - if (rc != KERN_SUCCESS) - return (rc); - - /* - * See if we can cache the data. Need a write lock to - * do this. While we hold the write lock, we can`t do - * *anything* which might block for memory. Otherwise - * a non-privileged thread might deadlock with the - * privileged threads. We can`t block while taking the - * write lock. Otherwise a non-privileged thread - * blocked in the vm_deallocate (while holding a read - * lock) will block a privileged thread. For the same - * reason, we can`t take a read lock and then use - * lock_read_to_write. - */ - - mutex_lock(&fp->f_lock); - - olddata[level] = fp->f_blk[level]; - oldsize[level] = fp->f_blksize[level]; - - fp->f_blkno[level] = ind_block_num; - fp->f_blk[level] = data; - fp->f_blksize[level] = size; - - /* - * Return to holding a read lock, and - * dispose of old data. - */ - - } - - if (level > 0) { - idx = file_block / fp->f_nindir[level-1]; - file_block %= fp->f_nindir[level-1]; - } - else - idx = file_block; - - ind_block_num = ((daddr_t *)data)[idx]; - } - - mutex_unlock(&fp->f_lock); - - /* - * After unlocking the file, free any blocks that - * we need to free. - */ - for (idx = 0; idx < NIADDR; idx++) - if (oldsize[idx] != 0) - (void) vm_deallocate(mach_task_self(), - olddata[idx], - oldsize[idx]); - - *disk_block_p = ind_block_num; - return (0); -} - -/* - * Read a portion of a file into an internal buffer. Return - * the location in the buffer and the amount in the buffer. - */ -static int -buf_read_file(fp, offset, buf_p, size_p) - register struct file *fp; - vm_offset_t offset; - vm_offset_t *buf_p; /* out */ - vm_size_t *size_p; /* out */ -{ - register - struct ext2_super_block *fs; - vm_offset_t off; - register daddr_t file_block; - daddr_t disk_block; - int rc; - vm_offset_t block_size; - - if (offset >= fp->i_ic.i_size) - return (FS_NOT_IN_FILE); - - fs = fp->f_fs; - - off = blkoff(fs, offset); - file_block = lblkno(fs, offset); - block_size = blksize(fs, fp, file_block); - - if (file_block != fp->f_buf_blkno) { - rc = block_map(fp, file_block, &disk_block); - if (rc != 0) - return (rc); - - if (fp->f_buf) - (void)vm_deallocate(mach_task_self(), - fp->f_buf, - fp->f_buf_size); - - if (disk_block == 0) { - (void)vm_allocate(mach_task_self(), - &fp->f_buf, - block_size, - TRUE); - fp->f_buf_size = block_size; - } - else { - rc = device_read(fp->f_dev, - 0, - (recnum_t) fsbtodb(fs, disk_block), - (int) block_size, - (char **) &fp->f_buf, - (mach_msg_type_number_t *)&fp->f_buf_size); - } - if (rc) - return (rc); - - fp->f_buf_blkno = file_block; - } - - /* - * Return address of byte in buffer corresponding to - * offset, and size of remainder of buffer after that - * byte. - */ - *buf_p = fp->f_buf + off; - *size_p = block_size - off; - - /* - * But truncate buffer at end of file. - */ - if (*size_p > fp->i_ic.i_size - offset) - *size_p = fp->i_ic.i_size - offset; - - return (0); -} - -/* - * Search a directory for a name and return its - * i_number. - */ -static int -search_directory(name, fp, inumber_p) - char * name; - register struct file *fp; - ino_t *inumber_p; /* out */ -{ - vm_offset_t buf; - vm_size_t buf_size; - vm_offset_t offset; - struct ext2_dir_entry_2 *dp; - int length; - kern_return_t rc; - char tmp_name[256]; - - length = strlen(name); - - offset = 0; - while (offset < fp->i_ic.i_size) { - rc = buf_read_file(fp, offset, &buf, &buf_size); - if (rc != KERN_SUCCESS) - return (rc); - - dp = (struct ext2_dir_entry_2 *)buf; - if (dp->inode != 0) { - strncpy (tmp_name, dp->name, dp->name_len); - tmp_name[dp->name_len] = '\0'; - if (dp->name_len == length && - !strcmp(name, tmp_name)) - { - /* found entry */ - *inumber_p = dp->inode; - return (0); - } - } - offset += dp->rec_len; - } - return (FS_NO_ENTRY); -} - -static int -read_fs(dev, fsp, gdp, gd_size_p) - mach_port_t dev; - struct ext2_super_block **fsp; - struct ext2_group_desc **gdp; - vm_size_t *gd_size_p; -{ - register - struct ext2_super_block *fs; - vm_offset_t buf; - vm_offset_t buf2; - mach_msg_type_number_t buf_size; - mach_msg_type_number_t buf2_size; - int error; - int gd_count; - int gd_blocks; - int gd_size; - int gd_location; - int gd_sector; - - /* - * Read the super block - */ - error = device_read(dev, 0, (recnum_t) SBLOCK, SBSIZE, - (char **) &buf, &buf_size); - if (error) - return (error); - - /* - * Check the superblock - */ - fs = (struct ext2_super_block *)buf; - if (fs->s_magic != EXT2_SUPER_MAGIC) { - (void) vm_deallocate(mach_task_self(), buf, buf_size); - return (FS_INVALID_FS); - } - - *fsp = fs; - - /* - * Compute the groups informations - */ - gd_count = (fs->s_blocks_count - fs->s_first_data_block + - fs->s_blocks_per_group - 1) / fs->s_blocks_per_group; - gd_blocks = (gd_count + EXT2_DESC_PER_BLOCK(fs) - 1) / - EXT2_DESC_PER_BLOCK(fs); - gd_size = gd_blocks * EXT2_BLOCK_SIZE(fs); - gd_location = fs->s_first_data_block + 1; - gd_sector = (gd_location * EXT2_BLOCK_SIZE(fs)) / DEV_BSIZE; - - /* - * Read the groups descriptors - */ - error = device_read(dev, 0, (recnum_t) gd_sector, gd_size, - (char **) &buf2, &buf2_size); - if (error) { - (void) vm_deallocate(mach_task_self(), buf, buf_size); - return error; - } - - *gdp = (struct ext2_group_desc *) buf2; - *gd_size_p = gd_size; - - return 0; -} - -static int -mount_fs(fp) - register struct file *fp; -{ - register struct ext2_super_block *fs; - int error; - - error = read_fs(fp->f_dev, &fp->f_fs, &fp->f_gd, &fp->f_gd_size); - if (error) - return (error); - - fs = fp->f_fs; - - /* - * Calculate indirect block levels. - */ - { - register int mult; - register int level; - - mult = 1; - for (level = 0; level < NIADDR; level++) { - mult *= NINDIR(fs); - fp->f_nindir[level] = mult; - } - } - - return (0); -} - -static void -unmount_fs(fp) - register struct file *fp; -{ - if (file_is_structured(fp)) { - (void) vm_deallocate(mach_task_self(), - (vm_offset_t) fp->f_fs, - SBSIZE); - (void) vm_deallocate(mach_task_self(), - (vm_offset_t) fp->f_gd, - fp->f_gd_size); - fp->f_fs = 0; - } -} - -/* - * Open a file. - */ -int -ext2_open_file(master_device_port, path, fp) - mach_port_t master_device_port; - char * path; - struct file *fp; -{ -#define RETURN(code) { rc = (code); goto exit; } - - register char *cp, *component; - register int c; /* char */ - register int rc; - ino_t inumber, parent_inumber; - int nlinks = 0; - - char namebuf[MAXPATHLEN+1]; - - if (path == 0 || *path == '\0') { - return FS_NO_ENTRY; - } - - /* - * Copy name into buffer to allow modifying it. - */ - strcpy(namebuf, path); - - /* - * Look for '/dev/xxx' at start of path, for - * root device. - */ - if (!strprefix(namebuf, "/dev/")) { - printf("no device name\n"); - return FS_NO_ENTRY; - } - - cp = namebuf + 5; /* device */ - component = cp; - while ((c = *cp) != '\0' && c != '/') { - cp++; - } - *cp = '\0'; - - bzero (fp, sizeof (struct file)); - - rc = device_open(master_device_port, - D_READ|D_WRITE, - component, - &fp->f_dev); - if (rc) - return rc; - - if (c == 0) { - fp->f_fs = 0; - goto out_ok; - } - - *cp = c; - - rc = mount_fs(fp); - if (rc) - return rc; - - inumber = (ino_t) ROOTINO; - if ((rc = read_inode(inumber, fp)) != 0) { - printf("can't read root inode\n"); - goto exit; - } - - while (*cp) { - - /* - * Check that current node is a directory. - */ - if ((fp->i_ic.i_mode & IFMT) != IFDIR) - RETURN (FS_NOT_DIRECTORY); - - /* - * Remove extra separators - */ - while (*cp == '/') - cp++; - - /* - * Get next component of path name. - */ - component = cp; - { - register int len = 0; - - while ((c = *cp) != '\0' && c != '/') { - if (len++ > MAXNAMLEN) - RETURN (FS_NAME_TOO_LONG); - if (c & 0200) - RETURN (FS_INVALID_PARAMETER); - cp++; - } - *cp = 0; - } - - /* - * Look up component in current directory. - * Save directory inumber in case we find a - * symbolic link. - */ - parent_inumber = inumber; - rc = search_directory(component, fp, &inumber); - if (rc) { - printf("%s: not found\n", path); - goto exit; - } - *cp = c; - - /* - * Open next component. - */ - if ((rc = read_inode(inumber, fp)) != 0) - goto exit; - - /* - * Check for symbolic link. - */ - if ((fp->i_ic.i_mode & IFMT) == IFLNK) { - - int link_len = fp->i_ic.i_size; - int len; - - len = strlen(cp) + 1; - - if (link_len + len >= MAXPATHLEN - 1) - RETURN (FS_NAME_TOO_LONG); - - if (++nlinks > MAXSYMLINKS) - RETURN (FS_SYMLINK_LOOP); - - memmove(&namebuf[link_len], cp, len); - -#ifdef IC_FASTLINK - if (fp->i_ic.i_blocks == 0) { - bcopy(fp->i_ic.i_block, namebuf, (unsigned) link_len); - } - else -#endif /* IC_FASTLINK */ - { - /* - * Read file for symbolic link - */ - vm_offset_t buf; - mach_msg_type_number_t buf_size; - daddr_t disk_block; - register struct ext2_super_block *fs = fp->f_fs; - - (void) block_map(fp, (daddr_t)0, &disk_block); - rc = device_read(fp->f_dev, - 0, - (recnum_t) fsbtodb(fs, disk_block), - (int) blksize(fs, fp, 0), - (char **) &buf, - &buf_size); - if (rc) - goto exit; - - bcopy((char *)buf, namebuf, (unsigned)link_len); - (void) vm_deallocate(mach_task_self(), buf, buf_size); - } - - /* - * If relative pathname, restart at parent directory. - * If absolute pathname, restart at root. - * If pathname begins '/dev/<device>/', - * restart at root of that device. - */ - cp = namebuf; - if (*cp != '/') { - inumber = parent_inumber; - } - else if (!strprefix(cp, "/dev/")) { - inumber = (ino_t)ROOTINO; - } - else { - cp += 5; - component = cp; - while ((c = *cp) != '\0' && c != '/') { - cp++; - } - *cp = '\0'; - - /* - * Unmount current file system and free buffers. - */ - ext2_close_file(fp); - - /* - * Open new root device. - */ - rc = device_open(master_device_port, - D_READ, - component, - &fp->f_dev); - if (rc) - return (rc); - - if (c == 0) { - fp->f_fs = 0; - goto out_ok; - } - - *cp = c; - - rc = mount_fs(fp); - if (rc) - return (rc); - - inumber = (ino_t)ROOTINO; - } - if ((rc = read_inode(inumber, fp)) != 0) - goto exit; - } - } - - /* - * Found terminal component. - */ - out_ok: - mutex_init(&fp->f_lock); - return 0; - - /* - * At error exit, close file to free storage. - */ - exit: - ext2_close_file(fp); - return rc; -} - -/* - * Close file - free all storage used. - */ -void -ext2_close_file(fp) - register struct file *fp; -{ - register int i; - - /* - * Free the disk super-block. - */ - unmount_fs(fp); - - /* - * Free the inode and data buffers. - */ - free_file_buffers(fp); -} - -int -ext2_file_is_directory(struct file *fp) -{ - return (fp->i_ic.i_mode & IFMT) == IFDIR; -} - -int -ext2_file_is_regular(struct file *fp) -{ - return (fp->i_ic.i_mode & IFMT) == IFREG; -} - -/* - * Copy a portion of a file into kernel memory. - * Cross block boundaries when necessary. - */ -int -ext2_read_file(fp, offset, start, size, resid) - register struct file *fp; - vm_offset_t offset; - vm_offset_t start; - vm_size_t size; - vm_size_t *resid; /* out */ -{ - int rc; - register vm_size_t csize; - vm_offset_t buf; - vm_size_t buf_size; - - while (size != 0) { - rc = buf_read_file(fp, offset, &buf, &buf_size); - if (rc) - return (rc); - - csize = size; - if (csize > buf_size) - csize = buf_size; - if (csize == 0) - break; - - bcopy((char *)buf, (char *)start, csize); - - offset += csize; - start += csize; - size -= csize; - } - if (resid) - *resid = size; - - return (0); -} - -/* simple utility: only works for 2^n */ -static int -log2(n) - register unsigned int n; -{ - register int i = 0; - - while ((n & 1) == 0) { - i++; - n >>= 1; - } - return i; -} - -/* - * Make an empty file_direct for a device. - */ -int -ext2_open_file_direct(dev, fdp, is_structured) - mach_port_t dev; - register struct file_direct *fdp; - boolean_t is_structured; -{ - struct ext2_super_block *fs; - struct ext2_group_desc *gd; - vm_size_t gd_size; - int rc; - - if (!is_structured) { - fdp->fd_dev = dev; - fdp->fd_blocks = (daddr_t *) 0; - fdp->fd_bsize = vm_page_size; - fdp->fd_bshift = log2(vm_page_size); - fdp->fd_fsbtodb = 0; /* later */ - fdp->fd_size = 0; /* later */ - return 0; - } - - rc = read_fs(dev, &fs, &gd, &gd_size); - if (rc) - return rc; - - fdp->fd_dev = dev; - fdp->fd_blocks = (daddr_t *) 0; - fdp->fd_size = 0; - fdp->fd_bsize = EXT2_BLOCK_SIZE(fs); - fdp->fd_bshift = log2(fdp->fd_bsize); - fdp->fd_fsbtodb = log2(fdp->fd_bsize / DEV_BSIZE); - - (void) vm_deallocate(mach_task_self(), - (vm_offset_t) fs, - SBSIZE); - (void) vm_deallocate(mach_task_self(), - (vm_offset_t) gd, - gd_size); - - return 0; -} - -/* - * Add blocks from a file to a file_direct. - */ -int -ext2_add_file_direct(fdp, fp) - register struct file_direct *fdp; - register struct file *fp; -{ - register struct ext2_super_block *fs; - long num_blocks, i; - vm_offset_t buffer; - vm_size_t size; - int rc; - - /* the file must be on the same device */ - - if (fdp->fd_dev != fp->f_dev) - return FS_INVALID_FS; - - if (!file_is_structured(fp)) { - int result[DEV_GET_SIZE_COUNT]; - natural_t count; - - count = DEV_GET_SIZE_COUNT; - rc = device_get_status( fdp->fd_dev, DEV_GET_SIZE, - result, &count); - if (rc) - return rc; - fdp->fd_size = result[DEV_GET_SIZE_DEVICE_SIZE] >> fdp->fd_bshift; - fdp->fd_fsbtodb = log2(fdp->fd_bsize/result[DEV_GET_SIZE_RECORD_SIZE]); - return 0; - } - - /* it must hold a file system */ - - fs = fp->f_fs; -/* - if (fdp->fd_bsize != fs->fs_bsize || - fdp->fd_fsbtodb != fs->fs_fsbtodb) -*/ - if (fdp->fd_bsize != EXT2_BLOCK_SIZE(fs)) - return FS_INVALID_FS; - - /* calculate number of blocks in the file, ignoring fragments */ - - num_blocks = lblkno(fs, fp->i_ic.i_size); - - /* allocate memory for a bigger array */ - - size = (num_blocks + fdp->fd_size) * sizeof(daddr_t); - rc = vm_allocate(mach_task_self(), &buffer, size, TRUE); - if (rc != KERN_SUCCESS) - return rc; - - /* lookup new block addresses */ - - for (i = 0; i < num_blocks; i++) { - daddr_t disk_block; - - rc = block_map(fp, (daddr_t) i, &disk_block); - if (rc != 0) { - (void) vm_deallocate(mach_task_self(), buffer, size); - return rc; - } - - ((daddr_t *) buffer)[fdp->fd_size + i] = disk_block; - } - - /* copy old addresses and install the new array */ - - if (fdp->fd_blocks != 0) { - bcopy((char *) fdp->fd_blocks, (char *) buffer, - fdp->fd_size * sizeof(daddr_t)); - - (void) vm_deallocate(mach_task_self(), - (vm_offset_t) fdp->fd_blocks, - (vm_size_t) (fdp->fd_size * sizeof(daddr_t))); - } - fdp->fd_blocks = (daddr_t *) buffer; - fdp->fd_size += num_blocks; - - /* deallocate cached blocks */ - - free_file_buffers(fp); - - return 0; -} - -int -ext2_remove_file_direct(fdp) - struct file_direct *fdp; -{ - if (fdp->fd_blocks) - (void) vm_deallocate(mach_task_self(), - (vm_offset_t) fdp->fd_blocks, - (vm_size_t) (fdp->fd_size * sizeof(daddr_t))); - fdp->fd_blocks = 0; /* sanity */ - /* xxx should lose a ref to fdp->fd_dev here (and elsewhere) xxx */ -} diff --git a/serverboot/ffs_compat.c b/serverboot/ffs_compat.c deleted file mode 100644 index 6e322b63..00000000 --- a/serverboot/ffs_compat.c +++ /dev/null @@ -1,65 +0,0 @@ -/* - * BSD FFS like functions used to ease porting bootstrap to Linux ext2 fs - * Copyright (C) 1994 Remy Card - * - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include <device/device_types.h> -#include <device/device.h> - -#include <mach/mach_traps.h> -#include <mach/mach_interface.h> - -#include <file_io.h> - -#define EXT2_INODES_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof (struct ext2_inode)) - -int ino2blk (struct ext2_super_block *fs, struct ext2_group_desc *gd, int ino) -{ - int group; - int blk; - - group = (ino - 1) / EXT2_INODES_PER_GROUP(fs); - blk = gd[group].bg_inode_table + - (((ino - 1) % EXT2_INODES_PER_GROUP(fs)) / - EXT2_INODES_PER_BLOCK(fs)); - return blk; -} - -int fsbtodb (struct ext2_super_block *fs, int b) -{ - return (b * EXT2_BLOCK_SIZE(fs)) / DEV_BSIZE; -} - -int itoo (struct ext2_super_block *fs, int ino) -{ - return (ino - 1) % EXT2_INODES_PER_BLOCK(fs); -} - -int blkoff (struct ext2_super_block * fs, vm_offset_t offset) -{ - return offset % EXT2_BLOCK_SIZE(fs); -} - -int lblkno (struct ext2_super_block * fs, vm_offset_t offset) -{ - return offset / EXT2_BLOCK_SIZE(fs); -} - -int blksize (struct ext2_super_block *fs, struct file *fp, daddr_t file_block) -{ - return EXT2_BLOCK_SIZE(fs); /* XXX - fix for fragments */ -} diff --git a/serverboot/ffs_compat.h b/serverboot/ffs_compat.h deleted file mode 100644 index d78840f5..00000000 --- a/serverboot/ffs_compat.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * BSD FFS like declarations used to ease porting bootstrap to Linux ext2 fs - * Copyright (C) 1994 Remy Card - * - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#define SBSIZE EXT2_MIN_BLOCK_SIZE /* Size of superblock */ -#define SBLOCK ((daddr_t) 2) /* Location of superblock */ - -#define NDADDR EXT2_NDIR_BLOCKS -#define NIADDR (EXT2_N_BLOCKS - EXT2_NDIR_BLOCKS) - -#define MAXNAMLEN 255 - -#define ROOTINO EXT2_ROOT_INO - -#define NINDIR(fs) EXT2_ADDR_PER_BLOCK(fs) - -#define IC_FASTLINK - -#define IFMT 00170000 -#define IFSOCK 0140000 -#define IFLNK 0120000 -#define IFREG 0100000 -#define IFBLK 0060000 -#define IFDIR 0040000 -#define IFCHR 0020000 -#define IFIFO 0010000 -#define ISUID 0004000 -#define ISGID 0002000 -#define ISVTX 0001000 - -#define f_fs u.ext2.ext2_fs -#define f_gd u.ext2.ext2_gd -#define f_gd_size u.ext2.ext2_gd_size -#define i_ic u.ext2.ext2_ic -#define f_nindir u.ext2.ext2_nindir -#define f_blk u.ext2.ext2_blk -#define f_blksize u.ext2.ext2_blksize -#define f_blkno u.ext2.ext2_blkno - diff --git a/serverboot/ffs_file_io.c b/serverboot/ffs_file_io.c deleted file mode 100644 index 1105eacc..00000000 --- a/serverboot/ffs_file_io.c +++ /dev/null @@ -1,969 +0,0 @@ -/* - * Mach Operating System - * Copyright (c) 1991,1990 Carnegie Mellon University - * All Rights Reserved. - * - * Permission to use, copy, modify and distribute this software and its - * documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" - * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR - * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to - * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 - * - * any improvements or extensions that they make and grant Carnegie Mellon - * the rights to redistribute these changes. - */ -/* - * Stand-alone file reading package. - */ - -#include <device/device_types.h> -#include <device/device.h> - -#include <mach/mach_traps.h> -#include <mach/mach_interface.h> - -#include "file_io.h" -#include "fs.h" -#include "dir.h" -#include "disk_inode_ffs.h" - -void close_file(); /* forward */ - -/* - * Free file buffers, but don't close file. - */ -static void -free_file_buffers(fp) - register struct file *fp; -{ - register int level; - - /* - * Free the indirect blocks - */ - for (level = 0; level < NIADDR; level++) { - if (fp->f_blk[level] != 0) { - (void) vm_deallocate(mach_task_self(), - fp->f_blk[level], - fp->f_blksize[level]); - fp->f_blk[level] = 0; - } - fp->f_blkno[level] = -1; - } - - /* - * Free the data block - */ - if (fp->f_buf != 0) { - (void) vm_deallocate(mach_task_self(), - fp->f_buf, - fp->f_buf_size); - fp->f_buf = 0; - } - fp->f_buf_blkno = -1; -} - -/* - * Read a new inode into a file structure. - */ -static int -read_inode(inumber, fp) - ino_t inumber; - register struct file *fp; -{ - vm_offset_t buf; - mach_msg_type_number_t buf_size; - register struct fs *fs; - daddr_t disk_block; - kern_return_t rc; - - fs = fp->f_fs; - disk_block = itod(fs, inumber); - - rc = device_read(fp->f_dev, - 0, - (recnum_t) fsbtodb(fp->f_fs, disk_block), - (int) fs->fs_bsize, - (char **)&buf, - &buf_size); - if (rc != KERN_SUCCESS) - return (rc); - - { - register struct dinode *dp; - - dp = (struct dinode *)buf; - dp += itoo(fs, inumber); - fp->i_ic = dp->di_ic; - fp->f_size = fp->i_size; - } - - (void) vm_deallocate(mach_task_self(), buf, buf_size); - - /* - * Clear out the old buffers - */ - free_file_buffers(fp); - - return (0); -} - -/* - * Given an offset in a file, find the disk block number that - * contains that block. - */ -static int -block_map(fp, file_block, disk_block_p) - struct file *fp; - daddr_t file_block; - daddr_t *disk_block_p; /* out */ -{ - int level; - int idx; - daddr_t ind_block_num; - kern_return_t rc; - - vm_offset_t olddata[NIADDR+1]; - vm_size_t oldsize[NIADDR+1]; - - /* - * Index structure of an inode: - * - * i_db[0..NDADDR-1] hold block numbers for blocks - * 0..NDADDR-1 - * - * i_ib[0] index block 0 is the single indirect - * block - * holds block numbers for blocks - * NDADDR .. NDADDR + NINDIR(fs)-1 - * - * i_ib[1] index block 1 is the double indirect - * block - * holds block numbers for INDEX blocks - * for blocks - * NDADDR + NINDIR(fs) .. - * NDADDR + NINDIR(fs) + NINDIR(fs)**2 - 1 - * - * i_ib[2] index block 2 is the triple indirect - * block - * holds block numbers for double-indirect - * blocks for blocks - * NDADDR + NINDIR(fs) + NINDIR(fs)**2 .. - * NDADDR + NINDIR(fs) + NINDIR(fs)**2 - * + NINDIR(fs)**3 - 1 - */ - - mutex_lock(&fp->f_lock); - - if (file_block < NDADDR) { - /* Direct block. */ - *disk_block_p = fp->i_db[file_block]; - mutex_unlock(&fp->f_lock); - return (0); - } - - file_block -= NDADDR; - - /* - * nindir[0] = NINDIR - * nindir[1] = NINDIR**2 - * nindir[2] = NINDIR**3 - * etc - */ - for (level = 0; level < NIADDR; level++) { - if (file_block < fp->f_nindir[level]) - break; - file_block -= fp->f_nindir[level]; - } - if (level == NIADDR) { - /* Block number too high */ - mutex_unlock(&fp->f_lock); - return (FS_NOT_IN_FILE); - } - - ind_block_num = fp->i_ib[level]; - - /* - * Initialize array of blocks to free. - */ - for (idx = 0; idx < NIADDR; idx++) - oldsize[idx] = 0; - - for (; level >= 0; level--) { - - vm_offset_t data; - mach_msg_type_number_t size; - - if (ind_block_num == 0) - break; - - if (fp->f_blkno[level] == ind_block_num) { - /* - * Cache hit. Just pick up the data. - */ - - data = fp->f_blk[level]; - } - else { - /* - * Drop our lock while doing the read. - * (The f_dev and f_fs fields don`t change.) - */ - mutex_unlock(&fp->f_lock); - - rc = device_read(fp->f_dev, - 0, - (recnum_t) fsbtodb(fp->f_fs, ind_block_num), - fp->f_fs->fs_bsize, - (char **)&data, - &size); - if (rc != KERN_SUCCESS) - return (rc); - - /* - * See if we can cache the data. Need a write lock to - * do this. While we hold the write lock, we can`t do - * *anything* which might block for memory. Otherwise - * a non-privileged thread might deadlock with the - * privileged threads. We can`t block while taking the - * write lock. Otherwise a non-privileged thread - * blocked in the vm_deallocate (while holding a read - * lock) will block a privileged thread. For the same - * reason, we can`t take a read lock and then use - * lock_read_to_write. - */ - - mutex_lock(&fp->f_lock); - - olddata[level] = fp->f_blk[level]; - oldsize[level] = fp->f_blksize[level]; - - fp->f_blkno[level] = ind_block_num; - fp->f_blk[level] = data; - fp->f_blksize[level] = size; - - /* - * Return to holding a read lock, and - * dispose of old data. - */ - - } - - if (level > 0) { - idx = file_block / fp->f_nindir[level-1]; - file_block %= fp->f_nindir[level-1]; - } - else - idx = file_block; - - ind_block_num = ((daddr_t *)data)[idx]; - } - - mutex_unlock(&fp->f_lock); - - /* - * After unlocking the file, free any blocks that - * we need to free. - */ - for (idx = 0; idx < NIADDR; idx++) - if (oldsize[idx] != 0) - (void) vm_deallocate(mach_task_self(), - olddata[idx], - oldsize[idx]); - - *disk_block_p = ind_block_num; - return (0); -} - -/* - * Read a portion of a file into an internal buffer. Return - * the location in the buffer and the amount in the buffer. - */ -static int -buf_read_file(fp, offset, buf_p, size_p) - register struct file *fp; - vm_offset_t offset; - vm_offset_t *buf_p; /* out */ - vm_size_t *size_p; /* out */ -{ - register struct fs *fs; - vm_offset_t off; - register daddr_t file_block; - daddr_t disk_block; - int rc; - vm_offset_t block_size; - - if (offset >= fp->i_size) - return (FS_NOT_IN_FILE); - - fs = fp->f_fs; - - off = blkoff(fs, offset); - file_block = lblkno(fs, offset); - block_size = blksize(fs, fp, file_block); - - if (file_block != fp->f_buf_blkno) { - rc = block_map(fp, file_block, &disk_block); - if (rc != 0) - return (rc); - - if (fp->f_buf) - (void)vm_deallocate(mach_task_self(), - fp->f_buf, - fp->f_buf_size); - - if (disk_block == 0) { - (void)vm_allocate(mach_task_self(), - &fp->f_buf, - block_size, - TRUE); - fp->f_buf_size = block_size; - } - else { - rc = device_read(fp->f_dev, - 0, - (recnum_t) fsbtodb(fs, disk_block), - (int) block_size, - (char **) &fp->f_buf, - (mach_msg_type_number_t *)&fp->f_buf_size); - } - if (rc) - return (rc); - - fp->f_buf_blkno = file_block; - } - - /* - * Return address of byte in buffer corresponding to - * offset, and size of remainder of buffer after that - * byte. - */ - *buf_p = fp->f_buf + off; - *size_p = block_size - off; - - /* - * But truncate buffer at end of file. - */ - if (*size_p > fp->i_size - offset) - *size_p = fp->i_size - offset; - - return (0); -} - -/* In 4.4 d_reclen is split into d_type and d_namlen */ -struct dirent_44 { - unsigned long d_fileno; - unsigned short d_reclen; - unsigned char d_type; - unsigned char d_namlen; - char d_name[255 + 1]; -}; - -/* - * Search a directory for a name and return its - * i_number. - */ -static int -search_directory(name, fp, inumber_p) - char * name; - register struct file *fp; - ino_t *inumber_p; /* out */ -{ - vm_offset_t buf; - vm_size_t buf_size; - vm_offset_t offset; - register struct dirent_44 *dp; - int length; - kern_return_t rc; - - length = strlen(name); - - offset = 0; - while (offset < fp->i_size) { - rc = buf_read_file(fp, offset, &buf, &buf_size); - if (rc != KERN_SUCCESS) - return (rc); - - dp = (struct dirent_44 *)buf; - if (dp->d_ino != 0) { - unsigned short namlen = dp->d_namlen; - /* - * If namlen is zero, then either this is a 4.3 file - * system or the namlen is really zero. In the latter - * case also the 4.3 d_namlen field is zero - * interpreted either way. - */ - if (namlen == 0) - namlen = ((struct direct *)dp)->d_namlen; - - if (namlen == length && - !strcmp(name, dp->d_name)) - { - /* found entry */ - *inumber_p = dp->d_ino; - return (0); - } - } - offset += dp->d_reclen; - } - return (FS_NO_ENTRY); -} - -static int -read_fs(dev, fsp) - mach_port_t dev; - struct fs **fsp; -{ - register struct fs *fs; - vm_offset_t buf; - mach_msg_type_number_t buf_size; - int error; - - error = device_read(dev, 0, (recnum_t) SBLOCK, SBSIZE, - (char **) &buf, &buf_size); - if (error) - return (error); - - fs = (struct fs *)buf; - if (fs->fs_magic != FS_MAGIC || - fs->fs_bsize > MAXBSIZE || - fs->fs_bsize < sizeof(struct fs)) { - (void) vm_deallocate(mach_task_self(), buf, buf_size); - return (FS_INVALID_FS); - } - /* don't read cylinder groups - we aren't modifying anything */ - - *fsp = fs; - return 0; -} - -static int -mount_fs(fp) - register struct file *fp; -{ - register struct fs *fs; - int error; - - error = read_fs(fp->f_dev, &fp->f_fs); - if (error) - return (error); - fs = fp->f_fs; - - /* - * Calculate indirect block levels. - */ - { - register int mult; - register int level; - - mult = 1; - for (level = 0; level < NIADDR; level++) { - mult *= NINDIR(fs); - fp->f_nindir[level] = mult; - } - } - - return (0); -} - -static void -unmount_fs(fp) - register struct file *fp; -{ - if (file_is_structured(fp)) { - (void) vm_deallocate(mach_task_self(), - (vm_offset_t) fp->f_fs, - SBSIZE); - fp->f_fs = 0; - } -} - -/* - * Open a file. - */ -int -ffs_open_file(master_device_port, path, fp) - mach_port_t master_device_port; - char * path; - struct file *fp; -{ -#define RETURN(code) { rc = (code); goto exit; } - - register char *cp, *component; - register int c; /* char */ - register int rc; - ino_t inumber, parent_inumber; - int nlinks = 0; - - char namebuf[MAXPATHLEN+1]; - - if (path == 0 || *path == '\0') { - return FS_NO_ENTRY; - } - - /* - * Copy name into buffer to allow modifying it. - */ - strcpy(namebuf, path); - - /* - * Look for '/dev/xxx' at start of path, for - * root device. - */ - if (!strprefix(namebuf, "/dev/")) { - printf("no device name\n"); - return FS_NO_ENTRY; - } - - cp = namebuf + 5; /* device */ - component = cp; - while ((c = *cp) != '\0' && c != '/') { - cp++; - } - *cp = '\0'; - - bzero (fp, sizeof (struct file)); - - rc = device_open(master_device_port, - D_READ|D_WRITE, - component, - &fp->f_dev); - if (rc) - return rc; - - if (c == 0) { - fp->f_fs = 0; - goto out_ok; - } - - *cp = c; - - rc = mount_fs(fp); - if (rc) - return rc; - - inumber = (ino_t) ROOTINO; - if ((rc = read_inode(inumber, fp)) != 0) { - printf("can't read root inode\n"); - goto exit; - } - - while (*cp) { - - /* - * Check that current node is a directory. - */ - if ((fp->i_mode & IFMT) != IFDIR) - RETURN (FS_NOT_DIRECTORY); - - /* - * Remove extra separators - */ - while (*cp == '/') - cp++; - - /* - * Get next component of path name. - */ - component = cp; - { - register int len = 0; - - while ((c = *cp) != '\0' && c != '/') { - if (len++ > MAXNAMLEN) - RETURN (FS_NAME_TOO_LONG); - if (c & 0200) - RETURN (FS_INVALID_PARAMETER); - cp++; - } - *cp = 0; - } - - /* - * Look up component in current directory. - * Save directory inumber in case we find a - * symbolic link. - */ - parent_inumber = inumber; - rc = search_directory(component, fp, &inumber); - if (rc) { - printf("%s: not found\n", path); - goto exit; - } - *cp = c; - - /* - * Open next component. - */ - if ((rc = read_inode(inumber, fp)) != 0) - goto exit; - - /* - * Check for symbolic link. - */ - if ((fp->i_mode & IFMT) == IFLNK) { - - int link_len = fp->i_size; - int len; - - len = strlen(cp) + 1; - - if (link_len + len >= MAXPATHLEN - 1) - RETURN (FS_NAME_TOO_LONG); - - if (++nlinks > MAXSYMLINKS) - RETURN (FS_SYMLINK_LOOP); - - memmove (&namebuf[link_len], cp, len); - -#ifdef IC_FASTLINK - if ((fp->i_flags & IC_FASTLINK) != 0) { - bcopy(fp->i_symlink, namebuf, (unsigned) link_len); - } - else -#endif /* IC_FASTLINK */ -#if !defined(DISABLE_BSD44_FASTLINKS) - /* - * There is no bit for fastlinks in 4.4 but instead - * all symlinks that fit into the inode are fastlinks. - * If the second block (ic_db[1]) is zero the symlink - * can't be a fastlink if its length is at least five. - * For symlinks of length one to four there is no easy - * way of knowing whether we are looking at a 4.4 - * fastlink or a 4.3 slowlink. This code always - * guesses the 4.4 way when in doubt. THIS BREAKS 4.3 - * SLOWLINKS OF LENGTH FOUR OR LESS. - */ - if ((link_len <= MAX_FASTLINK_SIZE && fp->i_ic.ic_db[1] != 0) - || (link_len <= 4)) - { - bcopy(fp->i_symlink, namebuf, (unsigned) link_len); - } - else -#endif /* !DISABLE_BSD44_FASTLINKS */ - - { - /* - * Read file for symbolic link - */ - vm_offset_t buf; - mach_msg_type_number_t buf_size; - daddr_t disk_block; - register struct fs *fs = fp->f_fs; - - (void) block_map(fp, (daddr_t)0, &disk_block); - rc = device_read(fp->f_dev, - 0, - (recnum_t) fsbtodb(fs, disk_block), - (int) blksize(fs, fp, 0), - (char **) &buf, - &buf_size); - if (rc) - goto exit; - - bcopy((char *)buf, namebuf, (unsigned)link_len); - (void) vm_deallocate(mach_task_self(), buf, buf_size); - } - - /* - * If relative pathname, restart at parent directory. - * If absolute pathname, restart at root. - * If pathname begins '/dev/<device>/', - * restart at root of that device. - */ - cp = namebuf; - if (*cp != '/') { - inumber = parent_inumber; - } - else if (!strprefix(cp, "/dev/")) { - inumber = (ino_t)ROOTINO; - } - else { - cp += 5; - component = cp; - while ((c = *cp) != '\0' && c != '/') { - cp++; - } - *cp = '\0'; - - /* - * Unmount current file system and free buffers. - */ - close_file(fp); - - /* - * Open new root device. - */ - rc = device_open(master_device_port, - D_READ, - component, - &fp->f_dev); - if (rc) - return (rc); - - if (c == 0) { - fp->f_fs = 0; - goto out_ok; - } - - *cp = c; - - rc = mount_fs(fp); - if (rc) - return (rc); - - inumber = (ino_t)ROOTINO; - } - if ((rc = read_inode(inumber, fp)) != 0) - goto exit; - } - } - - /* - * Found terminal component. - */ - out_ok: - mutex_init(&fp->f_lock); - return 0; - - /* - * At error exit, close file to free storage. - */ - exit: - close_file(fp); - return rc; -} - -/* - * Close file - free all storage used. - */ -void -ffs_close_file(fp) - register struct file *fp; -{ - register int i; - - /* - * Free the disk super-block. - */ - unmount_fs(fp); - - /* - * Free the inode and data buffers. - */ - free_file_buffers(fp); -} - -int -ffs_file_is_directory(struct file *fp) -{ - return (fp->i_mode & IFMT) == IFDIR; -} - -int -ffs_file_is_regular(struct file *fp) -{ - return (fp->i_mode & IFMT) == IFREG; -} - -/* - * Copy a portion of a file into kernel memory. - * Cross block boundaries when necessary. - */ -int -ffs_read_file(fp, offset, start, size, resid) - register struct file *fp; - vm_offset_t offset; - vm_offset_t start; - vm_size_t size; - vm_size_t *resid; /* out */ -{ - int rc; - register vm_size_t csize; - vm_offset_t buf; - vm_size_t buf_size; - - while (size != 0) { - rc = buf_read_file(fp, offset, &buf, &buf_size); - if (rc) - return (rc); - - csize = size; - if (csize > buf_size) - csize = buf_size; - if (csize == 0) - break; - - bcopy((char *)buf, (char *)start, csize); - - offset += csize; - start += csize; - size -= csize; - } - if (resid) - *resid = size; - - return (0); -} - -/* simple utility: only works for 2^n */ -static int -log2(n) - register unsigned int n; -{ - register int i = 0; - - while ((n & 1) == 0) { - i++; - n >>= 1; - } - return i; -} - -/* - * Make an empty file_direct for a device. - */ -int -ffs_open_file_direct(dev, fdp, is_structured) - mach_port_t dev; - register struct file_direct *fdp; - boolean_t is_structured; -{ - struct fs *fs; - int rc; - - if (!is_structured) { - fdp->fd_dev = dev; - fdp->fd_blocks = (daddr_t *) 0; - fdp->fd_bsize = vm_page_size; - fdp->fd_bshift = log2(vm_page_size); - fdp->fd_fsbtodb = 0; /* later */ - fdp->fd_size = 0; /* later */ - return 0; - } - - rc = read_fs(dev, &fs); - if (rc) - return rc; - - fdp->fd_dev = dev; - fdp->fd_blocks = (daddr_t *) 0; - fdp->fd_size = 0; - fdp->fd_bsize = fs->fs_bsize; - fdp->fd_bshift = fs->fs_bshift; - fdp->fd_fsbtodb = fs->fs_fsbtodb; - - (void) vm_deallocate(mach_task_self(), - (vm_offset_t) fs, - SBSIZE); - - return 0; -} - -/* - * Add blocks from a file to a file_direct. - */ -int -ffs_add_file_direct(fdp, fp) - register struct file_direct *fdp; - register struct file *fp; -{ - register struct fs *fs; - long num_blocks, i; - vm_offset_t buffer; - vm_size_t size; - int rc; - - /* the file must be on the same device */ - - if (fdp->fd_dev != fp->f_dev) - return FS_INVALID_FS; - - if (!file_is_structured(fp)) { - int result[DEV_GET_SIZE_COUNT]; - natural_t count; - - count = DEV_GET_SIZE_COUNT; - rc = device_get_status( fdp->fd_dev, DEV_GET_SIZE, - result, &count); - if (rc) - return rc; - fdp->fd_size = result[DEV_GET_SIZE_DEVICE_SIZE] >> fdp->fd_bshift; - fdp->fd_fsbtodb = log2(fdp->fd_bsize/result[DEV_GET_SIZE_RECORD_SIZE]); - return 0; - } - - /* it must hold a file system */ - - fs = fp->f_fs; - if (fdp->fd_bsize != fs->fs_bsize || - fdp->fd_fsbtodb != fs->fs_fsbtodb) - return FS_INVALID_FS; - - /* calculate number of blocks in the file, ignoring fragments */ - - num_blocks = lblkno(fs, fp->i_size); - - /* allocate memory for a bigger array */ - - size = (num_blocks + fdp->fd_size) * sizeof(daddr_t); - rc = vm_allocate(mach_task_self(), &buffer, size, TRUE); - if (rc != KERN_SUCCESS) - return rc; - - /* lookup new block addresses */ - - for (i = 0; i < num_blocks; i++) { - daddr_t disk_block; - - rc = block_map(fp, (daddr_t) i, &disk_block); - if (rc != 0) { - (void) vm_deallocate(mach_task_self(), buffer, size); - return rc; - } - - ((daddr_t *) buffer)[fdp->fd_size + i] = disk_block; - } - - /* copy old addresses and install the new array */ - - if (fdp->fd_blocks != 0) { - bcopy((char *) fdp->fd_blocks, (char *) buffer, - fdp->fd_size * sizeof(daddr_t)); - - (void) vm_deallocate(mach_task_self(), - (vm_offset_t) fdp->fd_blocks, - (vm_size_t) (fdp->fd_size * sizeof(daddr_t))); - } - fdp->fd_blocks = (daddr_t *) buffer; - fdp->fd_size += num_blocks; - - /* deallocate cached blocks */ - - free_file_buffers(fp); - - return 0; -} - -int -ffs_remove_file_direct(fdp) - struct file_direct *fdp; -{ - if (fdp->fd_blocks) - (void) vm_deallocate(mach_task_self(), - (vm_offset_t) fdp->fd_blocks, - (vm_size_t) (fdp->fd_size * sizeof(daddr_t))); - fdp->fd_blocks = 0; /* sanity */ - /* xxx should lose a ref to fdp->fd_dev here (and elsewhere) xxx */ -} diff --git a/serverboot/file_io.c b/serverboot/file_io.c deleted file mode 100644 index 99966f95..00000000 --- a/serverboot/file_io.c +++ /dev/null @@ -1,317 +0,0 @@ -/* - * Copyright (c) 1994 The University of Utah and - * the Computer Systems Laboratory at the University of Utah (CSL). - * All rights reserved. - * - * Permission to use, copy, modify and distribute this software is hereby - * granted provided that (1) source code retains these copyright, permission, - * and disclaimer notices, and (2) redistributions including binaries - * reproduce the notices in supporting documentation, and (3) all advertising - * materials mentioning features or use of this software display the following - * acknowledgement: ``This product includes software developed by the - * Computer Systems Laboratory at the University of Utah.'' - * - * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS - * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF - * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * CSL requests users of this software to return to csl-dist@cs.utah.edu any - * improvements that they make and grant CSL redistribution rights. - * - * Author: Bryan Ford, University of Utah CSL - * MINIX FS patches: Csizmazia Balazs, University ELTE, Hungary - */ -/* This is just an icky kludgy "VFS layer" (harhar) for ffs and ext2 and minix. */ - -#include "file_io.h" - -int -open_file(master_device_port, path, fp) - mach_port_t master_device_port; - char * path; - struct file *fp; -{ - int rc; - - if ((rc = ext2_open_file(master_device_port, path, fp)) - != FS_INVALID_FS) - { - if (rc == 0) - fp->f_fstype = EXT2_FS; - return rc; - } - if ( (rc = minix_open_file(master_device_port, path, fp)) - != FS_INVALID_FS ) - { - if (rc == 0) - fp->f_fstype = MINIX_FS; - return rc; - } - fp->f_fstype = BSD_FFS; - return ffs_open_file(master_device_port, path, fp); -} - -void -close_file(fp) - register struct file *fp; -{ - switch (fp->f_fstype) { - case EXT2_FS: - ext2_close_file(fp); - return; - case MINIX_FS: - minix_close_file(fp); - return; - default: - ffs_close_file(fp); - return; - } -} - -int -read_file(fp, offset, start, size, resid) - register struct file *fp; - vm_offset_t offset; - vm_offset_t start; - vm_size_t size; - vm_size_t *resid; /* out */ -{ - switch (fp->f_fstype) { - case EXT2_FS: - return ext2_read_file(fp, offset, start, size, resid); - case MINIX_FS: - return minix_read_file(fp, offset, start, size, resid); - default: - return ffs_read_file(fp, offset, start, size, resid); - } - -} - -int -file_is_directory(struct file *f) -{ - switch (f->f_fstype) { - case EXT2_FS: - return ext2_file_is_directory(f); - case MINIX_FS: - return minix_file_is_directory(f); - default: - return ffs_file_is_directory(f); - } -} - -int -file_is_regular(struct file *f) -{ - switch (f->f_fstype) { - case EXT2_FS: - return ext2_file_is_regular(f); - case MINIX_FS: - return minix_file_is_regular(f); - default: - return ffs_file_is_regular(f); - } - -} - -int -open_file_direct(dev, fdp, is_structured) - mach_port_t dev; - register struct file_direct *fdp; - boolean_t is_structured; -{ - int rc; - - - if ((rc = ext2_open_file_direct(dev, fdp, is_structured)) - != FS_INVALID_FS) - { - if (rc == 0) - fdp->f_fstype = EXT2_FS; - return rc; - } - if ( (rc = minix_open_file_direct(dev, fdp, is_structured) ) - != FS_INVALID_FS ) - { - if (rc == 0) - fdp->f_fstype = MINIX_FS; - return rc; - } - fdp->f_fstype = BSD_FFS; - return ffs_open_file_direct(dev, fdp, is_structured); -} - -int -add_file_direct(fdp, fp) - register struct file_direct *fdp; - register struct file *fp; -{ - switch (fp->f_fstype) { - case EXT2_FS: - return ext2_add_file_direct(fdp, fp); - case MINIX_FS: - return minix_add_file_direct(fdp, fp); - default: - return ffs_add_file_direct(fdp, fp); - } -} - - -int -remove_file_direct(fdp) - struct file_direct *fdp; -{ - switch (fdp->f_fstype) { - case EXT2_FS: - return ext2_remove_file_direct(fdp); - case MINIX_FS: - return minix_remove_file_direct(fdp); - default: - return ffs_remove_file_direct(fdp); - } -} - -/* - * some other stuff, that was previously defined as macro - */ - -int -file_is_structured(fp) - register struct file *fp; -{ - switch (fp->f_fstype) { - case EXT2_FS: - return (fp)->u.ext2.ext2_fs != 0; - case MINIX_FS: - return (fp)->u.minix.minix_fs != 0; - default: - return (fp)->u.ffs.ffs_fs != 0; - } -} - -/* - * Special read and write routines for default pager. - * Assume that all offsets and sizes are multiples - * of DEV_BSIZE. - */ - -#define fdir_blkoff(fdp, offset) /* offset % fd_bsize */ \ - ((offset) & ((fdp)->fd_bsize - 1)) -#define fdir_lblkno(fdp, offset) /* offset / fd_bsize */ \ - ((offset) >> (fdp)->fd_bshift) - -#define fdir_fsbtodb(fdp, block) /* offset * fd_bsize / DEV_BSIZE */ \ - ((block) << (fdp)->fd_fsbtodb) - -/* - * Read all or part of a data block, and - * return a pointer to the appropriate part. - * Caller must deallocate the block when done. - */ -int -page_read_file_direct(fdp, offset, size, addr, size_read) - register struct file_direct *fdp; - vm_offset_t offset; - vm_size_t size; - vm_offset_t *addr; /* out */ - mach_msg_type_number_t *size_read; /* out */ -{ - vm_offset_t off; - register daddr_t file_block; - daddr_t disk_block; - - if (offset % DEV_BSIZE != 0 || - size % DEV_BSIZE != 0) - panic("page_read_file_direct"); - - if (offset >= (fdp->fd_size << fdp->fd_bshift)) - return (FS_NOT_IN_FILE); - - off = fdir_blkoff(fdp, offset); - file_block = fdir_lblkno(fdp, offset); - - if (file_is_device(fdp)) { - disk_block = file_block; - } else { - disk_block = fdp->fd_blocks[file_block]; - if (disk_block == 0) - return (FS_NOT_IN_FILE); - - if (size > fdp->fd_bsize) { - /* Read only as much as is contiguous on disk. */ - daddr_t b = file_block + 1; - while (b < file_block + fdp->fd_size && - fdp->fd_blocks[b] == disk_block + fdir_fsbtodb(fdp, 1)) - ++b; - size = (b - file_block) * fdp->fd_bsize; - } - } - - return (device_read(fdp->fd_dev, - 0, - (recnum_t) (fdir_fsbtodb(fdp, disk_block) + btodb(off)), - (int) size, - (char **) addr, - size_read)); -} - -/* - * Write all or part of a data block, and - * return the amount written. - */ -int -page_write_file_direct(fdp, offset, addr, size, size_written) - register struct file_direct *fdp; - vm_offset_t offset; - vm_offset_t addr; - vm_size_t size; - vm_offset_t *size_written; /* out */ -{ - vm_offset_t off; - register daddr_t file_block; - daddr_t disk_block; - int rc, num_written; - vm_offset_t block_size; - - if (offset % DEV_BSIZE != 0 || - size % DEV_BSIZE != 0) - panic("page_write_file"); - - if (offset >= (fdp->fd_size << fdp->fd_bshift)) - return (FS_NOT_IN_FILE); - - off = fdir_blkoff(fdp, offset); - file_block = fdir_lblkno(fdp, offset); - - if (file_is_device(fdp)) { - disk_block = file_block; - } else { - disk_block = fdp->fd_blocks[file_block]; - if (disk_block == 0) - return (FS_NOT_IN_FILE); - - if (size > fdp->fd_bsize) { - /* Write only as much as is contiguous on disk. */ - daddr_t b = file_block + 1; - while (b < file_block + fdp->fd_size && - fdp->fd_blocks[b] == disk_block + fdir_fsbtodb(fdp, 1)) - ++b; - size = (b - file_block) * fdp->fd_bsize; - } - } - - /* - * Write the data. Wait for completion to keep - * reads from getting ahead of writes and reading - * stale data. - */ - rc = device_write( - fdp->fd_dev, - 0, - (recnum_t) (fdir_fsbtodb(fdp, disk_block) + btodb(off)), - (char *) addr, - size, - &num_written); - *size_written = num_written; - return rc; -} diff --git a/serverboot/file_io.h b/serverboot/file_io.h deleted file mode 100644 index 323e4e9a..00000000 --- a/serverboot/file_io.h +++ /dev/null @@ -1,200 +0,0 @@ -/* - * Mach Operating System - * Copyright (c) 1991,1990,1989,1988 Carnegie Mellon University - * All Rights Reserved. - * - * Permission to use, copy, modify and distribute this software and its - * documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" - * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR - * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to - * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 - * - * any improvements or extensions that they make and grant Carnegie Mellon - * the rights to redistribute these changes. - */ - -#ifndef _FILE_IO_H_ -#define _FILE_IO_H_ - -/* - * Read-only file IO. - */ - -#include <mach.h> -#include <cthreads.h> - -#include <stdint.h> -#include <device/device_types.h> - -/* Types used by the ext2 header files. */ -typedef u_int32_t __u32; -typedef int32_t __s32; -typedef u_int16_t __u16; -typedef int16_t __s16; -typedef u_int8_t __u8; -typedef int8_t __s8; - -#include <defs.h> -#include "minix_fs.h" -#include "../ext2fs/ext2_fs.h" /* snarf stolen linux header from ext2fs */ -#include "disk_inode.h" - -#define BSD_FFS 0 -#define EXT2_FS 1 -#define MINIX_FS 2 - -#define EXT2_NIADDR (EXT2_N_BLOCKS - EXT2_NDIR_BLOCKS) - -/* - * In-core open file. - */ -struct file { - struct mutex f_lock; /* lock */ - mach_port_t f_dev; /* port to device */ - vm_offset_t f_buf; /* buffer for data block */ - vm_size_t f_buf_size; /* size of data block */ - daddr_t f_buf_blkno; /* block number of data block */ - vm_size_t f_size; /* size in bytes of the file */ - - int f_fstype; /* contains fs-id */ - - union { - struct { - struct fs * ffs_fs; /* pointer to super-block */ - struct icommon ffs_ic; /* copy of on-disk inode */ - - /* number of blocks mapped by - indirect block at level i */ - int ffs_nindir[FFS_NIADDR+1]; - - /* buffer for indirect block at level i */ - vm_offset_t ffs_blk[FFS_NIADDR]; - - /* size of buffer */ - vm_size_t ffs_blksize[FFS_NIADDR]; - - /* disk address of block in buffer */ - daddr_t ffs_blkno[FFS_NIADDR]; - } ffs; - struct { - /* pointer to super-block */ - struct ext2_super_block*ext2_fs; - - /* pointer to group descriptors */ - struct ext2_group_desc* ext2_gd; - - /* size of group descriptors */ - vm_size_t ext2_gd_size; - - /* copy of on-disk inode */ - struct ext2_inode ext2_ic; - - /* number of blocks mapped by - indirect block at level i */ - int ext2_nindir[EXT2_NIADDR+1]; - - /* buffer for indirect block at level i */ - vm_offset_t ext2_blk[EXT2_NIADDR]; - - /* size of buffer */ - vm_size_t ext2_blksize[EXT2_NIADDR]; - - /* disk address of block in buffer */ - daddr_t ext2_blkno[EXT2_NIADDR]; - } ext2; - struct { - /* pointer to super-block */ - struct minix_super_block* minix_fs; - - /* copy of on-disk inode */ - struct minix_inode minix_ic; - - /* number of blocks mapped by - indirect block at level i */ - int minix_nindir[MINIX_NIADDR+1]; - - /* buffer for indirect block at level i */ - vm_offset_t minix_blk[MINIX_NIADDR]; - - /* size of buffer */ - vm_size_t minix_blksize[MINIX_NIADDR]; - - /* disk address of block in buffer */ - minix_daddr_t minix_blkno[MINIX_NIADDR]; - } minix; - } u; -}; - -/* - * In-core open file, with in-core block map. - */ -struct file_direct { - int f_fstype; /* XXX was: true if ext2, false if ffs */ - - mach_port_t fd_dev; /* port to device */ - daddr_t * fd_blocks; /* array of disk block addresses */ - long fd_size; /* number of blocks in the array */ - long fd_bsize; /* disk block size */ - long fd_bshift; /* log2(fd_bsize) */ - long fd_fsbtodb; /* log2(fd_bsize / disk sector size) */ -}; - -#define file_is_device(_fd_) ((_fd_)->fd_blocks == 0) - -/* - * Exported routines. - */ - -extern int open_file(); -extern void close_file(); -extern int read_file(); - -extern int open_file_direct(); -extern int add_file_direct(); -extern int remove_file_direct(); -extern int file_wire_direct(); -extern int page_read_file_direct(); -extern int page_write_file_direct(); - -/* - * Error codes for file system errors. - */ - -#include <errno.h> - -/* Just use the damn Hurd error numbers. This is old CMU/Utah code from - the days of personality-independent Mach where it made sense for this to - be a standalone universe. In the Hurd, we compile serverboot against - the regular C library anyway. */ - -#define FS_NOT_DIRECTORY ENOTDIR -#define FS_NO_ENTRY ENOENT -#define FS_NAME_TOO_LONG ENAMETOOLONG -#define FS_SYMLINK_LOOP ELOOP -#define FS_INVALID_FS EFTYPE /* ? */ -#define FS_NOT_IN_FILE EINVAL -#define FS_INVALID_PARAMETER EINVAL - -#if 0 -#define FS_NOT_DIRECTORY 5000 /* not a directory */ -#define FS_NO_ENTRY 5001 /* name not found */ -#define FS_NAME_TOO_LONG 5002 /* name too long */ -#define FS_SYMLINK_LOOP 5003 /* symbolic link loop */ -#define FS_INVALID_FS 5004 /* bad file system */ -#define FS_NOT_IN_FILE 5005 /* offset not in file */ -#define FS_INVALID_PARAMETER 5006 /* bad parameter to routine */ -#endif - - -#endif /* _FILE_IO_H_ */ diff --git a/serverboot/fs.h b/serverboot/fs.h deleted file mode 100644 index 5809ed93..00000000 --- a/serverboot/fs.h +++ /dev/null @@ -1,455 +0,0 @@ -/* - * Mach Operating System - * Copyright (c) 1991,1990 Carnegie Mellon University - * All Rights Reserved. - * - * Permission to use, copy, modify and distribute this software and its - * documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" - * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR - * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to - * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 - * - * any improvements or extensions that they make and grant Carnegie Mellon - * the rights to redistribute these changes. - */ -/* - * Copyright (c) 1982, 1986 Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms are permitted - * provided that the above copyright notice and this paragraph are - * duplicated in all such forms and that any documentation, - * advertising materials, and other materials related to such - * distribution and use acknowledge that the software was developed - * by the University of California, Berkeley. The name of the - * University may not be used to endorse or promote products derived - * from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. - * - * @(#)fs.h 7.7 (Berkeley) 5/9/89 - */ - -/* - * Each disk drive contains some number of file systems. - * A file system consists of a number of cylinder groups. - * Each cylinder group has inodes and data. - * - * A file system is described by its super-block, which in turn - * describes the cylinder groups. The super-block is critical - * data and is replicated in each cylinder group to protect against - * catastrophic loss. This is done at `newfs' time and the critical - * super-block data does not change, so the copies need not be - * referenced further unless disaster strikes. - * - * For file system fs, the offsets of the various blocks of interest - * are given in the super block as: - * [fs->fs_sblkno] Super-block - * [fs->fs_cblkno] Cylinder group block - * [fs->fs_iblkno] Inode blocks - * [fs->fs_dblkno] Data blocks - * The beginning of cylinder group cg in fs, is given by - * the ``cgbase(fs, cg)'' macro. - * - * The first boot and super blocks are given in absolute disk addresses. - * The byte-offset forms are preferred, as they don't imply a sector size. - */ -#define BBSIZE 8192 -#define SBSIZE 8192 -#define BBOFF ((off_t)(0)) -#define SBOFF ((off_t)(BBOFF + BBSIZE)) -#define BBLOCK ((daddr_t)(0)) -#define SBLOCK ((daddr_t)(BBLOCK + BBSIZE / DEV_BSIZE)) - -/* - * Addresses stored in inodes are capable of addressing fragments - * of `blocks'. File system blocks of at most size MAXBSIZE can - * be optionally broken into 2, 4, or 8 pieces, each of which is - * addressible; these pieces may be DEV_BSIZE, or some multiple of - * a DEV_BSIZE unit. - * - * Large files consist of exclusively large data blocks. To avoid - * undue wasted disk space, the last data block of a small file may be - * allocated as only as many fragments of a large block as are - * necessary. The file system format retains only a single pointer - * to such a fragment, which is a piece of a single large block that - * has been divided. The size of such a fragment is determinable from - * information in the inode, using the ``blksize(fs, ip, lbn)'' macro. - * - * The file system records space availability at the fragment level; - * to determine block availability, aligned fragments are examined. - * - * The root inode is the root of the file system. - * Inode 0 can't be used for normal purposes and - * historically bad blocks were linked to inode 1, - * thus the root inode is 2. (inode 1 is no longer used for - * this purpose, however numerous dump tapes make this - * assumption, so we are stuck with it) - */ -#define ROOTINO ((ino_t)2) /* i number of all roots */ - -/* - * MINBSIZE is the smallest allowable block size. - * In order to insure that it is possible to create files of size - * 2^32 with only two levels of indirection, MINBSIZE is set to 4096. - * MINBSIZE must be big enough to hold a cylinder group block, - * thus changes to (struct cg) must keep its size within MINBSIZE. - * Note that super blocks are always of size SBSIZE, - * and that both SBSIZE and MAXBSIZE must be >= MINBSIZE. - */ -#define MINBSIZE 4096 - -/* - * The path name on which the file system is mounted is maintained - * in fs_fsmnt. MAXMNTLEN defines the amount of space allocated in - * the super block for this name. - * The limit on the amount of summary information per file system - * is defined by MAXCSBUFS. It is currently parameterized for a - * maximum of two million cylinders. - */ -#define MAXMNTLEN 512 -#define MAXCSBUFS 32 - -/* - * Per cylinder group information; summarized in blocks allocated - * from first cylinder group data blocks. These blocks have to be - * read in from fs_csaddr (size fs_cssize) in addition to the - * super block. - * - * N.B. sizeof(struct csum) must be a power of two in order for - * the ``fs_cs'' macro to work (see below). - */ -struct csum { - int cs_ndir; /* number of directories */ - int cs_nbfree; /* number of free blocks */ - int cs_nifree; /* number of free inodes */ - int cs_nffree; /* number of free frags */ -}; - -/* - * Super block for a file system. - */ -#define FS_MAGIC 0x011954 -struct fs -{ - int xxx1; /* struct fs *fs_link;*/ - int xxx2; /* struct fs *fs_rlink;*/ - daddr_t fs_sblkno; /* addr of super-block in filesys */ - daddr_t fs_cblkno; /* offset of cyl-block in filesys */ - daddr_t fs_iblkno; /* offset of inode-blocks in filesys */ - daddr_t fs_dblkno; /* offset of first data after cg */ - int fs_cgoffset; /* cylinder group offset in cylinder */ - int fs_cgmask; /* used to calc mod fs_ntrak */ - time_t fs_time; /* last time written */ - int fs_size; /* number of blocks in fs */ - int fs_dsize; /* number of data blocks in fs */ - int fs_ncg; /* number of cylinder groups */ - int fs_bsize; /* size of basic blocks in fs */ - int fs_fsize; /* size of frag blocks in fs */ - int fs_frag; /* number of frags in a block in fs */ -/* these are configuration parameters */ - int fs_minfree; /* minimum percentage of free blocks */ - int fs_rotdelay; /* num of ms for optimal next block */ - int fs_rps; /* disk revolutions per second */ -/* these fields can be computed from the others */ - int fs_bmask; /* ``blkoff'' calc of blk offsets */ - int fs_fmask; /* ``fragoff'' calc of frag offsets */ - int fs_bshift; /* ``lblkno'' calc of logical blkno */ - int fs_fshift; /* ``numfrags'' calc number of frags */ -/* these are configuration parameters */ - int fs_maxcontig; /* max number of contiguous blks */ - int fs_maxbpg; /* max number of blks per cyl group */ -/* these fields can be computed from the others */ - int fs_fragshift; /* block to frag shift */ - int fs_fsbtodb; /* fsbtodb and dbtofsb shift constant */ - int fs_sbsize; /* actual size of super block */ - int fs_csmask; /* csum block offset */ - int fs_csshift; /* csum block number */ - int fs_nindir; /* value of NINDIR */ - int fs_inopb; /* value of INOPB */ - int fs_nspf; /* value of NSPF */ -/* yet another configuration parameter */ - int fs_optim; /* optimization preference, see below */ -/* these fields are derived from the hardware */ - int fs_npsect; /* # sectors/track including spares */ - int fs_interleave; /* hardware sector interleave */ - int fs_trackskew; /* sector 0 skew, per track */ - int fs_headswitch; /* head switch time, usec */ - int fs_trkseek; /* track-to-track seek, usec */ -/* sizes determined by number of cylinder groups and their sizes */ - daddr_t fs_csaddr; /* blk addr of cyl grp summary area */ - int fs_cssize; /* size of cyl grp summary area */ - int fs_cgsize; /* cylinder group size */ -/* these fields are derived from the hardware */ - int fs_ntrak; /* tracks per cylinder */ - int fs_nsect; /* sectors per track */ - int fs_spc; /* sectors per cylinder */ -/* this comes from the disk driver partitioning */ - int fs_ncyl; /* cylinders in file system */ -/* these fields can be computed from the others */ - int fs_cpg; /* cylinders per group */ - int fs_ipg; /* inodes per group */ - int fs_fpg; /* blocks per group * fs_frag */ -/* this data must be re-computed after crashes */ - struct csum fs_cstotal; /* cylinder summary information */ -/* these fields are cleared at mount time */ - char fs_fmod; /* super block modified flag */ - char fs_clean; /* file system is clean flag */ - char fs_ronly; /* mounted read-only flag */ - char fs_flags; /* currently unused flag */ - char fs_fsmnt[MAXMNTLEN]; /* name mounted on */ -/* these fields retain the current block allocation info */ - int fs_cgrotor; /* last cg searched */ -#if 1 - int was_fs_csp[MAXCSBUFS]; -#else - struct csum *fs_csp[MAXCSBUFS];/* list of fs_cs info buffers */ -#endif - int fs_cpc; /* cyl per cycle in postbl */ - short fs_opostbl[16][8]; /* old rotation block list head */ - long fs_sparecon[50]; /* reserved for future constants */ - long fs_contigsumsize; /* size of cluster summary array */ - long fs_maxsymlinklen; /* max length of an internal symlink */ - long fs_inodefmt; /* format of on-disk inodes */ - quad fs_maxfilesize; /* maximum representable file size */ - quad fs_qbmask; /* ~fs_bmask - for use with quad size */ - quad fs_qfmask; /* ~fs_fmask - for use with quad size */ - long fs_state; /* validate fs_clean field */ - int fs_postblformat; /* format of positional layout tables */ - int fs_nrpos; /* number of rotaional positions */ - int fs_postbloff; /* (short) rotation block list head */ - int fs_rotbloff; /* (u_char) blocks for each rotation */ - int fs_magic; /* magic number */ - u_char fs_space[1]; /* list of blocks for each rotation */ -/* actually longer */ -}; -/* - * Preference for optimization. - */ -#define FS_OPTTIME 0 /* minimize allocation time */ -#define FS_OPTSPACE 1 /* minimize disk fragmentation */ - -/* - * Rotational layout table format types - */ -#define FS_42POSTBLFMT -1 /* 4.2BSD rotational table format */ -#define FS_DYNAMICPOSTBLFMT 1 /* dynamic rotational table format */ -/* - * Macros for access to superblock array structures - */ -#define fs_postbl(fs, cylno) \ - (((fs)->fs_postblformat == FS_42POSTBLFMT) \ - ? ((fs)->fs_opostbl[cylno]) \ - : ((short *)((char *)(fs) + (fs)->fs_postbloff) + (cylno) * (fs)->fs_nrpos)) -#define fs_rotbl(fs) \ - (((fs)->fs_postblformat == FS_42POSTBLFMT) \ - ? ((fs)->fs_space) \ - : ((u_char *)((char *)(fs) + (fs)->fs_rotbloff))) - -/* - * Convert cylinder group to base address of its global summary info. - * - * N.B. This macro assumes that sizeof(struct csum) is a power of two. - */ -#define fs_cs(fs, indx) \ - fs_csp[(indx) >> (fs)->fs_csshift][(indx) & ~(fs)->fs_csmask] - -/* - * Cylinder group block for a file system. - */ -#define CG_MAGIC 0x090255 -struct cg { - int xxx1; /* struct cg *cg_link;*/ - int cg_magic; /* magic number */ - time_t cg_time; /* time last written */ - int cg_cgx; /* we are the cgx'th cylinder group */ - short cg_ncyl; /* number of cyl's this cg */ - short cg_niblk; /* number of inode blocks this cg */ - int cg_ndblk; /* number of data blocks this cg */ - struct csum cg_cs; /* cylinder summary information */ - int cg_rotor; /* position of last used block */ - int cg_frotor; /* position of last used frag */ - int cg_irotor; /* position of last used inode */ - int cg_frsum[MAXFRAG]; /* counts of available frags */ - int cg_btotoff; /* (long) block totals per cylinder */ - int cg_boff; /* (short) free block positions */ - int cg_iusedoff; /* (char) used inode map */ - int cg_freeoff; /* (u_char) free block map */ - int cg_nextfreeoff; /* (u_char) next available space */ - int cg_sparecon[16]; /* reserved for future use */ - u_char cg_space[1]; /* space for cylinder group maps */ -/* actually longer */ -}; -/* - * Macros for access to cylinder group array structures - */ -#define cg_blktot(cgp) \ - (((cgp)->cg_magic != CG_MAGIC) \ - ? (((struct ocg *)(cgp))->cg_btot) \ - : ((int *)((char *)(cgp) + (cgp)->cg_btotoff))) -#define cg_blks(fs, cgp, cylno) \ - (((cgp)->cg_magic != CG_MAGIC) \ - ? (((struct ocg *)(cgp))->cg_b[cylno]) \ - : ((short *)((char *)(cgp) + (cgp)->cg_boff) + (cylno) * (fs)->fs_nrpos)) -#define cg_inosused(cgp) \ - (((cgp)->cg_magic != CG_MAGIC) \ - ? (((struct ocg *)(cgp))->cg_iused) \ - : ((char *)((char *)(cgp) + (cgp)->cg_iusedoff))) -#define cg_blksfree(cgp) \ - (((cgp)->cg_magic != CG_MAGIC) \ - ? (((struct ocg *)(cgp))->cg_free) \ - : ((u_char *)((char *)(cgp) + (cgp)->cg_freeoff))) -#define cg_chkmagic(cgp) \ - ((cgp)->cg_magic == CG_MAGIC || ((struct ocg *)(cgp))->cg_magic == CG_MAGIC) - -/* - * The following structure is defined - * for compatibility with old file systems. - */ -struct ocg { - int xxx1; /* struct ocg *cg_link;*/ - int xxx2; /* struct ocg *cg_rlink;*/ - time_t cg_time; /* time last written */ - int cg_cgx; /* we are the cgx'th cylinder group */ - short cg_ncyl; /* number of cyl's this cg */ - short cg_niblk; /* number of inode blocks this cg */ - int cg_ndblk; /* number of data blocks this cg */ - struct csum cg_cs; /* cylinder summary information */ - int cg_rotor; /* position of last used block */ - int cg_frotor; /* position of last used frag */ - int cg_irotor; /* position of last used inode */ - int cg_frsum[8]; /* counts of available frags */ - int cg_btot[32]; /* block totals per cylinder */ - short cg_b[32][8]; /* positions of free blocks */ - char cg_iused[256]; /* used inode map */ - int cg_magic; /* magic number */ - u_char cg_free[1]; /* free block map */ -/* actually longer */ -}; - -/* - * Turn file system block numbers into disk block addresses. - * This maps file system blocks to device size blocks. - */ -#define fsbtodb(fs, b) ((b) << (fs)->fs_fsbtodb) -#define dbtofsb(fs, b) ((b) >> (fs)->fs_fsbtodb) - -/* - * Cylinder group macros to locate things in cylinder groups. - * They calc file system addresses of cylinder group data structures. - */ -#define cgbase(fs, c) ((daddr_t)((fs)->fs_fpg * (c))) -#define cgstart(fs, c) \ - (cgbase(fs, c) + (fs)->fs_cgoffset * ((c) & ~((fs)->fs_cgmask))) -#define cgsblock(fs, c) (cgstart(fs, c) + (fs)->fs_sblkno) /* super blk */ -#define cgtod(fs, c) (cgstart(fs, c) + (fs)->fs_cblkno) /* cg block */ -#define cgimin(fs, c) (cgstart(fs, c) + (fs)->fs_iblkno) /* inode blk */ -#define cgdmin(fs, c) (cgstart(fs, c) + (fs)->fs_dblkno) /* 1st data */ - -/* - * Macros for handling inode numbers: - * inode number to file system block offset. - * inode number to cylinder group number. - * inode number to file system block address. - */ -#define itoo(fs, x) ((x) % INOPB(fs)) -#define itog(fs, x) ((x) / (fs)->fs_ipg) -#define itod(fs, x) \ - ((daddr_t)(cgimin(fs, itog(fs, x)) + \ - (blkstofrags((fs), (((x) % (fs)->fs_ipg) / INOPB(fs)))))) - -/* - * Give cylinder group number for a file system block. - * Give cylinder group block number for a file system block. - */ -#define dtog(fs, d) ((d) / (fs)->fs_fpg) -#define dtogd(fs, d) ((d) % (fs)->fs_fpg) - -/* - * Extract the bits for a block from a map. - * Compute the cylinder and rotational position of a cyl block addr. - */ -#define blkmap(fs, map, loc) \ - (((map)[(loc) / NBBY] >> ((loc) % NBBY)) & (0xff >> (NBBY - (fs)->fs_frag))) -#define cbtocylno(fs, bno) \ - ((bno) * NSPF(fs) / (fs)->fs_spc) -#define cbtorpos(fs, bno) \ - (((bno) * NSPF(fs) % (fs)->fs_spc / (fs)->fs_nsect * (fs)->fs_trackskew + \ - (bno) * NSPF(fs) % (fs)->fs_spc % (fs)->fs_nsect * (fs)->fs_interleave) % \ - (fs)->fs_nsect * (fs)->fs_nrpos / (fs)->fs_npsect) - -/* - * The following macros optimize certain frequently calculated - * quantities by using shifts and masks in place of divisions - * modulos and multiplications. - */ -#define blkoff(fs, loc) /* calculates (loc % fs->fs_bsize) */ \ - ((loc) & ~(fs)->fs_bmask) -#define fragoff(fs, loc) /* calculates (loc % fs->fs_fsize) */ \ - ((loc) & ~(fs)->fs_fmask) -#define lblkno(fs, loc) /* calculates (loc / fs->fs_bsize) */ \ - ((loc) >> (fs)->fs_bshift) -#define numfrags(fs, loc) /* calculates (loc / fs->fs_fsize) */ \ - ((loc) >> (fs)->fs_fshift) -#define blkroundup(fs, size) /* calculates roundup(size, fs->fs_bsize) */ \ - (((size) + (fs)->fs_bsize - 1) & (fs)->fs_bmask) -#define fragroundup(fs, size) /* calculates roundup(size, fs->fs_fsize) */ \ - (((size) + (fs)->fs_fsize - 1) & (fs)->fs_fmask) -#define fragstoblks(fs, frags) /* calculates (frags / fs->fs_frag) */ \ - ((frags) >> (fs)->fs_fragshift) -#define blkstofrags(fs, blks) /* calculates (blks * fs->fs_frag) */ \ - ((blks) << (fs)->fs_fragshift) -#define fragnum(fs, fsb) /* calculates (fsb % fs->fs_frag) */ \ - ((fsb) & ((fs)->fs_frag - 1)) -#define blknum(fs, fsb) /* calculates rounddown(fsb, fs->fs_frag) */ \ - ((fsb) &~ ((fs)->fs_frag - 1)) - -/* - * Determine the number of available frags given a - * percentage to hold in reserve - */ -#define freespace(fs, percentreserved) \ - (blkstofrags((fs), (fs)->fs_cstotal.cs_nbfree) + \ - (fs)->fs_cstotal.cs_nffree - ((fs)->fs_dsize * (percentreserved) / 100)) - -/* - * Determining the size of a file block in the file system. - */ -#define blksize(fs, ip, lbn) \ - (((lbn) >= NDADDR || (ip)->i_size >= ((lbn) + 1) << (fs)->fs_bshift) \ - ? (fs)->fs_bsize \ - : (fragroundup(fs, blkoff(fs, (ip)->i_size)))) -#define dblksize(fs, dip, lbn) \ - (((lbn) >= NDADDR || (dip)->di_size >= ((lbn) + 1) << (fs)->fs_bshift) \ - ? (fs)->fs_bsize \ - : (fragroundup(fs, blkoff(fs, (dip)->di_size)))) - -/* - * Number of disk sectors per block; assumes DEV_BSIZE byte sector size. - */ -#define NSPB(fs) ((fs)->fs_nspf << (fs)->fs_fragshift) -#define NSPF(fs) ((fs)->fs_nspf) - -/* - * INOPB is the number of inodes in a secondary storage block. - */ -#define INOPB(fs) ((fs)->fs_inopb) -#define INOPF(fs) ((fs)->fs_inopb >> (fs)->fs_fragshift) - -/* - * NINDIR is the number of indirects in a file system block. - */ -#define NINDIR(fs) ((fs)->fs_nindir) - diff --git a/serverboot/gets.c b/serverboot/gets.c deleted file mode 100644 index 61d14460..00000000 --- a/serverboot/gets.c +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Mach Operating System - * Copyright (c) 1993-1989 Carnegie Mellon University. - * Copyright (c) 1994 The University of Utah and - * the Computer Systems Laboratory (CSL). - * All rights reserved. - * - * Permission to use, copy, modify and distribute this software and its - * documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON, THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF - * THIS SOFTWARE IN ITS "AS IS" CONDITION, AND DISCLAIM ANY LIABILITY - * OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF - * THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to - * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 - * - * any improvements or extensions that they make and grant Carnegie Mellon - * the rights to redistribute these changes. - */ - -#include <mach.h> -#include <device/device.h> -#include <varargs.h> - -extern mach_port_t __libmach_console_port; - -safe_gets(str, maxlen) - char *str; - int maxlen; -{ - register char *lp; - register int c; - - char inbuf[IO_INBAND_MAX]; - mach_msg_type_number_t count; - register char *ip; - char *strmax = str + maxlen - 1; /* allow space for trailing 0 */ - - lp = str; - for (;;) { - count = IO_INBAND_MAX; - (void) device_read_inband(__libmach_console_port, - (dev_mode_t)0, (recnum_t)0, - sizeof(inbuf), inbuf, &count); - for (ip = inbuf; ip < &inbuf[count]; ip++) { - c = *ip; - switch (c) { - case '\n': - case '\r': - printf("\n"); - *lp++ = 0; - return; - - case '\b': - case '#': - case '\177': - if (lp > str) { - printf("\b \b"); - lp--; - } - continue; - case '@': - case 'u'&037: - lp = str; - printf("\n\r"); - continue; - default: - if (c >= ' ' && c < '\177') { - if (lp < strmax) { - *lp++ = c; - printf("%c", c); - } - else { - printf("%c", '\007'); /* beep */ - } - } - } - } - } -} - diff --git a/serverboot/gunzip.c b/serverboot/gunzip.c deleted file mode 100644 index f74da111..00000000 --- a/serverboot/gunzip.c +++ /dev/null @@ -1,188 +0,0 @@ -/* Modified by okuji@kuicr.kyoto-u.ac.jp for use in serverboot. */ -/* Decompressing store backend - - Copyright (C) 1997 Free Software Foundation, Inc. - Written by Miles Bader <miles@gnu.ai.mit.edu> - This file is part of the GNU Hurd. - - The GNU Hurd is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2, or (at - your option) any later version. - - The GNU Hurd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ - -#include <stdio.h> -#include <string.h> -#include <setjmp.h> -#include <cthreads.h> -#include <errno.h> - -#include <file_io.h> - -/* gzip.h makes several annoying defines & decls, which we have to work - around. */ -#define file_t gzip_file_t -#include "gzip.h" -#undef file_t -#undef head - -#define IN_BUFFERING (256*1024) -#define OUT_BUFFERING (512*1024) - -static struct mutex unzip_lock = MUTEX_INITIALIZER; - -/* Uncompress the contents of FROM, which should contain a valid gzip file, - into memory, returning the result buffer in BUF & BUF_LEN. */ -int -serverboot_gunzip (struct file *from, void **buf, size_t *buf_len) -{ - /* Entry points to unzip engine. */ - int get_method (int); - extern long int bytes_out; - /* Callbacks from unzip for I/O and error interface. */ - extern int (*unzip_read) (char *buf, size_t maxread); - extern void (*unzip_write) (const char *buf, size_t nwrite); - extern void (*unzip_read_error) (void); - extern void (*unzip_error) (const char *msg); - - /* How we return errors from our hook functions. */ - jmp_buf zerr_jmp_buf; - int zerr; - - size_t offset = 0; /* Offset of read point in FROM. */ - - /* Read at most MAXREAD (or 0 if eof) bytes into BUF from our current - position in FROM. */ - int zread (char *buf, size_t maxread) - { - vm_size_t resid; - size_t did_read; - - if (from->f_size - offset < maxread) - did_read = from->f_size - offset; - else - did_read = maxread; - - zerr = read_file (from, offset, buf, did_read, &resid); - if (zerr) - longjmp (zerr_jmp_buf, 1); - - did_read -= resid; - offset += did_read; - - return did_read; - } - - size_t out_buf_offs = 0; /* Position in the output buffer. */ - - /* Write uncompress data to our output buffer. */ - void zwrite (const char *wbuf, size_t nwrite) - { - size_t old_buf_len = *buf_len; - - if (out_buf_offs + nwrite > old_buf_len) - /* Have to grow the output buffer. */ - { - void *old_buf = *buf; - void *new_buf = old_buf + old_buf_len; /* First try. */ - size_t new_buf_len = round_page (old_buf_len + old_buf_len + nwrite); - - /* Try to grow the buffer. */ - zerr = - vm_allocate (mach_task_self (), - (vm_address_t *)&new_buf, new_buf_len - old_buf_len, - 0); - if (zerr) - /* Can't do that, try to make a bigger buffer elsewhere. */ - { - new_buf = old_buf; - zerr = - vm_allocate (mach_task_self (), - (vm_address_t *)&new_buf, new_buf_len, 1); - if (zerr) - longjmp (zerr_jmp_buf, 1); - - if (out_buf_offs > 0) - /* Copy the old buffer into the start of the new & free it. */ - bcopy (old_buf, new_buf, out_buf_offs); - - vm_deallocate (mach_task_self (), - (vm_address_t)old_buf, old_buf_len); - - *buf = new_buf; - } - - *buf_len = new_buf_len; - } - - bcopy (wbuf, *buf + out_buf_offs, nwrite); - out_buf_offs += nwrite; - } - - void zreaderr (void) - { - zerr = EIO; - longjmp (zerr_jmp_buf, 1); - } - void zerror (const char *msg) - { - zerr = EINVAL; - longjmp (zerr_jmp_buf, 2); - } - - /* Try to guess a reasonable output buffer size. */ - *buf_len = round_page (from->f_size * 2); - zerr = vm_allocate (mach_task_self (), (vm_address_t *)buf, *buf_len, 1); - if (zerr) - return zerr; - - mutex_lock (&unzip_lock); - - unzip_read = zread; - unzip_write = zwrite; - unzip_read_error = zreaderr; - unzip_error = zerror; - - if (! setjmp (zerr_jmp_buf)) - { - if (get_method (0) != 0) - /* Not a happy gzip file. */ - zerr = EINVAL; - else - /* Matched gzip magic number. Ready to unzip. - Set up the output stream and let 'er rip. */ - { - /* Call the gunzip engine. */ - bytes_out = 0; - unzip (17, 23); /* Arguments ignored. */ - zerr = 0; - } - } - - mutex_unlock (&unzip_lock); - - if (zerr) - { - if (*buf_len > 0) - vm_deallocate (mach_task_self (), (vm_address_t)*buf, *buf_len); - } - else if (out_buf_offs < *buf_len) - /* Trim the output buffer to be the right length. */ - { - size_t end = round_page (out_buf_offs); - if (end < *buf_len) - vm_deallocate (mach_task_self (), - (vm_address_t)(*buf + end), *buf_len - end); - *buf_len = out_buf_offs; - } - - return zerr; -} diff --git a/serverboot/load.c b/serverboot/load.c deleted file mode 100644 index aa481943..00000000 --- a/serverboot/load.c +++ /dev/null @@ -1,555 +0,0 @@ -/* - * Mach Operating System - * Copyright (c) 1991,1990,1989,1988 Carnegie Mellon University - * All Rights Reserved. - * - * Permission to use, copy, modify and distribute this software and its - * documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" - * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR - * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to - * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 - * - * any improvements or extensions that they make and grant Carnegie Mellon - * the rights to redistribute these changes. - */ - -#include <stddef.h> -#include <assert.h> -#include <mach/mach_interface.h> -#include "mach-exec.h" -#include "../boot/boot_script.h" - -#include <file_io.h> - - -boolean_t load_protect_text = TRUE; - - -struct stuff -{ - struct file *fp; - task_t user_task; - - /* uncompressed image */ - vm_offset_t image_addr; - vm_size_t image_size; - - vm_offset_t aout_symtab_ofs; - vm_size_t aout_symtab_size; - vm_offset_t aout_strtab_ofs; - vm_size_t aout_strtab_size; -}; - -char *set_regs( - mach_port_t user_task, - mach_port_t user_thread, - struct exec_info *info, - int arg_size); - -static void read_symtab_from_file( - struct file *fp, - mach_port_t host_port, - task_t task, - char * symtab_name, - struct stuff *st); - -/* Callback functions for reading the executable file. */ -static int prog_read(void *handle, vm_offset_t file_ofs, void *buf, vm_size_t size, - vm_size_t *out_actual) -{ - struct stuff *st = handle; - vm_size_t resid; - int result; - - result = read_file(st->fp, file_ofs, buf, size, &resid); - if (result) - return result; - *out_actual = size - resid; - return 0; -} - -static int prog_read_exec(void *handle, vm_offset_t file_ofs, vm_size_t file_size, - vm_offset_t mem_addr, vm_size_t mem_size, - exec_sectype_t sec_type) -{ - struct stuff *st = handle; - vm_offset_t page_start = trunc_page(mem_addr); - vm_offset_t page_end = round_page(mem_addr + mem_size); - vm_prot_t mem_prot = sec_type & EXEC_SECTYPE_PROT_MASK; - vm_offset_t area_start; - int result; - - if (sec_type & EXEC_SECTYPE_AOUT_SYMTAB) - { - st->aout_symtab_ofs = file_ofs; - st->aout_symtab_size = file_size; - } - if (sec_type & EXEC_SECTYPE_AOUT_STRTAB) - { - st->aout_strtab_ofs = file_ofs; - st->aout_strtab_size = file_size; - } - - if (!(sec_type & EXEC_SECTYPE_ALLOC)) - return 0; - - assert(mem_size > 0); - assert(mem_size > file_size); - - /* - printf("section %08x-%08x-%08x prot %08x (%08x-%08x)\n", - mem_addr, mem_addr+file_size, mem_addr+mem_size, mem_prot, page_start, page_end); - */ - - result = vm_allocate(mach_task_self(), &area_start, page_end - page_start, TRUE); - if (result) return (result); - - if (file_size > 0) - { - vm_size_t resid; - - result = read_file(st->fp, file_ofs, area_start + (mem_addr - page_start), - file_size, &resid); - if (result) return result; - if (resid) return EX_CORRUPT; - } - - if (mem_size > file_size) - { - bzero((void*)area_start + (mem_addr + file_size - page_start), - mem_size - file_size); - } - - result = vm_allocate(st->user_task, &page_start, page_end - page_start, FALSE); - if (result) return (result); - assert(page_start == trunc_page(mem_addr)); - - result = vm_write(st->user_task, page_start, area_start, page_end - page_start); - if (result) return (result); - - result = vm_deallocate(mach_task_self(), area_start, page_end - page_start); - if (result) return (result); - - /* - * Protect the segment. - */ - if (load_protect_text && (mem_prot != VM_PROT_ALL)) { - result = vm_protect(st->user_task, page_start, page_end - page_start, - FALSE, mem_prot); - if (result) return (result); - } - - return 0; -} - -/* Callback functions for reading the uncompressed image. */ -static int image_read(void *handle, vm_offset_t file_ofs, void *buf, - vm_size_t size, vm_size_t *out_actual) -{ - struct stuff *st = handle; - bcopy(st->image_addr + file_ofs, buf, size); - *out_actual = size; - return 0; -} - -static int image_read_exec(void *handle, vm_offset_t file_ofs, - vm_size_t file_size, vm_offset_t mem_addr, - vm_size_t mem_size, exec_sectype_t sec_type) -{ - struct stuff *st = handle; - vm_offset_t page_start = trunc_page(mem_addr); - vm_offset_t page_end = round_page(mem_addr + mem_size); - vm_prot_t mem_prot = sec_type & EXEC_SECTYPE_PROT_MASK; - vm_offset_t area_start; - int result; - - if (sec_type & EXEC_SECTYPE_AOUT_SYMTAB) - { - st->aout_symtab_ofs = file_ofs; - st->aout_symtab_size = file_size; - } - if (sec_type & EXEC_SECTYPE_AOUT_STRTAB) - { - st->aout_strtab_ofs = file_ofs; - st->aout_strtab_size = file_size; - } - - if (!(sec_type & EXEC_SECTYPE_ALLOC)) - return 0; - - assert(mem_size > 0); - assert(mem_size > file_size); - - /* - printf("section %08x-%08x-%08x prot %08x (%08x-%08x)\n", - mem_addr, mem_addr+file_size, mem_addr+mem_size, mem_prot, page_start, page_end); - */ - - result = vm_allocate(mach_task_self(), &area_start, page_end - page_start, TRUE); - if (result) return (result); - - if (file_size > 0) - { - bcopy(st->image_addr + file_ofs, area_start + (mem_addr - page_start), - file_size); - } - - if (mem_size > file_size) - { - bzero((void*)area_start + (mem_addr + file_size - page_start), - mem_size - file_size); - } - - result = vm_allocate(st->user_task, &page_start, page_end - page_start, FALSE); - if (result) return (result); - assert(page_start == trunc_page(mem_addr)); - - result = vm_write(st->user_task, page_start, area_start, page_end - page_start); - if (result) return (result); - - result = vm_deallocate(mach_task_self(), area_start, page_end - page_start); - if (result) return (result); - - /* - * Protect the segment. - */ - if (load_protect_text && (mem_prot != VM_PROT_ALL)) { - result = vm_protect(st->user_task, page_start, page_end - page_start, - FALSE, mem_prot); - if (result) return (result); - } - - return 0; -} - -mach_port_t boot_script_read_file (const char *file) -{ return MACH_PORT_NULL; } /* XXX */ - -int -boot_script_exec_cmd (void *hook, - task_t user_task, - char *file_name, - int arg_count, char **argv, - char *argstrings, int argslen) -{ - extern mach_port_t bootstrap_master_device_port, bootstrap_master_host_port; - extern char *root_name; - extern char **environ; - int envc, env_len; - - int arg_len = argslen; - char *arg_pos; - - kern_return_t result; - thread_t user_thread; - struct file file; - char namebuf[MAXPATHLEN+1]; - - struct stuff st; - struct exec_info info; - - extern char * strbuild(); - - if (strcmp (file_name, "/dev/")) - (void) strbuild(namebuf, "/dev/", root_name, "/", file_name, - (char *)0); - else - strcpy (namebuf, file_name); - - /* - * Open the file - */ - bzero((char *)&file, sizeof(file)); - - result = open_file(bootstrap_master_device_port, namebuf, &file); - if (result != 0) { - panic ("%s: %s", namebuf, strerror (result)); - } - - env_len = 0; - for (envc = 0; environ[envc]; ++envc) - env_len += strlen (environ[envc]) + 1; - - /* - * Add space for: - * arg_count - * pointers to arguments - * trailing 0 pointer - * environment variables - * trailing 0 pointer - * and align to integer boundary - */ - arg_len += sizeof(integer_t) + (envc + 2 + arg_count) * sizeof(char *); - arg_len += env_len; - arg_len = (arg_len + (sizeof(integer_t) - 1)) & ~(sizeof(integer_t)-1); - - /* - * We refrain from checking IEXEC bits to make - * things a little easier when things went bad. - * Say you have ftp(1) but chmod(1) is gone. - */ - if (!file_is_regular(&file)) - panic("boot_load_program: %s is not a regular file", namebuf); - - /* - * Load the executable file. - */ - st.fp = &file; - st.user_task = user_task; - st.aout_symtab_size = 0; - st.aout_strtab_size = 0; - result = exec_load(prog_read, prog_read_exec, &st, &info); -#ifdef GZIP - if (result) - { - /* - * It might be gzip file. - */ - int err; - extern int serverboot_gunzip(struct file *, - vm_offset_t *, size_t *); - - err = serverboot_gunzip(st.fp, - &(st.image_addr), - &(st.image_size)); - if (!err) - { - result = exec_load(image_read, - image_read_exec, - &st, - &info); - vm_deallocate(mach_task_self(), - st.image_addr, - st.image_size); - } - } -#endif /* GZIP */ -#ifdef BZIP2 - if (result) - { - /* - * It might be bzip2 file. - */ - int err; - extern int serverboot_bunzip2(struct file *, - vm_offset_t *, size_t *); - - err = serverboot_bunzip2(st.fp, - &(st.image_addr), - &(st.image_size)); - if (!err) - { - result = exec_load(image_read, - image_read_exec, - &st, - &info); - vm_deallocate(mach_task_self(), - st.image_addr, - st.image_size); - } - } -#endif /* BZIP2 */ - if (result) - panic ("cannot load %s: %s", namebuf, strerror (result)); -#if 0 - printf("(serverboot): loaded %s; entrypoint %08x\n", namebuf, info.entry); -#endif - - /* - * Set up the stack and user registers. - */ - result = thread_create (user_task, &user_thread); - if (result) - panic ("can't create user thread for %s: %s", namebuf, - strerror (result)); - arg_pos = set_regs(user_task, user_thread, &info, arg_len); - - /* - * Read symbols from the executable file. - */ -#if 0 - printf("(serverboot): loading symbols from %s\n", namebuf); - read_symtab_from_file(&file, bootstrap_master_host_port, user_task, namebuf, &st); -#endif - - /* - * Copy out the arguments. - */ - { - vm_offset_t u_arg_start; - /* user start of argument list block */ - vm_offset_t k_arg_start; - /* kernel start of argument list block */ - vm_offset_t u_arg_page_start; - /* user start of args, page-aligned */ - vm_size_t arg_page_size; - /* page_aligned size of args */ - vm_offset_t k_arg_page_start; - /* kernel start of args, page-aligned */ - - register - char ** k_ap; /* kernel arglist address */ - char * u_cp; /* user argument string address */ - register - char * k_cp; /* kernel argument string address */ - register - int i; - - /* - * Get address of argument list in user space - */ - u_arg_start = (vm_offset_t)arg_pos; - - /* - * Round to page boundaries, and allocate kernel copy - */ - u_arg_page_start = trunc_page(u_arg_start); - arg_page_size = (vm_size_t)(round_page(u_arg_start + arg_len) - - u_arg_page_start); - - result = vm_allocate(mach_task_self(), - &k_arg_page_start, - (vm_size_t)arg_page_size, - TRUE); - if (result) - panic("boot_load_program: arg size"); - - /* - * Set up addresses corresponding to user pointers - * in the kernel block - */ - k_arg_start = k_arg_page_start + (u_arg_start - u_arg_page_start); - - k_ap = (char **)k_arg_start; - - /* - * Start the strings after the arg-count and pointers - */ - u_cp = (char *)u_arg_start + arg_count * sizeof(char *) - + envc * sizeof(char *) - + 2 * sizeof(char *) - + sizeof(integer_t); - k_cp = (char *)k_arg_start + arg_count * sizeof(char *) - + envc * sizeof(char *) - + 2 * sizeof(char *) - + sizeof(integer_t); - - /* - * first the argument count - */ - *k_ap++ = (char *)(intptr_t)arg_count; - - /* - * Then the strings and string pointers for each argument - */ - for (i = 0; i < arg_count; i++) - *k_ap++ = argv[i] - argstrings + u_cp; - *k_ap++ = (char *)0; - bcopy (argstrings, k_cp, argslen); - k_cp += argslen; - u_cp += argslen; - - for (i = 0; i < envc; i++) - *k_ap++ = environ[i] - environ[0] + u_cp; - *k_ap = (char *)0; - bcopy (environ[0], k_cp, env_len); - - /* - * Now write all of this to user space. - */ - (void) vm_write(user_task, - u_arg_page_start, - k_arg_page_start, - arg_page_size); - - (void) vm_deallocate(mach_task_self(), - k_arg_page_start, - arg_page_size); - } - - /* - * Close the file. - */ - close_file(&file); - - /* Resume the thread. */ - thread_resume (user_thread); - mach_port_deallocate (mach_task_self (), user_thread); - - return (0); -} - -/* - * Load symbols from file into kernel debugger. - */ -static void read_symtab_from_file( - struct file *fp, - mach_port_t host_port, - task_t task, - char * symtab_name, - struct stuff *st) -{ - vm_size_t resid; - kern_return_t result; - vm_size_t table_size; - vm_offset_t symtab; - -#if 0 - - if (!st->aout_symtab_size || !st->aout_strtab_size) - return; - - /* - * Allocate space for the symbol table. - */ - table_size = sizeof(vm_size_t) - + st->aout_symtab_size - + st->aout_strtab_size; - result= vm_allocate(mach_task_self(), - &symtab, - table_size, - TRUE); - if (result) { - printf("[ error %d allocating space for %s symbol table ]\n", - result, symtab_name); - return; - } - - /* - * Set the symbol table length word, - * then read in the symbol table and string table. - */ - *(vm_size_t*)symtab = st->aout_symtab_size; - result = read_file(fp, st->aout_symtab_ofs, - symtab + sizeof(vm_size_t), - st->aout_symtab_size + st->aout_strtab_size, - &resid); - if (result || resid) { - printf("[ no valid symbol table present for %s ]\n", - symtab_name); - } - else { - /* - * Load the symbols into the kernel. - */ - result = host_load_symbol_table( - host_port, - task, - symtab_name, - symtab, - table_size); - } - (void) vm_deallocate(mach_task_self(), symtab, table_size); -#endif -} diff --git a/serverboot/mach-exec.h b/serverboot/mach-exec.h deleted file mode 100644 index 94b234b0..00000000 --- a/serverboot/mach-exec.h +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Mach Operating System - * Copyright (c) 1991,1990,1989,1988 Carnegie Mellon University - * All Rights Reserved. - * - * Permission to use, copy, modify and distribute this software and its - * documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS - * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR - * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to - * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 - * - * any improvements or extensions that they make and grant Carnegie the - * rights to redistribute these changes. - */ - -#ifndef _MACH_EXEC_H_ -#define _MACH_EXEC_H_ - -#include <mach/machine/vm_types.h> -#include <mach/vm_prot.h> - -/* XXX */ -typedef enum -{ - EXEC_ELF = 1, - EXEC_AOUT = 2, -} exec_format_t; - -typedef struct exec_info -{ - /* Format of executable loaded - see above. */ - exec_format_t format; - - /* Program entrypoint. */ - vm_offset_t entry; - - /* Initial data pointer - only some architectures use this. */ - vm_offset_t init_dp; - - /* (ELF) Address of interpreter string for loading shared libraries, null if none. */ - vm_offset_t interp; - -} exec_info_t; - -typedef int exec_sectype_t; -#define EXEC_SECTYPE_READ VM_PROT_READ -#define EXEC_SECTYPE_WRITE VM_PROT_WRITE -#define EXEC_SECTYPE_EXECUTE VM_PROT_EXECUTE -#define EXEC_SECTYPE_PROT_MASK VM_PROT_ALL -#define EXEC_SECTYPE_ALLOC ((exec_sectype_t)0x000100) -#define EXEC_SECTYPE_LOAD ((exec_sectype_t)0x000200) -#define EXEC_SECTYPE_DEBUG ((exec_sectype_t)0x010000) -#define EXEC_SECTYPE_AOUT_SYMTAB ((exec_sectype_t)0x020000) -#define EXEC_SECTYPE_AOUT_STRTAB ((exec_sectype_t)0x040000) - -typedef int exec_read_func_t(void *handle, vm_offset_t file_ofs, - void *buf, vm_size_t size, - vm_size_t *out_actual); - -typedef int exec_read_exec_func_t(void *handle, - vm_offset_t file_ofs, vm_size_t file_size, - vm_offset_t mem_addr, vm_size_t mem_size, - exec_sectype_t section_type); - -/* - * Routines exported from libmach_exec.a - */ - -/* Generic function to interpret an executable "file" - and "load" it into "memory". - Doesn't really know about files, loading, or memory; - all file I/O and destination memory accesses - go through provided functions. - Thus, this is a very generic loading mechanism. - - The read() function is used to read metadata from the file - into the local address space. - - The read_exec() function is used to load the actual sections. - It is used for all kinds of sections - code, data, bss, debugging data. - The 'section_type' parameter specifies what type of section is being loaded. - - For code, data, and bss, the EXEC_SECTYPE_ALLOC flag will be set. - For code and data (i.e. stuff that's actually loaded from the file), - EXEC_SECTYPE_LOAD will also be set. - The EXEC_SECTYPE_PROT_MASK contains the intended access permissions - for the section. - 'file_size' may be less than 'mem_size'; - the remaining data must be zero-filled. - 'mem_size' is always greater than zero, but 'file_size' may be zero - (e.g. in the case of a bss section). - No two read_exec() calls for one executable - will load data into the same virtual memory page, - although they may load from arbitrary (possibly overlapping) file positions. - - For sections that aren't normally loaded into the process image - (e.g. debug sections), EXEC_SECTYPE_ALLOC isn't set, - but some other appropriate flag is set to indicate the type of section. - - The 'handle' is an opaque pointer which is simply passed on - to the read() and read_exec() functions. - - On return, the specified info structure is filled in - with information about the loaded executable. -*/ -int exec_load(exec_read_func_t *read, exec_read_exec_func_t *read_exec, - void *handle, exec_info_t *out_info); - -/* - * Error codes - */ - -#define EX_NOT_EXECUTABLE 6000 /* not a recognized executable format */ -#define EX_WRONG_ARCH 6001 /* valid executable, but wrong arch. */ -#define EX_CORRUPT 6002 /* recognized executable, but mangled */ -#define EX_BAD_LAYOUT 6003 /* something wrong with the memory or file image layout */ - - -#endif /* _MACH_EXEC_H_ */ diff --git a/serverboot/minix_ffs_compat.c b/serverboot/minix_ffs_compat.c deleted file mode 100644 index 7d493520..00000000 --- a/serverboot/minix_ffs_compat.c +++ /dev/null @@ -1,62 +0,0 @@ -/* - * BSD FFS like functions used to ease porting bootstrap to MINIX fs - * Copyright (C) 1994 Csizmazia Balazs, University ELTE, Hungary - * - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include <device/device_types.h> -#include <device/device.h> - -#include <mach/mach_traps.h> -#include <mach/mach_interface.h> - -#include <file_io.h> - -#define MINIX_BLOCK_SIZE 1024 - -int minix_ino2blk (struct minix_super_block *fs, int ino) -{ - int blk; - - blk=0 /* it's Mach */+2 /* boot+superblock */ + fs->s_imap_blocks + - fs->s_zmap_blocks + (ino-1)/MINIX_INODES_PER_BLOCK; - return blk; -} - -int minix_fsbtodb (struct minix_super_block *fs, int b) -{ - return (b * MINIX_BLOCK_SIZE) / DEV_BSIZE; -} - -int minix_itoo (struct minix_super_block *fs, int ino) -{ - return (ino - 1) % MINIX_INODES_PER_BLOCK; -} - -int minix_blkoff (struct minix_super_block * fs, vm_offset_t offset) -{ - return offset % MINIX_BLOCK_SIZE; -} - -int minix_lblkno (struct minix_super_block * fs, vm_offset_t offset) -{ - return offset / MINIX_BLOCK_SIZE; -} - -int minix_blksize (struct minix_super_block *fs, struct file *fp, minix_daddr_t file_block) -{ - return MINIX_BLOCK_SIZE; -} diff --git a/serverboot/minix_ffs_compat.h b/serverboot/minix_ffs_compat.h deleted file mode 100644 index cc038032..00000000 --- a/serverboot/minix_ffs_compat.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * BSD FFS like declarations used to ease porting bootstrap to MINIX fs - * Copyright (C) 1994 Csizmazia Balazs, University ELTE, Hungary - * - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#define MINIX_SBSIZE MINIX_BLOCK_SIZE /* Size of superblock */ -#define MINIX_SBLOCK ((minix_daddr_t) 2) /* Location of superblock */ - -#define MINIX_NDADDR 7 -#define MINIX_NIADDR 2 - -#define MINIX_MAXNAMLEN 14 - -#define MINIX_ROOTINO 1 /* MINIX ROOT INODE */ - -#define MINIX_NINDIR(fs) 512 /* DISK_ADDRESSES_PER_BLOCKS */ - -#define IFMT 00170000 -#define IFREG 0100000 -#define IFDIR 0040000 -#define ISVTX 0001000 - -#define f_fs u.minix.minix_fs -#define i_ic u.minix.minix_ic -#define f_nindir u.minix.minix_nindir -#define f_blk u.minix.minix_blk -#define f_blksize u.minix.minix_blksize -#define f_blkno u.minix.minix_blkno - diff --git a/serverboot/minix_file_io.c b/serverboot/minix_file_io.c deleted file mode 100644 index 17beb18c..00000000 --- a/serverboot/minix_file_io.c +++ /dev/null @@ -1,851 +0,0 @@ -/* - * Mach Operating System - * Copyright (c) 1991,1990 Carnegie Mellon University - * All Rights Reserved. - * - * Permission to use, copy, modify and distribute this software and its - * documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" - * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR - * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to - * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 - * - * any improvements or extensions that they make and grant Carnegie Mellon - * the rights to redistribute these changes. - */ -/* - * Stand-alone file reading package. - */ - -#include <device/device_types.h> -#include <device/device.h> - -#include <mach/mach_traps.h> -#include <mach/mach_interface.h> - -#include "file_io.h" -#include "minix_ffs_compat.h" -#include "minix_fs.h" - -void minix_close_file(); /* forward */ - -#define MINIX_NAME_LEN 14 -#define MINIX_BLOCK_SIZE 1024 - -/* - * Free file buffers, but don't close file. - */ -static void -free_file_buffers(fp) - register struct file *fp; -{ - register int level; - - /* - * Free the indirect blocks - */ - for (level = 0; level < MINIX_NIADDR; level++) { - if (fp->f_blk[level] != 0) { - (void) vm_deallocate(mach_task_self(), - fp->f_blk[level], - fp->f_blksize[level]); - fp->f_blk[level] = 0; - } - fp->f_blkno[level] = -1; - } - - /* - * Free the data block - */ - if (fp->f_buf != 0) { - (void) vm_deallocate(mach_task_self(), - fp->f_buf, - fp->f_buf_size); - fp->f_buf = 0; - } - fp->f_buf_blkno = -1; -} - -/* - * Read a new inode into a file structure. - */ -static int -read_inode(inumber, fp) - ino_t inumber; - register struct file *fp; -{ - vm_offset_t buf; - mach_msg_type_number_t buf_size; - register - struct minix_super_block *fs; - minix_daddr_t disk_block; - kern_return_t rc; - - fs = fp->f_fs; - disk_block = minix_ino2blk(fs, inumber); - - rc = device_read(fp->f_dev, - 0, - (recnum_t) minix_fsbtodb(fp->f_fs, disk_block), - (int) MINIX_BLOCK_SIZE, - (char **)&buf, - &buf_size); - if (rc != KERN_SUCCESS) - return (rc); - - { - register struct minix_inode *dp; - - dp = (struct minix_inode *)buf; - dp += minix_itoo(fs, inumber); - fp->i_ic = *dp; - fp->f_size = dp->i_size; - } - - (void) vm_deallocate(mach_task_self(), buf, buf_size); - - /* - * Clear out the old buffers - */ - free_file_buffers(fp); - - return (0); -} - -/* - * Given an offset in a file, find the disk block number that - * contains that block. - */ -static int -block_map(fp, file_block, disk_block_p) - struct file *fp; - minix_daddr_t file_block; - minix_daddr_t *disk_block_p; /* out */ -{ - int level; - int idx; - minix_daddr_t ind_block_num; - kern_return_t rc; - - vm_offset_t olddata[MINIX_NIADDR+1]; - vm_size_t oldsize[MINIX_NIADDR+1]; - - /* - * Index structure of an inode: - * - * i_db[0..NDADDR-1] hold block numbers for blocks - * 0..NDADDR-1 - * - * i_ib[0] index block 0 is the single indirect - * block - * holds block numbers for blocks - * NDADDR .. NDADDR + NINDIR(fs)-1 - * - * i_ib[1] index block 1 is the double indirect - * block - * holds block numbers for INDEX blocks - * for blocks - * NDADDR + NINDIR(fs) .. - * NDADDR + NINDIR(fs) + NINDIR(fs)**2 - 1 - * - * i_ib[2] index block 2 is the triple indirect - * block - * holds block numbers for double-indirect - * blocks for blocks - * NDADDR + NINDIR(fs) + NINDIR(fs)**2 .. - * NDADDR + NINDIR(fs) + NINDIR(fs)**2 - * + NINDIR(fs)**3 - 1 - */ - - mutex_lock(&fp->f_lock); - - if (file_block < MINIX_NDADDR) { - /* Direct block. */ - *disk_block_p = fp->i_ic.i_zone[file_block]; - mutex_unlock(&fp->f_lock); - return (0); - } - - file_block -= MINIX_NDADDR; - - /* - * nindir[0] = NINDIR - * nindir[1] = NINDIR**2 - * nindir[2] = NINDIR**3 - * etc - */ - for (level = 0; level < MINIX_NIADDR; level++) { - if (file_block < fp->f_nindir[level]) - break; - file_block -= fp->f_nindir[level]; - } - if (level == MINIX_NIADDR) { - /* Block number too high */ - mutex_unlock(&fp->f_lock); - return (FS_NOT_IN_FILE); - } - - ind_block_num = fp->i_ic.i_zone[level + MINIX_NDADDR]; - - /* - * Initialize array of blocks to free. - */ - for (idx = 0; idx < MINIX_NIADDR; idx++) - oldsize[idx] = 0; - - for (; level >= 0; level--) { - - vm_offset_t data; - mach_msg_type_number_t size; - - if (ind_block_num == 0) - break; - - if (fp->f_blkno[level] == ind_block_num) { - /* - * Cache hit. Just pick up the data. - */ - - data = fp->f_blk[level]; - } - else { - /* - * Drop our lock while doing the read. - * (The f_dev and f_fs fields don`t change.) - */ - mutex_unlock(&fp->f_lock); - - rc = device_read(fp->f_dev, - 0, - (recnum_t) minix_fsbtodb(fp->f_fs, ind_block_num), - MINIX_BLOCK_SIZE, - (char **)&data, - &size); - if (rc != KERN_SUCCESS) - return (rc); - - /* - * See if we can cache the data. Need a write lock to - * do this. While we hold the write lock, we can`t do - * *anything* which might block for memory. Otherwise - * a non-privileged thread might deadlock with the - * privileged threads. We can`t block while taking the - * write lock. Otherwise a non-privileged thread - * blocked in the vm_deallocate (while holding a read - * lock) will block a privileged thread. For the same - * reason, we can`t take a read lock and then use - * lock_read_to_write. - */ - - mutex_lock(&fp->f_lock); - - olddata[level] = fp->f_blk[level]; - oldsize[level] = fp->f_blksize[level]; - - fp->f_blkno[level] = ind_block_num; - fp->f_blk[level] = data; - fp->f_blksize[level] = size; - - /* - * Return to holding a read lock, and - * dispose of old data. - */ - - } - - if (level > 0) { - idx = file_block / fp->f_nindir[level-1]; - file_block %= fp->f_nindir[level-1]; - } - else - idx = file_block; - - ind_block_num = ((minix_daddr_t *)data)[idx]; - } - - mutex_unlock(&fp->f_lock); - - /* - * After unlocking the file, free any blocks that - * we need to free. - */ - for (idx = 0; idx < MINIX_NIADDR; idx++) - if (oldsize[idx] != 0) - (void) vm_deallocate(mach_task_self(), - olddata[idx], - oldsize[idx]); - - *disk_block_p = ind_block_num; - return (0); -} - -/* - * Read a portion of a file into an internal buffer. Return - * the location in the buffer and the amount in the buffer. - */ -static int -buf_read_file(fp, offset, buf_p, size_p) - register struct file *fp; - vm_offset_t offset; - vm_offset_t *buf_p; /* out */ - vm_size_t *size_p; /* out */ -{ - register - struct minix_super_block *fs; - vm_offset_t off; - register minix_daddr_t file_block; - minix_daddr_t disk_block; - int rc; - vm_offset_t block_size; - - if (offset >= fp->i_ic.i_size) - return (FS_NOT_IN_FILE); - - fs = fp->f_fs; - - off = minix_blkoff(fs, offset); - file_block = minix_lblkno(fs, offset); - block_size = minix_blksize(fs, fp, file_block); - - if (((daddr_t) file_block) != fp->f_buf_blkno) { - rc = block_map(fp, file_block, &disk_block); - if (rc != 0) - return (rc); - - if (fp->f_buf) - (void)vm_deallocate(mach_task_self(), - fp->f_buf, - fp->f_buf_size); - - if (disk_block == 0) { - (void)vm_allocate(mach_task_self(), - &fp->f_buf, - block_size, - TRUE); - fp->f_buf_size = block_size; - } - else { - rc = device_read(fp->f_dev, - 0, - (recnum_t) minix_fsbtodb(fs, disk_block), - (int) block_size, - (char **) &fp->f_buf, - (mach_msg_type_number_t *)&fp->f_buf_size); - } - if (rc) - return (rc); - - fp->f_buf_blkno = (daddr_t) file_block; - } - - /* - * Return address of byte in buffer corresponding to - * offset, and size of remainder of buffer after that - * byte. - */ - *buf_p = fp->f_buf + off; - *size_p = block_size - off; - - /* - * But truncate buffer at end of file. - */ - if (*size_p > fp->i_ic.i_size - offset) - *size_p = fp->i_ic.i_size - offset; - - return (0); -} - -/* - * Search a directory for a name and return its - * i_number. - */ -static int -search_directory(name, fp, inumber_p) - char * name; - register struct file *fp; - ino_t *inumber_p; /* out */ -{ - vm_offset_t buf; - vm_size_t buf_size; - vm_offset_t offset; - register struct minix_directory_entry *dp; - int length; - kern_return_t rc; - char tmp_name[15]; - - length = strlen(name); - - offset = 0; - while (offset < fp->i_ic.i_size) { - rc = buf_read_file(fp, offset, &buf, &buf_size); - if (rc != KERN_SUCCESS) - return (rc); - - dp = (struct minix_directory_entry *)buf; - if (dp->inode != 0) { - strncpy (tmp_name, dp->name, MINIX_NAME_LEN /* XXX it's 14 */); - tmp_name[MINIX_NAME_LEN] = '\0'; - if (strlen(tmp_name) == length && - !strcmp(name, tmp_name)) - { - /* found entry */ - *inumber_p = dp->inode; - return (0); - } - } - offset += 16 /* MINIX dir. entry length - MINIX FS Ver. 1. */; - } - return (FS_NO_ENTRY); -} - -static int -read_fs(dev, fsp) - mach_port_t dev; - struct minix_super_block **fsp; -{ - register - struct minix_super_block *fs; - vm_offset_t buf; - mach_msg_type_number_t buf_size; - int error; - - /* - * Read the super block - */ - error = device_read(dev, 0, (recnum_t) MINIX_SBLOCK, MINIX_SBSIZE, - (char **) &buf, &buf_size); - if (error) - return (error); - - /* - * Check the superblock - */ - fs = (struct minix_super_block *)buf; - if (fs->s_magic != MINIX_SUPER_MAGIC) { - (void) vm_deallocate(mach_task_self(), buf, buf_size); - return (FS_INVALID_FS); - } - - - *fsp = fs; - - return 0; -} - -static int -mount_fs(fp) - register struct file *fp; -{ - register struct minix_super_block *fs; - int error; - - error = read_fs(fp->f_dev, &fp->f_fs); - if (error) - return (error); - - fs = fp->f_fs; - - /* - * Calculate indirect block levels. - */ - { - register int mult; - register int level; - - mult = 1; - for (level = 0; level < MINIX_NIADDR; level++) { - mult *= MINIX_NINDIR(fs); - fp->f_nindir[level] = mult; - } - } - - return (0); -} - -static void -unmount_fs(fp) - register struct file *fp; -{ - if (file_is_structured(fp)) { - (void) vm_deallocate(mach_task_self(), - (vm_offset_t) fp->f_fs, - MINIX_SBSIZE); - fp->f_fs = 0; - } -} - -/* - * Open a file. - */ -int -minix_open_file(master_device_port, path, fp) - mach_port_t master_device_port; - char * path; - struct file *fp; -{ -#define RETURN(code) { rc = (code); goto exit; } - - register char *cp, *component; - register int c; /* char */ - register int rc; - ino_t inumber, parent_inumber; - int nlinks = 0; - - char namebuf[MAXPATHLEN+1]; - - if (path == 0 || *path == '\0') { - return FS_NO_ENTRY; - } - - /* - * Copy name into buffer to allow modifying it. - */ - strcpy(namebuf, path); - - /* - * Look for '/dev/xxx' at start of path, for - * root device. - */ - if (!strprefix(namebuf, "/dev/")) { - printf("no device name\n"); - return FS_NO_ENTRY; - } - - cp = namebuf + 5; /* device */ - component = cp; - while ((c = *cp) != '\0' && c != '/') { - cp++; - } - *cp = '\0'; - - bzero (fp, sizeof (struct file)); - - rc = device_open(master_device_port, - D_READ|D_WRITE, - component, - &fp->f_dev); - if (rc) - return rc; - - if (c == 0) { - fp->f_fs = 0; - goto out_ok; - } - - *cp = c; - - rc = mount_fs(fp); - if (rc) - return rc; - - inumber = (ino_t) MINIX_ROOTINO; - if ((rc = read_inode(inumber, fp)) != 0) { - printf("can't read root inode\n"); - goto exit; - } - - while (*cp) { - - /* - * Check that current node is a directory. - */ - if ((fp->i_ic.i_mode & IFMT) != IFDIR) - RETURN (FS_NOT_DIRECTORY); - - /* - * Remove extra separators - */ - while (*cp == '/') - cp++; - - /* - * Get next component of path name. - */ - component = cp; - { - register int len = 0; - - while ((c = *cp) != '\0' && c != '/') { - if (len++ > MINIX_MAXNAMLEN) - RETURN (FS_NAME_TOO_LONG); - if (c & 0200) - RETURN (FS_INVALID_PARAMETER); - cp++; - } - *cp = 0; - } - - /* - * Look up component in current directory. - * Save directory inumber in case we find a - * symbolic link. - */ - parent_inumber = inumber; - rc = search_directory(component, fp, &inumber); - if (rc) { - printf("%s: not found\n", path); - goto exit; - } - *cp = c; - - /* - * Open next component. - */ - if ((rc = read_inode(inumber, fp)) != 0) - goto exit; - - /* - * Check for symbolic link. - */ - } - - /* - * Found terminal component. - */ - out_ok: - mutex_init(&fp->f_lock); - return 0; - - /* - * At error exit, close file to free storage. - */ - exit: - minix_close_file(fp); - return rc; -} - -/* - * Close file - free all storage used. - */ -void -minix_close_file(fp) - register struct file *fp; -{ - register int i; - - /* - * Free the disk super-block. - */ - unmount_fs(fp); - - /* - * Free the inode and data buffers. - */ - free_file_buffers(fp); -} - -int -minix_file_is_directory(struct file *fp) -{ - return (fp->i_ic.i_mode & IFMT) == IFDIR; -} - -int -minix_file_is_regular(struct file *fp) -{ - return (fp->i_ic.i_mode & IFMT) == IFREG; -} - -/* - * Copy a portion of a file into kernel memory. - * Cross block boundaries when necessary. - */ -int -minix_read_file(fp, offset, start, size, resid) - register struct file *fp; - vm_offset_t offset; - vm_offset_t start; - vm_size_t size; - vm_size_t *resid; /* out */ -{ - int rc; - register vm_size_t csize; - vm_offset_t buf; - vm_size_t buf_size; - - while (size != 0) { - rc = buf_read_file(fp, offset, &buf, &buf_size); - if (rc) - return (rc); - - csize = size; - if (csize > buf_size) - csize = buf_size; - if (csize == 0) - break; - - bcopy((char *)buf, (char *)start, csize); - - offset += csize; - start += csize; - size -= csize; - } - if (resid) - *resid = size; - - return (0); -} - -/* simple utility: only works for 2^n */ -static int -log2(n) - register unsigned int n; -{ - register int i = 0; - - while ((n & 1) == 0) { - i++; - n >>= 1; - } - return i; -} - -/* - * Make an empty file_direct for a device. - */ -int -minix_open_file_direct(dev, fdp, is_structured) - mach_port_t dev; - register struct file_direct *fdp; - boolean_t is_structured; -{ - struct minix_super_block *fs; - int rc; - - if (!is_structured) { - fdp->fd_dev = dev; - fdp->fd_blocks = (daddr_t *) 0; - fdp->fd_bsize = vm_page_size; - fdp->fd_bshift = log2(vm_page_size); - fdp->fd_fsbtodb = 0; /* later */ - fdp->fd_size = 0; /* later */ - return 0; - } - - rc = read_fs(dev, &fs); - if (rc) - return rc; - - fdp->fd_dev = dev; - fdp->fd_blocks = (daddr_t *) 0; - fdp->fd_size = 0; - fdp->fd_bsize = MINIX_BLOCK_SIZE; - fdp->fd_bshift = log2(fdp->fd_bsize); - fdp->fd_fsbtodb = log2(fdp->fd_bsize / DEV_BSIZE); - - (void) vm_deallocate(mach_task_self(), - (vm_offset_t) fs, - MINIX_SBSIZE); - - return 0; -} - -/* - * Add blocks from a file to a file_direct. - */ -int -minix_add_file_direct(fdp, fp) - register struct file_direct *fdp; - register struct file *fp; -{ - register struct minix_super_block *fs; - long num_blocks, i; - vm_offset_t buffer; - vm_size_t size; - int rc; - - /* the file must be on the same device */ - - if (fdp->fd_dev != fp->f_dev) - return FS_INVALID_FS; - - if (!file_is_structured(fp)) { - int result[DEV_GET_SIZE_COUNT]; - natural_t count; - - count = DEV_GET_SIZE_COUNT; - rc = device_get_status( fdp->fd_dev, DEV_GET_SIZE, - result, &count); - if (rc) - return rc; - fdp->fd_size = result[DEV_GET_SIZE_DEVICE_SIZE] >> fdp->fd_bshift; - fdp->fd_fsbtodb = log2(fdp->fd_bsize/result[DEV_GET_SIZE_RECORD_SIZE]); - return 0; - } - - /* it must hold a file system */ - - fs = fp->f_fs; -/* - if (fdp->fd_bsize != fs->fs_bsize || - fdp->fd_fsbtodb != fs->fs_fsbtodb) -*/ - if (fdp->fd_bsize != MINIX_BLOCK_SIZE) - return FS_INVALID_FS; - - /* calculate number of blocks in the file, ignoring fragments */ - - num_blocks = minix_lblkno(fs, fp->i_ic.i_size); - - /* allocate memory for a bigger array */ - - size = (num_blocks + fdp->fd_size) * sizeof(minix_daddr_t); - rc = vm_allocate(mach_task_self(), &buffer, size, TRUE); - if (rc != KERN_SUCCESS) - return rc; - - /* lookup new block addresses */ - - for (i = 0; i < num_blocks; i++) { - minix_daddr_t disk_block; - - rc = block_map(fp, (minix_daddr_t) i, &disk_block); - if (rc != 0) { - (void) vm_deallocate(mach_task_self(), buffer, size); - return rc; - } - - ((minix_daddr_t *) buffer)[fdp->fd_size + i] = disk_block; - } - - /* copy old addresses and install the new array */ - - if (fdp->fd_blocks != 0) { - bcopy((char *) fdp->fd_blocks, (char *) buffer, - fdp->fd_size * sizeof(minix_daddr_t)); - - (void) vm_deallocate(mach_task_self(), - (vm_offset_t) fdp->fd_blocks, - (vm_size_t) (fdp->fd_size * sizeof(minix_daddr_t))); - } - fdp->fd_blocks = (daddr_t *) buffer; - fdp->fd_size += num_blocks; - - /* deallocate cached blocks */ - - free_file_buffers(fp); - - return 0; -} - -int -minix_remove_file_direct(fdp) - struct file_direct *fdp; -{ - if (fdp->fd_blocks) - (void) vm_deallocate(mach_task_self(), - (vm_offset_t) fdp->fd_blocks, - (vm_size_t) (fdp->fd_size * sizeof(minix_daddr_t))); - fdp->fd_blocks = 0; /* sanity */ - /* xxx should lose a ref to fdp->fd_dev here (and elsewhere) xxx */ -} diff --git a/serverboot/minix_fs.h b/serverboot/minix_fs.h deleted file mode 100644 index 678f3a0d..00000000 --- a/serverboot/minix_fs.h +++ /dev/null @@ -1,107 +0,0 @@ -/* - * minix_fs.h - * stolen (and slightly extended by csb) from the Linux distribution - * Copyright (C) 1994 Linus Torvalds - * - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#ifndef _LINUX_MINIX_FS_H -#define _LINUX_MINIX_FS_H - -/* - * The minix filesystem constants/structures - */ - -/* - * Thanks to Kees J Bot for sending me the definitions of the new - * minix filesystem (aka V2) with bigger inodes and 32-bit block - * pointers. It's not actually implemented yet, but I'll look into - * it. - */ - -#define MINIX_ROOT_INO 1 - -/* Not the same as the bogus LINK_MAX in <linux/limits.h>. Oh well. */ -#define MINIX_LINK_MAX 250 - -#define MINIX_I_MAP_SLOTS 8 -#define MINIX_Z_MAP_SLOTS 8 -#define MINIX_SUPER_MAGIC 0x137F /* original minix fs */ -#define MINIX_SUPER_MAGIC2 0x138F /* minix fs, 30 char names */ -#define NEW_MINIX_SUPER_MAGIC 0x2468 /* minix V2 - not implemented */ -#define MINIX_VALID_FS 0x0001 /* Clean fs. */ -#define MINIX_ERROR_FS 0x0002 /* fs has errors. */ - -#define MINIX_INODES_PER_BLOCK ((MINIX_BLOCK_SIZE)/(sizeof (struct minix_inode))) - -struct minix_inode { - unsigned short i_mode; - unsigned short i_uid; - unsigned long i_size; - unsigned long i_time; - unsigned char i_gid; - unsigned char i_nlinks; - unsigned short i_zone[9]; -}; - -/* - * The new minix inode has all the time entries, as well as - * long block numbers and a third indirect block (7+1+1+1 - * instead of 7+1+1). Also, some previously 8-bit values are - * now 16-bit. The inode is now 64 bytes instead of 32. - */ -struct new_minix_inode { - unsigned short i_mode; - unsigned short i_nlinks; - unsigned short i_uid; - unsigned short i_gid; - unsigned long i_size; - unsigned long i_atime; - unsigned long i_mtime; - unsigned long i_ctime; - unsigned long i_zone[10]; -}; - -/* - * minix super-block data on disk - */ -struct minix_super_block { - unsigned short s_ninodes; - unsigned short s_nzones; - unsigned short s_imap_blocks; - unsigned short s_zmap_blocks; - unsigned short s_firstdatazone; - unsigned short s_log_zone_size; - unsigned long s_max_size; - unsigned short s_magic; - unsigned short s_state; -}; - -struct minix_dir_entry { - unsigned short inode; - char name[0]; -}; - -struct minix_directory_entry { - unsigned short inode; - char name[14]; -}; - -#define MINIX_NIADDR 2 - -typedef unsigned short minix_daddr_t; - -#endif diff --git a/serverboot/minix_super.h b/serverboot/minix_super.h deleted file mode 100644 index 144cf064..00000000 --- a/serverboot/minix_super.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * minix_super.h - * stolen from the Linux distribution - * Copyright (C) 1994 Linus Torvalds - * - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#ifndef _LINUX_MINIX_FS_H -#define _LINUX_MINIX_FS_H - -struct minix_super_block { - unsigned short s_ninodes; - unsigned short s_nzones; - unsigned short s_imap_blocks; - unsigned short s_zmap_blocks; - unsigned short s_firstdatazone; - unsigned short s_log_zone_size; - unsigned long s_max_size; - unsigned short s_magic; - unsigned short s_state; -}; - - -struct minix_inode { - unsigned short i_mode; - unsigned short i_uid; - unsigned long i_size; - unsigned long i_time; - unsigned char i_gid; - unsigned char i_nlinks; - unsigned short i_zone[9]; -}; - -#define MINIX_NIADDR 2 - -#endif diff --git a/serverboot/panic.c b/serverboot/panic.c deleted file mode 100644 index 25924099..00000000 --- a/serverboot/panic.c +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Mach Operating System - * Copyright (c) 1991,1990,1989 Carnegie Mellon University - * All Rights Reserved. - * - * Permission to use, copy, modify and distribute this software and its - * documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" - * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR - * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to - * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 - * - * any improvements or extensions that they make and grant Carnegie Mellon - * the rights to redistribute these changes. - */ - -#include <mach/port.h> -#include <stdarg.h> -#include <stdio.h> -#include <errno.h> - -static mach_port_t master_host_port; - -panic_init(port) - mach_port_t port; -{ - master_host_port = port; -} - -/*VARARGS1*/ -panic (const char *s, ...) -{ - va_list listp; - - clearerr (stdout); - printf("%s: panic: ", program_invocation_name); - va_start(listp, s); - vprintf(s, listp); - va_end(listp); - printf("\n"); - -#ifdef PC532 - { int l; for (l=0;l < 1000000;l++) ; } -#endif /* PC532 */ -#define RB_DEBUGGER 0x1000 /* enter debugger NOW */ - (void) host_reboot(master_host_port, RB_DEBUGGER); - for (;;); -} diff --git a/serverboot/strfcns.c b/serverboot/strfcns.c deleted file mode 100644 index cbead7e4..00000000 --- a/serverboot/strfcns.c +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Mach Operating System - * Copyright (c) 1991 Carnegie Mellon University - * All Rights Reserved. - * - * Permission to use, copy, modify and distribute this software and its - * documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" - * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR - * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to - * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 - * - * any improvements or extensions that they make and grant Carnegie Mellon - * the rights to redistribute these changes. - */ -/* - * Character subroutines - */ - -#include <stdarg.h> - -#define EXPORT_BOOLEAN -#include <mach/boolean.h> - -/* - * Concatenate a group of strings together into a buffer. - * Return a pointer to the trailing '\0' character in - * the result string. - * The list of strings ends with a '(char *)0'. - */ -/*VARARGS1*/ -char * -strbuild(char *dest, ...) -{ - va_list argptr; - register char * src; - register int c; - - va_start(argptr, dest); - while ((src = va_arg(argptr, char *)) != (char *)0) { - - while ((c = *src++) != '\0') - *dest++ = c; - } - *dest = '\0'; - va_end(argptr); - return (dest); -} - -/* - * Return TRUE if string 2 is a prefix of string 1. - */ -boolean_t -strprefix(s1, s2) - register char *s1, *s2; -{ - register int c; - - while ((c = *s2++) != '\0') { - if (c != *s1++) - return (FALSE); - } - return (TRUE); -} |