Purely cosmetic whitespace/indentation changes (mmm, indent(1))

This commit is contained in:
thorpej 1997-03-22 09:13:48 +00:00
parent e321bba79a
commit edad9d2e05
6 changed files with 607 additions and 572 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: ls.c,v 1.1.1.1 1997/03/14 02:40:31 perry Exp $ */ /* $NetBSD: ls.c,v 1.2 1997/03/22 09:13:48 thorpej Exp $ */
/* /*
* Copyright (c) 1993 * Copyright (c) 1993
@ -42,77 +42,81 @@
#include "stand.h" #include "stand.h"
extern char *strerror __P((int)); /* XXX for now */ extern char *strerror __P((int)); /* XXX for now */
static char *typestr[] = { static char *typestr[] = {
"unknown", "unknown",
"FIFO", "FIFO",
"CHR", "CHR",
0, 0,
"DIR", "DIR",
0, 0,
"BLK", "BLK",
0, 0,
"REG", "REG",
0, 0,
"LNK", "LNK",
0, 0,
"SOCK", "SOCK",
0, 0,
"WHT" "WHT"
}; };
void ls(path) void
char *path; ls(path)
char *path;
{ {
int fd; int fd;
struct stat sb; struct stat sb;
size_t size; size_t size;
char dirbuf[DIRBLKSIZ]; char dirbuf[DIRBLKSIZ];
fd = open(path, 0); fd = open(path, 0);
if(fd < 0) { if (fd < 0) {
printf("ls: %s\n", strerror(errno)); printf("ls: %s\n", strerror(errno));
return; return;
}
if(fstat(fd, &sb) < 0) {
printf("stat: %s\n", strerror(errno));
goto out;
}
if((sb.st_mode & IFMT) != IFDIR) {
printf("%s: %s\n", path, strerror(ENOTDIR));
goto out;
}
while ((size = read(fd, dirbuf, DIRBLKSIZ)) == DIRBLKSIZ) {
struct direct *dp, *edp;
dp = (struct direct *)dirbuf;
edp = (struct direct *)(dirbuf + size);
while (dp < edp) {
if (dp->d_ino != (ino_t)0) {
char *t;
if((dp->d_namlen > MAXNAMLEN+1) ||
(dp->d_type > sizeof(typestr) / sizeof(char*) - 1) ||
!(t = typestr[dp->d_type])){
/* This does not handle "old" filesystems properly.
On little endian machines, we get a bogus type name
if the namlen matches a valid type identifier.
We could check if we read namlen "0" and handle this
case specially, if there were a pressing need... */
printf("bad dir entry\n");
goto out;
} }
if (fstat(fd, &sb) < 0) {
printf("stat: %s\n", strerror(errno));
goto out;
}
if ((sb.st_mode & IFMT) != IFDIR) {
printf("%s: %s\n", path, strerror(ENOTDIR));
goto out;
}
while ((size = read(fd, dirbuf, DIRBLKSIZ)) == DIRBLKSIZ) {
struct direct *dp, *edp;
printf("%d: %s (%s)\n", dp->d_ino, dp->d_name, t); dp = (struct direct *) dirbuf;
} edp = (struct direct *) (dirbuf + size);
dp = (struct direct *)((char *)dp + dp->d_reclen); while (dp < edp) {
} if (dp->d_ino != (ino_t) 0) {
} char *t;
if ((dp->d_namlen > MAXNAMLEN + 1) ||
(dp->d_type >
sizeof(typestr) / sizeof(char *) - 1) ||
!(t = typestr[dp->d_type])) {
/*
* This does not handle "old"
* filesystems properly. On little
* endian machines, we get a bogus
* type name if the namlen matches a
* valid type identifier. We could
* check if we read namlen "0" and
* handle this case specially, if
* there were a pressing need...
*/
printf("bad dir entry\n");
goto out;
}
printf("%d: %s (%s)\n", dp->d_ino,
dp->d_name, t);
}
dp = (struct direct *) ((char *) dp + dp->d_reclen);
}
}
out: out:
close(fd); close(fd);
} }

View File

@ -1,4 +1,4 @@
/* $NetBSD: nfswrapper.c,v 1.1.1.1 1997/03/14 02:40:31 perry Exp $ */ /* $NetBSD: nfswrapper.c,v 1.2 1997/03/22 09:13:50 thorpej Exp $ */
/* /*
* Copyright (c) 1996 * Copyright (c) 1996
@ -29,16 +29,13 @@
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * (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 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/ */
/* Makes the (filesystem dependant) mount /*
part of open. Necessary for interoperation with * Makes the (filesystem dependant) mount part of open. Necessary for
tftp filesystem on same net device layer. * interoperation with tftp filesystem on same net device layer. Assumes: -
Assumes: * socket descriptor (int) at open_file->f_devdata - server host IP in global
- socket descriptor (int) at open_file->f_devdata * rootip - path to mount in globel rootpath
- server host IP in global rootip
- path to mount in globel rootpath
*/ */
#include <sys/param.h> #include <sys/param.h>
@ -51,22 +48,22 @@
#include "nfswrapper.h" #include "nfswrapper.h"
int nfs_mountandopen(path, f) int
char *path; nfs_mountandopen(path, f)
struct open_file *f; char *path;
struct open_file *f;
{ {
int sock; int sock;
if(!rootpath[0]){ if (!rootpath[0]) {
printf("no rootpath, no nfs\n"); printf("no rootpath, no nfs\n");
return(ENXIO); return (ENXIO);
} }
sock = *(int *) (f->f_devdata);
sock= *(int*)(f->f_devdata); if (nfs_mount(sock, rootip, rootpath)) {
printf("mount failed\n");
if(nfs_mount(sock , rootip, rootpath)){ return (ENXIO);
printf("mount failed\n"); }
return(ENXIO); return (nfs_open(path, f));
}
return(nfs_open(path, f));
} }

View File

@ -1,4 +1,4 @@
/* $NetBSD: tftp.c,v 1.1.1.1 1997/03/14 02:40:31 perry Exp $ */ /* $NetBSD: tftp.c,v 1.2 1997/03/22 09:13:51 thorpej Exp $ */
/* /*
* Copyright (c) 1996 * Copyright (c) 1996
@ -32,14 +32,11 @@
* *
*/ */
/* Simple TFTP implementation for libsa. /*
Assumes: * Simple TFTP implementation for libsa. Assumes: - socket descriptor (int)
- socket descriptor (int) at open_file->f_devdata * at open_file->f_devdata - server host IP in global rootip Restrictions: -
- server host IP in global rootip * read only - lseek only with SEEK_SET or SEEK_CUR - no big time differences
Restrictions: * between transfers (<tftp timeout)
- read only
- lseek only with SEEK_SET or SEEK_CUR
- no big time differences between transfers (<tftp timeout)
*/ */
#include <sys/types.h> #include <sys/types.h>
@ -55,305 +52,331 @@
#include "tftp.h" #include "tftp.h"
static int tftpport = 2000; static int tftpport = 2000;
#define RSPACE 520 /* max data packet, rounded up */ #define RSPACE 520 /* max data packet, rounded up */
struct tftp_handle{ struct tftp_handle {
struct iodesc *iodesc; struct iodesc *iodesc;
int currblock; /* contents of lastdata */ int currblock; /* contents of lastdata */
int islastblock; /* flag */ int islastblock; /* flag */
int validsize; int validsize;
int off; int off;
char *path; /* saved for re-requests */ char *path; /* saved for re-requests */
struct{ struct {
u_char header[HEADER_SIZE]; u_char header[HEADER_SIZE];
struct tftphdr t; struct tftphdr t;
u_char space[RSPACE]; u_char space[RSPACE];
}lastdata; } lastdata;
}; };
static int tftperrors[8] = { static int tftperrors[8] = {
0, /* ??? */ 0, /* ??? */
ENOENT, ENOENT,
EPERM, EPERM,
ENOSPC, ENOSPC,
EINVAL, /* ??? */ EINVAL, /* ??? */
EINVAL, /* ??? */ EINVAL, /* ??? */
EEXIST, EEXIST,
EINVAL /* ??? */ EINVAL /* ??? */
}; };
static ssize_t recvtftp(d, pkt, len, tleft) static ssize_t
register struct iodesc *d; recvtftp(d, pkt, len, tleft)
register void *pkt; register struct iodesc *d;
register ssize_t len; register void *pkt;
time_t tleft; register ssize_t len;
time_t tleft;
{ {
struct tftphdr *t; struct tftphdr *t;
len = readudp(d, pkt, len, tleft); len = readudp(d, pkt, len, tleft);
if(len < 8) return(-1); if (len < 8)
return (-1);
t = (struct tftphdr *)pkt; t = (struct tftphdr *) pkt;
switch(ntohs(t->th_opcode)) { switch (ntohs(t->th_opcode)) {
case DATA: { case DATA: {
int got; int got;
if(htons(t->th_block) != d->xid) { /* expected block? */
return(-1); if (htons(t->th_block) != d->xid) {
} /*
if(d->xid == 1){ /* first data packet, from new port */ * Expected block?
register struct udphdr *uh; */
uh = (struct udphdr*)pkt - 1; return (-1);
d->destport = htons(uh->uh_sport); /* XXXXXX in net.c geswappt! */ }
} /* else check uh_sport has not changed??? */ if (d->xid == 1) {
got = len - (t->th_data - (char*)t); /*
return got; * First data packet from new port.
} */
case ERROR: register struct udphdr *uh;
if((unsigned)ntohs(t->th_code) >= 8) { uh = (struct udphdr *) pkt - 1;
printf("illegal tftp error %d\n", ntohs(t->th_code)); /* XXX in net.c - geswappt! */
errno = EIO; d->destport = htons(uh->uh_sport);
} else { } /* else check uh_sport has not changed??? */
#ifdef DEBUG got = len - (t->th_data - (char *) t);
printf("tftp-error %d\n", ntohs(t->th_code)); return got;
#endif
errno = tftperrors[ntohs(t->th_code)];
} }
return(-1); case ERROR:
default: if ((unsigned) ntohs(t->th_code) >= 8) {
printf("illegal tftp error %d\n", ntohs(t->th_code));
errno = EIO;
} else {
#ifdef DEBUG #ifdef DEBUG
printf("tftp type %d not handled\n", ntohs(t->th_opcode)); printf("tftp-error %d\n", ntohs(t->th_code));
#endif #endif
return(-1); errno = tftperrors[ntohs(t->th_code)];
} }
return (-1);
default:
#ifdef DEBUG
printf("tftp type %d not handled\n", ntohs(t->th_opcode));
#endif
return (-1);
}
} }
/* send request, expect first block (or error) */ /* send request, expect first block (or error) */
static int tftp_makereq(h) static int
struct tftp_handle *h; tftp_makereq(h)
struct tftp_handle *h;
{ {
struct{ struct {
u_char header[HEADER_SIZE]; u_char header[HEADER_SIZE];
struct tftphdr t; struct tftphdr t;
u_char space[FNAME_SIZE+6]; u_char space[FNAME_SIZE + 6];
}wbuf; } wbuf;
char *wtail; char *wtail;
int l; int l;
ssize_t res; ssize_t res;
struct tftphdr *t; struct tftphdr *t;
wbuf.t.th_opcode = htons((u_short)RRQ); wbuf.t.th_opcode = htons((u_short) RRQ);
wtail = wbuf.t.th_stuff; wtail = wbuf.t.th_stuff;
l = strlen(h->path); l = strlen(h->path);
bcopy(h->path,wtail, l + 1); bcopy(h->path, wtail, l + 1);
wtail += l + 1; wtail += l + 1;
bcopy("octet", wtail, 6); bcopy("octet", wtail, 6);
wtail += 6; wtail += 6;
t= &h->lastdata.t; t = &h->lastdata.t;
/* h->iodesc->myport = htons(--tftpport); */ /* h->iodesc->myport = htons(--tftpport); */
h->iodesc->myport = htons(tftpport + (getsecs() & 0x3ff)); h->iodesc->myport = htons(tftpport + (getsecs() & 0x3ff));
h->iodesc->destport = htons(IPPORT_TFTP); h->iodesc->destport = htons(IPPORT_TFTP);
h->iodesc->xid = 1; /* expected block */ h->iodesc->xid = 1; /* expected block */
res = sendrecv(h->iodesc, sendudp, &wbuf.t, wtail-(char*)&wbuf.t, res = sendrecv(h->iodesc, sendudp, &wbuf.t, wtail - (char *) &wbuf.t,
recvtftp, t, sizeof(*t) + RSPACE); recvtftp, t, sizeof(*t) + RSPACE);
if(res == -1) if (res == -1)
return(errno); return (errno);
h->currblock = 1; h->currblock = 1;
h->validsize = res; h->validsize = res;
h->islastblock = 0; h->islastblock = 0;
if(res < SEGSIZE) h->islastblock = 1; /* very short file */ if (res < SEGSIZE)
return(0); h->islastblock = 1; /* very short file */
return (0);
} }
/* ack block, expect next */ /* ack block, expect next */
static int tftp_getnextblock(h) static int
struct tftp_handle *h; tftp_getnextblock(h)
struct tftp_handle *h;
{ {
struct{ struct {
u_char header[HEADER_SIZE]; u_char header[HEADER_SIZE];
struct tftphdr t; struct tftphdr t;
}wbuf; } wbuf;
char *wtail; char *wtail;
int res; int res;
struct tftphdr *t; struct tftphdr *t;
wbuf.t.th_opcode = htons((u_short)ACK); wbuf.t.th_opcode = htons((u_short) ACK);
wtail = (char*)&wbuf.t.th_block; wtail = (char *) &wbuf.t.th_block;
wbuf.t.th_block = htons((u_short)h->currblock); wbuf.t.th_block = htons((u_short) h->currblock);
wtail += 2; wtail += 2;
t = &h->lastdata.t; t = &h->lastdata.t;
h->iodesc->xid = h->currblock + 1; /* expected block */ h->iodesc->xid = h->currblock + 1; /* expected block */
res = sendrecv(h->iodesc, sendudp, &wbuf.t, wtail - (char*)&wbuf.t, res = sendrecv(h->iodesc, sendudp, &wbuf.t, wtail - (char *) &wbuf.t,
recvtftp, t, sizeof(*t) + RSPACE); recvtftp, t, sizeof(*t) + RSPACE);
if(res == -1) /* 0 is OK! */ if (res == -1) /* 0 is OK! */
return(errno); return (errno);
h->currblock++; h->currblock++;
h->validsize = res; h->validsize = res;
if(res < SEGSIZE) h->islastblock = 1; /* EOF */ if (res < SEGSIZE)
return(0); h->islastblock = 1; /* EOF */
return (0);
} }
int tftp_open(path, f) int
char *path; tftp_open(path, f)
struct open_file *f; char *path;
struct open_file *f;
{ {
struct tftp_handle *tftpfile; struct tftp_handle *tftpfile;
struct iodesc *io; struct iodesc *io;
int res; int res;
tftpfile = (struct tftp_handle*)alloc(sizeof(*tftpfile)); tftpfile = (struct tftp_handle *) alloc(sizeof(*tftpfile));
if(!tftpfile) return(ENOMEM); if (!tftpfile)
return (ENOMEM);
tftpfile->iodesc = io = socktodesc(*(int*)(f->f_devdata)); tftpfile->iodesc = io = socktodesc(*(int *) (f->f_devdata));
io->destip = rootip; io->destip = rootip;
tftpfile->off = 0; tftpfile->off = 0;
tftpfile->path = path; /* XXXXXXX we hope it's static */ tftpfile->path = path; /* XXXXXXX we hope it's static */
res = tftp_makereq(tftpfile, path); res = tftp_makereq(tftpfile, path);
if(res) { if (res) {
free(tftpfile, sizeof(*tftpfile)); free(tftpfile, sizeof(*tftpfile));
return(res); return (res);
} }
f->f_fsdata = (void *) tftpfile;
f->f_fsdata = (void*)tftpfile; return (0);
return(0);
} }
int tftp_read(f, addr, size, resid) int
struct open_file *f; tftp_read(f, addr, size, resid)
void *addr; struct open_file *f;
size_t size; void *addr;
size_t *resid; /* out */ size_t size;
size_t *resid; /* out */
{ {
struct tftp_handle *tftpfile; struct tftp_handle *tftpfile;
static int tc = 0; static int tc = 0;
tftpfile = (struct tftp_handle*)f->f_fsdata; tftpfile = (struct tftp_handle *) f->f_fsdata;
while(size > 0){ while (size > 0) {
int needblock, count; int needblock, count;
if(!(tc++ % 16)) twiddle(); if (!(tc++ % 16))
twiddle();
needblock = tftpfile->off / SEGSIZE + 1; needblock = tftpfile->off / SEGSIZE + 1;
if(tftpfile->currblock > needblock) /* seek backwards */ if (tftpfile->currblock > needblock) /* seek backwards */
tftp_makereq(tftpfile); /* no error check, it worked for open */ tftp_makereq(tftpfile); /* no error check, it worked
* for open */
while(tftpfile->currblock < needblock){ while (tftpfile->currblock < needblock) {
int res; int res;
res = tftp_getnextblock(tftpfile); res = tftp_getnextblock(tftpfile);
if(res){ /* no answer */ if (res) { /* no answer */
#ifdef DEBUG #ifdef DEBUG
printf("tftp: read error\n"); printf("tftp: read error\n");
#endif #endif
return(res); return (res);
} }
if(tftpfile->islastblock) break; if (tftpfile->islastblock)
} break;
}
if(tftpfile->currblock == needblock){ if (tftpfile->currblock == needblock) {
int offinblock, inbuffer; int offinblock, inbuffer;
offinblock = tftpfile->off % SEGSIZE; offinblock = tftpfile->off % SEGSIZE;
inbuffer = tftpfile->validsize - offinblock; inbuffer = tftpfile->validsize - offinblock;
if(inbuffer < 0){ if (inbuffer < 0) {
#ifdef DEBUG #ifdef DEBUG
printf("tftp: invalid offset %d\n", tftpfile->off); printf("tftp: invalid offset %d\n",
tftpfile->off);
#endif #endif
return(EINVAL); return (EINVAL);
} }
count = (size < inbuffer ? size : inbuffer);
bcopy(tftpfile->lastdata.t.th_data + offinblock,
addr, count);
count = (size < inbuffer ? size : inbuffer); addr += count;
bcopy(tftpfile->lastdata.t.th_data + offinblock, addr, count); tftpfile->off += count;
size -= count;
addr += count; if ((tftpfile->islastblock) && (count == inbuffer))
tftpfile->off += count; break; /* EOF */
size -= count; } else {
if((tftpfile->islastblock) && (count == inbuffer)) break; /* EOF */
} else {
#ifdef DEBUG #ifdef DEBUG
printf("tftp: block %d not found\n", needblock); printf("tftp: block %d not found\n", needblock);
#endif #endif
return(EINVAL); return (EINVAL);
} }
} }
if(resid) if (resid)
*resid = size; *resid = size;
return(0); return (0);
} }
int tftp_close(f) int
struct open_file *f; tftp_close(f)
struct open_file *f;
{ {
struct tftp_handle *tftpfile; struct tftp_handle *tftpfile;
tftpfile = (struct tftp_handle*)f->f_fsdata; tftpfile = (struct tftp_handle *) f->f_fsdata;
/* let it time out ... */ /* let it time out ... */
if(tftpfile) free(tftpfile, sizeof(*tftpfile)); if (tftpfile)
return(0); free(tftpfile, sizeof(*tftpfile));
return (0);
} }
int tftp_write(f, start, size, resid) int
struct open_file *f; tftp_write(f, start, size, resid)
void *start; struct open_file *f;
size_t size; void *start;
size_t *resid; /* out */ size_t size;
size_t *resid; /* out */
{ {
return(EROFS); return (EROFS);
} }
int tftp_stat(f, sb) int
struct open_file *f; tftp_stat(f, sb)
struct stat *sb; struct open_file *f;
struct stat *sb;
{ {
struct tftp_handle *tftpfile; struct tftp_handle *tftpfile;
tftpfile = (struct tftp_handle*)f->f_fsdata; tftpfile = (struct tftp_handle *) f->f_fsdata;
sb->st_mode = 0444; sb->st_mode = 0444;
sb->st_nlink = 1; sb->st_nlink = 1;
sb->st_uid = 0; sb->st_uid = 0;
sb->st_gid = 0; sb->st_gid = 0;
sb->st_size = -1; sb->st_size = -1;
return(0); return (0);
} }
off_t tftp_seek(f, offset, where) off_t
struct open_file *f; tftp_seek(f, offset, where)
off_t offset; struct open_file *f;
int where; off_t offset;
int where;
{ {
struct tftp_handle *tftpfile; struct tftp_handle *tftpfile;
tftpfile = (struct tftp_handle*)f->f_fsdata; tftpfile = (struct tftp_handle *) f->f_fsdata;
switch (where) { switch (where) {
case SEEK_SET: case SEEK_SET:
tftpfile->off = offset; tftpfile->off = offset;
break; break;
case SEEK_CUR: case SEEK_CUR:
tftpfile->off += offset; tftpfile->off += offset;
break; break;
default: default:
errno = EOFFSET; errno = EOFFSET;
return(-1); return (-1);
} }
return(tftpfile->off); return (tftpfile->off);
} }

View File

@ -1,4 +1,4 @@
/* $NetBSD: dev_net.c,v 1.2 1997/03/20 16:14:22 is Exp $ */ /* $NetBSD: dev_net.c,v 1.3 1997/03/22 09:18:07 thorpej Exp $ */
/* /*
* Copyright (c) 1995 Gordon W. Ross * Copyright (c) 1995 Gordon W. Ross
@ -32,8 +32,8 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
/* network device for libsa /*
supports BOOTP, RARP and BOOTPARAM * network device for libsa supports BOOTP, RARP and BOOTPARAM
*/ */
#include <sys/param.h> #include <sys/param.h>
@ -50,30 +50,30 @@
#include <netif/netif_small.h> #include <netif/netif_small.h>
#ifdef SUPPORT_BOOTP #ifdef SUPPORT_BOOTP
void bootp __P((int)); void bootp __P((int));
#endif #endif
struct in_addr myip; /* init'ed as INADDR_ANY */ struct in_addr myip; /* init'ed as INADDR_ANY */
struct in_addr rootip, gateip, swapip, nameip; struct in_addr rootip, gateip, swapip, nameip;
n_long netmask; n_long netmask;
char rootpath[FNAME_SIZE]; char rootpath[FNAME_SIZE];
char bootfile[FNAME_SIZE]; char bootfile[FNAME_SIZE];
char hostname[FNAME_SIZE]; /* our hostname */ char hostname[FNAME_SIZE]; /* our hostname */
int hostnamelen; int hostnamelen;
#if defined(SUPPORT_BOOTP) || defined (SUPPORT_BOOTPARAM) #if defined(SUPPORT_BOOTP) || defined (SUPPORT_BOOTPARAM)
char domainname[FNAME_SIZE]; /* our DNS domain, not used */ char domainname[FNAME_SIZE]; /* our DNS domain, not used */
int domainnamelen; int domainnamelen;
#endif #endif
u_char bcea[6] = BA; u_char bcea[6] = BA;
static int netdev_sock; static int netdev_sock;
static int open_count; static int open_count;
int no_bootp = 0; int no_bootp = 0;
/* /*
* Called by devopen after it sets f->f_dev to our devsw entry. * Called by devopen after it sets f->f_dev to our devsw entry.
@ -81,114 +81,122 @@ int no_bootp = 0;
*/ */
int int
net_open(f, devname) net_open(f, devname)
struct open_file *f; struct open_file *f;
char *devname; /* Device part of file name (or NULL). */ char *devname;/* Device part of file name (or NULL). */
{ {
int error = 0; int error = 0;
/* On first open, do netif open */ /* On first open, do netif open */
if (open_count == 0) { if (open_count == 0) {
/* Find network interface. */ /* Find network interface. */
if ((netdev_sock = netif_open(devname)) < 0) if ((netdev_sock = netif_open(devname)) < 0)
return (ENXIO); return (ENXIO);
#ifdef SUPPORT_BOOTP #ifdef SUPPORT_BOOTP
if(!no_bootp){ if (!no_bootp) {
printf("configure network...trying bootp\n"); printf("configure network...trying bootp\n");
/* Get boot info using BOOTP way. (RFC951, RFC1048) */ /* Get boot info using BOOTP way. (RFC951, RFC1048) */
bootp(netdev_sock); bootp(netdev_sock);
} }
#endif #endif
if(myip.s_addr != INADDR_ANY){ /* got bootp reply or manually set*/ if (myip.s_addr != INADDR_ANY) { /* got bootp reply or
* manually set */
#ifdef TFTP_HACK #ifdef TFTP_HACK
int num, i; int num, i;
/* XXX (some) tftp servers don't like leading "/" */ /* XXX (some) tftp servers don't like leading "/" */
for(num = 0; bootfile[num] == '/'; num++); for (num = 0; bootfile[num] == '/'; num++);
for(i=0; bootfile[i] = bootfile[i + num]; i++); for (i = 0; bootfile[i] = bootfile[i + num]; i++);
#endif #endif
printf("boot: client IP address: %s\n", inet_ntoa(myip)); printf("boot: client IP address: %s\n",
printf("boot: client name: %s\n", hostname); inet_ntoa(myip));
} else { printf("boot: client name: %s\n", hostname);
} else {
#ifdef SUPPORT_RARP #ifdef SUPPORT_RARP
/* no answer, /*
Get boot info using RARP and Sun bootparams. */ * no answer, Get boot info using RARP and Sun
printf("configure network...trying rarp\n"); * bootparams.
*/
printf("configure network...trying rarp\n");
/* Get our IP address. (rarp.c) */ /* Get our IP address. (rarp.c) */
if (rarp_getipaddress(netdev_sock)){ if (rarp_getipaddress(netdev_sock)) {
error=EIO; error = EIO;
goto bad; goto bad;
} }
printf("boot: client IP address: %s\n", inet_ntoa(myip)); printf("boot: client IP address: %s\n",
inet_ntoa(myip));
#ifdef SUPPORT_BOOTPARAM #ifdef SUPPORT_BOOTPARAM
/* Get our hostname, server IP address. */ /* Get our hostname, server IP address. */
if (!bp_whoami(netdev_sock)){ if (!bp_whoami(netdev_sock)) {
printf("boot: client name: %s\n", hostname); printf("boot: client name: %s\n", hostname);
/* Get the root pathname. */ /* Get the root pathname. */
bp_getfile(netdev_sock, "root", &rootip, rootpath); bp_getfile(netdev_sock, "root", &rootip,
} rootpath);
}
#else #else
/* else /*
fallback: use rarp server address */ * else fallback: use rarp server address
*/
#endif #endif
#else /* no SUPPORT_RARP */ #else /* no SUPPORT_RARP */
error=EIO; error = EIO;
goto bad; goto bad;
#endif #endif
} }
printf("boot: server: %s, rootpath: %s, bootfile: %s\n", printf("boot: server: %s, rootpath: %s, bootfile: %s\n",
inet_ntoa(rootip), rootpath, bootfile); inet_ntoa(rootip), rootpath, bootfile);
} }
open_count++; open_count++;
f->f_devdata = &netdev_sock; f->f_devdata = &netdev_sock;
return (error); return (error);
bad: bad:
printf("net_open failed\n"); printf("net_open failed\n");
netif_close(netdev_sock); netif_close(netdev_sock);
return(error); return (error);
} }
int int
net_close(f) net_close(f)
struct open_file *f; struct open_file *f;
{ {
/* On last close, do netif close, etc. */ /* On last close, do netif close, etc. */
if (--open_count == 0) if (--open_count == 0)
netif_close(netdev_sock); netif_close(netdev_sock);
#ifdef DEBUG #ifdef DEBUG
if(open_count < 0) panic("net_close"); if (open_count < 0)
panic("net_close");
#endif #endif
f->f_devdata = NULL; f->f_devdata = NULL;
return(0); return (0);
} }
int int
net_ioctl(f, c, d) net_ioctl(f, c, d)
struct open_file *f; struct open_file *f;
u_long c; u_long c;
void *d; void *d;
{ {
return EIO; return EIO;
} }
int int
net_strategy(d, f, b, s, buf, r) net_strategy(d, f, b, s, buf, r)
void *d; void *d;
int f; int f;
daddr_t b; daddr_t b;
size_t s; size_t s;
void *buf; void *buf;
size_t *r; size_t *r;
{ {
return EIO; return EIO;
} }

View File

@ -1,4 +1,4 @@
/* $NetBSD: devopen.c,v 1.1.1.1 1997/03/14 02:40:31 perry Exp $ */ /* $NetBSD: devopen.c,v 1.2 1997/03/22 09:18:10 thorpej Exp $ */
/* /*
* Copyright (c) 1996 * Copyright (c) 1996
@ -32,8 +32,8 @@
* *
*/ */
/* bootfile from tftp overrides! /*
TODO: pass (net) device to net_open * bootfile from tftp overrides! TODO: pass (net) device to net_open
*/ */
#include <sys/param.h> #include <sys/param.h>
@ -41,26 +41,26 @@
#include <netinet/in_systm.h> #include <netinet/in_systm.h>
#include <lib/libsa/stand.h> #include <lib/libsa/stand.h>
#include <lib/libsa/net.h> /* global "bootfile" */ #include <lib/libsa/net.h> /* global "bootfile" */
int int
devopen(f, fname, file) devopen(f, fname, file)
struct open_file *f; struct open_file *f;
const char *fname; const char *fname;
char **file; char **file;
{ {
struct devsw *dp; struct devsw *dp;
int error=0; int error = 0;
dp = &devsw[0]; dp = &devsw[0];
f->f_dev = dp; f->f_dev = dp;
error = (*dp->dv_open)(f, 0); error = (*dp->dv_open) (f, 0);
if(bootfile[0]) if (bootfile[0])
*file = bootfile; *file = bootfile;
else else
*file = (char*)fname; *file = (char *) fname;
return (error); return (error);
} }

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.1.1.1 1997/03/14 02:40:31 perry Exp $ */ /* $NetBSD: main.c,v 1.2 1997/03/22 09:18:12 thorpej Exp $ */
/* /*
* Copyright (c) 1996 * Copyright (c) 1996
@ -43,16 +43,16 @@
#include <libi386.h> #include <libi386.h>
extern char *strerror __P((int)); /* XXX missing in stand.h */ extern char *strerror __P((int)); /* XXX missing in stand.h */
int errno; int errno;
static char *consdev; static char *consdev;
extern char version[]; extern char version[];
extern char etherdev[]; extern char etherdev[];
#ifdef SUPPORT_NFS /* XXX */ #ifdef SUPPORT_NFS /* XXX */
int debug = 0; int debug = 0;
#endif #endif
#define TIMEOUT 5 #define TIMEOUT 5
@ -63,219 +63,222 @@ int debug = 0;
#ifdef COMPAT_OLDBOOT #ifdef COMPAT_OLDBOOT
int int
parsebootfile(fname, fsname, devname, unit, partition, file) parsebootfile(fname, fsname, devname, unit, partition, file)
const char *fname; const char *fname;
char **fsname; /* out */ char **fsname; /* out */
char **devname; /* out */ char **devname;/* out */
unsigned int *unit, *partition; /* out */ unsigned int *unit, *partition; /* out */
const char **file; /* out */ const char **file; /* out */
{ {
return(EINVAL); return (EINVAL);
} }
int biosdisk_gettype(f) int
struct open_file *f; biosdisk_gettype(f)
struct open_file *f;
{ {
return(0); return (0);
} }
#endif #endif
int bootit(filename, howto) int
const char *filename; bootit(filename, howto)
int howto; const char *filename;
int howto;
{ {
if(exec_netbsd(filename, 0, howto, etherdev, "pc") < 0) if (exec_netbsd(filename, 0, howto, etherdev, "pc") < 0)
printf("boot: %s\n", strerror(errno)); printf("boot: %s\n", strerror(errno));
else else
printf("boot returned\n"); printf("boot returned\n");
return(-1); return (-1);
} }
static void helpme() static void
helpme()
{ {
printf("commands are:\n" printf("commands are:\n"
"boot [filename] [-adrs]\n" "boot [filename] [-adrs]\n"
" (ex. \"netbsd.old -s\"\n" " (ex. \"netbsd.old -s\"\n"
"help|?\n" "help|?\n"
"quit\n"); "quit\n");
} }
/* /*
* chops the head from the arguments and returns the arguments if any, * chops the head from the arguments and returns the arguments if any,
* or possibly an empty string. * or possibly an empty string.
*/ */
static char * static char *
gettrailer(arg) gettrailer(arg)
char *arg; char *arg;
{ {
char *options; char *options;
if ((options = strchr(arg, ' ')) == NULL) if ((options = strchr(arg, ' ')) == NULL)
options = ""; options = "";
else else
*options++ = '\0'; *options++ = '\0';
/* trim leading blanks */ /* trim leading blanks */
while (*options && *options == ' ') while (*options && *options == ' ')
options++; options++;
return(options); return (options);
} }
static int static int
parseopts(opts, howto) parseopts(opts, howto)
char *opts; char *opts;
int *howto; int *howto;
{ {
int tmpopt = 0; int tmpopt = 0;
opts++; /* skip - */ opts++; /* skip - */
while (*opts && *opts != ' ') { while (*opts && *opts != ' ') {
tmpopt |= netbsd_opt(*opts); tmpopt |= netbsd_opt(*opts);
if(tmpopt == -1) { if (tmpopt == -1) {
printf("-%c: unknown flag\n", *opts); printf("-%c: unknown flag\n", *opts);
helpme(); helpme();
return(0); return (0);
} }
opts++; opts++;
} }
*howto = tmpopt; *howto = tmpopt;
return(1); return (1);
} }
static int static int
parseboot(arg, filename, howto) parseboot(arg, filename, howto)
char *arg; char *arg;
char **filename; char **filename;
int *howto; int *howto;
{ {
char *opts = NULL; char *opts = NULL;
*filename = 0; *filename = 0;
*howto = 0; *howto = 0;
/* if there were no arguments */ /* if there were no arguments */
if (!*arg) if (!*arg)
return(1); return (1);
/* format is... */ /* format is... */
/*[[xxNx:]filename] [-adrs]*/ /* [[xxNx:]filename] [-adrs] */
/* check for just args */ /* check for just args */
if (arg[0] == '-'){ if (arg[0] == '-') {
opts = arg; opts = arg;
} else { /* at least a file name */ } else { /* at least a file name */
*filename = arg; *filename = arg;
opts = gettrailer(arg); opts = gettrailer(arg);
if (!*opts) if (!*opts)
opts = NULL; opts = NULL;
else if (*opts != '-') { else if (*opts != '-') {
printf("invalid arguments\n"); printf("invalid arguments\n");
helpme(); helpme();
return(0); return (0);
} }
} }
/* at this point, we have dealt with filenames. */ /* at this point, we have dealt with filenames. */
/* now, deal with options */ /* now, deal with options */
if (opts) { if (opts) {
if (!parseopts(opts, howto)) if (!parseopts(opts, howto))
return(0); return (0);
} }
return (1);
return(1);
} }
static void static void
docommand(arg) docommand(arg)
char *arg; char *arg;
{ {
char *options; char *options;
options = gettrailer(arg); options = gettrailer(arg);
if ((strcmp("help", arg) == 0) || if ((strcmp("help", arg) == 0) ||
(strcmp("?", arg) == 0)) { (strcmp("?", arg) == 0)) {
helpme(); helpme();
return; return;
} }
if (strcmp("quit", arg) == 0){ if (strcmp("quit", arg) == 0) {
printf("Exiting... goodbye...\n"); printf("Exiting... goodbye...\n");
exit(0); exit(0);
} }
if (strcmp("boot", arg) == 0){ if (strcmp("boot", arg) == 0) {
char *filename; char *filename;
int howto; int howto;
if(parseboot(options, &filename, &howto)) if (parseboot(options, &filename, &howto))
bootit(filename, howto); bootit(filename, howto);
return; return;
} }
printf("unknown command\n"); printf("unknown command\n");
helpme(); helpme();
} }
void bootmenu() void
bootmenu()
{ {
printf("\ntype \"?\" or \"help\" for help.\n"); printf("\ntype \"?\" or \"help\" for help.\n");
for(;;) { for (;;) {
char input[80]; char input[80];
input[0] = '\0'; input[0] = '\0';
printf("> "); printf("> ");
gets(input); gets(input);
docommand(input); docommand(input);
} }
} }
static int static int
awaitkey(void) awaitkey(void)
{ {
int i; int i;
i = TIMEOUT * POLL_FREQ; i = TIMEOUT * POLL_FREQ;
while (i--) { while (i--) {
if(iskey()) { if (iskey()) {
/* flush input buffer */ /* flush input buffer */
while(iskey()) while (iskey())
getchar(); getchar();
return(1); return (1);
} }
delay(1000000 / POLL_FREQ); delay(1000000 / POLL_FREQ);
if (!(i % POLL_FREQ)) if (!(i % POLL_FREQ))
printf("%d\b", i/POLL_FREQ); printf("%d\b", i / POLL_FREQ);
} }
printf("0\n"); printf("0\n");
return(0); return (0);
} }
static void static void
print_banner(void) print_banner(void)
{ {
printf("\n" printf("\n"
">> NetBSD BOOT: %d/%d k [%s]\n", ">> NetBSD BOOT: %d/%d k [%s]\n",
getbasemem(), getbasemem(),
getextmem(), getextmem(),
version); version);
} }
int int
main() main()
{ {
consdev = initio(CONSDEV_AUTO); consdev = initio(CONSDEV_AUTO);
gateA20(); gateA20();
print_banner(); print_banner();
printf("press any key for boot menu\n" printf("press any key for boot menu\n"
"starting in %d\b", TIMEOUT); "starting in %d\b", TIMEOUT);
if(awaitkey()) if (awaitkey())
bootmenu(); /* does not return */ bootmenu(); /* does not return */
bootit("netbsd", 0); bootit("netbsd", 0);
/* if that fails, let BIOS look for boot device */ /* if that fails, let BIOS look for boot device */
return(1); return (1);
} }