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

📄 nfs3xdr.c

📁 linux 内核源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
	if (!(p = decode_fh(p, &args->fh)))		return 0;	p = xdr_decode_hyper(p, &args->cookie);	args->verf   = p; p += 2;	args->dircount = ~0;	args->count  = ntohl(*p++);	if (args->count > PAGE_SIZE)		args->count = PAGE_SIZE;	args->buffer =		page_address(rqstp->rq_respages[rqstp->rq_resused++]);	return xdr_argsize_check(rqstp, p);}intnfs3svc_decode_readdirplusargs(struct svc_rqst *rqstp, __be32 *p,					struct nfsd3_readdirargs *args){	int len, pn;	u32 max_blocksize = svc_max_payload(rqstp);	if (!(p = decode_fh(p, &args->fh)))		return 0;	p = xdr_decode_hyper(p, &args->cookie);	args->verf     = p; p += 2;	args->dircount = ntohl(*p++);	args->count    = ntohl(*p++);	len = (args->count > max_blocksize) ? max_blocksize :						  args->count;	args->count = len;	while (len > 0) {		pn = rqstp->rq_resused++;		if (!args->buffer)			args->buffer = page_address(rqstp->rq_respages[pn]);		len -= PAGE_SIZE;	}	return xdr_argsize_check(rqstp, p);}intnfs3svc_decode_commitargs(struct svc_rqst *rqstp, __be32 *p,					struct nfsd3_commitargs *args){	if (!(p = decode_fh(p, &args->fh)))		return 0;	p = xdr_decode_hyper(p, &args->offset);	args->count = ntohl(*p++);	return xdr_argsize_check(rqstp, p);}/* * XDR encode functions *//* * There must be an encoding function for void results so svc_process * will work properly. */intnfs3svc_encode_voidres(struct svc_rqst *rqstp, __be32 *p, void *dummy){	return xdr_ressize_check(rqstp, p);}/* GETATTR */intnfs3svc_encode_attrstat(struct svc_rqst *rqstp, __be32 *p,					struct nfsd3_attrstat *resp){	if (resp->status == 0) {		lease_get_mtime(resp->fh.fh_dentry->d_inode,				&resp->stat.mtime);		p = encode_fattr3(rqstp, p, &resp->fh, &resp->stat);	}	return xdr_ressize_check(rqstp, p);}/* SETATTR, REMOVE, RMDIR */intnfs3svc_encode_wccstat(struct svc_rqst *rqstp, __be32 *p,					struct nfsd3_attrstat *resp){	p = encode_wcc_data(rqstp, p, &resp->fh);	return xdr_ressize_check(rqstp, p);}/* LOOKUP */intnfs3svc_encode_diropres(struct svc_rqst *rqstp, __be32 *p,					struct nfsd3_diropres *resp){	if (resp->status == 0) {		p = encode_fh(p, &resp->fh);		p = encode_post_op_attr(rqstp, p, &resp->fh);	}	p = encode_post_op_attr(rqstp, p, &resp->dirfh);	return xdr_ressize_check(rqstp, p);}/* ACCESS */intnfs3svc_encode_accessres(struct svc_rqst *rqstp, __be32 *p,					struct nfsd3_accessres *resp){	p = encode_post_op_attr(rqstp, p, &resp->fh);	if (resp->status == 0)		*p++ = htonl(resp->access);	return xdr_ressize_check(rqstp, p);}/* READLINK */intnfs3svc_encode_readlinkres(struct svc_rqst *rqstp, __be32 *p,					struct nfsd3_readlinkres *resp){	p = encode_post_op_attr(rqstp, p, &resp->fh);	if (resp->status == 0) {		*p++ = htonl(resp->len);		xdr_ressize_check(rqstp, p);		rqstp->rq_res.page_len = resp->len;		if (resp->len & 3) {			/* need to pad the tail */			rqstp->rq_res.tail[0].iov_base = p;			*p = 0;			rqstp->rq_res.tail[0].iov_len = 4 - (resp->len&3);		}		return 1;	} else		return xdr_ressize_check(rqstp, p);}/* READ */intnfs3svc_encode_readres(struct svc_rqst *rqstp, __be32 *p,					struct nfsd3_readres *resp){	p = encode_post_op_attr(rqstp, p, &resp->fh);	if (resp->status == 0) {		*p++ = htonl(resp->count);		*p++ = htonl(resp->eof);		*p++ = htonl(resp->count);	/* xdr opaque count */		xdr_ressize_check(rqstp, p);		/* now update rqstp->rq_res to reflect data aswell */		rqstp->rq_res.page_len = resp->count;		if (resp->count & 3) {			/* need to pad the tail */			rqstp->rq_res.tail[0].iov_base = p;			*p = 0;			rqstp->rq_res.tail[0].iov_len = 4 - (resp->count & 3);		}		return 1;	} else		return xdr_ressize_check(rqstp, p);}/* WRITE */intnfs3svc_encode_writeres(struct svc_rqst *rqstp, __be32 *p,					struct nfsd3_writeres *resp){	p = encode_wcc_data(rqstp, p, &resp->fh);	if (resp->status == 0) {		*p++ = htonl(resp->count);		*p++ = htonl(resp->committed);		*p++ = htonl(nfssvc_boot.tv_sec);		*p++ = htonl(nfssvc_boot.tv_usec);	}	return xdr_ressize_check(rqstp, p);}/* CREATE, MKDIR, SYMLINK, MKNOD */intnfs3svc_encode_createres(struct svc_rqst *rqstp, __be32 *p,					struct nfsd3_diropres *resp){	if (resp->status == 0) {		*p++ = xdr_one;		p = encode_fh(p, &resp->fh);		p = encode_post_op_attr(rqstp, p, &resp->fh);	}	p = encode_wcc_data(rqstp, p, &resp->dirfh);	return xdr_ressize_check(rqstp, p);}/* RENAME */intnfs3svc_encode_renameres(struct svc_rqst *rqstp, __be32 *p,					struct nfsd3_renameres *resp){	p = encode_wcc_data(rqstp, p, &resp->ffh);	p = encode_wcc_data(rqstp, p, &resp->tfh);	return xdr_ressize_check(rqstp, p);}/* LINK */intnfs3svc_encode_linkres(struct svc_rqst *rqstp, __be32 *p,					struct nfsd3_linkres *resp){	p = encode_post_op_attr(rqstp, p, &resp->fh);	p = encode_wcc_data(rqstp, p, &resp->tfh);	return xdr_ressize_check(rqstp, p);}/* READDIR */intnfs3svc_encode_readdirres(struct svc_rqst *rqstp, __be32 *p,					struct nfsd3_readdirres *resp){	p = encode_post_op_attr(rqstp, p, &resp->fh);	if (resp->status == 0) {		/* stupid readdir cookie */		memcpy(p, resp->verf, 8); p += 2;		xdr_ressize_check(rqstp, p);		if (rqstp->rq_res.head[0].iov_len + (2<<2) > PAGE_SIZE)			return 1; /*No room for trailer */		rqstp->rq_res.page_len = (resp->count) << 2;		/* add the 'tail' to the end of the 'head' page - page 0. */		rqstp->rq_res.tail[0].iov_base = p;		*p++ = 0;		/* no more entries */		*p++ = htonl(resp->common.err == nfserr_eof);		rqstp->rq_res.tail[0].iov_len = 2<<2;		return 1;	} else		return xdr_ressize_check(rqstp, p);}static __be32 *encode_entry_baggage(struct nfsd3_readdirres *cd, __be32 *p, const char *name,	     int namlen, u64 ino){	*p++ = xdr_one;				 /* mark entry present */	p    = xdr_encode_hyper(p, ino);	 /* file id */	p    = xdr_encode_array(p, name, namlen);/* name length & name */	cd->offset = p;				/* remember pointer */	p = xdr_encode_hyper(p, NFS_OFFSET_MAX);/* offset of next entry */	return p;}static __be32 *encode_entryplus_baggage(struct nfsd3_readdirres *cd, __be32 *p,		struct svc_fh *fhp){		p = encode_post_op_attr(cd->rqstp, p, fhp);		*p++ = xdr_one;			/* yes, a file handle follows */		p = encode_fh(p, fhp);		fh_put(fhp);		return p;}static intcompose_entry_fh(struct nfsd3_readdirres *cd, struct svc_fh *fhp,		const char *name, int namlen){	struct svc_export	*exp;	struct dentry		*dparent, *dchild;	int rv = 0;	dparent = cd->fh.fh_dentry;	exp  = cd->fh.fh_export;	fh_init(fhp, NFS3_FHSIZE);	if (isdotent(name, namlen)) {		if (namlen == 2) {			dchild = dget_parent(dparent);			if (dchild == dparent) {				/* filesystem root - cannot return filehandle for ".." */				dput(dchild);				return 1;			}		} else			dchild = dget(dparent);	} else		dchild = lookup_one_len(name, dparent, namlen);	if (IS_ERR(dchild))		return 1;	if (d_mountpoint(dchild) ||	    fh_compose(fhp, exp, dchild, &cd->fh) != 0 ||	    !dchild->d_inode)		rv = 1;	dput(dchild);	return rv;}/* * Encode a directory entry. This one works for both normal readdir * and readdirplus. * The normal readdir reply requires 2 (fileid) + 1 (stringlen) * + string + 2 (cookie) + 1 (next) words, i.e. 6 + strlen. *  * The readdirplus baggage is 1+21 words for post_op_attr, plus the * file handle. */#define NFS3_ENTRY_BAGGAGE	(2 + 1 + 2 + 1)#define NFS3_ENTRYPLUS_BAGGAGE	(1 + 21 + 1 + (NFS3_FHSIZE >> 2))static intencode_entry(struct readdir_cd *ccd, const char *name, int namlen,	     loff_t offset, u64 ino, unsigned int d_type, int plus){	struct nfsd3_readdirres *cd = container_of(ccd, struct nfsd3_readdirres,		       					common);	__be32		*p = cd->buffer;	caddr_t		curr_page_addr = NULL;	int		pn;		/* current page number */	int		slen;		/* string (name) length */	int		elen;		/* estimated entry length in words */	int		num_entry_words = 0;	/* actual number of words */	if (cd->offset) {		u64 offset64 = offset;		if (unlikely(cd->offset1)) {			/* we ended up with offset on a page boundary */			*cd->offset = htonl(offset64 >> 32);			*cd->offset1 = htonl(offset64 & 0xffffffff);			cd->offset1 = NULL;		} else {			xdr_encode_hyper(cd->offset, offset64);		}	}	/*	dprintk("encode_entry(%.*s @%ld%s)\n",		namlen, name, (long) offset, plus? " plus" : "");	 */	/* truncate filename if too long */	if (namlen > NFS3_MAXNAMLEN)		namlen = NFS3_MAXNAMLEN;	slen = XDR_QUADLEN(namlen);	elen = slen + NFS3_ENTRY_BAGGAGE		+ (plus? NFS3_ENTRYPLUS_BAGGAGE : 0);	if (cd->buflen < elen) {		cd->common.err = nfserr_toosmall;		return -EINVAL;	}	/* determine which page in rq_respages[] we are currently filling */	for (pn=1; pn < cd->rqstp->rq_resused; pn++) {		curr_page_addr = page_address(cd->rqstp->rq_respages[pn]);		if (((caddr_t)cd->buffer >= curr_page_addr) &&		    ((caddr_t)cd->buffer <  curr_page_addr + PAGE_SIZE))			break;	}	if ((caddr_t)(cd->buffer + elen) < (curr_page_addr + PAGE_SIZE)) {		/* encode entry in current page */		p = encode_entry_baggage(cd, p, name, namlen, ino);		/* throw in readdirplus baggage */		if (plus) {			struct svc_fh	fh;			if (compose_entry_fh(cd, &fh, name, namlen) > 0) {				*p++ = 0;				*p++ = 0;			} else				p = encode_entryplus_baggage(cd, p, &fh);		}		num_entry_words = p - cd->buffer;	} else if (cd->rqstp->rq_respages[pn+1] != NULL) {		/* temporarily encode entry into next page, then move back to		 * current and next page in rq_respages[] */		__be32 *p1, *tmp;		int len1, len2;		/* grab next page for temporary storage of entry */		p1 = tmp = page_address(cd->rqstp->rq_respages[pn+1]);		p1 = encode_entry_baggage(cd, p1, name, namlen, ino);		/* throw in readdirplus baggage */		if (plus) {			struct svc_fh	fh;			if (compose_entry_fh(cd, &fh, name, namlen) > 0) {				/* zero out the filehandle */				*p1++ = 0;				*p1++ = 0;			} else				p1 = encode_entryplus_baggage(cd, p1, &fh);		}		/* determine entry word length and lengths to go in pages */		num_entry_words = p1 - tmp;		len1 = curr_page_addr + PAGE_SIZE - (caddr_t)cd->buffer;		if ((num_entry_words << 2) < len1) {			/* the actual number of words in the entry is less			 * than elen and can still fit in the current page			 */			memmove(p, tmp, num_entry_words << 2);			p += num_entry_words;			/* update offset */			cd->offset = cd->buffer + (cd->offset - tmp);		} else {			unsigned int offset_r = (cd->offset - tmp) << 2;			/* update pointer to offset location.			 * This is a 64bit quantity, so we need to			 * deal with 3 cases:			 *  -	entirely in first page			 *  -	entirely in second page			 *  -	4 bytes in each page			 */			if (offset_r + 8 <= len1) {				cd->offset = p + (cd->offset - tmp);			} else if (offset_r >= len1) {				cd->offset -= len1 >> 2;			} else {				/* sitting on the fence */				BUG_ON(offset_r != len1 - 4);				cd->offset = p + (cd->offset - tmp);				cd->offset1 = tmp;			}			len2 = (num_entry_words << 2) - len1;			/* move from temp page to current and next pages */			memmove(p, tmp, len1);			memmove(tmp, (caddr_t)tmp+len1, len2);			p = tmp + (len2 >> 2);		}	}	else {		cd->common.err = nfserr_toosmall;		return -EINVAL;	}	cd->buflen -= num_entry_words;	cd->buffer = p;	cd->common.err = nfs_ok;	return 0;}intnfs3svc_encode_entry(void *cd, const char *name,		     int namlen, loff_t offset, u64 ino, unsigned int d_type){	return encode_entry(cd, name, namlen, offset, ino, d_type, 0);}intnfs3svc_encode_entry_plus(void *cd, const char *name,			  int namlen, loff_t offset, u64 ino,			  unsigned int d_type){	return encode_entry(cd, name, namlen, offset, ino, d_type, 1);}/* FSSTAT */intnfs3svc_encode_fsstatres(struct svc_rqst *rqstp, __be32 *p,					struct nfsd3_fsstatres *resp){	struct kstatfs	*s = &resp->stats;	u64		bs = s->f_bsize;	*p++ = xdr_zero;	/* no post_op_attr */	if (resp->status == 0) {		p = xdr_encode_hyper(p, bs * s->f_blocks);	/* total bytes */		p = xdr_encode_hyper(p, bs * s->f_bfree);	/* free bytes */		p = xdr_encode_hyper(p, bs * s->f_bavail);	/* user available bytes */		p = xdr_encode_hyper(p, s->f_files);	/* total inodes */		p = xdr_encode_hyper(p, s->f_ffree);	/* free inodes */		p = xdr_encode_hyper(p, s->f_ffree);	/* user available inodes */		*p++ = htonl(resp->invarsec);	/* mean unchanged time */	}	return xdr_ressize_check(rqstp, p);}/* FSINFO */intnfs3svc_encode_fsinfores(struct svc_rqst *rqstp, __be32 *p,					struct nfsd3_fsinfores *resp){	*p++ = xdr_zero;	/* no post_op_attr */	if (resp->status == 0) {		*p++ = htonl(resp->f_rtmax);		*p++ = htonl(resp->f_rtpref);		*p++ = htonl(resp->f_rtmult);		*p++ = htonl(resp->f_wtmax);		*p++ = htonl(resp->f_wtpref);		*p++ = htonl(resp->f_wtmult);		*p++ = htonl(resp->f_dtpref);		p = xdr_encode_hyper(p, resp->f_maxfilesize);		*p++ = xdr_one;		*p++ = xdr_zero;		*p++ = htonl(resp->f_properties);	}	return xdr_ressize_check(rqstp, p);}/* PATHCONF */intnfs3svc_encode_pathconfres(struct svc_rqst *rqstp, __be32 *p,					struct nfsd3_pathconfres *resp){	*p++ = xdr_zero;	/* no post_op_attr */	if (resp->status == 0) {		*p++ = htonl(resp->p_link_max);		*p++ = htonl(resp->p_name_max);		*p++ = htonl(resp->p_no_trunc);		*p++ = htonl(resp->p_chown_restricted);		*p++ = htonl(resp->p_case_insensitive);		*p++ = htonl(resp->p_case_preserving);	}	return xdr_ressize_check(rqstp, p);}/* COMMIT */intnfs3svc_encode_commitres(struct svc_rqst *rqstp, __be32 *p,					struct nfsd3_commitres *resp){	p = encode_wcc_data(rqstp, p, &resp->fh);	/* Write verifier */	if (resp->status == 0) {		*p++ = htonl(nfssvc_boot.tv_sec);		*p++ = htonl(nfssvc_boot.tv_usec);	}	return xdr_ressize_check(rqstp, p);}/* * XDR release functions */intnfs3svc_release_fhandle(struct svc_rqst *rqstp, __be32 *p,					struct nfsd3_attrstat *resp){	fh_put(&resp->fh);	return 1;}intnfs3svc_release_fhandle2(struct svc_rqst *rqstp, __be32 *p,					struct nfsd3_fhandle_pair *resp){	fh_put(&resp->fh1);	fh_put(&resp->fh2);	return 1;}

⌨️ 快捷键说明

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