Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/x68k/stand Implement ls command.



details:   https://anonhg.NetBSD.org/src/rev/c944ebb29a3d
branches:  trunk
changeset: 515584:c944ebb29a3d
user:      minoura <minoura%NetBSD.org@localhost>
date:      Sat Sep 29 03:50:12 2001 +0000

description:
Implement ls command.
Correct bootdev detection.
Other minor changes.

diffstat:

 sys/arch/x68k/stand/boot/boot.c     |  58 +++++++++++++++++++++++++++++-------
 sys/arch/x68k/stand/libsa/Makefile  |   4 +-
 sys/arch/x68k/stand/libsa/devopen.c |   8 +++-
 sys/arch/x68k/stand/libsa/libx68k.h |   8 +++-
 sys/arch/x68k/stand/libsa/sdcd.c    |  22 ++++++++++++-
 5 files changed, 81 insertions(+), 19 deletions(-)

diffs (250 lines):

diff -r a1e60e624deb -r c944ebb29a3d sys/arch/x68k/stand/boot/boot.c
--- a/sys/arch/x68k/stand/boot/boot.c   Sat Sep 29 03:45:13 2001 +0000
+++ b/sys/arch/x68k/stand/boot/boot.c   Sat Sep 29 03:50:12 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: boot.c,v 1.3 2001/09/29 01:42:26 minoura Exp $ */
+/*     $NetBSD: boot.c,v 1.4 2001/09/29 03:50:12 minoura Exp $ */
 
 /*
  * Copyright (c) 2001 Minoura Makoto
@@ -43,8 +43,6 @@
 #define HEAP_END       ((void*) 0x000fffff)
 #define EXSCSI_BDID    ((void*) 0x00ea0001)
 #define SRAM_MEMSIZE   (*((long*) 0x00ed0008))
-/* check whether the bootinf is SCSI or floppy */
-#define BINF_ISFD(pbinf)       (*((char *)(pbinf) + 1) == 0)
 
 char default_kernel[20] = "sd0a:netbsd";
 int mpu, bootdev, hostadaptor;
@@ -54,6 +52,7 @@
 static int get_scsi_host_adapter(void);
 static void doboot(const char *, int);
 static void boot(char *);
+static void ls(char *);
 int bootmenu(void);
 void bootmain(int);
 extern int detectmpu(void);
@@ -93,10 +92,12 @@
        printf("        fd<UNIT>a, UNIT=0-3, format is detected.\n");
        printf(" file:  netbsd, netbsd.gz, etc.\n");
        printf(" flags: abdqsv\n");
+       printf("ls [dev:][directory]\n");
+       printf("halt\nreboot\n");
 }
 
 static void
-doboot (const char *file, int flags)
+doboot(const char *file, int flags)
 {
        u_long          marks[MARK_MAX];
        int fd;
@@ -114,7 +115,7 @@
        }
 
        printf("dev = %x, unit = %d, part = %c, name = %s\n",
-               dev, unit, part + 'a', name);
+              dev, unit, part + 'a', name);
 
        if (dev == 0) {         /* SCSI */
                dev = X68K_MAKESCSIBOOTDEV(X68K_MAJOR_SD,
@@ -190,7 +191,28 @@
                return;
        }
 }
-               
+
+static void
+ls(char *arg)
+{
+       char filename[80];
+
+       devopen_open_dir = 1;
+       if (*arg == 0) {
+               strcpy(filename, default_kernel);
+               strcpy(strchr(filename, ':')+1, "/");
+       } else if (strchr(arg, ':') == 0) {
+               strcpy(filename, default_kernel);
+               strcpy(strchr(filename, ':')+1, arg);
+       } else {
+               strcpy(filename, arg);
+               if (*(strchr(arg, ':')+1) == 0)
+                       strcat(filename, "/");
+       }
+       ufs_ls(filename);
+       devopen_open_dir = 0;
+}
+
 int
 bootmenu(void)
 {
@@ -215,10 +237,10 @@
                printf("trying %s.\n", default_kernel);
                doboot(default_kernel, 0);
                printf("Could not start %s; ", default_kernel);
-               exit(1);
        }
 
-       printf("Please use the absolute unit# (e.g. SCSI ID) instead of the NetBSD ones.\n");
+       printf("Please use the absolute unit# (e.g. SCSI ID)"
+              " instead of the NetBSD ones.\n");
        for (;;) {
                char *p, *options;
 
@@ -232,8 +254,10 @@
                else if (strcmp("help", p) == 0 ||
                         strcmp("?", p) == 0)
                        help();
-               else if (strcmp("reboot", p) == 0)
+               else if ((strcmp("halt", p) == 0) ||(strcmp("reboot", p) == 0))
                        exit(0);
+               else if (strcmp("ls", p) == 0)
+                       ls(options);
                else
                        printf("Unknown command %s\n", p);
        }
@@ -263,13 +287,25 @@
        console_device = consio_init(console_device);
        setheap(HEAP_START, HEAP_END);
 
-       if (BINF_ISFD(&bootdev)) {
+       switch (B_TYPE(bootdev)) {
+       case X68K_MAJOR_FD:
                default_kernel[0] = 'f';
                default_kernel[2] = '0' + B_UNIT(bootdev);
                default_kernel[3] = 'a';
-       } else {
+               break;
+       case X68K_MAJOR_SD:
+               default_kernel[2] = '0' + B_X68K_SCSI_ID(bootdev);
+               default_kernel[3] =
+                       'a' + sd_getbsdpartition(B_X68K_SCSI_ID(bootdev),
+                                                B_X68K_SCSI_PART(bootdev));
+               break;
+       case X68K_MAJOR_CD:
+               default_kernel[0] = 'c';
                default_kernel[2] = '0' + B_X68K_SCSI_ID(bootdev);
                default_kernel[3] = 'a';
+               break;
+       default:
+               printf("Warning: unknown boot device: %x\n", bootdev);
        }
        print_title("NetBSD/x68k bootstrap loader version %s", BOOT_VERS);
        bootmenu();
diff -r a1e60e624deb -r c944ebb29a3d sys/arch/x68k/stand/libsa/Makefile
--- a/sys/arch/x68k/stand/libsa/Makefile        Sat Sep 29 03:45:13 2001 +0000
+++ b/sys/arch/x68k/stand/libsa/Makefile        Sat Sep 29 03:50:12 2001 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.4 2001/09/29 03:44:04 minoura Exp $
+#      $NetBSD: Makefile,v 1.5 2001/09/29 03:50:13 minoura Exp $
 
 S=             ${.CURDIR}/../../../..
 LIBSADIR=      $S/lib/libsa
@@ -14,7 +14,7 @@
 SRCS+=         close.c closeall.c cread.c dev.c fstat.c ioctl.c lseek.c
 SRCS+=         open.c read.c stat.c
 SRCS+=         loadfile.c
-SRCS+=         cd9660.c lfs.c nfs.c ufs.c ustarfs.c
+SRCS+=         cd9660.c lfs.c nfs.c ufs.c ufs_ls.c ustarfs.c
 #SRCS+=                arp.c ether.c in_cksum.c net.c netif.c rpc.c udp.c
 #SRCS+=                bootp.c
 
diff -r a1e60e624deb -r c944ebb29a3d sys/arch/x68k/stand/libsa/devopen.c
--- a/sys/arch/x68k/stand/libsa/devopen.c       Sat Sep 29 03:45:13 2001 +0000
+++ b/sys/arch/x68k/stand/libsa/devopen.c       Sat Sep 29 03:50:12 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: devopen.c,v 1.1 2001/09/27 10:03:28 minoura Exp $      */
+/*     $NetBSD: devopen.c,v 1.2 2001/09/29 03:50:13 minoura Exp $      */
 
 /*
  * Copyright (c) 2001 Minoura Makoto
@@ -33,6 +33,7 @@
 #include "libx68k.h"
 
 extern struct devspec devspec[]; /* defined in conf.c */
+int devopen_open_dir = 0;
 
 /*
  * Parse a device spec.
@@ -71,8 +72,11 @@
        if (*s++ != ':')
                return (ENODEV);
 
-       if (*s == '/')
+       if (*s == '/') {
                s++;
+               if (devopen_open_dir && *s == 0)
+                       s--;
+       }
        (const char*) *file = s;
 
        return 0;
diff -r a1e60e624deb -r c944ebb29a3d sys/arch/x68k/stand/libsa/libx68k.h
--- a/sys/arch/x68k/stand/libsa/libx68k.h       Sat Sep 29 03:45:13 2001 +0000
+++ b/sys/arch/x68k/stand/libsa/libx68k.h       Sat Sep 29 03:50:12 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: libx68k.h,v 1.1 2001/09/27 10:03:28 minoura Exp $      */
+/*     $NetBSD: libx68k.h,v 1.2 2001/09/29 03:50:13 minoura Exp $      */
 
 /*
  * Copyright (c) 2001 Minoura Makoto
@@ -52,7 +52,7 @@
 int sdstrategy(void *devdata, int rw, daddr_t blk, size_t, void*, size_t*);
 int sdopen(struct open_file *, ...);
 int sdclose(struct open_file*);
-int sdgetpartition(int, unsigned);
+int sdgetbsdpartition(int, int);
 int cdstrategy(void *devdata, int rw, daddr_t blk, size_t, void*, size_t*);
 int cdopen(struct open_file *, ...);
 int cdclose(struct open_file*);
@@ -64,3 +64,7 @@
 
 /* devopen.c */
 int devparse(const char *, int *, int *, int *, char **);
+extern int devopen_open_dir;
+
+/* chdsk.c */
+int changedisk_hook(struct open_file *);
diff -r a1e60e624deb -r c944ebb29a3d sys/arch/x68k/stand/libsa/sdcd.c
--- a/sys/arch/x68k/stand/libsa/sdcd.c  Sat Sep 29 03:45:13 2001 +0000
+++ b/sys/arch/x68k/stand/libsa/sdcd.c  Sat Sep 29 03:50:12 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sdcd.c,v 1.1 2001/09/27 10:03:28 minoura Exp $ */
+/*     $NetBSD: sdcd.c,v 1.2 2001/09/29 03:50:13 minoura Exp $ */
 
 /*
  * Copyright (c) 2001 MINOURA Makoto.
@@ -187,15 +187,33 @@
 }
 
 int
-sd_getpartition (int id, unsigned parttop)
+sd_getbsdpartition (int id, int humanpart)
 {
        int error, i;
+       char *buffer;
+       struct dos_partition *parttbl;
+       unsigned parttop;
+
+       if (humanpart < 2)
+               humanpart++;
 
        error = readdisklabel(id);
        if (error) {
                printf ("Reading disklabel: %s\n", strerror(error));
                return -1;
        }
+       buffer = alloca(2048);
+       error = IOCS_S_READ(8 >> current_blklen, 8 >> current_blklen,
+                           id, current_blklen, buffer);
+       if (error < 0) {
+               printf ("Reading partition table: %s\n", strerror(error));
+               return -1;
+       }
+       parttbl = (void*) (buffer + DOSBBSECTOR);
+       if (strncmp (buffer, "X68K", 4) != 0)
+               return 0;
+       parttop = parttbl[humanpart].dp_start;
+       parttop = parttop<<(2-current_blklen);
 
        for (i = 0; i < current_npart; i++) {
                if (partitions[i].start == parttop)



Home | Main Index | Thread Index | Old Index