Deleted Added
full compact
nfs.c (252700) nfs.c (252701)
1/* $NetBSD: nfs.c,v 1.2 1998/01/24 12:43:09 drochner Exp $ */
2
3/*-
4 * Copyright (c) 1993 John Brezak
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 15 unchanged lines hidden (view full) ---

24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#include <sys/cdefs.h>
1/* $NetBSD: nfs.c,v 1.2 1998/01/24 12:43:09 drochner Exp $ */
2
3/*-
4 * Copyright (c) 1993 John Brezak
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 15 unchanged lines hidden (view full) ---

24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#include <sys/cdefs.h>
32__FBSDID("$FreeBSD: stable/9/lib/libstand/nfs.c 252700 2013-07-04 15:19:45Z mav $");
32__FBSDID("$FreeBSD: stable/9/lib/libstand/nfs.c 252701 2013-07-04 15:21:27Z mav $");
33
34#include <sys/param.h>
35#include <sys/time.h>
36#include <sys/socket.h>
37#include <sys/stat.h>
38#include <string.h>
39
40#include <netinet/in.h>

--- 135 unchanged lines hidden (view full) ---

176};
177
178struct nfs_iodesc {
179 struct iodesc *iodesc;
180 off_t off;
181 uint32_t fhsize;
182 u_char fh[NFS_V3MAXFHSIZE];
183 struct nfsv3_fattrs fa; /* all in network order */
33
34#include <sys/param.h>
35#include <sys/time.h>
36#include <sys/socket.h>
37#include <sys/stat.h>
38#include <string.h>
39
40#include <netinet/in.h>

--- 135 unchanged lines hidden (view full) ---

176};
177
178struct nfs_iodesc {
179 struct iodesc *iodesc;
180 off_t off;
181 uint32_t fhsize;
182 u_char fh[NFS_V3MAXFHSIZE];
183 struct nfsv3_fattrs fa; /* all in network order */
184 uint64_t cookie;
184};
185#endif /* OLD_NFSV2 */
186
187/*
188 * XXX interactions with tftp? See nfswrapper.c for a confusing
189 * issue.
190 */
191int nfs_open(const char *path, struct open_file *f);

--- 558 unchanged lines hidden (view full) ---

750static int
751nfs_readdir(struct open_file *f, struct dirent *d)
752{
753 struct nfs_iodesc *fp = (struct nfs_iodesc *)f->f_fsdata;
754 struct nfs_readdir_args *args;
755 struct nfs_readdir_data *rd;
756 struct nfs_readdir_off *roff = NULL;
757 static char *buf;
185};
186#endif /* OLD_NFSV2 */
187
188/*
189 * XXX interactions with tftp? See nfswrapper.c for a confusing
190 * issue.
191 */
192int nfs_open(const char *path, struct open_file *f);

--- 558 unchanged lines hidden (view full) ---

751static int
752nfs_readdir(struct open_file *f, struct dirent *d)
753{
754 struct nfs_iodesc *fp = (struct nfs_iodesc *)f->f_fsdata;
755 struct nfs_readdir_args *args;
756 struct nfs_readdir_data *rd;
757 struct nfs_readdir_off *roff = NULL;
758 static char *buf;
759 static struct nfs_iodesc *pfp = NULL;
758 static n_long cookie = 0;
759 size_t cc;
760 n_long eof;
761
762 struct {
763 n_long h[RPC_HEADER_WORDS];
764 struct nfs_readdir_args d;
765 } sdata;
766 static struct {
767 n_long h[RPC_HEADER_WORDS];
768 u_char d[NFS_READDIRSIZE];
769 } rdata;
770
760 static n_long cookie = 0;
761 size_t cc;
762 n_long eof;
763
764 struct {
765 n_long h[RPC_HEADER_WORDS];
766 struct nfs_readdir_args d;
767 } sdata;
768 static struct {
769 n_long h[RPC_HEADER_WORDS];
770 u_char d[NFS_READDIRSIZE];
771 } rdata;
772
771 if (cookie == 0) {
773 if (fp != pfp || fp->off != cookie) {
774 pfp = NULL;
772 refill:
773 args = &sdata.d;
774 bzero(args, sizeof(*args));
775
776 bcopy(fp->fh, args->fh, NFS_FHSIZE);
775 refill:
776 args = &sdata.d;
777 bzero(args, sizeof(*args));
778
779 bcopy(fp->fh, args->fh, NFS_FHSIZE);
777 args->cookie = htonl(cookie);
780 args->cookie = htonl(fp->off);
778 args->count = htonl(NFS_READDIRSIZE);
779
780 cc = rpc_call(fp->iodesc, NFS_PROG, NFS_VER2, NFSPROC_READDIR,
781 args, sizeof(*args),
782 rdata.d, sizeof(rdata.d));
783 buf = rdata.d;
784 roff = (struct nfs_readdir_off *)buf;
785 if (ntohl(roff->cookie) != 0)
786 return EIO;
781 args->count = htonl(NFS_READDIRSIZE);
782
783 cc = rpc_call(fp->iodesc, NFS_PROG, NFS_VER2, NFSPROC_READDIR,
784 args, sizeof(*args),
785 rdata.d, sizeof(rdata.d));
786 buf = rdata.d;
787 roff = (struct nfs_readdir_off *)buf;
788 if (ntohl(roff->cookie) != 0)
789 return EIO;
790 pfp = fp;
791 cookie = fp->off;
787 }
788 roff = (struct nfs_readdir_off *)buf;
789
790 if (ntohl(roff->follows) == 0) {
791 eof = ntohl((roff+1)->cookie);
792 if (eof) {
793 cookie = 0;
794 return ENOENT;

--- 4 unchanged lines hidden (view full) ---

799 buf += sizeof(struct nfs_readdir_off);
800 rd = (struct nfs_readdir_data *)buf;
801 d->d_namlen = ntohl(rd->len);
802 bcopy(rd->name, d->d_name, d->d_namlen);
803 d->d_name[d->d_namlen] = '\0';
804
805 buf += (sizeof(struct nfs_readdir_data) + roundup(htonl(rd->len),4));
806 roff = (struct nfs_readdir_off *)buf;
792 }
793 roff = (struct nfs_readdir_off *)buf;
794
795 if (ntohl(roff->follows) == 0) {
796 eof = ntohl((roff+1)->cookie);
797 if (eof) {
798 cookie = 0;
799 return ENOENT;

--- 4 unchanged lines hidden (view full) ---

804 buf += sizeof(struct nfs_readdir_off);
805 rd = (struct nfs_readdir_data *)buf;
806 d->d_namlen = ntohl(rd->len);
807 bcopy(rd->name, d->d_name, d->d_namlen);
808 d->d_name[d->d_namlen] = '\0';
809
810 buf += (sizeof(struct nfs_readdir_data) + roundup(htonl(rd->len),4));
811 roff = (struct nfs_readdir_off *)buf;
807 cookie = ntohl(roff->cookie);
812 fp->off = cookie = ntohl(roff->cookie);
808 return 0;
809}
810#else /* !OLD_NFSV2 */
811/*
812 * Fetch the root file handle (call mount daemon)
813 * Return zero or error number.
814 */
815int

--- 439 unchanged lines hidden (view full) ---

1255 free(path);
1256#else
1257 currfd->iodesc = desc;
1258
1259 error = nfs_lookupfh(&nfs_root_node, upath, currfd);
1260#endif
1261 if (!error) {
1262 currfd->off = 0;
813 return 0;
814}
815#else /* !OLD_NFSV2 */
816/*
817 * Fetch the root file handle (call mount daemon)
818 * Return zero or error number.
819 */
820int

--- 439 unchanged lines hidden (view full) ---

1260 free(path);
1261#else
1262 currfd->iodesc = desc;
1263
1264 error = nfs_lookupfh(&nfs_root_node, upath, currfd);
1265#endif
1266 if (!error) {
1267 currfd->off = 0;
1268 currfd->cookie = 0;
1263 f->f_fsdata = (void *)currfd;
1264 return (0);
1265 }
1266
1267#ifdef NFS_DEBUG
1268 if (debug)
1269 printf("nfs_open: %s lookupfh failed: %s\n",
1270 path, strerror(error));

--- 122 unchanged lines hidden (view full) ---

1393
1394static int
1395nfs_readdir(struct open_file *f, struct dirent *d)
1396{
1397 struct nfs_iodesc *fp = (struct nfs_iodesc *)f->f_fsdata;
1398 struct nfsv3_readdir_repl *repl;
1399 struct nfsv3_readdir_entry *rent;
1400 static char *buf;
1269 f->f_fsdata = (void *)currfd;
1270 return (0);
1271 }
1272
1273#ifdef NFS_DEBUG
1274 if (debug)
1275 printf("nfs_open: %s lookupfh failed: %s\n",
1276 path, strerror(error));

--- 122 unchanged lines hidden (view full) ---

1399
1400static int
1401nfs_readdir(struct open_file *f, struct dirent *d)
1402{
1403 struct nfs_iodesc *fp = (struct nfs_iodesc *)f->f_fsdata;
1404 struct nfsv3_readdir_repl *repl;
1405 struct nfsv3_readdir_entry *rent;
1406 static char *buf;
1401 static uint32_t cookie0 = 0;
1402 static uint32_t cookie1 = 0;
1407 static struct nfs_iodesc *pfp = NULL;
1408 static uint64_t cookie = 0;
1403 size_t cc;
1409 size_t cc;
1404 static uint32_t cookieverf0 = 0;
1405 static uint32_t cookieverf1 = 0;
1406 int pos;
1407
1408 struct args {
1409 uint32_t fhsize;
1410 uint32_t fhpluscookie[5 + NFS_V3MAXFHSIZE];
1411 } *args;
1412 struct {
1413 uint32_t h[RPC_HEADER_WORDS];
1414 struct args d;
1415 } sdata;
1416 static struct {
1417 uint32_t h[RPC_HEADER_WORDS];
1418 u_char d[NFS_READDIRSIZE];
1419 } rdata;
1420
1410 int pos;
1411
1412 struct args {
1413 uint32_t fhsize;
1414 uint32_t fhpluscookie[5 + NFS_V3MAXFHSIZE];
1415 } *args;
1416 struct {
1417 uint32_t h[RPC_HEADER_WORDS];
1418 struct args d;
1419 } sdata;
1420 static struct {
1421 uint32_t h[RPC_HEADER_WORDS];
1422 u_char d[NFS_READDIRSIZE];
1423 } rdata;
1424
1421 if (cookie0 == 0 && cookie1 == 0) {
1425 if (fp != pfp || fp->off != cookie) {
1426 pfp = NULL;
1422 refill:
1423 args = &sdata.d;
1424 bzero(args, sizeof(*args));
1425
1426 args->fhsize = htonl(fp->fhsize);
1427 bcopy(fp->fh, args->fhpluscookie, fp->fhsize);
1428 pos = roundup(fp->fhsize, sizeof(uint32_t)) / sizeof(uint32_t);
1427 refill:
1428 args = &sdata.d;
1429 bzero(args, sizeof(*args));
1430
1431 args->fhsize = htonl(fp->fhsize);
1432 bcopy(fp->fh, args->fhpluscookie, fp->fhsize);
1433 pos = roundup(fp->fhsize, sizeof(uint32_t)) / sizeof(uint32_t);
1429 args->fhpluscookie[pos++] = cookie0;
1430 args->fhpluscookie[pos++] = cookie1;
1431 args->fhpluscookie[pos++] = cookieverf0;
1432 args->fhpluscookie[pos++] = cookieverf1;
1434 args->fhpluscookie[pos++] = htonl(fp->off >> 32);
1435 args->fhpluscookie[pos++] = htonl(fp->off);
1436 args->fhpluscookie[pos++] = htonl(fp->cookie >> 32);
1437 args->fhpluscookie[pos++] = htonl(fp->cookie);
1433 args->fhpluscookie[pos] = htonl(NFS_READDIRSIZE);
1434
1435 cc = rpc_call(fp->iodesc, NFS_PROG, NFS_VER3, NFSPROCV3_READDIR,
1436 args, 6 * sizeof(uint32_t) +
1437 roundup(fp->fhsize, sizeof(uint32_t)),
1438 rdata.d, sizeof(rdata.d));
1439 buf = rdata.d;
1440 repl = (struct nfsv3_readdir_repl *)buf;
1441 if (repl->errno != 0)
1442 return (ntohl(repl->errno));
1438 args->fhpluscookie[pos] = htonl(NFS_READDIRSIZE);
1439
1440 cc = rpc_call(fp->iodesc, NFS_PROG, NFS_VER3, NFSPROCV3_READDIR,
1441 args, 6 * sizeof(uint32_t) +
1442 roundup(fp->fhsize, sizeof(uint32_t)),
1443 rdata.d, sizeof(rdata.d));
1444 buf = rdata.d;
1445 repl = (struct nfsv3_readdir_repl *)buf;
1446 if (repl->errno != 0)
1447 return (ntohl(repl->errno));
1443 cookieverf0 = repl->cookiev0;
1444 cookieverf1 = repl->cookiev1;
1448 pfp = fp;
1449 cookie = fp->off;
1450 fp->cookie = ((uint64_t)ntohl(repl->cookiev0) << 32) |
1451 ntohl(repl->cookiev1);
1445 buf += sizeof (struct nfsv3_readdir_repl);
1446 }
1447 rent = (struct nfsv3_readdir_entry *)buf;
1448
1449 if (rent->follows == 0) {
1450 /* fid0 is actually eof */
1451 if (rent->fid0 != 0) {
1452 buf += sizeof (struct nfsv3_readdir_repl);
1453 }
1454 rent = (struct nfsv3_readdir_entry *)buf;
1455
1456 if (rent->follows == 0) {
1457 /* fid0 is actually eof */
1458 if (rent->fid0 != 0) {
1452 cookie0 = 0;
1453 cookie1 = 0;
1454 cookieverf0 = 0;
1455 cookieverf1 = 0;
1459 cookie = 0;
1456 return (ENOENT);
1457 }
1458 goto refill;
1459 }
1460
1461 d->d_namlen = ntohl(rent->len);
1462 bcopy(rent->nameplus, d->d_name, d->d_namlen);
1463 d->d_name[d->d_namlen] = '\0';
1464
1465 pos = roundup(d->d_namlen, sizeof(uint32_t)) / sizeof(uint32_t);
1460 return (ENOENT);
1461 }
1462 goto refill;
1463 }
1464
1465 d->d_namlen = ntohl(rent->len);
1466 bcopy(rent->nameplus, d->d_name, d->d_namlen);
1467 d->d_name[d->d_namlen] = '\0';
1468
1469 pos = roundup(d->d_namlen, sizeof(uint32_t)) / sizeof(uint32_t);
1466 cookie0 = rent->nameplus[pos++];
1467 cookie1 = rent->nameplus[pos++];
1470 fp->off = cookie = ((uint64_t)ntohl(rent->nameplus[pos]) << 32) |
1471 ntohl(rent->nameplus[pos + 1]);
1472 pos += 2;
1468 buf = (u_char *)&rent->nameplus[pos];
1469 return (0);
1470}
1471#endif /* OLD_NFSV2 */
1473 buf = (u_char *)&rent->nameplus[pos];
1474 return (0);
1475}
1476#endif /* OLD_NFSV2 */