Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 229163
b: refs/heads/master
c: 5f96e5e
h: refs/heads/master
i:
  229161: b704b21
  229159: 8ad8f90
v: v3
  • Loading branch information
Chuck Lever authored and Trond Myklebust committed Dec 16, 2010
1 parent 8fd5f43 commit 23187b4
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 42 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 661ad4239a51a2169a366a227c68cf3b654ab936
refs/heads/master: 5f96e5e31b4f4a2f126adfe0586a7555c11b0562
97 changes: 56 additions & 41 deletions trunk/fs/nfs/nfs2xdr.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,46 +88,6 @@ static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
}


/*
* Common NFS XDR functions as inlines
*/
static inline __be32*
xdr_decode_time(__be32 *p, struct timespec *timep)
{
timep->tv_sec = ntohl(*p++);
/* Convert microseconds into nanoseconds */
timep->tv_nsec = ntohl(*p++) * 1000;
return p;
}

static __be32 *
xdr_decode_fattr(__be32 *p, struct nfs_fattr *fattr)
{
u32 rdev, type;
type = ntohl(*p++);
fattr->mode = ntohl(*p++);
fattr->nlink = ntohl(*p++);
fattr->uid = ntohl(*p++);
fattr->gid = ntohl(*p++);
fattr->size = ntohl(*p++);
fattr->du.nfs2.blocksize = ntohl(*p++);
rdev = ntohl(*p++);
fattr->du.nfs2.blocks = ntohl(*p++);
fattr->fsid.major = ntohl(*p++);
fattr->fsid.minor = 0;
fattr->fileid = ntohl(*p++);
p = xdr_decode_time(p, &fattr->atime);
p = xdr_decode_time(p, &fattr->mtime);
p = xdr_decode_time(p, &fattr->ctime);
fattr->valid |= NFS_ATTR_FATTR_V2;
fattr->rdev = new_decode_dev(rdev);
if (type == NFCHR && rdev == NFS2_FIFO_DEV) {
fattr->mode = (fattr->mode & ~S_IFMT) | S_IFIFO;
fattr->rdev = 0;
}
return p;
}

/*
* Encode/decode NFSv2 basic data types
*
Expand Down Expand Up @@ -207,6 +167,27 @@ static int decode_stat(struct xdr_stream *xdr, enum nfs_stat *status)
return -EIO;
}

/*
* 2.3.2. ftype
*
* enum ftype {
* NFNON = 0,
* NFREG = 1,
* NFDIR = 2,
* NFBLK = 3,
* NFCHR = 4,
* NFLNK = 5
* };
*
*/
static __be32 *xdr_decode_ftype(__be32 *p, u32 *type)
{
*type = be32_to_cpup(p++);
if (unlikely(*type > NF2FIFO))
*type = NFBAD;
return p;
}

/*
* 2.3.3. fhandle
*
Expand Down Expand Up @@ -269,6 +250,13 @@ static __be32 *xdr_encode_current_server_time(__be32 *p,
return p;
}

static __be32 *xdr_decode_time(__be32 *p, struct timespec *timep)
{
timep->tv_sec = be32_to_cpup(p++);
timep->tv_nsec = be32_to_cpup(p++) * NSEC_PER_USEC;
return p;
}

/*
* 2.3.5. fattr
*
Expand All @@ -292,12 +280,39 @@ static __be32 *xdr_encode_current_server_time(__be32 *p,
*/
static int decode_fattr(struct xdr_stream *xdr, struct nfs_fattr *fattr)
{
u32 rdev, type;
__be32 *p;

p = xdr_inline_decode(xdr, NFS_fattr_sz << 2);
if (unlikely(p == NULL))
goto out_overflow;
xdr_decode_fattr(p, fattr);

fattr->valid |= NFS_ATTR_FATTR_V2;

p = xdr_decode_ftype(p, &type);

fattr->mode = be32_to_cpup(p++);
fattr->nlink = be32_to_cpup(p++);
fattr->uid = be32_to_cpup(p++);
fattr->gid = be32_to_cpup(p++);
fattr->size = be32_to_cpup(p++);
fattr->du.nfs2.blocksize = be32_to_cpup(p++);

rdev = be32_to_cpup(p++);
fattr->rdev = new_decode_dev(rdev);
if (type == (u32)NFCHR && rdev == (u32)NFS2_FIFO_DEV) {
fattr->mode = (fattr->mode & ~S_IFMT) | S_IFIFO;
fattr->rdev = 0;
}

fattr->du.nfs2.blocks = be32_to_cpup(p++);
fattr->fsid.major = be32_to_cpup(p++);
fattr->fsid.minor = 0;
fattr->fileid = be32_to_cpup(p++);

p = xdr_decode_time(p, &fattr->atime);
p = xdr_decode_time(p, &fattr->mtime);
xdr_decode_time(p, &fattr->ctime);
return 0;
out_overflow:
print_overflow_msg(__func__, xdr);
Expand Down

0 comments on commit 23187b4

Please sign in to comment.