Purely cosmetic whitespace/indentation changes (mmm, indent(1))
This commit is contained in:
parent
e321bba79a
commit
edad9d2e05
@ -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
|
||||
@ -42,77 +42,81 @@
|
||||
|
||||
#include "stand.h"
|
||||
|
||||
extern char *strerror __P((int)); /* XXX for now */
|
||||
extern char *strerror __P((int)); /* XXX for now */
|
||||
|
||||
static char *typestr[] = {
|
||||
"unknown",
|
||||
"FIFO",
|
||||
"CHR",
|
||||
0,
|
||||
"DIR",
|
||||
0,
|
||||
"BLK",
|
||||
0,
|
||||
"REG",
|
||||
0,
|
||||
"LNK",
|
||||
0,
|
||||
"SOCK",
|
||||
0,
|
||||
"WHT"
|
||||
static char *typestr[] = {
|
||||
"unknown",
|
||||
"FIFO",
|
||||
"CHR",
|
||||
0,
|
||||
"DIR",
|
||||
0,
|
||||
"BLK",
|
||||
0,
|
||||
"REG",
|
||||
0,
|
||||
"LNK",
|
||||
0,
|
||||
"SOCK",
|
||||
0,
|
||||
"WHT"
|
||||
};
|
||||
|
||||
void ls(path)
|
||||
char *path;
|
||||
void
|
||||
ls(path)
|
||||
char *path;
|
||||
{
|
||||
int fd;
|
||||
struct stat sb;
|
||||
size_t size;
|
||||
char dirbuf[DIRBLKSIZ];
|
||||
int fd;
|
||||
struct stat sb;
|
||||
size_t size;
|
||||
char dirbuf[DIRBLKSIZ];
|
||||
|
||||
fd = open(path, 0);
|
||||
if(fd < 0) {
|
||||
printf("ls: %s\n", strerror(errno));
|
||||
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;
|
||||
fd = open(path, 0);
|
||||
if (fd < 0) {
|
||||
printf("ls: %s\n", strerror(errno));
|
||||
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;
|
||||
|
||||
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:
|
||||
close(fd);
|
||||
close(fd);
|
||||
}
|
||||
|
@ -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
|
||||
@ -29,16 +29,13 @@
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
/* Makes the (filesystem dependant) mount
|
||||
part of open. Necessary for interoperation with
|
||||
tftp filesystem on same net device layer.
|
||||
Assumes:
|
||||
- socket descriptor (int) at open_file->f_devdata
|
||||
- server host IP in global rootip
|
||||
- path to mount in globel rootpath
|
||||
/*
|
||||
* Makes the (filesystem dependant) mount part of open. Necessary for
|
||||
* interoperation with tftp filesystem on same net device layer. Assumes: -
|
||||
* socket descriptor (int) at open_file->f_devdata - server host IP in global
|
||||
* rootip - path to mount in globel rootpath
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
@ -51,22 +48,22 @@
|
||||
|
||||
#include "nfswrapper.h"
|
||||
|
||||
int nfs_mountandopen(path, f)
|
||||
char *path;
|
||||
struct open_file *f;
|
||||
int
|
||||
nfs_mountandopen(path, f)
|
||||
char *path;
|
||||
struct open_file *f;
|
||||
{
|
||||
int sock;
|
||||
int sock;
|
||||
|
||||
if(!rootpath[0]){
|
||||
printf("no rootpath, no nfs\n");
|
||||
return(ENXIO);
|
||||
}
|
||||
if (!rootpath[0]) {
|
||||
printf("no rootpath, no nfs\n");
|
||||
return (ENXIO);
|
||||
}
|
||||
sock = *(int *) (f->f_devdata);
|
||||
|
||||
sock= *(int*)(f->f_devdata);
|
||||
|
||||
if(nfs_mount(sock , rootip, rootpath)){
|
||||
printf("mount failed\n");
|
||||
return(ENXIO);
|
||||
}
|
||||
return(nfs_open(path, f));
|
||||
if (nfs_mount(sock, rootip, rootpath)) {
|
||||
printf("mount failed\n");
|
||||
return (ENXIO);
|
||||
}
|
||||
return (nfs_open(path, f));
|
||||
}
|
||||
|
@ -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
|
||||
@ -32,14 +32,11 @@
|
||||
*
|
||||
*/
|
||||
|
||||
/* Simple TFTP implementation for libsa.
|
||||
Assumes:
|
||||
- socket descriptor (int) at open_file->f_devdata
|
||||
- server host IP in global rootip
|
||||
Restrictions:
|
||||
- read only
|
||||
- lseek only with SEEK_SET or SEEK_CUR
|
||||
- no big time differences between transfers (<tftp timeout)
|
||||
/*
|
||||
* Simple TFTP implementation for libsa. Assumes: - socket descriptor (int)
|
||||
* at open_file->f_devdata - server host IP in global rootip Restrictions: -
|
||||
* read only - lseek only with SEEK_SET or SEEK_CUR - no big time differences
|
||||
* between transfers (<tftp timeout)
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
@ -55,305 +52,331 @@
|
||||
|
||||
#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 iodesc *iodesc;
|
||||
int currblock; /* contents of lastdata */
|
||||
int islastblock; /* flag */
|
||||
int validsize;
|
||||
int off;
|
||||
char *path; /* saved for re-requests */
|
||||
struct{
|
||||
u_char header[HEADER_SIZE];
|
||||
struct tftphdr t;
|
||||
u_char space[RSPACE];
|
||||
}lastdata;
|
||||
struct tftp_handle {
|
||||
struct iodesc *iodesc;
|
||||
int currblock; /* contents of lastdata */
|
||||
int islastblock; /* flag */
|
||||
int validsize;
|
||||
int off;
|
||||
char *path; /* saved for re-requests */
|
||||
struct {
|
||||
u_char header[HEADER_SIZE];
|
||||
struct tftphdr t;
|
||||
u_char space[RSPACE];
|
||||
} lastdata;
|
||||
};
|
||||
|
||||
static int tftperrors[8] = {
|
||||
0, /* ??? */
|
||||
ENOENT,
|
||||
EPERM,
|
||||
ENOSPC,
|
||||
EINVAL, /* ??? */
|
||||
EINVAL, /* ??? */
|
||||
EEXIST,
|
||||
EINVAL /* ??? */
|
||||
0, /* ??? */
|
||||
ENOENT,
|
||||
EPERM,
|
||||
ENOSPC,
|
||||
EINVAL, /* ??? */
|
||||
EINVAL, /* ??? */
|
||||
EEXIST,
|
||||
EINVAL /* ??? */
|
||||
};
|
||||
|
||||
static ssize_t recvtftp(d, pkt, len, tleft)
|
||||
register struct iodesc *d;
|
||||
register void *pkt;
|
||||
register ssize_t len;
|
||||
time_t tleft;
|
||||
static ssize_t
|
||||
recvtftp(d, pkt, len, tleft)
|
||||
register struct iodesc *d;
|
||||
register void *pkt;
|
||||
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;
|
||||
switch(ntohs(t->th_opcode)) {
|
||||
case DATA: {
|
||||
int got;
|
||||
if(htons(t->th_block) != d->xid) { /* expected block? */
|
||||
return(-1);
|
||||
}
|
||||
if(d->xid == 1){ /* first data packet, from new port */
|
||||
register struct udphdr *uh;
|
||||
uh = (struct udphdr*)pkt - 1;
|
||||
d->destport = htons(uh->uh_sport); /* XXXXXX in net.c geswappt! */
|
||||
} /* else check uh_sport has not changed??? */
|
||||
got = len - (t->th_data - (char*)t);
|
||||
return got;
|
||||
}
|
||||
case ERROR:
|
||||
if((unsigned)ntohs(t->th_code) >= 8) {
|
||||
printf("illegal tftp error %d\n", ntohs(t->th_code));
|
||||
errno = EIO;
|
||||
} else {
|
||||
#ifdef DEBUG
|
||||
printf("tftp-error %d\n", ntohs(t->th_code));
|
||||
#endif
|
||||
errno = tftperrors[ntohs(t->th_code)];
|
||||
t = (struct tftphdr *) pkt;
|
||||
switch (ntohs(t->th_opcode)) {
|
||||
case DATA: {
|
||||
int got;
|
||||
|
||||
if (htons(t->th_block) != d->xid) {
|
||||
/*
|
||||
* Expected block?
|
||||
*/
|
||||
return (-1);
|
||||
}
|
||||
if (d->xid == 1) {
|
||||
/*
|
||||
* First data packet from new port.
|
||||
*/
|
||||
register struct udphdr *uh;
|
||||
uh = (struct udphdr *) pkt - 1;
|
||||
/* XXX in net.c - geswappt! */
|
||||
d->destport = htons(uh->uh_sport);
|
||||
} /* else check uh_sport has not changed??? */
|
||||
got = len - (t->th_data - (char *) t);
|
||||
return got;
|
||||
}
|
||||
return(-1);
|
||||
default:
|
||||
case ERROR:
|
||||
if ((unsigned) ntohs(t->th_code) >= 8) {
|
||||
printf("illegal tftp error %d\n", ntohs(t->th_code));
|
||||
errno = EIO;
|
||||
} else {
|
||||
#ifdef DEBUG
|
||||
printf("tftp type %d not handled\n", ntohs(t->th_opcode));
|
||||
printf("tftp-error %d\n", ntohs(t->th_code));
|
||||
#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) */
|
||||
static int tftp_makereq(h)
|
||||
struct tftp_handle *h;
|
||||
static int
|
||||
tftp_makereq(h)
|
||||
struct tftp_handle *h;
|
||||
{
|
||||
struct{
|
||||
u_char header[HEADER_SIZE];
|
||||
struct tftphdr t;
|
||||
u_char space[FNAME_SIZE+6];
|
||||
}wbuf;
|
||||
char *wtail;
|
||||
int l;
|
||||
ssize_t res;
|
||||
struct tftphdr *t;
|
||||
struct {
|
||||
u_char header[HEADER_SIZE];
|
||||
struct tftphdr t;
|
||||
u_char space[FNAME_SIZE + 6];
|
||||
} wbuf;
|
||||
char *wtail;
|
||||
int l;
|
||||
ssize_t res;
|
||||
struct tftphdr *t;
|
||||
|
||||
wbuf.t.th_opcode = htons((u_short)RRQ);
|
||||
wtail = wbuf.t.th_stuff;
|
||||
l = strlen(h->path);
|
||||
bcopy(h->path,wtail, l + 1);
|
||||
wtail += l + 1;
|
||||
bcopy("octet", wtail, 6);
|
||||
wtail += 6;
|
||||
wbuf.t.th_opcode = htons((u_short) RRQ);
|
||||
wtail = wbuf.t.th_stuff;
|
||||
l = strlen(h->path);
|
||||
bcopy(h->path, wtail, l + 1);
|
||||
wtail += l + 1;
|
||||
bcopy("octet", wtail, 6);
|
||||
wtail += 6;
|
||||
|
||||
t= &h->lastdata.t;
|
||||
t = &h->lastdata.t;
|
||||
|
||||
/* h->iodesc->myport = htons(--tftpport); */
|
||||
h->iodesc->myport = htons(tftpport + (getsecs() & 0x3ff));
|
||||
h->iodesc->destport = htons(IPPORT_TFTP);
|
||||
h->iodesc->xid = 1; /* expected block */
|
||||
/* h->iodesc->myport = htons(--tftpport); */
|
||||
h->iodesc->myport = htons(tftpport + (getsecs() & 0x3ff));
|
||||
h->iodesc->destport = htons(IPPORT_TFTP);
|
||||
h->iodesc->xid = 1; /* expected block */
|
||||
|
||||
res = sendrecv(h->iodesc, sendudp, &wbuf.t, wtail-(char*)&wbuf.t,
|
||||
recvtftp, t, sizeof(*t) + RSPACE);
|
||||
res = sendrecv(h->iodesc, sendudp, &wbuf.t, wtail - (char *) &wbuf.t,
|
||||
recvtftp, t, sizeof(*t) + RSPACE);
|
||||
|
||||
if(res == -1)
|
||||
return(errno);
|
||||
if (res == -1)
|
||||
return (errno);
|
||||
|
||||
h->currblock = 1;
|
||||
h->validsize = res;
|
||||
h->islastblock = 0;
|
||||
if(res < SEGSIZE) h->islastblock = 1; /* very short file */
|
||||
return(0);
|
||||
h->currblock = 1;
|
||||
h->validsize = res;
|
||||
h->islastblock = 0;
|
||||
if (res < SEGSIZE)
|
||||
h->islastblock = 1; /* very short file */
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* ack block, expect next */
|
||||
static int tftp_getnextblock(h)
|
||||
struct tftp_handle *h;
|
||||
static int
|
||||
tftp_getnextblock(h)
|
||||
struct tftp_handle *h;
|
||||
{
|
||||
struct{
|
||||
u_char header[HEADER_SIZE];
|
||||
struct tftphdr t;
|
||||
}wbuf;
|
||||
char *wtail;
|
||||
int res;
|
||||
struct tftphdr *t;
|
||||
struct {
|
||||
u_char header[HEADER_SIZE];
|
||||
struct tftphdr t;
|
||||
} wbuf;
|
||||
char *wtail;
|
||||
int res;
|
||||
struct tftphdr *t;
|
||||
|
||||
wbuf.t.th_opcode = htons((u_short)ACK);
|
||||
wtail = (char*)&wbuf.t.th_block;
|
||||
wbuf.t.th_block = htons((u_short)h->currblock);
|
||||
wtail += 2;
|
||||
wbuf.t.th_opcode = htons((u_short) ACK);
|
||||
wtail = (char *) &wbuf.t.th_block;
|
||||
wbuf.t.th_block = htons((u_short) h->currblock);
|
||||
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,
|
||||
recvtftp, t, sizeof(*t) + RSPACE);
|
||||
res = sendrecv(h->iodesc, sendudp, &wbuf.t, wtail - (char *) &wbuf.t,
|
||||
recvtftp, t, sizeof(*t) + RSPACE);
|
||||
|
||||
if(res == -1) /* 0 is OK! */
|
||||
return(errno);
|
||||
if (res == -1) /* 0 is OK! */
|
||||
return (errno);
|
||||
|
||||
h->currblock++;
|
||||
h->validsize = res;
|
||||
if(res < SEGSIZE) h->islastblock = 1; /* EOF */
|
||||
return(0);
|
||||
h->currblock++;
|
||||
h->validsize = res;
|
||||
if (res < SEGSIZE)
|
||||
h->islastblock = 1; /* EOF */
|
||||
return (0);
|
||||
}
|
||||
|
||||
int tftp_open(path, f)
|
||||
char *path;
|
||||
struct open_file *f;
|
||||
int
|
||||
tftp_open(path, f)
|
||||
char *path;
|
||||
struct open_file *f;
|
||||
{
|
||||
struct tftp_handle *tftpfile;
|
||||
struct iodesc *io;
|
||||
int res;
|
||||
struct tftp_handle *tftpfile;
|
||||
struct iodesc *io;
|
||||
int res;
|
||||
|
||||
tftpfile = (struct tftp_handle*)alloc(sizeof(*tftpfile));
|
||||
if(!tftpfile) return(ENOMEM);
|
||||
tftpfile = (struct tftp_handle *) alloc(sizeof(*tftpfile));
|
||||
if (!tftpfile)
|
||||
return (ENOMEM);
|
||||
|
||||
tftpfile->iodesc = io = socktodesc(*(int*)(f->f_devdata));
|
||||
io->destip = rootip;
|
||||
tftpfile->off = 0;
|
||||
tftpfile->path = path; /* XXXXXXX we hope it's static */
|
||||
tftpfile->iodesc = io = socktodesc(*(int *) (f->f_devdata));
|
||||
io->destip = rootip;
|
||||
tftpfile->off = 0;
|
||||
tftpfile->path = path; /* XXXXXXX we hope it's static */
|
||||
|
||||
res = tftp_makereq(tftpfile, path);
|
||||
res = tftp_makereq(tftpfile, path);
|
||||
|
||||
if(res) {
|
||||
free(tftpfile, sizeof(*tftpfile));
|
||||
return(res);
|
||||
}
|
||||
|
||||
f->f_fsdata = (void*)tftpfile;
|
||||
return(0);
|
||||
if (res) {
|
||||
free(tftpfile, sizeof(*tftpfile));
|
||||
return (res);
|
||||
}
|
||||
f->f_fsdata = (void *) tftpfile;
|
||||
return (0);
|
||||
}
|
||||
|
||||
int tftp_read(f, addr, size, resid)
|
||||
struct open_file *f;
|
||||
void *addr;
|
||||
size_t size;
|
||||
size_t *resid; /* out */
|
||||
int
|
||||
tftp_read(f, addr, size, resid)
|
||||
struct open_file *f;
|
||||
void *addr;
|
||||
size_t size;
|
||||
size_t *resid; /* out */
|
||||
{
|
||||
struct tftp_handle *tftpfile;
|
||||
static int tc = 0;
|
||||
tftpfile = (struct tftp_handle*)f->f_fsdata;
|
||||
struct tftp_handle *tftpfile;
|
||||
static int tc = 0;
|
||||
tftpfile = (struct tftp_handle *) f->f_fsdata;
|
||||
|
||||
while(size > 0){
|
||||
int needblock, count;
|
||||
while (size > 0) {
|
||||
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 */
|
||||
tftp_makereq(tftpfile); /* no error check, it worked for open */
|
||||
if (tftpfile->currblock > needblock) /* seek backwards */
|
||||
tftp_makereq(tftpfile); /* no error check, it worked
|
||||
* for open */
|
||||
|
||||
while(tftpfile->currblock < needblock){
|
||||
int res;
|
||||
while (tftpfile->currblock < needblock) {
|
||||
int res;
|
||||
|
||||
res = tftp_getnextblock(tftpfile);
|
||||
if(res){ /* no answer */
|
||||
res = tftp_getnextblock(tftpfile);
|
||||
if (res) { /* no answer */
|
||||
#ifdef DEBUG
|
||||
printf("tftp: read error\n");
|
||||
printf("tftp: read error\n");
|
||||
#endif
|
||||
return(res);
|
||||
}
|
||||
if(tftpfile->islastblock) break;
|
||||
}
|
||||
return (res);
|
||||
}
|
||||
if (tftpfile->islastblock)
|
||||
break;
|
||||
}
|
||||
|
||||
if(tftpfile->currblock == needblock){
|
||||
int offinblock, inbuffer;
|
||||
if (tftpfile->currblock == needblock) {
|
||||
int offinblock, inbuffer;
|
||||
|
||||
offinblock = tftpfile->off % SEGSIZE;
|
||||
offinblock = tftpfile->off % SEGSIZE;
|
||||
|
||||
inbuffer = tftpfile->validsize - offinblock;
|
||||
if(inbuffer < 0){
|
||||
inbuffer = tftpfile->validsize - offinblock;
|
||||
if (inbuffer < 0) {
|
||||
#ifdef DEBUG
|
||||
printf("tftp: invalid offset %d\n", tftpfile->off);
|
||||
printf("tftp: invalid offset %d\n",
|
||||
tftpfile->off);
|
||||
#endif
|
||||
return(EINVAL);
|
||||
}
|
||||
return (EINVAL);
|
||||
}
|
||||
count = (size < inbuffer ? size : inbuffer);
|
||||
bcopy(tftpfile->lastdata.t.th_data + offinblock,
|
||||
addr, count);
|
||||
|
||||
count = (size < inbuffer ? size : inbuffer);
|
||||
bcopy(tftpfile->lastdata.t.th_data + offinblock, addr, count);
|
||||
addr += count;
|
||||
tftpfile->off += count;
|
||||
size -= count;
|
||||
|
||||
addr += count;
|
||||
tftpfile->off += count;
|
||||
size -= count;
|
||||
|
||||
if((tftpfile->islastblock) && (count == inbuffer)) break; /* EOF */
|
||||
} else {
|
||||
if ((tftpfile->islastblock) && (count == inbuffer))
|
||||
break; /* EOF */
|
||||
} else {
|
||||
#ifdef DEBUG
|
||||
printf("tftp: block %d not found\n", needblock);
|
||||
printf("tftp: block %d not found\n", needblock);
|
||||
#endif
|
||||
return(EINVAL);
|
||||
}
|
||||
return (EINVAL);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if(resid)
|
||||
*resid = size;
|
||||
return(0);
|
||||
if (resid)
|
||||
*resid = size;
|
||||
return (0);
|
||||
}
|
||||
|
||||
int tftp_close(f)
|
||||
struct open_file *f;
|
||||
int
|
||||
tftp_close(f)
|
||||
struct open_file *f;
|
||||
{
|
||||
struct tftp_handle *tftpfile;
|
||||
tftpfile = (struct tftp_handle*)f->f_fsdata;
|
||||
struct tftp_handle *tftpfile;
|
||||
tftpfile = (struct tftp_handle *) f->f_fsdata;
|
||||
|
||||
/* let it time out ... */
|
||||
/* let it time out ... */
|
||||
|
||||
if(tftpfile) free(tftpfile, sizeof(*tftpfile));
|
||||
return(0);
|
||||
if (tftpfile)
|
||||
free(tftpfile, sizeof(*tftpfile));
|
||||
return (0);
|
||||
}
|
||||
|
||||
int tftp_write(f, start, size, resid)
|
||||
struct open_file *f;
|
||||
void *start;
|
||||
size_t size;
|
||||
size_t *resid; /* out */
|
||||
int
|
||||
tftp_write(f, start, size, resid)
|
||||
struct open_file *f;
|
||||
void *start;
|
||||
size_t size;
|
||||
size_t *resid; /* out */
|
||||
{
|
||||
return(EROFS);
|
||||
return (EROFS);
|
||||
}
|
||||
|
||||
int tftp_stat(f, sb)
|
||||
struct open_file *f;
|
||||
struct stat *sb;
|
||||
int
|
||||
tftp_stat(f, sb)
|
||||
struct open_file *f;
|
||||
struct stat *sb;
|
||||
{
|
||||
struct tftp_handle *tftpfile;
|
||||
tftpfile = (struct tftp_handle*)f->f_fsdata;
|
||||
struct tftp_handle *tftpfile;
|
||||
tftpfile = (struct tftp_handle *) f->f_fsdata;
|
||||
|
||||
sb->st_mode = 0444;
|
||||
sb->st_nlink = 1;
|
||||
sb->st_uid = 0;
|
||||
sb->st_gid = 0;
|
||||
sb->st_size = -1;
|
||||
return(0);
|
||||
sb->st_mode = 0444;
|
||||
sb->st_nlink = 1;
|
||||
sb->st_uid = 0;
|
||||
sb->st_gid = 0;
|
||||
sb->st_size = -1;
|
||||
return (0);
|
||||
}
|
||||
|
||||
off_t tftp_seek(f, offset, where)
|
||||
struct open_file *f;
|
||||
off_t offset;
|
||||
int where;
|
||||
off_t
|
||||
tftp_seek(f, offset, where)
|
||||
struct open_file *f;
|
||||
off_t offset;
|
||||
int where;
|
||||
{
|
||||
struct tftp_handle *tftpfile;
|
||||
tftpfile = (struct tftp_handle*)f->f_fsdata;
|
||||
struct tftp_handle *tftpfile;
|
||||
tftpfile = (struct tftp_handle *) f->f_fsdata;
|
||||
|
||||
switch (where) {
|
||||
case SEEK_SET:
|
||||
tftpfile->off = offset;
|
||||
break;
|
||||
case SEEK_CUR:
|
||||
tftpfile->off += offset;
|
||||
break;
|
||||
default:
|
||||
errno = EOFFSET;
|
||||
return(-1);
|
||||
}
|
||||
return(tftpfile->off);
|
||||
switch (where) {
|
||||
case SEEK_SET:
|
||||
tftpfile->off = offset;
|
||||
break;
|
||||
case SEEK_CUR:
|
||||
tftpfile->off += offset;
|
||||
break;
|
||||
default:
|
||||
errno = EOFFSET;
|
||||
return (-1);
|
||||
}
|
||||
return (tftpfile->off);
|
||||
}
|
||||
|
@ -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
|
||||
@ -32,8 +32,8 @@
|
||||
* 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>
|
||||
@ -50,30 +50,30 @@
|
||||
#include <netif/netif_small.h>
|
||||
|
||||
#ifdef SUPPORT_BOOTP
|
||||
void bootp __P((int));
|
||||
void bootp __P((int));
|
||||
#endif
|
||||
|
||||
struct in_addr myip; /* init'ed as INADDR_ANY */
|
||||
struct in_addr rootip, gateip, swapip, nameip;
|
||||
n_long netmask;
|
||||
struct in_addr myip; /* init'ed as INADDR_ANY */
|
||||
struct in_addr rootip, gateip, swapip, nameip;
|
||||
n_long netmask;
|
||||
|
||||
char rootpath[FNAME_SIZE];
|
||||
char bootfile[FNAME_SIZE];
|
||||
char rootpath[FNAME_SIZE];
|
||||
char bootfile[FNAME_SIZE];
|
||||
|
||||
char hostname[FNAME_SIZE]; /* our hostname */
|
||||
char hostname[FNAME_SIZE]; /* our hostname */
|
||||
int hostnamelen;
|
||||
|
||||
#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;
|
||||
#endif
|
||||
|
||||
u_char bcea[6] = BA;
|
||||
u_char bcea[6] = BA;
|
||||
|
||||
static int netdev_sock;
|
||||
static int open_count;
|
||||
static int netdev_sock;
|
||||
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.
|
||||
@ -81,114 +81,122 @@ int no_bootp = 0;
|
||||
*/
|
||||
int
|
||||
net_open(f, devname)
|
||||
struct open_file *f;
|
||||
char *devname; /* Device part of file name (or NULL). */
|
||||
struct open_file *f;
|
||||
char *devname;/* Device part of file name (or NULL). */
|
||||
{
|
||||
int error = 0;
|
||||
/* On first open, do netif open */
|
||||
if (open_count == 0) {
|
||||
int error = 0;
|
||||
/* On first open, do netif open */
|
||||
if (open_count == 0) {
|
||||
|
||||
/* Find network interface. */
|
||||
if ((netdev_sock = netif_open(devname)) < 0)
|
||||
return (ENXIO);
|
||||
/* Find network interface. */
|
||||
if ((netdev_sock = netif_open(devname)) < 0)
|
||||
return (ENXIO);
|
||||
|
||||
#ifdef SUPPORT_BOOTP
|
||||
if(!no_bootp){
|
||||
printf("configure network...trying bootp\n");
|
||||
/* Get boot info using BOOTP way. (RFC951, RFC1048) */
|
||||
bootp(netdev_sock);
|
||||
}
|
||||
if (!no_bootp) {
|
||||
printf("configure network...trying bootp\n");
|
||||
/* Get boot info using BOOTP way. (RFC951, RFC1048) */
|
||||
bootp(netdev_sock);
|
||||
}
|
||||
#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
|
||||
int num, i;
|
||||
/* XXX (some) tftp servers don't like leading "/" */
|
||||
for(num = 0; bootfile[num] == '/'; num++);
|
||||
for(i=0; bootfile[i] = bootfile[i + num]; i++);
|
||||
int num, i;
|
||||
/* XXX (some) tftp servers don't like leading "/" */
|
||||
for (num = 0; bootfile[num] == '/'; num++);
|
||||
for (i = 0; bootfile[i] = bootfile[i + num]; i++);
|
||||
#endif
|
||||
|
||||
printf("boot: client IP address: %s\n", inet_ntoa(myip));
|
||||
printf("boot: client name: %s\n", hostname);
|
||||
} else {
|
||||
printf("boot: client IP address: %s\n",
|
||||
inet_ntoa(myip));
|
||||
printf("boot: client name: %s\n", hostname);
|
||||
} else {
|
||||
|
||||
#ifdef SUPPORT_RARP
|
||||
/* no answer,
|
||||
Get boot info using RARP and Sun bootparams. */
|
||||
printf("configure network...trying rarp\n");
|
||||
/*
|
||||
* no answer, Get boot info using RARP and Sun
|
||||
* bootparams.
|
||||
*/
|
||||
printf("configure network...trying rarp\n");
|
||||
|
||||
/* Get our IP address. (rarp.c) */
|
||||
if (rarp_getipaddress(netdev_sock)){
|
||||
error=EIO;
|
||||
goto bad;
|
||||
}
|
||||
printf("boot: client IP address: %s\n", inet_ntoa(myip));
|
||||
/* Get our IP address. (rarp.c) */
|
||||
if (rarp_getipaddress(netdev_sock)) {
|
||||
error = EIO;
|
||||
goto bad;
|
||||
}
|
||||
printf("boot: client IP address: %s\n",
|
||||
inet_ntoa(myip));
|
||||
|
||||
#ifdef SUPPORT_BOOTPARAM
|
||||
/* Get our hostname, server IP address. */
|
||||
if (!bp_whoami(netdev_sock)){
|
||||
printf("boot: client name: %s\n", hostname);
|
||||
/* Get our hostname, server IP address. */
|
||||
if (!bp_whoami(netdev_sock)) {
|
||||
printf("boot: client name: %s\n", hostname);
|
||||
|
||||
/* Get the root pathname. */
|
||||
bp_getfile(netdev_sock, "root", &rootip, rootpath);
|
||||
}
|
||||
/* Get the root pathname. */
|
||||
bp_getfile(netdev_sock, "root", &rootip,
|
||||
rootpath);
|
||||
}
|
||||
#else
|
||||
/* else
|
||||
fallback: use rarp server address */
|
||||
/*
|
||||
* else fallback: use rarp server address
|
||||
*/
|
||||
#endif
|
||||
|
||||
#else /* no SUPPORT_RARP */
|
||||
error=EIO;
|
||||
goto bad;
|
||||
#else /* no SUPPORT_RARP */
|
||||
error = EIO;
|
||||
goto bad;
|
||||
#endif
|
||||
|
||||
}
|
||||
printf("boot: server: %s, rootpath: %s, bootfile: %s\n",
|
||||
inet_ntoa(rootip), rootpath, bootfile);
|
||||
}
|
||||
open_count++;
|
||||
f->f_devdata = &netdev_sock;
|
||||
return (error);
|
||||
}
|
||||
printf("boot: server: %s, rootpath: %s, bootfile: %s\n",
|
||||
inet_ntoa(rootip), rootpath, bootfile);
|
||||
}
|
||||
open_count++;
|
||||
f->f_devdata = &netdev_sock;
|
||||
return (error);
|
||||
|
||||
bad:
|
||||
printf("net_open failed\n");
|
||||
netif_close(netdev_sock);
|
||||
return(error);
|
||||
bad:
|
||||
printf("net_open failed\n");
|
||||
netif_close(netdev_sock);
|
||||
return (error);
|
||||
}
|
||||
|
||||
int
|
||||
net_close(f)
|
||||
struct open_file *f;
|
||||
struct open_file *f;
|
||||
{
|
||||
/* On last close, do netif close, etc. */
|
||||
if (--open_count == 0)
|
||||
netif_close(netdev_sock);
|
||||
/* On last close, do netif close, etc. */
|
||||
if (--open_count == 0)
|
||||
netif_close(netdev_sock);
|
||||
#ifdef DEBUG
|
||||
if(open_count < 0) panic("net_close");
|
||||
if (open_count < 0)
|
||||
panic("net_close");
|
||||
#endif
|
||||
f->f_devdata = NULL;
|
||||
f->f_devdata = NULL;
|
||||
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
net_ioctl(f, c, d)
|
||||
struct open_file *f;
|
||||
u_long c;
|
||||
void *d;
|
||||
struct open_file *f;
|
||||
u_long c;
|
||||
void *d;
|
||||
{
|
||||
return EIO;
|
||||
return EIO;
|
||||
}
|
||||
|
||||
int
|
||||
net_strategy(d, f, b, s, buf, r)
|
||||
void *d;
|
||||
int f;
|
||||
daddr_t b;
|
||||
size_t s;
|
||||
void *buf;
|
||||
size_t *r;
|
||||
void *d;
|
||||
int f;
|
||||
daddr_t b;
|
||||
size_t s;
|
||||
void *buf;
|
||||
size_t *r;
|
||||
{
|
||||
return EIO;
|
||||
return EIO;
|
||||
}
|
||||
|
@ -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
|
||||
@ -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>
|
||||
@ -41,26 +41,26 @@
|
||||
#include <netinet/in_systm.h>
|
||||
|
||||
#include <lib/libsa/stand.h>
|
||||
#include <lib/libsa/net.h> /* global "bootfile" */
|
||||
#include <lib/libsa/net.h> /* global "bootfile" */
|
||||
|
||||
int
|
||||
devopen(f, fname, file)
|
||||
struct open_file *f;
|
||||
const char *fname;
|
||||
char **file;
|
||||
struct open_file *f;
|
||||
const char *fname;
|
||||
char **file;
|
||||
{
|
||||
struct devsw *dp;
|
||||
int error=0;
|
||||
struct devsw *dp;
|
||||
int error = 0;
|
||||
|
||||
dp = &devsw[0];
|
||||
f->f_dev = dp;
|
||||
dp = &devsw[0];
|
||||
f->f_dev = dp;
|
||||
|
||||
error = (*dp->dv_open)(f, 0);
|
||||
error = (*dp->dv_open) (f, 0);
|
||||
|
||||
if(bootfile[0])
|
||||
*file = bootfile;
|
||||
else
|
||||
*file = (char*)fname;
|
||||
if (bootfile[0])
|
||||
*file = bootfile;
|
||||
else
|
||||
*file = (char *) fname;
|
||||
|
||||
return (error);
|
||||
return (error);
|
||||
}
|
||||
|
@ -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
|
||||
@ -43,16 +43,16 @@
|
||||
|
||||
#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;
|
||||
static char *consdev;
|
||||
int errno;
|
||||
static char *consdev;
|
||||
|
||||
extern char version[];
|
||||
extern char etherdev[];
|
||||
extern char version[];
|
||||
extern char etherdev[];
|
||||
|
||||
#ifdef SUPPORT_NFS /* XXX */
|
||||
int debug = 0;
|
||||
#ifdef SUPPORT_NFS /* XXX */
|
||||
int debug = 0;
|
||||
#endif
|
||||
|
||||
#define TIMEOUT 5
|
||||
@ -63,219 +63,222 @@ int debug = 0;
|
||||
#ifdef COMPAT_OLDBOOT
|
||||
int
|
||||
parsebootfile(fname, fsname, devname, unit, partition, file)
|
||||
const char *fname;
|
||||
char **fsname; /* out */
|
||||
char **devname; /* out */
|
||||
unsigned int *unit, *partition; /* out */
|
||||
const char **file; /* out */
|
||||
const char *fname;
|
||||
char **fsname; /* out */
|
||||
char **devname;/* out */
|
||||
unsigned int *unit, *partition; /* out */
|
||||
const char **file; /* out */
|
||||
{
|
||||
return(EINVAL);
|
||||
return (EINVAL);
|
||||
}
|
||||
|
||||
int biosdisk_gettype(f)
|
||||
struct open_file *f;
|
||||
int
|
||||
biosdisk_gettype(f)
|
||||
struct open_file *f;
|
||||
{
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
|
||||
int bootit(filename, howto)
|
||||
const char *filename;
|
||||
int howto;
|
||||
int
|
||||
bootit(filename, howto)
|
||||
const char *filename;
|
||||
int howto;
|
||||
{
|
||||
if(exec_netbsd(filename, 0, howto, etherdev, "pc") < 0)
|
||||
printf("boot: %s\n", strerror(errno));
|
||||
else
|
||||
printf("boot returned\n");
|
||||
return(-1);
|
||||
if (exec_netbsd(filename, 0, howto, etherdev, "pc") < 0)
|
||||
printf("boot: %s\n", strerror(errno));
|
||||
else
|
||||
printf("boot returned\n");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
static void helpme()
|
||||
static void
|
||||
helpme()
|
||||
{
|
||||
printf("commands are:\n"
|
||||
"boot [filename] [-adrs]\n"
|
||||
" (ex. \"netbsd.old -s\"\n"
|
||||
"help|?\n"
|
||||
"quit\n");
|
||||
printf("commands are:\n"
|
||||
"boot [filename] [-adrs]\n"
|
||||
" (ex. \"netbsd.old -s\"\n"
|
||||
"help|?\n"
|
||||
"quit\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* chops the head from the arguments and returns the arguments if any,
|
||||
* or possibly an empty string.
|
||||
*/
|
||||
static char *
|
||||
static char *
|
||||
gettrailer(arg)
|
||||
char *arg;
|
||||
char *arg;
|
||||
{
|
||||
char *options;
|
||||
char *options;
|
||||
|
||||
if ((options = strchr(arg, ' ')) == NULL)
|
||||
options = "";
|
||||
else
|
||||
*options++ = '\0';
|
||||
/* trim leading blanks */
|
||||
while (*options && *options == ' ')
|
||||
options++;
|
||||
if ((options = strchr(arg, ' ')) == NULL)
|
||||
options = "";
|
||||
else
|
||||
*options++ = '\0';
|
||||
/* trim leading blanks */
|
||||
while (*options && *options == ' ')
|
||||
options++;
|
||||
|
||||
return(options);
|
||||
return (options);
|
||||
}
|
||||
|
||||
static int
|
||||
parseopts(opts, howto)
|
||||
char *opts;
|
||||
int *howto;
|
||||
char *opts;
|
||||
int *howto;
|
||||
{
|
||||
int tmpopt = 0;
|
||||
int tmpopt = 0;
|
||||
|
||||
opts++; /* skip - */
|
||||
while (*opts && *opts != ' ') {
|
||||
tmpopt |= netbsd_opt(*opts);
|
||||
if(tmpopt == -1) {
|
||||
printf("-%c: unknown flag\n", *opts);
|
||||
helpme();
|
||||
return(0);
|
||||
}
|
||||
opts++;
|
||||
}
|
||||
*howto = tmpopt;
|
||||
return(1);
|
||||
opts++; /* skip - */
|
||||
while (*opts && *opts != ' ') {
|
||||
tmpopt |= netbsd_opt(*opts);
|
||||
if (tmpopt == -1) {
|
||||
printf("-%c: unknown flag\n", *opts);
|
||||
helpme();
|
||||
return (0);
|
||||
}
|
||||
opts++;
|
||||
}
|
||||
*howto = tmpopt;
|
||||
return (1);
|
||||
}
|
||||
|
||||
static int
|
||||
parseboot(arg, filename, howto)
|
||||
char *arg;
|
||||
char **filename;
|
||||
int *howto;
|
||||
char *arg;
|
||||
char **filename;
|
||||
int *howto;
|
||||
{
|
||||
char *opts = NULL;
|
||||
char *opts = NULL;
|
||||
|
||||
*filename = 0;
|
||||
*howto = 0;
|
||||
*filename = 0;
|
||||
*howto = 0;
|
||||
|
||||
/* if there were no arguments */
|
||||
if (!*arg)
|
||||
return(1);
|
||||
/* if there were no arguments */
|
||||
if (!*arg)
|
||||
return (1);
|
||||
|
||||
/* format is... */
|
||||
/*[[xxNx:]filename] [-adrs]*/
|
||||
/* format is... */
|
||||
/* [[xxNx:]filename] [-adrs] */
|
||||
|
||||
/* check for just args */
|
||||
if (arg[0] == '-'){
|
||||
opts = arg;
|
||||
} else { /* at least a file name */
|
||||
*filename = arg;
|
||||
/* check for just args */
|
||||
if (arg[0] == '-') {
|
||||
opts = arg;
|
||||
} else { /* at least a file name */
|
||||
*filename = arg;
|
||||
|
||||
opts = gettrailer(arg);
|
||||
if (!*opts)
|
||||
opts = NULL;
|
||||
else if (*opts != '-') {
|
||||
printf("invalid arguments\n");
|
||||
helpme();
|
||||
return(0);
|
||||
}
|
||||
}
|
||||
/* at this point, we have dealt with filenames. */
|
||||
opts = gettrailer(arg);
|
||||
if (!*opts)
|
||||
opts = NULL;
|
||||
else if (*opts != '-') {
|
||||
printf("invalid arguments\n");
|
||||
helpme();
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
/* at this point, we have dealt with filenames. */
|
||||
|
||||
/* now, deal with options */
|
||||
if (opts) {
|
||||
if (!parseopts(opts, howto))
|
||||
return(0);
|
||||
}
|
||||
|
||||
return(1);
|
||||
/* now, deal with options */
|
||||
if (opts) {
|
||||
if (!parseopts(opts, howto))
|
||||
return (0);
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
static void
|
||||
docommand(arg)
|
||||
char *arg;
|
||||
char *arg;
|
||||
{
|
||||
char *options;
|
||||
char *options;
|
||||
|
||||
options = gettrailer(arg);
|
||||
options = gettrailer(arg);
|
||||
|
||||
if ((strcmp("help", arg) == 0) ||
|
||||
(strcmp("?", arg) == 0)) {
|
||||
helpme();
|
||||
return;
|
||||
}
|
||||
if (strcmp("quit", arg) == 0){
|
||||
printf("Exiting... goodbye...\n");
|
||||
exit(0);
|
||||
}
|
||||
if (strcmp("boot", arg) == 0){
|
||||
char *filename;
|
||||
int howto;
|
||||
if(parseboot(options, &filename, &howto))
|
||||
bootit(filename, howto);
|
||||
return;
|
||||
}
|
||||
printf("unknown command\n");
|
||||
helpme();
|
||||
if ((strcmp("help", arg) == 0) ||
|
||||
(strcmp("?", arg) == 0)) {
|
||||
helpme();
|
||||
return;
|
||||
}
|
||||
if (strcmp("quit", arg) == 0) {
|
||||
printf("Exiting... goodbye...\n");
|
||||
exit(0);
|
||||
}
|
||||
if (strcmp("boot", arg) == 0) {
|
||||
char *filename;
|
||||
int howto;
|
||||
if (parseboot(options, &filename, &howto))
|
||||
bootit(filename, howto);
|
||||
return;
|
||||
}
|
||||
printf("unknown command\n");
|
||||
helpme();
|
||||
}
|
||||
|
||||
void bootmenu()
|
||||
void
|
||||
bootmenu()
|
||||
{
|
||||
printf("\ntype \"?\" or \"help\" for help.\n");
|
||||
for(;;) {
|
||||
char input[80];
|
||||
printf("\ntype \"?\" or \"help\" for help.\n");
|
||||
for (;;) {
|
||||
char input[80];
|
||||
|
||||
input[0] = '\0';
|
||||
printf("> ");
|
||||
gets(input);
|
||||
input[0] = '\0';
|
||||
printf("> ");
|
||||
gets(input);
|
||||
|
||||
docommand(input);
|
||||
}
|
||||
docommand(input);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
awaitkey(void)
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
i = TIMEOUT * POLL_FREQ;
|
||||
i = TIMEOUT * POLL_FREQ;
|
||||
|
||||
while (i--) {
|
||||
if(iskey()) {
|
||||
/* flush input buffer */
|
||||
while(iskey())
|
||||
getchar();
|
||||
while (i--) {
|
||||
if (iskey()) {
|
||||
/* flush input buffer */
|
||||
while (iskey())
|
||||
getchar();
|
||||
|
||||
return(1);
|
||||
}
|
||||
delay(1000000 / POLL_FREQ);
|
||||
if (!(i % POLL_FREQ))
|
||||
printf("%d\b", i/POLL_FREQ);
|
||||
}
|
||||
printf("0\n");
|
||||
return(0);
|
||||
return (1);
|
||||
}
|
||||
delay(1000000 / POLL_FREQ);
|
||||
if (!(i % POLL_FREQ))
|
||||
printf("%d\b", i / POLL_FREQ);
|
||||
}
|
||||
printf("0\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void
|
||||
print_banner(void)
|
||||
{
|
||||
printf("\n"
|
||||
">> NetBSD BOOT: %d/%d k [%s]\n",
|
||||
getbasemem(),
|
||||
getextmem(),
|
||||
version);
|
||||
printf("\n"
|
||||
">> NetBSD BOOT: %d/%d k [%s]\n",
|
||||
getbasemem(),
|
||||
getextmem(),
|
||||
version);
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
consdev = initio(CONSDEV_AUTO);
|
||||
gateA20();
|
||||
consdev = initio(CONSDEV_AUTO);
|
||||
gateA20();
|
||||
|
||||
print_banner();
|
||||
print_banner();
|
||||
|
||||
printf("press any key for boot menu\n"
|
||||
"starting in %d\b", TIMEOUT);
|
||||
printf("press any key for boot menu\n"
|
||||
"starting in %d\b", TIMEOUT);
|
||||
|
||||
if(awaitkey())
|
||||
bootmenu(); /* does not return */
|
||||
if (awaitkey())
|
||||
bootmenu(); /* does not return */
|
||||
|
||||
bootit("netbsd", 0);
|
||||
bootit("netbsd", 0);
|
||||
|
||||
/* if that fails, let BIOS look for boot device */
|
||||
return(1);
|
||||
/* if that fails, let BIOS look for boot device */
|
||||
return (1);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user