⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nfs_xdr.c

📁 <B>Digital的Unix操作系统VAX 4.2源码</B>
💻 C
📖 第 1 页 / 共 2 页
字号:
#ifndef lintstatic	char	*sccsid = "@(#)nfs_xdr.c	4.1	(ULTRIX)	7/2/90";#endif lint/************************************************************************ *									* *			Copyright (c) 1986 by				* *		Digital Equipment Corporation, Maynard, MA		* *			All rights reserved.				* *									* *   This software is furnished under a license and may be used and	* *   copied  only  in accordance with the terms of such license and	* *   with the  inclusion  of  the  above  copyright  notice.   This	* *   software  or  any  other copies thereof may not be provided or	* *   otherwise made available to any other person.  No title to and	* *   ownership of the software is hereby transferred.			* *									* *   This software is  derived  from  software  received  from  the	* *   University    of   California,   Berkeley,   and   from   Bell	* *   Laboratories.  Use, duplication, or disclosure is  subject  to	* *   restrictions  under  license  agreements  with  University  of	* *   California and with AT&T.						* *									* *   The information in this software is subject to change  without	* *   notice  and should not be construed as a commitment by Digital	* *   Equipment Corporation.						* *									* *   Digital assumes no responsibility for the use  or  reliability	* *   of its software on equipment which is not supplied by Digital.	* *									* ************************************************************************//* *	Portions of this software have been licensed to  *	Digital Equipment Company, Maynard, MA. *	Copyright (c) 1986 Sun Microsystems, Inc.  ALL RIGHTS RESERVED. *//* * *   Modification history: * * 28 Aug 89 -- condylis *	Added SMP locking around sleep/wakeup mechanism for *	returning of type 2 mbuf data in rrokfree() and rrokwakeup(). */#include "../h/param.h"#include "../h/mount.h"#include "../h/systm.h"#include "../h/user.h"#include "../h/file.h"#include "../h/dir.h"#include "../h/mbuf.h"#include "../h/fs_types.h"#include "../h/smp_lock.h"#include "../net/netinet/in.h"#include "../nfs/nfs_clnt.h"#include "../net/rpc/types.h"#include "../net/rpc/xdr.h"#include "../nfs/nfs.h"#include "../nfs/vfs.h"#include "../nfs/vnode.h"#ifdef GFSDEBUGextern short GFS[];#endif#ifdef NFSDEBUGextern int nfsdebug;char *xdropnames[] = {"encode", "decode", "free"};#endif/* * SMP lock for sleep/wakeup mechanism around releasing of * type 2 mbuf data by networking code. */struct	lock_t	lk_nfsrrok;/* * These are the XDR routines used to serialize and deserialize * the various structures passed as parameters accross the network * between NFS clients and servers. *//* * File access handle * The fhandle struct is treated a opaque data on the wire */bool_txdr_fhandle(xdrs, fh)	XDR *xdrs;	fhandle_t *fh;{	if (xdr_opaque(xdrs, (caddr_t)fh, NFS_FHSIZE)) {#ifdef NFSDEBUG		dprint(nfsdebug, 6, "xdr_fhandle: %s %o %d\n",		    xdropnames[(int)xdrs->x_op], fh->fh_fsid, fh->fh_fno);#endif		return (TRUE);	}#ifdef NFSDEBUG	dprint(nfsdebug, 2, "xdr_fhandle %s FAILED\n",	    xdropnames[(int)xdrs->x_op]);#endif	return (FALSE);}/* * Arguments to remote write and writecache */bool_txdr_writeargs(xdrs, wa)	XDR *xdrs;	struct nfswriteargs *wa;{	if (xdr_fhandle(xdrs, &wa->wa_fhandle) &&	    xdr_long(xdrs, (long *)&wa->wa_begoff) &&	    xdr_long(xdrs, (long *)&wa->wa_offset) &&	    xdr_long(xdrs, (long *)&wa->wa_totcount) &&	    xdr_bytes(xdrs, &wa->wa_data, (u_int *)&wa->wa_count,	      NFS_MAXDATA) ) {#ifdef NFSDEBUG		dprint(nfsdebug, 6, "xdr_writeargs: %s off %d ct %d\n",		    xdropnames[(int)xdrs->x_op],		    wa->wa_offset, wa->wa_totcount);#endif		return (TRUE);	}#ifdef NFSDEBUG	dprint(nfsdebug, 2, "xdr_writeargs: %s FAILED\n",	    xdropnames[(int)xdrs->x_op]);#endif	return (FALSE);}/* * File attributes */bool_txdr_fattr(xdrs, na)	XDR *xdrs;	register struct nfsfattr *na;{	register long *ptr;#ifdef NFSDEBUG	dprint(nfsdebug, 6, "xdr_fattr: %s\n",	    xdropnames[(int)xdrs->x_op]);#endif	if (xdrs->x_op == XDR_ENCODE) {		ptr = XDR_INLINE(xdrs, 17 * BYTES_PER_XDR_UNIT);		if (ptr != NULL) {			IXDR_PUT_ENUM(ptr, na->na_type);			IXDR_PUT_LONG(ptr, na->na_mode);			IXDR_PUT_LONG(ptr, na->na_nlink);			IXDR_PUT_LONG(ptr, na->na_uid);			IXDR_PUT_LONG(ptr, na->na_gid);			IXDR_PUT_LONG(ptr, na->na_size);			IXDR_PUT_LONG(ptr, na->na_blocksize);			IXDR_PUT_LONG(ptr, na->na_rdev);			IXDR_PUT_LONG(ptr, na->na_blocks);			IXDR_PUT_LONG(ptr, na->na_fsid);			IXDR_PUT_LONG(ptr, na->na_nodeid);			IXDR_PUT_LONG(ptr, na->na_atime.tv_sec);			IXDR_PUT_LONG(ptr, na->na_atime.tv_usec);			IXDR_PUT_LONG(ptr, na->na_mtime.tv_sec);			IXDR_PUT_LONG(ptr, na->na_mtime.tv_usec);			IXDR_PUT_LONG(ptr, na->na_ctime.tv_sec);			IXDR_PUT_LONG(ptr, na->na_ctime.tv_usec);			return (TRUE);		}	} else {		ptr = XDR_INLINE(xdrs, 17 * BYTES_PER_XDR_UNIT);		if (ptr != NULL) {			na->na_type = IXDR_GET_ENUM(ptr, enum nfsftype);			na->na_mode = IXDR_GET_LONG(ptr);			na->na_nlink = IXDR_GET_LONG(ptr);			na->na_uid = IXDR_GET_LONG(ptr);			na->na_gid = IXDR_GET_LONG(ptr);			na->na_size = IXDR_GET_LONG(ptr);			na->na_blocksize = IXDR_GET_LONG(ptr);			na->na_rdev = IXDR_GET_LONG(ptr);			na->na_blocks = IXDR_GET_LONG(ptr);			na->na_fsid = IXDR_GET_LONG(ptr);			na->na_nodeid = IXDR_GET_LONG(ptr);			na->na_atime.tv_sec = IXDR_GET_LONG(ptr);			na->na_atime.tv_usec = IXDR_GET_LONG(ptr);			na->na_mtime.tv_sec = IXDR_GET_LONG(ptr);			na->na_mtime.tv_usec = IXDR_GET_LONG(ptr);			na->na_ctime.tv_sec = IXDR_GET_LONG(ptr);			na->na_ctime.tv_usec = IXDR_GET_LONG(ptr);			return (TRUE);		}	}	if (xdr_enum(xdrs, (enum_t *)&na->na_type) &&	    xdr_u_long(xdrs, &na->na_mode) &&	    xdr_u_long(xdrs, &na->na_nlink) &&	    xdr_u_long(xdrs, &na->na_uid) &&	    xdr_u_long(xdrs, &na->na_gid) &&	    xdr_u_long(xdrs, &na->na_size) &&	    xdr_u_long(xdrs, &na->na_blocksize) &&	    xdr_u_long(xdrs, &na->na_rdev) &&	    xdr_u_long(xdrs, &na->na_blocks) &&	    xdr_u_long(xdrs, &na->na_fsid) &&	    xdr_u_long(xdrs, &na->na_nodeid) &&	    xdr_timeval(xdrs, &na->na_atime) &&	    xdr_timeval(xdrs, &na->na_mtime) &&	    xdr_timeval(xdrs, &na->na_ctime) ) {		return (TRUE);	}#ifdef NFSDEBUG	dprint(nfsdebug, 2, "xdr_fattr: %s FAILED\n",	    xdropnames[(int)xdrs->x_op]);#endif	return (FALSE);}/* * Arguments to remote read */bool_txdr_readargs(xdrs, ra)	XDR *xdrs;	struct nfsreadargs *ra;{	if (xdr_fhandle(xdrs, &ra->ra_fhandle) &&	    xdr_long(xdrs, (long *)&ra->ra_offset) &&	    xdr_long(xdrs, (long *)&ra->ra_count) &&	    xdr_long(xdrs, (long *)&ra->ra_totcount) ) {#ifdef NFSDEBUG		dprint(nfsdebug, 6, "xdr_readargs: %s off %d ct %d\n",		    xdropnames[(int)xdrs->x_op],		    ra->ra_offset, ra->ra_totcount);#endif		return (TRUE);	}#ifdef NFSDEBUG	dprint(nfsdebug, 2, "xdr_raedargs: %s FAILED\n",	    xdropnames[(int)xdrs->x_op]);#endif	return (FALSE);}/* * Info necessary to free the bp which is also an mbuf */struct rrokinfo {	int	(*func)();	int	done;	struct vnode *vp;	struct buf *bp;};	staticrrokfree(rip)	struct rrokinfo *rip;{	int s;	struct mbuf *n;	s = splimp();	smp_lock(&lk_nfsrrok, LK_RETRY);	while (rip->done == 0) {		sleep_unlock((caddr_t)rip, PZERO-1, &lk_nfsrrok);		smp_lock(&lk_nfsrrok, LK_RETRY);	}	smp_unlock(&lk_nfsrrok);	(void) splx(s);	VOP_BRELSE(rip->vp, rip->bp);	VN_RELE(rip->vp);	MFREE(dtom(rip), n);#ifdef lint	n = n;#endif lint}/* * Wake up user process to free bp and vp (rrokfree) */staticrrokwakeup(rip)	struct rrokinfo *rip;{	int s;	s = splimp();	smp_lock(&lk_nfsrrok, LK_RETRY);	rip->done = 1;	smp_unlock(&lk_nfsrrok);	(void) splx(s);	wakeup((caddr_t)rip);}/* * Status OK portion of remote read reply */bool_txdr_rrok(xdrs, rrok)	XDR *xdrs;	struct nfsrrok *rrok;{	if (xdr_fattr(xdrs, &rrok->rrok_attr)) {		if (xdrs->x_op == XDR_ENCODE && rrok->rrok_bp) {			/* server side */			struct mbuf *m;			struct rrokinfo *rip;			MGET(m, M_WAIT, MT_DATA);			if (m == NULL) {				printf("xdr_rrok: FAILED, can't get mbuf\n");				/*				 *  Release resources since rrokfree				 *  will not be called				 */				VOP_BRELSE(rrok->rrok_vp, rrok->rrok_bp);				VN_RELE(rrok->rrok_vp);				return(FALSE);			}			rip = mtod(m, struct rrokinfo *);			rip->func = rrokfree;			rip->done = 0;			rip->vp = rrok->rrok_vp;			rip->bp = rrok->rrok_bp;			xdrs->x_public = (caddr_t)rip;			if (xdrmbuf_putbuf(xdrs, rrok->rrok_data,			    (u_int)rrok->rrok_count, rrokwakeup, (int)rip)) {#ifdef NFSDEBUG				dprint(nfsdebug, 6, "xdr_rrok: %s %d addr %x\n",				    xdropnames[(int)xdrs->x_op],				    rrok->rrok_count, rrok->rrok_data);#endif				return (TRUE);			} else {				rip->done = 1;			}		} else {			/* client side */			if (xdr_bytes(xdrs, &rrok->rrok_data,			    (u_int *)&rrok->rrok_count, NFS_MAXDATA) ) {#ifdef NFSDEBUG				dprint(nfsdebug, 6, "xdr_rrok: %s %d addr %x\n",				    xdropnames[(int)xdrs->x_op],				    rrok->rrok_count, rrok->rrok_data);#endif				return (TRUE);			}		}	}#ifdef NFSDEBUG	dprint(nfsdebug, 2, "xdr_rrok: %s FAILED\n",	    xdropnames[(int)xdrs->x_op]);#endif	return (FALSE);}struct xdr_discrim rdres_discrim[2] = {	{ (int)NFS_OK, xdr_rrok },	{ __dontcare__, NULL_xdrproc_t }};/* * Reply from remote read */bool_txdr_rdresult(xdrs, rr)	XDR *xdrs;	struct nfsrdresult *rr;{#ifdef NFSDEBUG	dprint(nfsdebug, 6, "xdr_rdresult: %s\n", xdropnames[(int)xdrs->x_op]);#endif	if (xdr_union(xdrs, (enum_t *)&(rr->rr_status),	      (caddr_t)&(rr->rr_ok), rdres_discrim, xdr_void) ) {		return (TRUE);	}#ifdef NFSDEBUG	dprint(nfsdebug, 2, "xdr_rdresult: %s FAILED\n",	    xdropnames[(int)xdrs->x_op]);#endif	return (FALSE);}/* * File attributes which can be set */bool_txdr_sattr(xdrs, sa)	XDR *xdrs;	struct nfssattr *sa;{	if (xdr_u_long(xdrs, &sa->sa_mode) &&	    xdr_u_long(xdrs, &sa->sa_uid) &&	    xdr_u_long(xdrs, &sa->sa_gid) &&	    xdr_u_long(xdrs, &sa->sa_size) &&	    xdr_timeval(xdrs, &sa->sa_atime) &&	    xdr_timeval(xdrs, &sa->sa_mtime) ) {#ifdef NFSDEBUG		dprint(nfsdebug, 6,		    "xdr_sattr: %s mode %o uid %d gid %d size %d\n",		    xdropnames[(int)xdrs->x_op], sa->sa_mode, sa->sa_uid,		    sa->sa_gid, sa->sa_size);#endif		return (TRUE);	}#ifdef NFSDEBUG	dprint(nfsdebug, 2, "xdr_sattr: %s FAILED\n",	    xdropnames[(int)xdrs->x_op]);#endif	return (FALSE);}struct xdr_discrim attrstat_discrim[2] = {	{ (int)NFS_OK, xdr_fattr },	{ __dontcare__, NULL_xdrproc_t }};/* * Reply status with file attributes */bool_txdr_attrstat(xdrs, ns)	XDR *xdrs;	struct nfsattrstat *ns;{	if (xdr_union(xdrs, (enum_t *)&(ns->ns_status),	      (caddr_t)&(ns->ns_attr), attrstat_discrim, xdr_void) ) {#ifdef NFSDEBUG		dprint(nfsdebug, 6, "xdr_attrstat: %s stat %d\n",		    xdropnames[(int)xdrs->x_op], ns->ns_status);#endif		return (TRUE);	}#ifdef NFSDEBUG	dprint(nfsdebug, 2, "xdr_attrstat: %s FAILED\n",	    xdropnames[(int)xdrs->x_op]);#endif	return (FALSE);}/* * NFS_OK part of read sym link reply union */bool_txdr_srok(xdrs, srok)	XDR *xdrs;	struct nfssrok *srok;{	if (xdr_bytes(xdrs, &srok->srok_data, (u_int *)&srok->srok_count,	    NFS_MAXPATHLEN) ) {		return (TRUE);	}#ifdef NFSDEBUG	dprint(nfsdebug, 2, "xdr_srok: %s FAILED\n",	    xdropnames[(int)xdrs->x_op]);#endif	return (FALSE);}struct xdr_discrim rdlnres_discrim[2] = {	{ (int)NFS_OK, xdr_srok },	{ __dontcare__, NULL_xdrproc_t }};/* * Result of reading symbolic link */bool_txdr_rdlnres(xdrs, rl)	XDR *xdrs;	struct nfsrdlnres *rl;{#ifdef NFSDEBUG	dprint(nfsdebug, 6, "xdr_rdlnres: %s\n", xdropnames[(int)xdrs->x_op]);#endif	if (xdr_union(xdrs, (enum_t *)&(rl->rl_status),	      (caddr_t)&(rl->rl_srok), rdlnres_discrim, xdr_void) ) {		return (TRUE);	}#ifdef NFSDEBUG	dprint(nfsdebug, 2, "xdr_rdlnres: %s FAILED\n",	    xdropnames[(int)xdrs->x_op]);#endif	return (FALSE);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -