From: niklas Date: Sun, 8 Dec 1996 15:15:44 +0000 (+0000) Subject: Merge to NetBSD 961207 X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=79dbd5ceb790c1a6e35c11a8bfd3df05746466e4;p=openbsd Merge to NetBSD 961207 --- diff --git a/sys/lib/libsa/Makefile b/sys/lib/libsa/Makefile index 0004b7adca5..4165ff0a6c2 100644 --- a/sys/lib/libsa/Makefile +++ b/sys/lib/libsa/Makefile @@ -1,5 +1,5 @@ -# $OpenBSD: Makefile,v 1.8 1996/10/16 12:46:32 mickey Exp $ -# $NetBSD: Makefile,v 1.10 1995/10/01 06:00:32 phil Exp $ +# $OpenBSD: Makefile,v 1.9 1996/12/08 15:15:44 niklas Exp $ +# $NetBSD: Makefile,v 1.13 1996/10/02 16:19:51 ws Exp $ LIB= sa @@ -7,10 +7,13 @@ DIR=${SAREL}${SADIR} .PATH: ${DIR} -#DEBUGFLAGS= -DNETIF_DEBUG -DETHER_DEBUG -DNFS_DEBUG -DRPC_DEBUG -DRARP_DEBUG -DDEBUG -DPARANOID -Wall +#DEBUGFLAGS= -DBOOTP_DEBUG -DNETIF_DEBUG -DETHER_DEBUG -DNFS_DEBUG -DRPC_DEBUG -DRARP_DEBUG -DDEBUG -DPARANOID -Wall #DEBUGFLAGS= -ansi -pedantic -Wall AFLAGS+=${XAFLAGS} CFLAGS+=${XCFLAGS} -D_STANDALONE -DCOMPAT_UFS $(DEBUGFLAGS) -I${DIR} -I${DIR}/../.. +# +# Needed for PowerPC +CFLAGS+=$(EXTRACFLAGS) CPPFLAGS+=${XCPPFLAGS} .if ${MACHINE_ARCH}=="i386" @@ -35,7 +38,7 @@ SRCS+= arp.c ether.c in_cksum.c net.c netif.c rpc.c SRCS+= bootp.c rarp.c bootparam.c # boot filesystems -SRCS+= ufs.c nfs.c +SRCS+= ufs.c nfs.c cd9660.c NOPROFILE= NOPIC= diff --git a/sys/lib/libsa/Makefile.inc b/sys/lib/libsa/Makefile.inc index 297da86a287..95e1c5373ed 100644 --- a/sys/lib/libsa/Makefile.inc +++ b/sys/lib/libsa/Makefile.inc @@ -1,5 +1,5 @@ -# $OpenBSD: Makefile.inc,v 1.3 1996/09/23 14:18:45 mickey Exp $ -# $NetBSD: Makefile.inc,v 1.4 1995/10/01 06:00:38 phil Exp $ +# $OpenBSD: Makefile.inc,v 1.4 1996/12/08 15:15:44 niklas Exp $ +# $NetBSD: Makefile.inc,v 1.5 1996/09/30 16:01:18 ws Exp $ # # NOTE: $S must correspond to the top of the 'sys' tree SADIR= $S/lib/libsa @@ -15,7 +15,8 @@ SAMAKE= \ LD='${LD}' \ XCPPFLAGS="${CPPFLAGS}" \ SAREL="${SAREL}" \ - SADIR="${SADIR}" + SADIR="${SADIR}" \ + EXTRACFLAGS="${EXTRACFLAGS}" ${SALIB}: .NOTMAIN __always_make_salib @echo making sure the stand-alone library is up to date... diff --git a/sys/lib/libsa/alloc.c b/sys/lib/libsa/alloc.c index eb6b4e9cbe6..785b4a77d73 100644 --- a/sys/lib/libsa/alloc.c +++ b/sys/lib/libsa/alloc.c @@ -1,5 +1,5 @@ -/* $OpenBSD: alloc.c,v 1.2 1996/09/23 14:18:46 mickey Exp $ */ -/* $NetBSD: alloc.c,v 1.3 1994/10/26 05:44:34 cgd Exp $ */ +/* $OpenBSD: alloc.c,v 1.3 1996/12/08 15:15:45 niklas Exp $ */ +/* $NetBSD: alloc.c,v 1.4 1996/09/26 23:15:00 cgd Exp $ */ /*- * Copyright (c) 1993 @@ -90,8 +90,8 @@ alloc(size) f = f->next; } if (f == (struct fl *)0) { - f = (struct fl *)top; - top += ALIGN(size); + f = (struct fl *)ALIGN(top); + top = (char *)f + ALIGN(size); } else *prev = f->next; return ((void *)f); diff --git a/sys/lib/libsa/arp.c b/sys/lib/libsa/arp.c index fe4d3c4443f..60f4c155b8d 100644 --- a/sys/lib/libsa/arp.c +++ b/sys/lib/libsa/arp.c @@ -1,5 +1,5 @@ -/* $OpenBSD: arp.c,v 1.4 1996/10/16 14:18:34 mickey Exp $ */ -/* $NetBSD: arp.c,v 1.13 1995/12/08 04:12:53 gwr Exp $ */ +/* $OpenBSD: arp.c,v 1.5 1996/12/08 15:15:45 niklas Exp $ */ +/* $NetBSD: arp.c,v 1.15 1996/10/13 02:28:58 christos Exp $ */ /* * Copyright (c) 1992 Regents of the University of California. @@ -135,10 +135,9 @@ arpwhohas(d, addr) #ifdef ARP_DEBUG if (debug) { printf("arp: response from %s\n", - ether_sprintf(rbuf.eh.ether_shost)); + ether_sprintf(rbuf.eh.ether_shost)); printf("arp: cacheing %s --> %s\n", - inet_ntoa(addr), - ether_sprintf(ah->arp_sha)); + inet_ntoa(addr), ether_sprintf(ah->arp_sha)); } #endif MACPY(ah->arp_sha, al->ea); @@ -289,8 +288,7 @@ arp_reply(d, pkt) #ifdef ARP_DEBUG if (debug) { - printf("arp_reply: to %s\n", - ether_sprintf(arp->arp_sha)); + printf("arp_reply: to %s\n", ether_sprintf(arp->arp_sha)); } #endif diff --git a/sys/lib/libsa/bootp.c b/sys/lib/libsa/bootp.c index 948a68fe106..144dc26ae27 100644 --- a/sys/lib/libsa/bootp.c +++ b/sys/lib/libsa/bootp.c @@ -1,5 +1,5 @@ -/* $OpenBSD: bootp.c,v 1.5 1996/10/16 14:18:35 mickey Exp $ */ -/* $NetBSD: bootp.c,v 1.7 1995/09/18 21:19:20 pk Exp $ */ +/* $OpenBSD: bootp.c,v 1.6 1996/12/08 15:15:46 niklas Exp $ */ +/* $NetBSD: bootp.c,v 1.10 1996/10/13 02:28:59 christos Exp $ */ /* * Copyright (c) 1992 Regents of the University of California. @@ -303,7 +303,7 @@ vend_rfc1048(cp, len) ep = cp + len; /* Step over magic cookie */ - cp += sizeof(long); + cp += sizeof(int); while (cp < ep) { tag = *cp++; diff --git a/sys/lib/libsa/bootp.h b/sys/lib/libsa/bootp.h index 726dc618628..8731adfa153 100644 --- a/sys/lib/libsa/bootp.h +++ b/sys/lib/libsa/bootp.h @@ -1,5 +1,5 @@ -/* $OpenBSD: bootp.h,v 1.3 1996/09/27 07:44:42 mickey Exp $ */ -/* $NetBSD: bootp.h,v 1.2 1994/10/26 05:44:39 cgd Exp $ */ +/* $OpenBSD: bootp.h,v 1.4 1996/12/08 15:15:46 niklas Exp $ */ +/* $NetBSD: bootp.h,v 1.3 1996/09/26 23:22:01 cgd Exp $ */ /* * Bootstrap Protocol (BOOTP). RFC951 and RFC1048. @@ -33,7 +33,7 @@ struct bootp { u_char bp_htype; /* hardware addr type */ u_char bp_hlen; /* hardware addr length */ u_char bp_hops; /* gateway hops */ - u_long bp_xid; /* transaction ID */ + u_int bp_xid; /* transaction ID */ u_short bp_secs; /* seconds since boot began */ u_short bp_flags; /* RFC1532 broadcast, etc. */ struct in_addr bp_ciaddr; /* client IP address */ @@ -116,7 +116,7 @@ struct bootp { struct cmu_vend { unsigned char v_magic[4]; /* magic number */ - unsigned long v_flags; /* flags/opcodes, etc. */ + unsigned int v_flags; /* flags/opcodes, etc. */ struct in_addr v_smask; /* Subnet mask */ struct in_addr v_dgate; /* Default gateway */ struct in_addr v_dns1, v_dns2; /* Domain name servers */ diff --git a/sys/lib/libsa/bootparam.c b/sys/lib/libsa/bootparam.c index f0ddfd26b83..f81b5041c85 100644 --- a/sys/lib/libsa/bootparam.c +++ b/sys/lib/libsa/bootparam.c @@ -1,5 +1,5 @@ -/* $OpenBSD: bootparam.c,v 1.6 1996/10/16 14:18:35 mickey Exp $ */ -/* $NetBSD: bootparam.c,v 1.7 1996/02/26 23:05:14 gwr Exp $ */ +/* $OpenBSD: bootparam.c,v 1.7 1996/12/08 15:15:47 niklas Exp $ */ +/* $NetBSD: bootparam.c,v 1.10 1996/10/14 21:16:55 thorpej Exp $ */ /* * Copyright (c) 1995 Gordon W. Ross @@ -51,6 +51,12 @@ #include "rpc.h" #include "bootparam.h" +#ifdef DEBUG_RPC +#define RPC_PRINTF(a) printf a +#else +#define RPC_PRINTF(a) +#endif + struct in_addr bp_server_addr; /* net order */ n_short bp_server_port; /* net order */ @@ -124,14 +130,10 @@ bp_whoami(sockfd) struct iodesc *d; int len, x; -#ifdef RPC_DEBUG - printf("bp_whoami: myip=%s\n", inet_ntoa(myip)); -#endif + RPC_PRINTF(("bp_whoami: myip=%s\n", inet_ntoa(myip))); if (!(d = socktodesc(sockfd))) { -#ifdef RPC_DEBUG - printf("bp_whoami: bad socket. %d\n", sockfd); -#endif + RPC_PRINTF(("bp_whoami: bad socket. %d\n", sockfd)); return (-1); } args = &sdata.d; @@ -175,10 +177,8 @@ bp_whoami(sockfd) */ bp_server_port = repl->port; -#ifdef RPC_DEBUG - printf("bp_whoami: server at %s:%d\n", - inet_ntoa(bp_server_addr), ntohs(bp_server_port)); -#endif + RPC_PRINTF(("bp_whoami: server at %s:%d\n", + inet_ntoa(bp_server_addr), ntohs(bp_server_port))); /* We have just done a portmap call, so cache the portnum. */ rpc_pmap_putcache(bp_server_addr, @@ -199,26 +199,20 @@ bp_whoami(sockfd) /* client name */ hostnamelen = MAXHOSTNAMELEN-1; if (xdr_string_decode(&recv_head, hostname, &hostnamelen)) { -#ifdef RPC_DEBUG - printf("bp_whoami: bad hostname\n"); -#endif + RPC_PRINTF(("bp_whoami: bad hostname\n")); return (-1); } /* domain name */ domainnamelen = MAXHOSTNAMELEN-1; if (xdr_string_decode(&recv_head, domainname, &domainnamelen)) { -#ifdef RPC_DEBUG - printf("bp_whoami: bad domainname\n"); -#endif + RPC_PRINTF(("bp_whoami: bad domainname\n")); return (-1); } /* gateway address */ if (xdr_inaddr_decode(&recv_head, &gateip)) { -#ifdef RPC_DEBUG - printf("bp_whoami: bad gateway\n"); -#endif + RPC_PRINTF(("bp_whoami: bad gateway\n")); return (-1); } @@ -256,9 +250,7 @@ bp_getfile(sockfd, key, serv_addr, pathname) int sn_len, path_len, rlen; if (!(d = socktodesc(sockfd))) { -#ifdef RPC_DEBUG - printf("bp_getfile: bad socket. %d\n", sockfd); -#endif + RPC_PRINTF(("bp_getfile: bad socket. %d\n", sockfd)); return (-1); } @@ -271,17 +263,13 @@ bp_getfile(sockfd, key, serv_addr, pathname) /* client name (hostname) */ if (xdr_string_encode(&send_tail, hostname, hostnamelen)) { -#ifdef RPC_DEBUG - printf("bp_getfile: bad client\n"); -#endif + RPC_PRINTF(("bp_getfile: bad client\n")); return (-1); } /* key name (root or swap) */ if (xdr_string_encode(&send_tail, key, strlen(key))) { -#ifdef RPC_DEBUG - printf("bp_getfile: bad key\n"); -#endif + RPC_PRINTF(("bp_getfile: bad key\n")); return (-1); } @@ -295,9 +283,7 @@ bp_getfile(sockfd, key, serv_addr, pathname) sdata.d, send_tail - (char*)sdata.d, rdata.d, sizeof(rdata.d)); if (rlen < 4) { -#ifdef RPC_DEBUG - printf("bp_getfile: short reply\n"); -#endif + RPC_PRINTF(("bp_getfile: short reply\n")); errno = EBADRPC; return (-1); } @@ -310,26 +296,20 @@ bp_getfile(sockfd, key, serv_addr, pathname) /* server name */ sn_len = FNAME_SIZE-1; if (xdr_string_decode(&recv_head, serv_name, &sn_len)) { -#ifdef RPC_DEBUG - printf("bp_getfile: bad server name\n"); -#endif + RPC_PRINTF(("bp_getfile: bad server name\n")); return (-1); } /* server IP address (mountd/NFS) */ if (xdr_inaddr_decode(&recv_head, serv_addr)) { -#ifdef RPC_DEBUG - printf("bp_getfile: bad server addr\n"); -#endif + RPC_PRINTF(("bp_getfile: bad server addr\n")); return (-1); } /* server pathname */ path_len = MAXPATHLEN-1; if (xdr_string_decode(&recv_head, pathname, &path_len)) { -#ifdef RPC_DEBUG - printf("bp_getfile: bad server path\n"); -#endif + RPC_PRINTF(("bp_getfile: bad server path\n")); return (-1); } @@ -446,10 +426,8 @@ xdr_inaddr_decode(pkt, ia) xi = (struct xdr_inaddr *) *pkt; *pkt += sizeof(*xi); if (xi->atype != htonl(1)) { -#ifdef RPC_DEBUG - printf("xdr_inaddr_decode: bad addrtype=%ld\n", - ntohl(xi->atype)); -#endif + RPC_PRINTF(("xdr_inaddr_decode: bad addrtype=%d\n", + ntohl(xi->atype))); return(-1); } diff --git a/sys/lib/libsa/cd9660.c b/sys/lib/libsa/cd9660.c new file mode 100644 index 00000000000..0d0704f34c3 --- /dev/null +++ b/sys/lib/libsa/cd9660.c @@ -0,0 +1,405 @@ +/* $NetBSD: cd9660.c,v 1.1 1996/09/30 16:01:19 ws Exp $ */ + +/* + * Copyright (C) 1996 Wolfgang Solfrank. + * Copyright (C) 1996 TooLs GmbH. + * 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 TooLs GmbH. + * 4. The name of TooLs GmbH may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``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 TOOLS GMBH 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. + */ + +/* + * Stand-alone ISO9660 file reading package. + * + * Note: This doesn't support Rock Ridge extensions, extended attributes, + * blocksizes other than 2048 bytes, multi-extent files, etc. + */ +#include + +#include + +/* THIS IS AN UGLY HACK!!! XXX */ +struct fid; +struct mbuf; +struct nameidata; +struct netexport { int x; }; +struct proc; +struct statfs; +struct ucred; +#include +/* These once were in iso.h, but got deleted??? */ +extern __inline int +isonum_722(p) + unsigned char *p; +{ + return ((char)*p << 8)|p[1]; +} + +extern __inline int +isonum_732(p) + unsigned char *p; +{ + return (*p << 24)|(p[1] << 16)|(p[2] << 8)|p[3]; +} + +#include "stand.h" +#include "cd9660.h" + +struct file { + off_t off; /* Current offset within file */ + daddr_t bno; /* Starting block number */ + off_t size; /* Size of file */ +}; + +struct ptable_ent { + char namlen [ISODCL( 1, 1)]; /* 711 */ + char extlen [ISODCL( 2, 2)]; /* 711 */ + char block [ISODCL( 3, 6)]; /* 732 */ + char parent [ISODCL( 7, 8)]; /* 722 */ + char name [1]; +}; +#define PTFIXSZ 8 +#define PTSIZE(pp) roundup(PTFIXSZ + isonum_711((pp)->namlen), 2) + +#define cdb2devb(bno) ((bno) * ISO_DEFAULT_BLOCK_SIZE / DEV_BSIZE) + +static int +toupper(c) + int c; +{ + return c >= 'a' && c <= 'z' ? c - 'a' + 'A' : c; +} + +static int +pnmatch(path, pp) + char *path; + struct ptable_ent *pp; +{ + char *cp; + int i; + + cp = pp->name; + for (i = isonum_711(pp->namlen); --i >= 0; path++, cp++) { + if (toupper(*path) == *cp) + continue; + return 0; + } + if (*path != '/') + return 0; + return 1; +} + +static int +dirmatch(path, dp) + char *path; + struct iso_directory_record *dp; +{ + char *cp; + int i; + + /* This needs to be a regular file */ + if (dp->flags[0] & 6) + return 0; + + cp = dp->name; + for (i = isonum_711(dp->name_len); --i >= 0; path++, cp++) { + if (!*path) + break; + if (toupper(*path) == *cp) + continue; + return 0; + } + if (*path) + return 0; + /* + * Allow stripping of trailing dots and the version number. + * Note that this will find the first instead of the last version + * of a file. + */ + if (i >= 0 && (*cp == ';' || *cp == '.')) { + /* This is to prevent matching of numeric extensions */ + if (*cp == '.' && cp[1] != ';') + return 0; + while (--i >= 0) + if (*++cp != ';' && (*cp < '0' || *cp > '9')) + return 0; + } + return 1; +} + +int +cd9660_open(path, f) + char *path; + struct open_file *f; +{ + struct file *fp = 0; + void *buf; + struct iso_primary_descriptor *vd; + size_t buf_size, read, psize, dsize; + daddr_t bno; + int parent, ent; + struct ptable_ent *pp; + struct iso_directory_record *dp; + int rc; + + /* First find the volume descriptor */ + buf = alloc(buf_size = ISO_DEFAULT_BLOCK_SIZE); + vd = buf; + for (bno = 16;; bno++) { + twiddle(); + rc = f->f_dev->dv_strategy(f->f_devdata, F_READ, cdb2devb(bno), + ISO_DEFAULT_BLOCK_SIZE, buf, &read); + if (rc) + goto out; + if (read != ISO_DEFAULT_BLOCK_SIZE) { + rc = EIO; + goto out; + } + rc = EINVAL; + if (bcmp(vd->id, ISO_STANDARD_ID, sizeof vd->id) != 0) + goto out; + if (isonum_711(vd->type) == ISO_VD_END) + goto out; + if (isonum_711(vd->type) == ISO_VD_PRIMARY) + break; + } + if (isonum_723(vd->logical_block_size) != ISO_DEFAULT_BLOCK_SIZE) + goto out; + + /* Now get the path table and lookup the directory of the file */ + bno = isonum_732(vd->type_m_path_table); + psize = isonum_733(vd->path_table_size); + + if (psize > ISO_DEFAULT_BLOCK_SIZE) { + free(buf, ISO_DEFAULT_BLOCK_SIZE); + buf = alloc(buf_size = roundup(psize, ISO_DEFAULT_BLOCK_SIZE)); + } + + twiddle(); + rc = f->f_dev->dv_strategy(f->f_devdata, F_READ, cdb2devb(bno), + buf_size, buf, &read); + if (rc) + goto out; + if (read != buf_size) { + rc = EIO; + goto out; + } + + parent = 1; + pp = (struct ptable_ent *)buf; + ent = 1; + bno = isonum_732(pp->block) + isonum_711(pp->extlen); + + rc = ENOENT; + while (*path) { + if ((void *)pp >= buf + psize) + break; + if (isonum_722(pp->parent) != parent) + break; + if (!pnmatch(path, pp)) { + pp = (struct ptable_ent *)((void *)pp + PTSIZE(pp)); + ent++; + continue; + } + path += isonum_711(pp->namlen) + 1; + parent = ent; + bno = isonum_732(pp->block) + isonum_711(pp->extlen); + while ((void *)pp < buf + psize) { + if (isonum_722(pp->parent) == parent) + break; + pp = (struct ptable_ent *)((void *)pp + PTSIZE(pp)); + ent++; + } + } + + /* Now bno has the start of the directory that supposedly contains the file */ + bno--; + dsize = 1; /* Something stupid, but > 0 XXX */ + for (psize = 0; psize < dsize;) { + if (!(psize % ISO_DEFAULT_BLOCK_SIZE)) { + bno++; + twiddle(); + rc = f->f_dev->dv_strategy(f->f_devdata, F_READ, + cdb2devb(bno), + ISO_DEFAULT_BLOCK_SIZE, + buf, &read); + if (rc) + goto out; + if (read != ISO_DEFAULT_BLOCK_SIZE) { + rc = EIO; + goto out; + } + dp = (struct iso_directory_record *)buf; + } + if (!isonum_711(dp->length)) { + if ((void *)dp == buf) + psize += ISO_DEFAULT_BLOCK_SIZE; + else + psize = roundup(psize, ISO_DEFAULT_BLOCK_SIZE); + continue; + } + if (dsize == 1) + dsize = isonum_733(dp->size); + if (dirmatch(path, dp)) + break; + psize += isonum_711(dp->length); + dp = (struct iso_directory_record *)((void *)dp + isonum_711(dp->length)); + } + + if (psize >= dsize) { + rc = ENOENT; + goto out; + } + + /* allocate file system specific data structure */ + fp = alloc(sizeof(struct file)); + bzero(fp, sizeof(struct file)); + f->f_fsdata = (void *)fp; + + fp->off = 0; + fp->bno = isonum_733(dp->extent); + fp->size = isonum_733(dp->size); + free(buf, buf_size); + + return 0; + +out: + if (fp) + free(fp, sizeof(struct file)); + free(buf, buf_size); + + return rc; +} + +int +cd9660_close(f) + struct open_file *f; +{ + struct file *fp = (struct file *)f->f_fsdata; + + f->f_fsdata = 0; + free(fp, sizeof *fp); + + return 0; +} + +int +cd9660_read(f, start, size, resid) + struct open_file *f; + void *start; + size_t size; + size_t *resid; +{ + struct file *fp = (struct file *)f->f_fsdata; + int rc = 0; + daddr_t bno; + char buf[ISO_DEFAULT_BLOCK_SIZE]; + char *dp; + size_t read, off; + + while (size) { + if (fp->off < 0 || fp->off >= fp->size) + break; + bno = fp->off / ISO_DEFAULT_BLOCK_SIZE + fp->bno; + if (fp->off & (ISO_DEFAULT_BLOCK_SIZE - 1) + || size < ISO_DEFAULT_BLOCK_SIZE) + dp = buf; + else + dp = start; + twiddle(); + rc = f->f_dev->dv_strategy(f->f_devdata, F_READ, cdb2devb(bno), + ISO_DEFAULT_BLOCK_SIZE, dp, &read); + if (rc) + return rc; + if (read != ISO_DEFAULT_BLOCK_SIZE) + return EIO; + if (dp == buf) { + off = fp->off & (ISO_DEFAULT_BLOCK_SIZE - 1); + if (read > off + size) + read = off + size; + read -= off; + bcopy(buf + off, start, read); + start += read; + fp->off += read; + size -= read; + } else { + start += ISO_DEFAULT_BLOCK_SIZE; + fp->off += ISO_DEFAULT_BLOCK_SIZE; + size -= ISO_DEFAULT_BLOCK_SIZE; + } + } + if (resid) + *resid = size; + return rc; +} + +int +cd9660_write(f, start, size, resid) + struct open_file *f; + void *start; + size_t size; + size_t *resid; +{ + return EROFS; +} + +off_t +cd9660_seek(f, offset, where) + struct open_file *f; + off_t offset; + int where; +{ + struct file *fp = (struct file *)f->f_fsdata; + + switch (where) { + case SEEK_SET: + fp->off = offset; + break; + case SEEK_CUR: + fp->off += offset; + break; + case SEEK_END: + fp->off = fp->size - offset; + break; + default: + return -1; + } + return fp->off; +} + +int +cd9660_stat(f, sb) + struct open_file *f; + struct stat *sb; +{ + struct file *fp = (struct file *)f->f_fsdata; + + /* only importatn stuff */ + sb->st_mode = S_IFREG | S_IRUSR | S_IRGRP | S_IROTH; + sb->st_uid = sb->st_gid = 0; + sb->st_size = fp->size; + return 0; +} diff --git a/sys/lib/libsa/cd9660.h b/sys/lib/libsa/cd9660.h new file mode 100644 index 00000000000..6031323a380 --- /dev/null +++ b/sys/lib/libsa/cd9660.h @@ -0,0 +1,41 @@ +/* $NetBSD: cd9660.h,v 1.1 1996/09/30 16:01:20 ws Exp $ */ + +/* + * Copyright (C) 1996 Wolfgang Solfrank. + * Copyright (C) 1996 TooLs GmbH. + * 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 TooLs GmbH. + * 4. The name of TooLs GmbH may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``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 TOOLS GMBH 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. + */ + +int cd9660_open __P((char *path, struct open_file *f)); +int cd9660_close __P((struct open_file *f)); +int cd9660_read __P((struct open_file *f, void *buf, + size_t size, size_t *resid)); +int cd9660_write __P((struct open_file *f, void *buf, + size_t size, size_t *resid)); +off_t cd9660_seek __P((struct open_file *f, off_t offset, int where)); +int cd9660_stat __P((struct open_file *f, struct stat *sb)); diff --git a/sys/lib/libsa/ether.c b/sys/lib/libsa/ether.c index 0d086b5e261..c298ca423e0 100644 --- a/sys/lib/libsa/ether.c +++ b/sys/lib/libsa/ether.c @@ -1,5 +1,5 @@ -/* $OpenBSD: ether.c,v 1.3 1996/10/16 14:18:36 mickey Exp $ */ -/* $NetBSD: ether.c,v 1.6 1995/09/14 23:45:25 pk Exp $ */ +/* $OpenBSD: ether.c,v 1.4 1996/12/08 15:15:49 niklas Exp $ */ +/* $NetBSD: ether.c,v 1.8 1996/10/13 02:29:00 christos Exp $ */ /* * Copyright (c) 1992 Regents of the University of California. @@ -120,7 +120,7 @@ readether(d, pkt, len, tleft, etype) #ifdef ETHER_DEBUG if (debug) printf("readether: not ours (ea=%s)\n", - ether_sprintf(eh->ether_dhost)); + ether_sprintf(eh->ether_dhost)); #endif return (-1); } diff --git a/sys/lib/libsa/exec.c b/sys/lib/libsa/exec.c index 7483bc1c2ca..85d74296677 100644 --- a/sys/lib/libsa/exec.c +++ b/sys/lib/libsa/exec.c @@ -1,5 +1,5 @@ -/* $OpenBSD: exec.c,v 1.6 1996/10/16 13:01:23 mickey Exp $ */ -/* $NetBSD: exec.c,v 1.12.4.1 1996/06/02 12:08:48 ragge Exp $ */ +/* $OpenBSD: exec.c,v 1.7 1996/12/08 15:15:49 niklas Exp $ */ +/* $NetBSD: exec.c,v 1.15 1996/10/13 02:29:01 christos Exp $ */ /*- * Copyright (c) 1982, 1986, 1990, 1993 diff --git a/sys/lib/libsa/exit.c b/sys/lib/libsa/exit.c index 1cb2e7a0d2e..ef9654aa8c9 100644 --- a/sys/lib/libsa/exit.c +++ b/sys/lib/libsa/exit.c @@ -1,5 +1,5 @@ -/* $OpenBSD: exit.c,v 1.2 1996/02/29 13:29:22 niklas Exp $ */ -/* $NetBSD: exit.c,v 1.8 1996/02/09 16:10:59 gwr Exp $ */ +/* $OpenBSD: exit.c,v 1.3 1996/12/08 15:15:50 niklas Exp $ */ +/* $NetBSD: exit.c,v 1.11 1996/12/01 20:22:19 pk Exp $ */ /*- * Copyright (c) 1993 John Brezak diff --git a/sys/lib/libsa/getfile.c b/sys/lib/libsa/getfile.c index 64401bff267..553c8cc3a83 100644 --- a/sys/lib/libsa/getfile.c +++ b/sys/lib/libsa/getfile.c @@ -1,5 +1,5 @@ -/* $OpenBSD: getfile.c,v 1.2 1996/09/23 14:18:53 mickey Exp $ */ -/* $NetBSD: getfile.c,v 1.3 1994/10/26 05:44:45 cgd Exp $ */ +/* $OpenBSD: getfile.c,v 1.3 1996/12/08 15:15:50 niklas Exp $ */ +/* $NetBSD: getfile.c,v 1.6 1996/10/14 04:49:21 cgd Exp $ */ /*- * Copyright (c) 1993 @@ -37,6 +37,8 @@ */ #include "stand.h" +#define CTRL(x) (x&037) + int getfile(prompt, mode) char *prompt; @@ -48,6 +50,8 @@ getfile(prompt, mode) do { printf("%s: ", prompt); gets(buf); + if (buf[0] == CTRL('d') && buf[1] == 0) + return (-1); } while ((fd = open(buf, mode)) < 0); return (fd); diff --git a/sys/lib/libsa/lseek.c b/sys/lib/libsa/lseek.c index ea6d0f13530..02f6443fd39 100644 --- a/sys/lib/libsa/lseek.c +++ b/sys/lib/libsa/lseek.c @@ -1,5 +1,5 @@ -/* $OpenBSD: lseek.c,v 1.2 1996/09/23 14:18:56 mickey Exp $ */ -/* $NetBSD: lseek.c,v 1.2 1994/10/26 05:44:51 cgd Exp $ */ +/* $OpenBSD: lseek.c,v 1.3 1996/12/08 15:15:51 niklas Exp $ */ +/* $NetBSD: lseek.c,v 1.3 1996/06/21 20:09:03 pk Exp $ */ /*- * Copyright (c) 1993 @@ -80,10 +80,23 @@ lseek(fd, offset, where) return (-1); } - /* seek is not supported on raw devices */ if (f->f_flags & F_RAW) { - errno = EOFFSET; - return ((off_t)-1); + /* + * On RAW devices, update internal offset. + */ + switch (where) { + case SEEK_SET: + f->f_offset = offset; + break; + case SEEK_CUR: + f->f_offset += offset; + break; + case SEEK_END: + default: + errno = EOFFSET; + return (-1); + } + return (f->f_offset); } return (f->f_ops->seek)(f, offset, where); diff --git a/sys/lib/libsa/net.c b/sys/lib/libsa/net.c index 9626c47afef..998340cd997 100644 --- a/sys/lib/libsa/net.c +++ b/sys/lib/libsa/net.c @@ -1,5 +1,5 @@ -/* $OpenBSD: net.c,v 1.6 1996/10/16 14:24:08 mickey Exp $ */ -/* $NetBSD: net.c,v 1.12 1995/12/13 23:38:10 pk Exp $ */ +/* $OpenBSD: net.c,v 1.7 1996/12/08 15:15:51 niklas Exp $ */ +/* $NetBSD: net.c,v 1.14 1996/10/13 02:29:02 christos Exp $ */ /* * Copyright (c) 1992 Regents of the University of California. @@ -76,9 +76,9 @@ sendudp(d, pkt, len) printf("sendudp: d=%x called.\n", (u_int)d); if (d) { printf("saddr: %s:%d", - inet_ntoa(d->myip), ntohs(d->myport)); + inet_ntoa(d->myip), ntohs(d->myport)); printf(" daddr: %s:%d\n", - inet_ntoa(d->destip), ntohs(d->destport)); + inet_ntoa(d->destip), ntohs(d->destport)); } } #endif diff --git a/sys/lib/libsa/netif.c b/sys/lib/libsa/netif.c index ea902399afe..b4e70493dfe 100644 --- a/sys/lib/libsa/netif.c +++ b/sys/lib/libsa/netif.c @@ -1,5 +1,5 @@ -/* $OpenBSD: netif.c,v 1.3 1996/10/29 08:44:09 mickey Exp $ */ -/* $NetBSD: netif.c,v 1.5 1995/09/18 21:19:34 pk Exp $ */ +/* $OpenBSD: netif.c,v 1.4 1996/12/08 15:15:52 niklas Exp $ */ +/* $NetBSD: netif.c,v 1.7 1996/10/13 02:29:03 christos Exp $ */ /* * Copyright (c) 1993 Adam Glass @@ -314,7 +314,7 @@ fnd: panic("netboot: no interfaces left untried"); if (netif_probe(nif, machdep_hint)) { printf("netboot: couldn't probe %s%d\n", - nif->nif_driver->netif_bname, nif->nif_unit); + nif->nif_driver->netif_bname, nif->nif_unit); errno = EINVAL; return(-1); } diff --git a/sys/lib/libsa/nfs.c b/sys/lib/libsa/nfs.c index b31ecc8da50..a09d4698d0a 100644 --- a/sys/lib/libsa/nfs.c +++ b/sys/lib/libsa/nfs.c @@ -1,5 +1,5 @@ -/* $OpenBSD: nfs.c,v 1.5 1996/10/15 09:58:34 mickey Exp $ */ -/* $NetBSD: nfs.c,v 1.15 1996/05/14 10:28:26 leo Exp $ */ +/* $OpenBSD: nfs.c,v 1.6 1996/12/08 15:15:52 niklas Exp $ */ +/* $NetBSD: nfs.c,v 1.19 1996/10/13 02:29:04 christos Exp $ */ /*- * Copyright (c) 1993 John Brezak @@ -38,8 +38,8 @@ #include #include -#include -#include +#include "rpcv2.h" +#include "nfsv2.h" #include "stand.h" #include "net.h" @@ -82,6 +82,12 @@ struct nfs_read_repl { u_char data[NFSREAD_SIZE]; }; +struct nfs_readlnk_repl { + n_long errno; + n_long len; + char path[NFS_MAXPATHLEN]; +}; + struct nfs_iodesc { struct iodesc *iodesc; off_t off; @@ -221,6 +227,51 @@ nfs_lookupfh(d, name, newfd) return (0); } +/* + * Get the destination of a symbolic link. + */ +int +nfs_readlink(d, buf) + struct nfs_iodesc *d; + char *buf; +{ + struct { + n_long h[RPC_HEADER_WORDS]; + u_char fh[NFS_FHSIZE]; + } sdata; + struct { + n_long h[RPC_HEADER_WORDS]; + struct nfs_readlnk_repl d; + } rdata; + ssize_t cc; + +#ifdef NFS_DEBUG + if (debug) + printf("readlink: called\n"); +#endif + + bcopy(d->fh, sdata.fh, NFS_FHSIZE); + cc = rpc_call(d->iodesc, NFS_PROG, NFS_VER2, NFSPROC_READLINK, + sdata.fh, NFS_FHSIZE, + &rdata.d, sizeof(rdata.d)); + if (cc == -1) + return (errno); + + if (cc < 4) + return (EIO); + + if (rdata.d.errno) + return (ntohl(rdata.d.errno)); + + rdata.d.len = ntohl(rdata.d.len); + if (rdata.d.len > NFS_MAXPATHLEN) + return (ENAMETOOLONG); + + bcopy(rdata.d.path, buf, rdata.d.len); + buf[rdata.d.len] = 0; + return (0); +} + /* * Read data from a file. * Return transfer count or -1 (and set errno) @@ -330,7 +381,12 @@ nfs_open(path, f) char *path; struct open_file *f; { - struct nfs_iodesc *newfd; + struct nfs_iodesc *newfd, *currfd; + register char *cp, *ncp; + register int c; + char namebuf[NFS_MAXPATHLEN + 1]; + char linkbuf[NFS_MAXPATHLEN + 1]; + int nlinks = 0; int error = 0; #ifdef NFS_DEBUG @@ -342,24 +398,118 @@ nfs_open(path, f) return (ENXIO); } - /* allocate file system specific data structure */ - newfd = alloc(sizeof(*newfd)); - newfd->iodesc = nfs_root_node.iodesc; - newfd->off = 0; + currfd = &nfs_root_node; + newfd = 0; + + cp = path; + while (*cp) { + /* + * Remove extra separators + */ + while (*cp == '/') + cp++; + + if (*cp == '\0') + break; + /* + * Check that current node is a directory. + */ + if (currfd->fa.fa_type != htonl(NFDIR)) { + error = ENOTDIR; + goto out; + } + + /* allocate file system specific data structure */ + newfd = alloc(sizeof(*newfd)); + newfd->iodesc = currfd->iodesc; + newfd->off = 0; + + /* + * Get next component of path name. + */ + { + register int len = 0; + + ncp = cp; + while ((c = *cp) != '\0' && c != '/') { + if (++len > NFS_MAXNAMLEN) { + error = ENOENT; + goto out; + } + cp++; + } + *cp = '\0'; + } + + /* lookup a file handle */ + error = nfs_lookupfh(currfd, ncp, newfd); + *cp = c; + if (error) + goto out; + + /* + * Check for symbolic link + */ + if (newfd->fa.fa_type == htonl(NFLNK)) { + int link_len, len; + + error = nfs_readlink(newfd, linkbuf); + if (error) + goto out; + + link_len = strlen(linkbuf); + len = strlen(cp); + + if (link_len + len > MAXPATHLEN + || ++nlinks > MAXSYMLINKS) { + error = ENOENT; + goto out; + } + + bcopy(cp, &namebuf[link_len], len + 1); + bcopy(linkbuf, namebuf, link_len); + + /* + * If absolute pathname, restart at root. + * If relative pathname, restart at parent directory. + */ + cp = namebuf; + if (*cp == '/') { + if (currfd != &nfs_root_node) + free(currfd, sizeof(*currfd)); + currfd = &nfs_root_node; + } + + free(newfd, sizeof(*newfd)); + newfd = 0; + + continue; + } + + if (currfd != &nfs_root_node) + free(currfd, sizeof(*currfd)); + currfd = newfd; + newfd = 0; + } + + error = 0; - /* lookup a file handle */ - error = nfs_lookupfh(&nfs_root_node, path, newfd); +out: if (!error) { - f->f_fsdata = (void *)newfd; + f->f_fsdata = (void *)currfd; return (0); } - + #ifdef NFS_DEBUG if (debug) printf("nfs_open: %s lookupfh failed: %s\n", - path, strerror(error)); + path, strerror(error)); #endif - free(newfd, sizeof(*newfd)); + if (currfd != &nfs_root_node) + free(currfd, sizeof(*currfd)); + if (newfd) + free(newfd, sizeof(*newfd)); + return (error); } diff --git a/sys/lib/libsa/nfs.h b/sys/lib/libsa/nfs.h index eb3e7826b64..53588045f24 100644 --- a/sys/lib/libsa/nfs.h +++ b/sys/lib/libsa/nfs.h @@ -1,5 +1,5 @@ -/* $OpenBSD: nfs.h,v 1.4 1996/11/27 19:52:23 niklas Exp $ */ -/* $NetBSD: nfs.h,v 1.4 1995/09/18 21:19:39 pk Exp $ */ +/* $OpenBSD: nfs.h,v 1.5 1996/12/08 15:15:53 niklas Exp $ */ +/* $NetBSD: nfs.h,v 1.5 1996/07/10 18:32:33 cgd Exp $ */ /*- * Copyright (c) 1993 diff --git a/sys/lib/libsa/nfsv2.h b/sys/lib/libsa/nfsv2.h new file mode 100644 index 00000000000..1d7d9d4c8f9 --- /dev/null +++ b/sys/lib/libsa/nfsv2.h @@ -0,0 +1,166 @@ +/* $NetBSD: nfsv2.h,v 1.2 1996/02/26 23:05:23 gwr Exp $ */ + +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Rick Macklem at The University of Guelph. + * + * 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 the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 THE REGENTS OR CONTRIBUTORS 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. + * + * @(#)nfsv2.h 8.1 (Berkeley) 6/10/93 + */ + +/* + * nfs definitions as per the version 2 specs + */ + +/* + * Constants as defined in the Sun NFS Version 2 spec. + * "NFS: Network File System Protocol Specification" RFC1094 + */ + +#define NFS_PORT 2049 +#define NFS_PROG 100003 +#define NFS_VER2 2 +#define NFS_MAXDGRAMDATA 8192 +#define NFS_MAXDATA 32768 +#define NFS_MAXPATHLEN 1024 +#define NFS_MAXNAMLEN 255 +#define NFS_FHSIZE 32 +#define NFS_MAXPKTHDR 404 +#define NFS_MAXPACKET (NFS_MAXPKTHDR+NFS_MAXDATA) +#define NFS_MINPACKET 20 +#define NFS_FABLKSIZE 512 /* Size in bytes of a block wrt fa_blocks */ + +/* Stat numbers for rpc returns */ +#define NFS_OK 0 +#define NFSERR_PERM 1 +#define NFSERR_NOENT 2 +#define NFSERR_IO 5 +#define NFSERR_NXIO 6 +#define NFSERR_ACCES 13 +#define NFSERR_EXIST 17 +#define NFSERR_NODEV 19 +#define NFSERR_NOTDIR 20 +#define NFSERR_ISDIR 21 +#define NFSERR_FBIG 27 +#define NFSERR_NOSPC 28 +#define NFSERR_ROFS 30 +#define NFSERR_NAMETOL 63 +#define NFSERR_NOTEMPTY 66 +#define NFSERR_DQUOT 69 +#define NFSERR_STALE 70 +#define NFSERR_WFLUSH 99 + +/* Sizes in bytes of various nfs rpc components */ +#define NFSX_FH 32 +#define NFSX_UNSIGNED 4 +#define NFSX_FATTR 68 +#define NFSX_SATTR 32 +#define NFSX_STATFS 20 +#define NFSX_COOKIE 4 + +/* nfs rpc procedure numbers */ +#define NFSPROC_NULL 0 +#define NFSPROC_GETATTR 1 +#define NFSPROC_SETATTR 2 +#define NFSPROC_NOOP 3 +#define NFSPROC_ROOT NFSPROC_NOOP /* Obsolete */ +#define NFSPROC_LOOKUP 4 +#define NFSPROC_READLINK 5 +#define NFSPROC_READ 6 +#define NFSPROC_WRITECACHE NFSPROC_NOOP /* Obsolete */ +#define NFSPROC_WRITE 8 +#define NFSPROC_CREATE 9 +#define NFSPROC_REMOVE 10 +#define NFSPROC_RENAME 11 +#define NFSPROC_LINK 12 +#define NFSPROC_SYMLINK 13 +#define NFSPROC_MKDIR 14 +#define NFSPROC_RMDIR 15 +#define NFSPROC_READDIR 16 +#define NFSPROC_STATFS 17 + +#define NFS_NPROCS 18 + + +/* File types */ +typedef enum { + NFNON=0, + NFREG=1, + NFDIR=2, + NFBLK=3, + NFCHR=4, + NFLNK=5 +} nfstype; + +/* Structs for common parts of the rpc's */ +struct nfsv2_time { + n_long nfs_sec; + n_long nfs_usec; +}; + +/* + * File attributes and setable attributes. + */ +struct nfsv2_fattr { + n_long fa_type; + n_long fa_mode; + n_long fa_nlink; + n_long fa_uid; + n_long fa_gid; + n_long fa_size; + n_long fa_blocksize; + n_long fa_rdev; + n_long fa_blocks; + n_long fa_fsid; + n_long fa_fileid; + struct nfsv2_time fa_atime; + struct nfsv2_time fa_mtime; + struct nfsv2_time fa_ctime; +}; + +struct nfsv2_sattr { + n_long sa_mode; + n_long sa_uid; + n_long sa_gid; + n_long sa_size; + struct nfsv2_time sa_atime; + struct nfsv2_time sa_mtime; +}; + +struct nfsv2_statfs { + n_long sf_tsize; + n_long sf_bsize; + n_long sf_blocks; + n_long sf_bfree; + n_long sf_bavail; +}; diff --git a/sys/lib/libsa/open.c b/sys/lib/libsa/open.c index 27c97a14e72..99cc9100ea6 100644 --- a/sys/lib/libsa/open.c +++ b/sys/lib/libsa/open.c @@ -1,5 +1,5 @@ -/* $OpenBSD: open.c,v 1.4 1996/09/23 14:19:01 mickey Exp $ */ -/* $NetBSD: open.c,v 1.10 1996/01/13 22:25:41 leo Exp $ */ +/* $OpenBSD: open.c,v 1.5 1996/12/08 15:15:54 niklas Exp $ */ +/* $NetBSD: open.c,v 1.12 1996/09/30 16:01:21 ws Exp $ */ /*- * Copyright (c) 1993 @@ -105,7 +105,7 @@ fnd: /* see if we opened a raw device; otherwise, 'file' is the file name. */ if (file == (char *)0 || *file == '\0') { f->f_flags |= F_RAW; - return (0); + return (fd); } /* pass file name to the different filesystem open routines */ @@ -120,6 +120,7 @@ fnd: if (!error) error = ENOENT; + f->f_dev->dv_close(f); err: f->f_flags = 0; errno = error; diff --git a/sys/lib/libsa/printf.c b/sys/lib/libsa/printf.c index 7bbab8e3b19..b5f6317ef02 100644 --- a/sys/lib/libsa/printf.c +++ b/sys/lib/libsa/printf.c @@ -1,5 +1,5 @@ -/* $OpenBSD: printf.c,v 1.5 1996/10/29 07:47:48 mickey Exp $ */ -/* $NetBSD: printf.c,v 1.7 1996/02/08 20:19:36 gwr Exp $ */ +/* $OpenBSD: printf.c,v 1.6 1996/12/08 15:15:54 niklas Exp $ */ +/* $NetBSD: printf.c,v 1.10 1996/11/30 04:19:21 gwr Exp $ */ /*- * Copyright (c) 1993 @@ -70,7 +70,7 @@ #include "stand.h" static void kprintn __P((void (*)(int), u_long, int)); -static void kprintf __P((void (*)(int), const char *, va_list)); +static void kdoprnt __P((void (*)(int), const char *, va_list)); #ifndef STRIPPED static void sputchar __P((int)); @@ -99,7 +99,7 @@ sprintf(buf, fmt, va_alist) #else va_start(ap); #endif - kprintf(sputchar, fmt, ap); + kdoprnt(sputchar, fmt, ap); va_end(ap); *sbuf = '\0'; } @@ -120,18 +120,18 @@ printf(fmt, va_alist) #else va_start(ap); #endif - kprintf(putchar, fmt, ap); + kdoprnt(putchar, fmt, ap); va_end(ap); } void vprintf(const char *fmt, va_list ap) { - kprintf(putchar, fmt, ap); + kdoprnt(putchar, fmt, ap); } static void -kprintf(put, fmt, ap) +kdoprnt(put, fmt, ap) void (*put)__P((int)); const char *fmt; va_list ap; diff --git a/sys/lib/libsa/rarp.c b/sys/lib/libsa/rarp.c index ad2efc61d7e..23196ecf769 100644 --- a/sys/lib/libsa/rarp.c +++ b/sys/lib/libsa/rarp.c @@ -1,5 +1,5 @@ -/* $OpenBSD: rarp.c,v 1.4 1996/10/16 14:26:46 mickey Exp $ */ -/* $NetBSD: rarp.c,v 1.10 1995/09/23 03:36:10 gwr Exp $ */ +/* $OpenBSD: rarp.c,v 1.5 1996/12/08 15:15:55 niklas Exp $ */ +/* $NetBSD: rarp.c,v 1.13 1996/10/13 02:29:05 christos Exp $ */ /* * Copyright (c) 1992 Regents of the University of California. diff --git a/sys/lib/libsa/read.c b/sys/lib/libsa/read.c index 3e12a716003..c1612521101 100644 --- a/sys/lib/libsa/read.c +++ b/sys/lib/libsa/read.c @@ -1,5 +1,5 @@ -/* $OpenBSD: read.c,v 1.2 1996/09/23 14:19:02 mickey Exp $ */ -/* $NetBSD: read.c,v 1.5 1995/09/14 23:45:35 pk Exp $ */ +/* $OpenBSD: read.c,v 1.3 1996/12/08 15:15:55 niklas Exp $ */ +/* $NetBSD: read.c,v 1.7 1996/06/21 20:29:28 pk Exp $ */ /*- * Copyright (c) 1993 @@ -65,6 +65,7 @@ * rights to redistribute these changes. */ +#include #include "stand.h" ssize_t @@ -83,9 +84,10 @@ read(fd, dest, bcount) if (f->f_flags & F_RAW) { twiddle(); errno = (f->f_dev->dv_strategy)(f->f_devdata, F_READ, - (daddr_t)0, bcount, dest, &resid); + btodb(f->f_offset), bcount, dest, &resid); if (errno) return (-1); + f->f_offset += resid; return (resid); } resid = bcount; diff --git a/sys/lib/libsa/rpc.c b/sys/lib/libsa/rpc.c index 818d28999b0..07583710c83 100644 --- a/sys/lib/libsa/rpc.c +++ b/sys/lib/libsa/rpc.c @@ -1,5 +1,5 @@ -/* $OpenBSD: rpc.c,v 1.6 1996/11/27 19:52:25 niklas Exp $ */ -/* $NetBSD: rpc.c,v 1.12 1996/02/26 23:05:26 gwr Exp $ */ +/* $OpenBSD: rpc.c,v 1.7 1996/12/08 15:15:56 niklas Exp $ */ +/* $NetBSD: rpc.c,v 1.16 1996/10/13 02:29:06 christos Exp $ */ /* * Copyright (c) 1992 Regents of the University of California. @@ -128,7 +128,7 @@ rpc_call(d, prog, vers, proc, sdata, slen, rdata, rlen) #ifdef RPC_DEBUG if (debug) printf("rpc_call: prog=0x%x vers=%d proc=%d\n", - prog, vers, proc); + prog, vers, proc); #endif port = rpc_getport(d, prog, vers); @@ -240,7 +240,7 @@ recvrpc(d, pkt, len, tleft) { register struct rpc_reply *reply; ssize_t n; - long x; + int x; errno = 0; #ifdef RPC_DEBUG @@ -319,8 +319,8 @@ rpc_fromaddr(pkt, addr, port) int rpc_pmap_num; struct pmap_list { struct in_addr addr; /* server, net order */ - u_long prog; /* host order */ - u_long vers; /* host order */ + u_int prog; /* host order */ + u_int vers; /* host order */ int port; /* host order */ } rpc_pmap_list[PMAP_NUM]; @@ -328,8 +328,8 @@ struct pmap_list { int rpc_pmap_getcache(addr, prog, vers) struct in_addr addr; /* server, net order */ - u_long prog; /* host order */ - u_long vers; /* host order */ + u_int prog; /* host order */ + u_int vers; /* host order */ { struct pmap_list *pl; @@ -346,8 +346,8 @@ rpc_pmap_getcache(addr, prog, vers) void rpc_pmap_putcache(addr, prog, vers, port) struct in_addr addr; /* server, net order */ - u_long prog; /* host order */ - u_long vers; /* host order */ + u_int prog; /* host order */ + u_int vers; /* host order */ int port; /* host order */ { struct pmap_list *pl; diff --git a/sys/lib/libsa/rpc.h b/sys/lib/libsa/rpc.h index 26105a605c1..70f57aa43c9 100644 --- a/sys/lib/libsa/rpc.h +++ b/sys/lib/libsa/rpc.h @@ -1,5 +1,5 @@ -/* $OpenBSD: rpc.h,v 1.2 1996/09/23 14:19:03 mickey Exp $ */ -/* $NetBSD: rpc.h,v 1.7 1995/09/23 03:36:12 gwr Exp $ */ +/* $OpenBSD: rpc.h,v 1.3 1996/12/08 15:15:56 niklas Exp $ */ +/* $NetBSD: rpc.h,v 1.8 1996/09/26 23:22:03 cgd Exp $ */ /* * Copyright (c) 1992 Regents of the University of California. @@ -53,8 +53,8 @@ ssize_t rpc_call __P((struct iodesc *, n_long, n_long, n_long, void *, size_t, void *, size_t)); void rpc_fromaddr __P((void *, struct in_addr *, u_short *)); -int rpc_pmap_getcache __P((struct in_addr, u_long, u_long)); -void rpc_pmap_putcache __P((struct in_addr, u_long, u_long, int)); +int rpc_pmap_getcache __P((struct in_addr, u_int, u_int)); +void rpc_pmap_putcache __P((struct in_addr, u_int, u_int, int)); extern int rpc_port; /* decrement before bind */ diff --git a/sys/lib/libsa/rpcv2.h b/sys/lib/libsa/rpcv2.h new file mode 100644 index 00000000000..e4d2dbeb628 --- /dev/null +++ b/sys/lib/libsa/rpcv2.h @@ -0,0 +1,89 @@ +/* $NetBSD: rpcv2.h,v 1.1 1996/02/26 23:05:32 gwr Exp $ */ + +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Rick Macklem at The University of Guelph. + * + * 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 the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 THE REGENTS OR CONTRIBUTORS 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. + * + * @(#)rpcv2.h 8.1 (Berkeley) 6/10/93 + */ + +/* + * Definitions for Sun RPC Version 2, from + * "RPC: Remote Procedure Call Protocol Specification" RFC1057 + */ + +/* Version # */ +#define RPC_VER2 2 + +/* Authentication */ +#define RPCAUTH_NULL 0 +#define RPCAUTH_UNIX 1 +#define RPCAUTH_SHORT 2 +#define RPCAUTH_MAXSIZ 400 +#define RPCAUTH_UNIXGIDS 16 + +/* Rpc Constants */ +#define RPC_CALL 0 +#define RPC_REPLY 1 +#define RPC_MSGACCEPTED 0 +#define RPC_MSGDENIED 1 +#define RPC_PROGUNAVAIL 1 +#define RPC_PROGMISMATCH 2 +#define RPC_PROCUNAVAIL 3 +#define RPC_GARBAGE 4 /* I like this one */ +#define RPC_MISMATCH 0 +#define RPC_AUTHERR 1 + +/* Authentication failures */ +#define AUTH_BADCRED 1 +#define AUTH_REJECTCRED 2 +#define AUTH_BADVERF 3 +#define AUTH_REJECTVERF 4 +#define AUTH_TOOWEAK 5 /* Give em wheaties */ + +/* Sizes of rpc header parts */ +#define RPC_SIZ 24 +#define RPC_REPLYSIZ 28 + +/* RPC Prog definitions */ +#define RPCPROG_MNT 100005 +#define RPCMNT_VER1 1 +#define RPCMNT_MOUNT 1 +#define RPCMNT_DUMP 2 +#define RPCMNT_UMOUNT 3 +#define RPCMNT_UMNTALL 4 +#define RPCMNT_EXPORT 5 +#define RPCMNT_NAMELEN 255 +#define RPCMNT_PATHLEN 1024 +#define RPCPROG_NFS 100003 diff --git a/sys/lib/libsa/stand.h b/sys/lib/libsa/stand.h index 0a26b276266..f81be0701d8 100644 --- a/sys/lib/libsa/stand.h +++ b/sys/lib/libsa/stand.h @@ -1,5 +1,5 @@ -/* $OpenBSD: stand.h,v 1.14 1996/11/27 11:59:43 mickey Exp $ */ -/* $NetBSD: stand.h,v 1.13 1996/01/13 22:25:42 leo Exp $ */ +/* $OpenBSD: stand.h,v 1.15 1996/12/08 15:15:57 niklas Exp $ */ +/* $NetBSD: stand.h,v 1.18 1996/11/30 04:35:51 gwr Exp $ */ /*- * Copyright (c) 1993 @@ -114,6 +114,7 @@ struct open_file { void *f_devdata; /* device specific data */ struct fs_ops *f_ops; /* pointer to file system operations */ void *f_fsdata; /* file system specific data */ + off_t f_offset; /* current file offset (F_RAW) */ }; #define SOPEN_MAX 4 @@ -146,7 +147,7 @@ u_int dkcksum __P((struct disklabel *)); void printf __P((const char *, ...)); void sprintf __P((char *, const char *, ...)); -void vprintf __P((const char *format, va_list ap)); +void vprintf __P((const char *, _BSD_VA_LIST_)); void twiddle __P((void)); void gets __P((char *)); __dead void panic __P((const char *, ...)) __attribute__((noreturn)); diff --git a/sys/lib/libsa/strerror.c b/sys/lib/libsa/strerror.c index 646b7aad38b..b1b61ab9084 100644 --- a/sys/lib/libsa/strerror.c +++ b/sys/lib/libsa/strerror.c @@ -1,5 +1,5 @@ -/* $OpenBSD: strerror.c,v 1.3 1996/09/23 14:19:05 mickey Exp $ */ -/* $NetBSD: strerror.c,v 1.8 1995/09/17 00:49:47 pk Exp $ */ +/* $OpenBSD: strerror.c,v 1.4 1996/12/08 15:15:58 niklas Exp $ */ +/* $NetBSD: strerror.c,v 1.11 1996/10/13 02:29:08 christos Exp $ */ /*- * Copyright (c) 1993 diff --git a/sys/lib/libsa/ufs.c b/sys/lib/libsa/ufs.c index 86082cf053d..8adb7048477 100644 --- a/sys/lib/libsa/ufs.c +++ b/sys/lib/libsa/ufs.c @@ -1,5 +1,5 @@ -/* $OpenBSD: ufs.c,v 1.7 1996/10/16 14:02:55 mickey Exp $ */ -/* $NetBSD: ufs.c,v 1.14.4.1 1996/06/02 12:08:45 ragge Exp $ */ +/* $OpenBSD: ufs.c,v 1.8 1996/12/08 15:15:58 niklas Exp $ */ +/* $NetBSD: ufs.c,v 1.16 1996/09/30 16:01:22 ws Exp $ */ /*- * Copyright (c) 1993 @@ -556,8 +556,10 @@ ufs_open(path, f) out: if (buf) free(buf, fs->fs_bsize); - if (rc) + if (rc) { + free(fp->f_fs, SBSIZE); free(fp, sizeof(struct file)); + } return (rc); } diff --git a/sys/lib/libsa/write.c b/sys/lib/libsa/write.c index 38afa8abb32..ead77c74710 100644 --- a/sys/lib/libsa/write.c +++ b/sys/lib/libsa/write.c @@ -1,5 +1,5 @@ -/* $OpenBSD: write.c,v 1.2 1996/09/23 14:19:07 mickey Exp $ */ -/* $NetBSD: write.c,v 1.5 1995/09/14 23:45:41 pk Exp $ */ +/* $OpenBSD: write.c,v 1.3 1996/12/08 15:15:59 niklas Exp $ */ +/* $NetBSD: write.c,v 1.7 1996/06/21 20:29:30 pk Exp $ */ /*- * Copyright (c) 1993 @@ -65,6 +65,7 @@ * rights to redistribute these changes. */ +#include #include "stand.h" ssize_t @@ -83,9 +84,10 @@ write(fd, dest, bcount) if (f->f_flags & F_RAW) { twiddle(); errno = (f->f_dev->dv_strategy)(f->f_devdata, F_WRITE, - (daddr_t)0, bcount, dest, &resid); + btodb(f->f_offset), bcount, dest, &resid); if (errno) return (-1); + f->f_offset += resid; return (resid); } resid = bcount;