diff options
-rw-r--r-- | sbin/bim/Makefile | 8 | ||||
-rw-r--r-- | sbin/bim/bim.c | 654 | ||||
-rw-r--r-- | sbin/bim/cmdtable.h | 128 | ||||
-rw-r--r-- | sbin/bim/command.c | 292 | ||||
-rw-r--r-- | sbin/bim/command.h | 97 | ||||
-rw-r--r-- | sbin/bim/images.h | 79 |
6 files changed, 0 insertions, 1258 deletions
diff --git a/sbin/bim/Makefile b/sbin/bim/Makefile deleted file mode 100644 index 9a5fcae614c..00000000000 --- a/sbin/bim/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -# $OpenBSD: Makefile,v 1.3 1997/09/21 11:36:04 deraadt Exp $ - -PROG = bim -SRCS = bim.c command.c -NOMAN = noman - -.include <bsd.prog.mk> - diff --git a/sbin/bim/bim.c b/sbin/bim/bim.c deleted file mode 100644 index 4de3382304a..00000000000 --- a/sbin/bim/bim.c +++ /dev/null @@ -1,654 +0,0 @@ -/* $OpenBSD: bim.c,v 1.5 1997/09/04 00:51:52 mickey Exp $ */ -/* $NetBSD: bim.c,v 1.4 1995/09/28 07:08:49 phil Exp $ */ - -/* - * Copyright (c) 1994 Philip A. Nelson. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Philip A. Nelson. - * 4. The name of Philip A. Nelson may not be used to endorse or promote - * products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY PHILIP NELSON ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL PHILIP NELSON BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * Boot Image Manager - * - * (First copy called "hdsetup" and was written under Minix.) - * - * Phil Nelson - * Sept 30, 1990 - */ - -#include <sys/types.h> -#include <sys/param.h> -#include <unistd.h> -#include <stdio.h> -#include <fcntl.h> -#include <a.out.h> -#include <string.h> -#include <ctype.h> - -#define DKTYPENAMES -#include <sys/disklabel.h> -#include "images.h" - -#define TRUE 1 -#define FALSE 0 -#define MAXARGCMDS 20 - -#define BLOCK_SIZE 1024 - -#define DEFAULT_DEVICE "/dev/sd0c" - -/* Global data.... */ -char disk_info [BLOCK_SIZE]; -int disk_fd; /* The file descriptor for the disk. */ - -struct disklabel *dk_label = (struct disklabel *) &disk_info[LABELOFFSET]; -struct imageinfo *im_table = - (struct imageinfo *) (&disk_info[LABELOFFSET] + sizeof(struct disklabel)); - -int label_changed = FALSE; -int images_changed = FALSE; -int secsize; -extern char * __progname; - -/* Utility routines... */ -/***********************/ - -void usage () -{ - printf ("usage: %s [-c command [-c command ...]] [device]\n",__progname); - printf (" Maximum of %d commands\n", MAXARGCMDS); - exit (-2); -} - -void getlf ( inchar ) - char inchar; -{ - while ( inchar != '\n') inchar = getchar(); -} - -void getstr (str, size) - char *str; - int size; -{ - char inchar; - int count; - - count = 0; - inchar = getchar(); - while (count < size-1 && inchar != '\n') { - *str++ = inchar; - count++; - inchar = getchar(); - } - *str++ = 0; - getlf (inchar); -} - -/* Checksum a disk label */ -unsigned short -dkcksum(lp) - struct disklabel *lp; -{ - register unsigned short *start, *end, sum = 0; - - start = (unsigned short *)lp; - end = (unsigned short*)&lp->d_partitions[lp->d_npartitions]; - while (start < end) sum ^= *start++; - return sum; -} - - -void save_images () -{ - int count; - - count = (int) lseek (disk_fd, (off_t) 0, SEEK_SET); - if (count != 0) - err (3, "lseek in saving image info"); - count = write (disk_fd, disk_info, BLOCK_SIZE); - if (count != BLOCK_SIZE) - err ("write in saveing image info"); - sync (); -} - -/* Get a number using the prompt routine. */ -GetInt (num, prompt_str) - int *num; - char *prompt_str; -{ - char answer[80]; - - prompt (answer, 80, prompt_str); - while (!Str2Int (answer, num)) - { - printf ("Bad number.\n"); - prompt (answer, 80, prompt_str); - } -} - - -/* This function will initialize the image information . */ - -void init_images (badmagic) -char badmagic; -{ - char answer[80]; - int index; - - if (badmagic) { - printf ("Image information has improper magic number.\n"); - while (TRUE) { - prompt (answer,3,"Do you want the images initialized? (y or n) "); - if (answer[0] == 'y') break; - if (answer[0] == 'n') errx (3, "images not initialized."); - } - } - - /* Initialize the image table. */ - im_table->ii_magic = IMAGE_MAGIC; - im_table->ii_boot_partition = -1; - for (index = 0; index < dk_label->d_npartitions; index++) - if (dk_label->d_partitions[index].p_fstype == FS_BOOT) - { - im_table->ii_boot_partition = index; - break; - } - im_table->ii_boot_count = MAXIMAGES; - im_table->ii_boot_used = 0; - im_table->ii_boot_default = -1; - images_changed = TRUE; -} - - -/* Print out the header and other information about the disk. */ - -int display_part(num, args, syntax) - int num; - char **args; - char *syntax; -{ - int count; - - printf ("\nDisk: %s Type: %s\n", dk_label->d_packname, - dk_label->d_typename); - printf ("Physical Sector Size = %d\n", dk_label->d_secsize); - printf ("Disk Size = %ld\n", dk_label->d_secperunit); - - /* Disk Partitions. */ - printf (" partition type sector start length in sectors\n"); - for (count = 0; count < dk_label->d_npartitions; count++) { - if (dk_label->d_partitions[count].p_fstype != FS_UNUSED) { - printf (" %5c ", 'a'+count); - printf ("%14s", fstypenames[dk_label->d_partitions[count].p_fstype]); - printf ("%14ld %17ld\n", - dk_label->d_partitions[count].p_offset, - dk_label->d_partitions[count].p_size); - } - } - printf ("\n"); - - return FALSE; -} - -int display_image(num, args, syntax) - int num; - char **args; - char *syntax; -{ - int count; - - /* Boot Images. */ - if (im_table->ii_boot_partition != -1) - printf ("Boot partition = %c\n", 'a'+im_table->ii_boot_partition); - if (im_table->ii_boot_default != -1) - printf ("Default boot image = %d\n", im_table->ii_boot_default); - printf ("Boot Images: total of %d\n",im_table->ii_boot_count); - printf (" (image address and size in sectors.)\n"); - printf ("Image address size load addr run addr name\n"); - for (count = 0; count < im_table->ii_boot_used; count++) { - printf ("%5d %8lx %6lx %9lx %9lx %s\n", count, - im_table->ii_images[count].boot_address/secsize, - im_table->ii_images[count].boot_size/secsize, - im_table->ii_images[count].boot_load_adr, - im_table->ii_images[count].boot_run_adr, - im_table->ii_images[count].boot_name ); - } - printf ("\n"); - return FALSE; -} - -int display_head(num, args, syntax) - int num; - char **args; - char *syntax; -{ - printf ("\nDisk: %s Type: %s\n", dk_label->d_packname, - dk_label->d_typename); - printf ("Physical Sector Size = %d\n", dk_label->d_secsize); - printf ("Disk Size = %ld\n", dk_label->d_secperunit); - - return FALSE; -} - - -/* Utility routine for moving boot images. These are byte addresses - relative to the start of the files. */ - -int copy_bytes (from_fd, from_adr, to_fd, to_adr, number) - int from_fd, from_adr, to_fd, to_adr, number; -{ - int count; - int index; - int index1; - int left; - int xfer_size; - char buffer [BLOCK_SIZE]; - - /* Check the parameters. */ - if (to_adr > from_adr && from_fd == to_fd) - { - printf ("There is a system error. (copy_bytes)\n"); - return 0; - } - - /* Do the copy. */ - for (index = 0; index < number; index += BLOCK_SIZE) - { - count = lseek (from_fd, (off_t) (from_adr+index), SEEK_SET); - if (count != from_adr+index) - { - printf ("Error in copying (seek from)\n"); - return 0; - } - count = read (from_fd, buffer, BLOCK_SIZE); - if (count != BLOCK_SIZE) - { - if (index != number-1 || count < 0) - { - printf ("Error in copying (read from)\n"); - return 0; - } - else - { - while (count < BLOCK_SIZE) - buffer[count++] = 0; - } - } - count = lseek (to_fd, (off_t) (to_adr+index), SEEK_SET); - if (count != to_adr+index) - { - printf ("Error in copying (seek to)\n"); - return 0; - } - count = write (to_fd, buffer, BLOCK_SIZE); - if (count != BLOCK_SIZE) - { - printf ("Error in copying (write to)\n"); - return 0; - } - } - - /* Success. */ - return 1; -} - - -/* Add a boot image. */ -int -add_image (num, args, syntax) - int num; - char **args; - char *syntax; -{ - struct exec im_exec; /* Information about a new image. */ - int im_file; - int im_size; /* Size of text and data in bytes. Rounded up to a full - block in both text and data. */ - int which_image; /* Which image is to be operated upon. */ - int count; /* read/write counts. */ - int index; /* temporary variable for loops. */ - - int part_size; /* The total size of the boot partition (in bytes). */ - int total_size; /* The total size of all images (in bytes). */ - int boot_start; /* Byte address of start of boot partition. */ - int new_size; /* The new total size of all images. */ - int im_addr; /* Byte address of the new boot image. */ - unsigned int im_load_adr; /* The memory load address. */ - unsigned int im_run_adr; /* The memory run address. */ - char *nptr; /* Pointer for makeing name lower case. */ - - /* Check argument numbers. */ - if (num != 2 && num !=3) - { - printf ("Syntax: %s\n", syntax); - return FALSE; - } - - /* Check for a boot partition. */ - if (im_table->ii_boot_partition == -1) - { - printf ("There is no boot partition.\n"); - return FALSE; - } - - /* Any free images? */ - which_image = im_table->ii_boot_used; - if (which_image == im_table->ii_boot_count) - { - printf ("No more boot image slots available.\n"); - return FALSE; - } - - /* Open the file. */ - im_file = open (args[1], O_RDONLY); - if (im_file < 0) - { - printf ("Could not open %s\n", args[1]); - return FALSE; - } - - /* check the exec header. */ - count = read (im_file, (char *) &im_exec, sizeof(struct exec)); - if (count != sizeof(struct exec)) - { - printf ("Read problems for file %s\n", args[1]); - close (im_file); - return FALSE; - } - - if (N_GETMAGIC(im_exec) != ZMAGIC || N_GETMID(im_exec) != MID_MACHINE) - { - printf ("%s is not a a pc532 executable file.\n", args[1]); - close (im_file); - return FALSE; - } - - if (im_exec.a_entry < 0x2000) - { - printf ("%s has a load address less than 0x2000.\n", args[1]); - close (im_file); - return; - } - im_load_adr = im_exec.a_entry - sizeof(im_exec); /* & ~(__LDPGSZ-1); */ - im_run_adr = im_exec.a_entry; - - if (im_load_adr > 0xFFFFFF) - { - im_load_adr = im_load_adr & 0xFFFFFF; - im_run_adr = im_run_adr & 0xFFFFFF; - printf ("%s has a load address greater than 0xFFFFFF.\n", args[1]); - printf ( - "using the address:\n\tload address = 0x%x\n\trun address = 0x%x\n", - im_load_adr, im_run_adr); - } - - /* Check the sizes. */ - boot_start = dk_label->d_partitions[im_table->ii_boot_partition].p_offset - * secsize; - part_size = dk_label->d_partitions[im_table->ii_boot_partition].p_size - * secsize; - total_size = 0; - for (index = 0; index < im_table->ii_boot_used; index++) - total_size = total_size + im_table->ii_images [index].boot_size; - - /* Calculate other things. */ - im_size = im_exec.a_text + im_exec.a_data; - - /* Final check. */ - new_size = total_size + im_size; - if (new_size > part_size) - { - printf ("Image too big to fit in boot partition.\n"); - close(im_file); - } - - /* Add the image. */ - im_addr = (total_size+secsize-1)/secsize * secsize; - im_table->ii_images [which_image].boot_address = im_addr; - im_table->ii_images [which_image].boot_size = im_size; - im_table->ii_images [which_image].boot_load_adr = im_load_adr; - im_table->ii_images [which_image].boot_run_adr = im_run_adr; - if (num == 3) - strncpy (im_table->ii_images [which_image].boot_name, args[2], 15); - else - strncpy (im_table->ii_images [which_image].boot_name, args[1], 15); - if (copy_bytes (im_file,0,disk_fd,boot_start+im_addr,im_size)) - { - im_table->ii_boot_used++; - /* Make name lowercase and report on image. */ - for (nptr = im_table->ii_images[which_image].boot_name; - *nptr != 0; - nptr++) - if (isupper(*nptr)) *nptr = tolower (*nptr); - printf ("added image %d (%s).\n", which_image, - im_table->ii_images[which_image].boot_name); - close (im_file); - } - else - { - printf ("Problems in installing image.\n"); - close (im_file); - return FALSE; - } - - /* Save the changes. */ - save_images (); - return FALSE; -} - -/* Delete a boot image. */ -int -delete_image (num, args, syntax) - int num; - char **args; - char *syntax; -{ - int which_image; /* Which image is to be operated upon. */ - int index; /* temporary variable for loops. */ - int boot_start; /* Zone number of start of boot partition. */ - int del_size; /* Size of the deleted image. */ - - /* Check arguments. */ - if (num != 2) - { - printf ("Syntax: %s\n", syntax); - return FALSE; - } - - /* Find the image. */ - which_image = -1; - for (index = which_image; index < im_table->ii_boot_used; index++) - if (strcmp(im_table->ii_images[index].boot_name,args[1]) == 0) - { - which_image = index; - break; - } - - if (which_image == -1) - if (!Str2Int(args[1],&which_image)) - { - printf ("Syntax: %s\n", syntax); - return FALSE; - } - - if (which_image < 0 || which_image >= im_table->ii_boot_used) - { - printf ("Delete: No such image (%s)\n", args[1]); - return FALSE; - } - - /* Report on image we are deleteing. */ - printf ("deleting image %d (%s).\n", which_image, - im_table->ii_images[which_image].boot_name); - - /* Do the delete. */ - boot_start = dk_label->d_partitions[im_table->ii_boot_partition].p_offset - * dk_label->d_secsize; - del_size = im_table->ii_images[which_image].boot_size; - for (index = which_image; index < im_table->ii_boot_used-1; index++) - { - copy_bytes ( - disk_fd, boot_start+im_table->ii_images[index+1].boot_address, - disk_fd, boot_start+im_table->ii_images[index+1].boot_address-del_size, - im_table->ii_images[index+1].boot_size); - im_table->ii_images[index] = im_table->ii_images[index+1]; - im_table->ii_images[index].boot_address -= del_size; - } - im_table->ii_boot_used--; - if (which_image == im_table->ii_boot_default) - im_table->ii_boot_default = -1; - else if (which_image < im_table->ii_boot_default) - im_table->ii_boot_default--; - - /* Save the changes. */ - save_images (); - return FALSE; -} - -/* Set the default boot image. */ -int -set_default_image (num, args, syntax) - int num; - char **args; - char *syntax; -{ - int which_image; - - if (num != 2 || !Str2Int(args[1],&which_image)) - { - printf ("Syntax: %s\n", syntax); - return FALSE; - } - - if (which_image >= im_table->ii_boot_used) - { - printf ("No such image.\n"); - return FALSE; - } - - im_table->ii_boot_default = which_image; - images_changed = TRUE; - return FALSE; -} - -/* Initialize the disk or just the image portion. */ - -int -initialize (num, args, syntax) - int num; - char **args; - char *syntax; -{ - /* Check the args */ - if ( num > 1) - { - printf ("Syntax: %s\n", syntax); - return FALSE; - } - - init_images (FALSE); - return FALSE; -} - - -/* Write the disk header and exit. */ - -int write_exit (num, args, syntax) - int num; - char **args; - char *syntax; -{ - if (images_changed) save_images (); - - return TRUE; -} - - -/* The main program! */ -/*********************/ - -main (argc, argv) -int argc; -char *argv[]; -{ - int count; /* Used by reads. */ - char answer, *fname; - int cmdscnt; /* Number of argument line commands. */ - char *argcmds[MAXARGCMDS]; - extern int optind, opterr; - extern char *optarg; - int optchar; - int index; - - /* Check the parameters. */ - cmdscnt = 0; - opterr = TRUE; - fname = DEFAULT_DEVICE; - while ((optchar = getopt (argc, argv, "c:")) != -1) - switch (optchar) { - case 'c': if (cmdscnt == MAXARGCMDS) usage(); - argcmds[cmdscnt++] = optarg; - break; - case '?': usage (); - } - - if (argc - optind > 1) usage(); - if (optind < argc) fname = argv[optind]; - - disk_fd = open(fname, O_RDWR); - if (disk_fd < 0) err(3, "%s", fname); - - /* Read the disk information block. */ - count = read (disk_fd, disk_info, BLOCK_SIZE); - if (count != BLOCK_SIZE) errx(3, "Could not read info block on %s", fname); - - /* Check for correct information and set up pointers. */ - if (dk_label->d_magic != DISKMAGIC) - err (3, "Could not find a disk label on %s", fname); - if (im_table->ii_magic != IMAGE_MAGIC) init_images (TRUE); - if (dkcksum (dk_label) != 0) - warnx ("Warning: bad checksum in disk label."); - - /* initialize secsize. */ - secsize = dk_label->d_secsize; - - /* do the commands.... */ - if (cmdscnt > 0) - { - /* Process the argv commands. */ - for (index = 0; index < cmdscnt; index++) - one_command (argcmds[index]); - } - else - { - /* Interactive command loop. */ - display_part (0,NULL,NULL); - display_image (0,NULL,NULL); - command_loop (); - } -} diff --git a/sbin/bim/cmdtable.h b/sbin/bim/cmdtable.h deleted file mode 100644 index 30a31af9f33..00000000000 --- a/sbin/bim/cmdtable.h +++ /dev/null @@ -1,128 +0,0 @@ -/* $OpenBSD: cmdtable.h,v 1.2 1996/06/23 14:29:56 deraadt Exp $ */ -/* $NetBSD: cmdtable.h,v 1.2 1995/03/18 12:28:13 cgd Exp $ */ - -/* - * Copyright (c) 1994 Philip A. Nelson. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Philip A. Nelson. - * 4. The name of Philip A. Nelson may not be used to endorse or promote - * products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY PHILIP NELSON ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL PHILIP NELSON BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * cmdtable.h - this is where the command table is defined. - * - * The user must complete this command table. It is started. - */ - -/* procedure definitions. */ -#ifndef NO_HELP -CMD_PROC (help); -#endif - -/* hdsetup commands. */ -CMD_PROC (write_exit); -CMD_PROC (set_default_image); -CMD_PROC (add_image); -CMD_PROC (delete_image); -CMD_PROC (display_part); -CMD_PROC (display_image); -CMD_PROC (display_head); -CMD_PROC (initialize); - -/* The command definitions. This is where the user should add new - command definitions. - - Field definition: - - { proc_name, "command_name", "Syntax", "Help" } - - NOTE: For an alphabetical list from the help command, list the - commands in alphabetical order on the name field. */ - -CONST -struct command cmd_table [] = { /* Command Table */ - -{ add_image, "add", -"ADD <file_name> [image_name].", -"Add the executable file to the image table. The image name will\n\ -be the same as the <file_name> unless otherwise specified." -}, - -{ delete_image, "delete", -"DELETE <image_id>.", -"Delete the specified image from the image table." -}, - -{ set_default_image, "default", "DEFAULT <image_number>.", -"Specifies the image that shall be used during an autoboot or a monitor\n\ -boot command without any arguments." -}, - -{ write_exit, "exit", "EXIT", -"Terminates the command processor writing the header if necessary." -}, - -{ display_head, "header", "HEADER", -"Display the disk label header information without the partitions." -}, - -#ifndef NO_HELP -{ help, "help", "HELP [<command> ...].", -"Provides help for all listed <command>s. If there none, prints a list \n\ -of the commands." -}, -#endif - -{ display_image, "images", "IMAGES", -"Display the image information." -}, - -{ initialize, "init", "INIT", -"Initialize the image information." -}, - -{ display_part, "partitions", "PARTITIONS", -"Display the partition information. Unused partitions are not displayed." -}, - -#ifndef NO_HELP -{ help, "?", "", -"Prints a list of commands." -}, -#endif - -{ write_exit, "quit", "QUIT", -"Same as exit." -}, - -}; - -#define CMDLEN (sizeof (cmd_table) / sizeof (struct command)) - - -/* The prompt! */ -#define PROMPT "bim (? for help): " diff --git a/sbin/bim/command.c b/sbin/bim/command.c deleted file mode 100644 index 2fbb85442de..00000000000 --- a/sbin/bim/command.c +++ /dev/null @@ -1,292 +0,0 @@ -/* $OpenBSD: command.c,v 1.2 1996/06/23 14:29:57 deraadt Exp $ */ -/* $NetBSD: command.c,v 1.2 1995/03/18 12:28:15 cgd Exp $ */ - -/* - * Copyright (c) 1994 Philip A. Nelson. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Philip A. Nelson. - * 4. The name of Philip A. Nelson may not be used to endorse or promote - * products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY PHILIP NELSON ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL PHILIP NELSON BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * command.c - The routines to implement the command processor. - * - * The user must add to "cmdtable.h" all commands that are available. - */ - -#include <stdio.h> -#include <ctype.h> -#include "command.h" -#include "cmdtable.h" - - -/* This allows the user to define the prompt in cmdtable.h */ -#ifndef PROMPT -#define PROMPT "Command (? for help): " -#endif - - -/* Other procedure prototypes. */ -PROTO (void prompt, (char *, int, char *)); -PROTO (int parse, (char *, char **)); -PROTO (CONST struct command *find_entry, (char *)); -PROTO (int StrCmp, (char *, char *)); - -/* A pointer to a function to be called after every command. - A NULL pointer says no function is to be executed. - The int parameter is the "done" flag.. TRUE => last command */ - -PROTO (void (*after_cmd), (int)) = NULL; - -/* This is the command processor loop. */ - -command_loop () -{ - char cmdline [LINELEN]; - char *args [MAXARGS]; - int numargs; - CONST struct command *cmd; - int done = FALSE; - - int ix; - - while (!done) { - prompt(cmdline, LINELEN, PROMPT); - numargs = parse (cmdline, args); - if (numargs == BLANK_LINE) continue; - cmd = find_entry (args[0]); - if (cmd != NULL) - { - done = (*(cmd->fn)) (numargs, args, cmd->syntax); - if (after_cmd != NULL) - (*(after_cmd)) (done); - } - else - printf ("Unknown command\n"); - } -} - -/* This is the command processor for a single command. */ -int -one_command (cmdline) - char *cmdline; -{ - char *args [MAXARGS]; - int numargs; - CONST struct command *cmd; - int done; - - numargs = parse (cmdline, args); - if (numargs == BLANK_LINE) return 0; - cmd = find_entry (args[0]); - if (cmd != NULL) - { - done = (*(cmd->fn)) (numargs, args, cmd->syntax); - if (after_cmd != NULL) - (*(after_cmd)) (done); - return done; - } - else - return 0; -} - -/* prompt procedure.... Write out the prompt and then read - a response. */ - -void prompt (cmdline, linelen, promptstr) - char *cmdline; - int linelen; - char *promptstr; -{ - int incount = 0; - int inchar; - - /* Give the prompt. */ - printf ("%s", promptstr); - fflush (stdout); - - /* Read chars until newline or EOF, toss chars that won't fit in the - array. */ - while (TRUE) - { - inchar = getchar(); - if (inchar == '\n' || inchar == EOF) break; - if (++incount < linelen) *cmdline++ = inchar; - } - *cmdline = 0; -} - - -/* parse the arguments on an input line. It returns an array of - pointers to substrings in the original string. It puts the string - terminator in the original line. */ - -int parse (cmdline, args) - char *cmdline; - char **args; -{ - int index; - int argcnt = BLANK_LINE; - - /* Initialize the args. */ - for (index = 0; index < MAXARGS; index++) - args[index] = NULL; - - /* Start looking for the commands */ - while (*cmdline != 0) - { - while (isspace(*cmdline)) cmdline++; /* skip blanks. */ - if (*cmdline != 0) - { - /* Start of new argument. */ - if (argcnt < MAXARGS) args[argcnt] = cmdline; - while (!isspace(*cmdline) && *cmdline != 0) cmdline++; - if (*cmdline != 0) *cmdline++ = 0; - argcnt++; - } - } - return (argcnt < MAXARGS ? argcnt : MAXARGS -1); -} - - -/* Search cmd_tbl for 1) a command matching what the user typed or 2) - * a unique command which is a superstring of what the user typed. - */ - -CONST struct command * -find_entry (name) -char *name; -{ - CONST struct command *item, *save; - int subcount = 0; - - for (item = cmd_table; item < cmd_table + CMDLEN; item++) - switch (StrCmp (name, item->name)) { - case CMP_MATCH: - return item; - case CMP_SUBSTR: - subcount++; - save = item; - break; - case CMP_NOMATCH: - break; - } - return (subcount == 1)? save : NULL; -} - - -/* Returns CMP_MATCH if strings are the same, CMP_SUBSTR if p1 is a - * proper substring of p2, and CMP_NOMATCH if neither. - */ -int -StrCmp (p1, p2) -register char *p1, *p2; -{ - while (*p1 == *p2 && *p1 != '\0') { - ++p1; - ++p2; - } - if (*p1 == '\0') - return (*p2 == '\0')? CMP_MATCH: CMP_SUBSTR; - return CMP_NOMATCH; -} - - -/* Other routines that may be helpful in evaluating arguments.... - */ - -int -Str2Int (str, num) - char *str; - int *num; -{ - if (!isdigit(*str) && *str != '-') return FALSE; - *num = atoi (str); - return TRUE; -} - - - -#ifndef NO_HELP -/* "?" command handler. Print help and list of commands. - */ -help_cmds () -{ - CONST struct command *q; - - printf("\nFor additional help, type HELP <command>. Commands are:\n"); - for (q = cmd_table; q < cmd_table + CMDLEN; ++q) - if ((q - cmd_table) % 5 == 4) - printf ("%s\n", q -> name); - else - printf ("%-15s", q -> name); - if ((q - cmd_table) % 5 != 0) - printf ("\n"); - printf ("\n"); -} - -/* The default help routine. This may be redefined by the user. */ -int help (num, args, syntax) - int num; - char **args; - char *syntax; -{ - CONST struct command *item; - int index; - int show_cmds = FALSE; - char dummy[2]; - - if (args[0][0] == '?') num = 1; /* Force "no args" for ?. */ - - /* Print help for each argument. */ - if (num > 1) - for (index = 1; index < num; index++) - { - item = find_entry (args[index]); - if (item != NULL) - { - printf ("\n"); - if (item -> syntax[0] != 0) - printf ("Syntax: %s\n", item -> syntax); - printf ("%s\n\n", item -> help); - if (index < num-1) prompt (dummy, 1, "cr to continue:"); - } - else - { - printf ("unknow command %s.\n", args[index]); - show_cmds = TRUE; - } - } - - if (show_cmds || num == 1) - help_cmds (); - - return FALSE; -} -#endif - - diff --git a/sbin/bim/command.h b/sbin/bim/command.h deleted file mode 100644 index 269efd7fd7b..00000000000 --- a/sbin/bim/command.h +++ /dev/null @@ -1,97 +0,0 @@ -/* $OpenBSD: command.h,v 1.2 1996/06/23 14:29:57 deraadt Exp $ */ -/* $NetBSD: command.h,v 1.2 1995/03/18 12:28:17 cgd Exp $ */ - -/* - * Copyright (c) 1994 Philip A. Nelson. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Philip A. Nelson. - * 4. The name of Philip A. Nelson may not be used to endorse or promote - * products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY PHILIP NELSON ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL PHILIP NELSON BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * Command tool - a library for building command languages fast. - * - * Philip A. Nelson, Oct 1991 - * - * Some code is lifted from the PC532 monitor/debugger written - * by Bruce Culbertson. (Thanks Bruce!) - */ - -/* Defines that depend on ANSI or not ANSI. */ - -#ifdef __STDC__ -#define CMD_PROC(name) int name (int, char **, char *) -#define PROTO(name,args) name args -#define CONST const -#else -#define CMD_PROC(name) name (); -#define PROTO(name,args) name () -#define CONST -#endif - - -/* The commands are stored in a table that includes their name, a pointer - to the function that processes the command and a help message. */ - -struct command { /* The commands, their names, help */ - PROTO (int (*fn), (int, char **, char *)); - char *name; - char *syntax; - char *help; -}; - -/* The command loop will do the following: - a) prompt the user for a command. - b) read the command line. - c) break the input line into arguments. - d) search for the command in the command table. - e) If the command is found, call the routine to process it. - f) IF the return value from the command is NON ZERO, exit the loop. - -Each function to process a command must be defined as follows: - - int name ( int num, char ** cmd_args ) where num is the number - of arguments (the command name is not counted) and the cmd_args is - an array of pointers to the arguments. cmd_args[0] is the command - name. cmd_args[1] is the first argument. - -*/ - - -/* Constants defining the limits of the command processor. - */ -#define TRUE 1 -#define FALSE 0 -#define LINELEN 256 -#define MAXARGS 16 -#define BLANK_LINE 0 - -/* Stuff for myStrCmp() - */ -#define CMP_NOMATCH 0 -#define CMP_MATCH 1 -#define CMP_SUBSTR 2 diff --git a/sbin/bim/images.h b/sbin/bim/images.h deleted file mode 100644 index 70fa379dab7..00000000000 --- a/sbin/bim/images.h +++ /dev/null @@ -1,79 +0,0 @@ -/* $OpenBSD: images.h,v 1.2 1996/06/23 14:29:58 deraadt Exp $ */ -/* $NetBSD: images.h,v 1.2 1995/03/18 12:28:19 cgd Exp $ */ - -/* - * Copyright (c) 1994 Philip A. Nelson. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Philip A. Nelson. - * 4. The name of Philip A. Nelson may not be used to endorse or promote - * products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY PHILIP NELSON ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL PHILIP NELSON BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * This is the description of the images information that - * follows the BSD label on a pc532 disk (first 1k block). - * - * Phil Nelson, Oct 23, 1991 - * - * - * These structures are expected to reside on the first 1K bytes - * of a disk. Their order and structures as follows: - * - * ------------------- - * | nothing | - * ------------------- - * | BSD disk_label | - * ------------------- - * | pc532 boot_info | - * ------------------- - */ - -/* Constants for the header block. */ -#define IMAGE_MAGIC 0x6ef2b7d5L - -#ifndef MAXIMAGES -#define MAXIMAGES 8 -#endif - -/* This is the header block. */ - -struct imageinfo { - long ii_magic; /* The magic number. */ - short ii_boot_partition; /* The partition that holds the image. */ - short ii_boot_count; /* The number of boot entries. (>=1) */ - short ii_boot_used; /* The number of boot entries used. */ - short ii_boot_default; /* The default boot image. */ - struct { - long boot_address; /* The byte address of the boot image. - This address is relative to start of - the boot partition. */ - long boot_size; /* The size of the boot image in zones. */ - long boot_load_adr; /* Where to load the image, real memory. */ - long boot_run_adr; /* The jump address to start the image. */ - char boot_name[16]; /* A title for the image. */ - } ii_images[MAXIMAGES]; -}; - |