Deleted Added
full compact
nfs.c (59824) nfs.c (59853)
1/* $FreeBSD: head/lib/libstand/nfs.c 59824 2000-05-01 10:53:21Z ps $ */
1/* $FreeBSD: head/lib/libstand/nfs.c 59853 2000-05-01 15:03:52Z ps $ */
2/* $NetBSD: nfs.c,v 1.2 1998/01/24 12:43:09 drochner Exp $ */
3
4/*-
5 * Copyright (c) 1993 John Brezak
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions

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

86#ifndef NFS_NOSYMLINK
87struct nfs_readlnk_repl {
88 n_long errno;
89 n_long len;
90 char path[NFS_MAXPATHLEN];
91};
92#endif
93
2/* $NetBSD: nfs.c,v 1.2 1998/01/24 12:43:09 drochner Exp $ */
3
4/*-
5 * Copyright (c) 1993 John Brezak
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions

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

86#ifndef NFS_NOSYMLINK
87struct nfs_readlnk_repl {
88 n_long errno;
89 n_long len;
90 char path[NFS_MAXPATHLEN];
91};
92#endif
93
94struct nfs_readdir_args {
95 u_char fh[NFS_FHSIZE];
96 n_long cookie;
97 n_long count;
98};
99
100struct nfs_readdir_data {
101 n_long fileid;
102 n_long len;
103 char name[0];
104};
105
106struct nfs_readdir_off {
107 n_long cookie;
108 n_long follows;
109};
110
94struct nfs_iodesc {
95 struct iodesc *iodesc;
96 off_t off;
97 u_char fh[NFS_FHSIZE];
98 struct nfsv2_fattrs fa; /* all in network order */
99};
100
101/*
102 * XXX interactions with tftp? See nfswrapper.c for a confusing
103 * issue.
104 */
105int nfs_open(const char *path, struct open_file *f);
106static int nfs_close(struct open_file *f);
107static int nfs_read(struct open_file *f, void *buf, size_t size, size_t *resid);
108static int nfs_write(struct open_file *f, void *buf, size_t size, size_t *resid);
109static off_t nfs_seek(struct open_file *f, off_t offset, int where);
110static int nfs_stat(struct open_file *f, struct stat *sb);
111struct nfs_iodesc {
112 struct iodesc *iodesc;
113 off_t off;
114 u_char fh[NFS_FHSIZE];
115 struct nfsv2_fattrs fa; /* all in network order */
116};
117
118/*
119 * XXX interactions with tftp? See nfswrapper.c for a confusing
120 * issue.
121 */
122int nfs_open(const char *path, struct open_file *f);
123static int nfs_close(struct open_file *f);
124static int nfs_read(struct open_file *f, void *buf, size_t size, size_t *resid);
125static int nfs_write(struct open_file *f, void *buf, size_t size, size_t *resid);
126static off_t nfs_seek(struct open_file *f, off_t offset, int where);
127static int nfs_stat(struct open_file *f, struct stat *sb);
128static int nfs_readdir(struct open_file *f, struct dirent *d);
111
112static struct nfs_iodesc nfs_root_node;
113
114struct fs_ops nfs_fsops = {
115 "nfs",
116 nfs_open,
117 nfs_close,
118 nfs_read,
119 nfs_write,
120 nfs_seek,
121 nfs_stat,
129
130static struct nfs_iodesc nfs_root_node;
131
132struct fs_ops nfs_fsops = {
133 "nfs",
134 nfs_open,
135 nfs_close,
136 nfs_read,
137 nfs_write,
138 nfs_seek,
139 nfs_stat,
122 null_readdir
140 nfs_readdir
123};
124
125/*
126 * Fetch the root file handle (call mount daemon)
127 * Return zero or error number.
128 */
129int
130nfs_getrootfh(d, path, fhp)

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

660 sb->st_mode = mode;
661 sb->st_nlink = ntohl(fp->fa.fa_nlink);
662 sb->st_uid = ntohl(fp->fa.fa_uid);
663 sb->st_gid = ntohl(fp->fa.fa_gid);
664 sb->st_size = ntohl(fp->fa.fa_size);
665
666 return (0);
667}
141};
142
143/*
144 * Fetch the root file handle (call mount daemon)
145 * Return zero or error number.
146 */
147int
148nfs_getrootfh(d, path, fhp)

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

678 sb->st_mode = mode;
679 sb->st_nlink = ntohl(fp->fa.fa_nlink);
680 sb->st_uid = ntohl(fp->fa.fa_uid);
681 sb->st_gid = ntohl(fp->fa.fa_gid);
682 sb->st_size = ntohl(fp->fa.fa_size);
683
684 return (0);
685}
686
687static int
688nfs_readdir(struct open_file *f, struct dirent *d)
689{
690 register struct nfs_iodesc *fp = (struct nfs_iodesc *)f->f_fsdata;
691 struct nfs_readdir_args *args;
692 struct nfs_readdir_data *rd;
693 struct nfs_readdir_off *roff = NULL;
694 static char *buf;
695 static n_long cookie = 0;
696 size_t cc;
697 n_long eof;
698
699 struct {
700 n_long h[RPC_HEADER_WORDS];
701 struct nfs_readdir_args d;
702 } sdata;
703 static struct {
704 n_long h[RPC_HEADER_WORDS];
705 u_char d[NFS_READDIRSIZE];
706 } rdata;
707
708 if (cookie == 0) {
709 refill:
710 args = &sdata.d;
711 bzero(args, sizeof(*args));
712
713 bcopy(fp->fh, args->fh, NFS_FHSIZE);
714 args->cookie = htonl(cookie);
715 args->count = htonl(NFS_READDIRSIZE);
716
717 cc = rpc_call(fp->iodesc, NFS_PROG, NFS_VER2, NFSPROC_READDIR,
718 args, sizeof(*args),
719 rdata.d, sizeof(rdata.d));
720 buf = rdata.d;
721 roff = (struct nfs_readdir_off *)buf;
722 if (ntohl(roff->cookie) != 0)
723 return 1;
724 }
725 roff = (struct nfs_readdir_off *)buf;
726
727 if (ntohl(roff->follows) == 0) {
728 eof = ntohl((roff+1)->cookie);
729 if (eof) {
730 cookie = 0;
731 return 1;
732 }
733 goto refill;
734 }
735
736 buf += sizeof(struct nfs_readdir_off);
737 rd = (struct nfs_readdir_data *)buf;
738 d->d_namlen = ntohl(rd->len);
739 bcopy(rd->name, d->d_name, d->d_namlen);
740 d->d_name[d->d_namlen] = '\0';
741
742 buf += (sizeof(struct nfs_readdir_data) + roundup(htonl(rd->len),4));
743 roff = (struct nfs_readdir_off *)buf;
744 cookie = ntohl(roff->cookie);
745 return 0;
746}