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

📄 nfs3xdr.c

📁 嵌入式系统设计与实例开发实验教材二源码 多线程应用程序设计 串行端口程序设计 AD接口实验 CAN总线通信实验 GPS通信实验 Linux内核移植与编译实验 IC卡读写实验 SD驱动使
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * linux/fs/nfsd/nfs3xdr.c * * XDR support for nfsd/protocol version 3. * * Copyright (C) 1995, 1996, 1997 Olaf Kirch <okir@monad.swb.de> */#include <linux/types.h>#include <linux/sched.h>#include <linux/nfs3.h>#include <linux/sunrpc/xdr.h>#include <linux/sunrpc/svc.h>#include <linux/nfsd/nfsd.h>#include <linux/nfsd/xdr3.h>#define NFSDDBG_FACILITY		NFSDDBG_XDR#ifdef NFSD_OPTIMIZE_SPACE# define inline#endif/* * Mapping of S_IF* types to NFS file types */static u32	nfs3_ftypes[] = {	NF3NON,  NF3FIFO, NF3CHR, NF3BAD,	NF3DIR,  NF3BAD,  NF3BLK, NF3BAD,	NF3REG,  NF3BAD,  NF3LNK, NF3BAD,	NF3SOCK, NF3BAD,  NF3LNK, NF3BAD,};/* * XDR functions for basic NFS types */static inline u32 *encode_time3(u32 *p, time_t secs){	*p++ = htonl((u32) secs); *p++ = 0;	return p;}static inline u32 *decode_time3(u32 *p, time_t *secp){	*secp = ntohl(*p++);	return p + 1;}static inline u32 *decode_fh(u32 *p, struct svc_fh *fhp){	int size;	fh_init(fhp, NFS3_FHSIZE);	size = ntohl(*p++);	if (size > NFS3_FHSIZE)		return NULL;	memcpy(&fhp->fh_handle.fh_base, p, size);	fhp->fh_handle.fh_size = size;	return p + XDR_QUADLEN(size);}static inline u32 *encode_fh(u32 *p, struct svc_fh *fhp){	int size = fhp->fh_handle.fh_size;	*p++ = htonl(size);	if (size) p[XDR_QUADLEN(size)-1]=0;	memcpy(p, &fhp->fh_handle.fh_base, size);	return p + XDR_QUADLEN(size);}/* * Decode a file name and make sure that the path contains * no slashes or null bytes. */static inline u32 *decode_filename(u32 *p, char **namp, int *lenp){	char		*name;	int		i;	if ((p = xdr_decode_string_inplace(p, namp, lenp, NFS3_MAXNAMLEN)) != NULL) {		for (i = 0, name = *namp; i < *lenp; i++, name++) {			if (*name == '\0' || *name == '/')				return NULL;		}	}	return p;}static inline u32 *decode_pathname(u32 *p, char **namp, int *lenp){	char		*name;	int		i;	if ((p = xdr_decode_string(p, namp, lenp, NFS3_MAXPATHLEN)) != NULL) {		for (i = 0, name = *namp; i < *lenp; i++, name++) {			if (*name == '\0')				return NULL;		}	}	return p;}static inline u32 *decode_sattr3(u32 *p, struct iattr *iap){	u32	tmp;	iap->ia_valid = 0;	if (*p++) {		iap->ia_valid |= ATTR_MODE;		iap->ia_mode = ntohl(*p++);	}	if (*p++) {		iap->ia_valid |= ATTR_UID;		iap->ia_uid = ntohl(*p++);	}	if (*p++) {		iap->ia_valid |= ATTR_GID;		iap->ia_gid = ntohl(*p++);	}	if (*p++) {		u64	newsize;		iap->ia_valid |= ATTR_SIZE;		p = xdr_decode_hyper(p, &newsize);		if (newsize <= NFS_OFFSET_MAX)			iap->ia_size = newsize;		else			iap->ia_size = NFS_OFFSET_MAX;	}	if ((tmp = ntohl(*p++)) == 1) {	/* set to server time */		iap->ia_valid |= ATTR_ATIME;	} else if (tmp == 2) {		/* set to client time */		iap->ia_valid |= ATTR_ATIME | ATTR_ATIME_SET;		iap->ia_atime = ntohl(*p++), p++;	}	if ((tmp = ntohl(*p++)) == 1) {	/* set to server time */		iap->ia_valid |= ATTR_MTIME;	} else if (tmp == 2) {		/* set to client time */		iap->ia_valid |= ATTR_MTIME | ATTR_MTIME_SET;		iap->ia_mtime = ntohl(*p++), p++;	}	return p;}static inline u32 *encode_fattr3(struct svc_rqst *rqstp, u32 *p, struct dentry *dentry){	struct inode	*inode = dentry->d_inode;	*p++ = htonl(nfs3_ftypes[(inode->i_mode & S_IFMT) >> 12]);	*p++ = htonl((u32) inode->i_mode);	*p++ = htonl((u32) inode->i_nlink);	*p++ = htonl((u32) nfsd_ruid(rqstp, inode->i_uid));	*p++ = htonl((u32) nfsd_rgid(rqstp, inode->i_gid));	if (S_ISLNK(inode->i_mode) && inode->i_size > NFS3_MAXPATHLEN) {		p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);	} else {		p = xdr_encode_hyper(p, (u64) inode->i_size);	}	if (inode->i_blksize == 0 && inode->i_blocks == 0)		/* Minix file system(?) i_size is (hopefully) close enough */		p = xdr_encode_hyper(p, (u64)(inode->i_size +511)& ~511);	else		p = xdr_encode_hyper(p, ((u64)inode->i_blocks) << 9);	*p++ = htonl((u32) MAJOR(inode->i_rdev));	*p++ = htonl((u32) MINOR(inode->i_rdev));	p = xdr_encode_hyper(p, (u64) inode->i_dev);	p = xdr_encode_hyper(p, (u64) inode->i_ino);	p = encode_time3(p, inode->i_atime);	p = encode_time3(p, lease_get_mtime(inode));	p = encode_time3(p, inode->i_ctime);	return p;}static inline u32 *encode_saved_post_attr(struct svc_rqst *rqstp, u32 *p, struct svc_fh *fhp){	struct inode	*inode = fhp->fh_dentry->d_inode;	/* Attributes to follow */	*p++ = xdr_one;	*p++ = htonl(nfs3_ftypes[(fhp->fh_post_mode & S_IFMT) >> 12]);	*p++ = htonl((u32) fhp->fh_post_mode);	*p++ = htonl((u32) fhp->fh_post_nlink);	*p++ = htonl((u32) nfsd_ruid(rqstp, fhp->fh_post_uid));	*p++ = htonl((u32) nfsd_rgid(rqstp, fhp->fh_post_gid));	if (S_ISLNK(fhp->fh_post_mode) && fhp->fh_post_size > NFS3_MAXPATHLEN) {		p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);	} else {		p = xdr_encode_hyper(p, (u64) fhp->fh_post_size);	}	p = xdr_encode_hyper(p, ((u64)fhp->fh_post_blocks) << 9);	*p++ = htonl((u32) MAJOR(fhp->fh_post_rdev));	*p++ = htonl((u32) MINOR(fhp->fh_post_rdev));	p = xdr_encode_hyper(p, (u64) inode->i_dev);	p = xdr_encode_hyper(p, (u64) inode->i_ino);	p = encode_time3(p, fhp->fh_post_atime);	p = encode_time3(p, fhp->fh_post_mtime);	p = encode_time3(p, fhp->fh_post_ctime);	return p;}/* * Encode post-operation attributes. * The inode may be NULL if the call failed because of a stale file * handle. In this case, no attributes are returned. */static u32 *encode_post_op_attr(struct svc_rqst *rqstp, u32 *p, struct dentry *dentry){	if (dentry && dentry->d_inode != NULL) {		*p++ = xdr_one;		/* attributes follow */		return encode_fattr3(rqstp, p, dentry);	}	*p++ = xdr_zero;	return p;}/* * Enocde weak cache consistency data */static u32 *encode_wcc_data(struct svc_rqst *rqstp, u32 *p, struct svc_fh *fhp){	struct dentry	*dentry = fhp->fh_dentry;	if (dentry && dentry->d_inode && fhp->fh_post_saved) {		if (fhp->fh_pre_saved) {			*p++ = xdr_one;			p = xdr_encode_hyper(p, (u64) fhp->fh_pre_size);			p = encode_time3(p, fhp->fh_pre_mtime);			p = encode_time3(p, fhp->fh_pre_ctime);		} else {			*p++ = xdr_zero;		}		return encode_saved_post_attr(rqstp, p, fhp);	}	/* no pre- or post-attrs */	*p++ = xdr_zero;	return encode_post_op_attr(rqstp, p, dentry);}/* * Check buffer bounds after decoding arguments */static inline intxdr_argsize_check(struct svc_rqst *rqstp, u32 *p){	struct svc_buf	*buf = &rqstp->rq_argbuf;	return p - buf->base <= buf->buflen;}static inline intxdr_ressize_check(struct svc_rqst *rqstp, u32 *p){	struct svc_buf	*buf = &rqstp->rq_resbuf;	buf->len = p - buf->base;	dprintk("nfsd: ressize_check p %p base %p len %d\n",			p, buf->base, buf->buflen);	return (buf->len <= buf->buflen);}/* * XDR decode functions */intnfs3svc_decode_fhandle(struct svc_rqst *rqstp, u32 *p, struct svc_fh *fhp){	if (!(p = decode_fh(p, fhp)))		return 0;	return xdr_argsize_check(rqstp, p);}intnfs3svc_decode_sattrargs(struct svc_rqst *rqstp, u32 *p,					struct nfsd3_sattrargs *args){	if (!(p = decode_fh(p, &args->fh))	 || !(p = decode_sattr3(p, &args->attrs)))		return 0;	if ((args->check_guard = ntohl(*p++)) != 0)		p = decode_time3(p, &args->guardtime);	return xdr_argsize_check(rqstp, p);}intnfs3svc_decode_diropargs(struct svc_rqst *rqstp, u32 *p,					struct nfsd3_diropargs *args){	if (!(p = decode_fh(p, &args->fh))	 || !(p = decode_filename(p, &args->name, &args->len)))		return 0;	return xdr_argsize_check(rqstp, p);}intnfs3svc_decode_accessargs(struct svc_rqst *rqstp, u32 *p,					struct nfsd3_accessargs *args){	if (!(p = decode_fh(p, &args->fh)))		return 0;	args->access = ntohl(*p++);	return xdr_argsize_check(rqstp, p);}intnfs3svc_decode_readargs(struct svc_rqst *rqstp, u32 *p,					struct nfsd3_readargs *args){	if (!(p = decode_fh(p, &args->fh))	 || !(p = xdr_decode_hyper(p, &args->offset)))		return 0;	args->count = ntohl(*p++);	return xdr_argsize_check(rqstp, p);}intnfs3svc_decode_writeargs(struct svc_rqst *rqstp, u32 *p,					struct nfsd3_writeargs *args){	if (!(p = decode_fh(p, &args->fh))	 || !(p = xdr_decode_hyper(p, &args->offset)))		return 0;	args->count = ntohl(*p++);	args->stable = ntohl(*p++);	args->len = ntohl(*p++);	args->data = (char *) p;	p += XDR_QUADLEN(args->len);	return xdr_argsize_check(rqstp, p);}intnfs3svc_decode_createargs(struct svc_rqst *rqstp, u32 *p,					struct nfsd3_createargs *args){	if (!(p = decode_fh(p, &args->fh))	 || !(p = decode_filename(p, &args->name, &args->len)))		return 0;	switch (args->createmode = ntohl(*p++)) {	case NFS3_CREATE_UNCHECKED:	case NFS3_CREATE_GUARDED:		if (!(p = decode_sattr3(p, &args->attrs)))			return 0;		break;	case NFS3_CREATE_EXCLUSIVE:		args->verf = p;		p += 2;		break;	default:		return 0;	}	return xdr_argsize_check(rqstp, p);}intnfs3svc_decode_mkdirargs(struct svc_rqst *rqstp, u32 *p,					struct nfsd3_createargs *args){	if (!(p = decode_fh(p, &args->fh))	 || !(p = decode_filename(p, &args->name, &args->len))	 || !(p = decode_sattr3(p, &args->attrs)))		return 0;	return xdr_argsize_check(rqstp, p);}intnfs3svc_decode_symlinkargs(struct svc_rqst *rqstp, u32 *p,					struct nfsd3_symlinkargs *args){	if (!(p = decode_fh(p, &args->ffh))	 || !(p = decode_filename(p, &args->fname, &args->flen))	 || !(p = decode_sattr3(p, &args->attrs))	 || !(p = decode_pathname(p, &args->tname, &args->tlen)))		return 0;	return xdr_argsize_check(rqstp, p);}intnfs3svc_decode_mknodargs(struct svc_rqst *rqstp, u32 *p,					struct nfsd3_mknodargs *args){	if (!(p = decode_fh(p, &args->fh))	 || !(p = decode_filename(p, &args->name, &args->len)))		return 0;	args->ftype = ntohl(*p++);	if (args->ftype == NF3BLK  || args->ftype == NF3CHR	 || args->ftype == NF3SOCK || args->ftype == NF3FIFO) {		if (!(p = decode_sattr3(p, &args->attrs)))			return 0;	}	if (args->ftype == NF3BLK || args->ftype == NF3CHR) {		args->major = ntohl(*p++);

⌨️ 快捷键说明

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