Commit bca79478 authored by Trond Myklebust's avatar Trond Myklebust

NFS: Fix the type of struct nfs_fattr->mode

There is no point in using anything other than umode_t, since we copy the
content pretty much directly into inode->i_mode.
Signed-off-by: default avatarTrond Myklebust <Trond.Myklebust@netapp.com>
parent 1ca277d8
...@@ -156,7 +156,7 @@ int nfs4_path_walk(struct nfs_server *server, ...@@ -156,7 +156,7 @@ int nfs4_path_walk(struct nfs_server *server,
return ret; return ret;
} }
if (fattr.type != NFDIR) { if (!S_ISDIR(fattr.mode)) {
printk(KERN_ERR "nfs4_get_root:" printk(KERN_ERR "nfs4_get_root:"
" getroot encountered non-directory\n"); " getroot encountered non-directory\n");
return -ENOTDIR; return -ENOTDIR;
...@@ -213,7 +213,7 @@ int nfs4_path_walk(struct nfs_server *server, ...@@ -213,7 +213,7 @@ int nfs4_path_walk(struct nfs_server *server,
return ret; return ret;
} }
if (fattr.type != NFDIR) { if (!S_ISDIR(fattr.mode)) {
printk(KERN_ERR "nfs4_get_root:" printk(KERN_ERR "nfs4_get_root:"
" lookupfh encountered non-directory\n"); " lookupfh encountered non-directory\n");
return -ENOTDIR; return -ENOTDIR;
......
...@@ -120,8 +120,8 @@ xdr_decode_time(__be32 *p, struct timespec *timep) ...@@ -120,8 +120,8 @@ xdr_decode_time(__be32 *p, struct timespec *timep)
static __be32 * static __be32 *
xdr_decode_fattr(__be32 *p, struct nfs_fattr *fattr) xdr_decode_fattr(__be32 *p, struct nfs_fattr *fattr)
{ {
u32 rdev; u32 rdev, type;
fattr->type = (enum nfs_ftype) ntohl(*p++); type = ntohl(*p++);
fattr->mode = ntohl(*p++); fattr->mode = ntohl(*p++);
fattr->nlink = ntohl(*p++); fattr->nlink = ntohl(*p++);
fattr->uid = ntohl(*p++); fattr->uid = ntohl(*p++);
...@@ -138,8 +138,7 @@ xdr_decode_fattr(__be32 *p, struct nfs_fattr *fattr) ...@@ -138,8 +138,7 @@ xdr_decode_fattr(__be32 *p, struct nfs_fattr *fattr)
p = xdr_decode_time(p, &fattr->ctime); p = xdr_decode_time(p, &fattr->ctime);
fattr->valid |= NFS_ATTR_FATTR_V2; fattr->valid |= NFS_ATTR_FATTR_V2;
fattr->rdev = new_decode_dev(rdev); fattr->rdev = new_decode_dev(rdev);
if (fattr->type == NFCHR && rdev == NFS2_FIFO_DEV) { if (type == NFCHR && rdev == NFS2_FIFO_DEV) {
fattr->type = NFFIFO;
fattr->mode = (fattr->mode & ~S_IFMT) | S_IFIFO; fattr->mode = (fattr->mode & ~S_IFMT) | S_IFIFO;
fattr->rdev = 0; fattr->rdev = 0;
} }
......
...@@ -91,19 +91,15 @@ ...@@ -91,19 +91,15 @@
/* /*
* Map file type to S_IFMT bits * Map file type to S_IFMT bits
*/ */
static struct { static const umode_t nfs_type2fmt[] = {
unsigned int mode; [NF3BAD] = 0,
unsigned int nfs2type; [NF3REG] = S_IFREG,
} nfs_type2fmt[] = { [NF3DIR] = S_IFDIR,
{ 0, NFNON }, [NF3BLK] = S_IFBLK,
{ S_IFREG, NFREG }, [NF3CHR] = S_IFCHR,
{ S_IFDIR, NFDIR }, [NF3LNK] = S_IFLNK,
{ S_IFBLK, NFBLK }, [NF3SOCK] = S_IFSOCK,
{ S_IFCHR, NFCHR }, [NF3FIFO] = S_IFIFO,
{ S_IFLNK, NFLNK },
{ S_IFSOCK, NFSOCK },
{ S_IFIFO, NFFIFO },
{ 0, NFBAD }
}; };
/* /*
...@@ -148,13 +144,12 @@ static __be32 * ...@@ -148,13 +144,12 @@ static __be32 *
xdr_decode_fattr(__be32 *p, struct nfs_fattr *fattr) xdr_decode_fattr(__be32 *p, struct nfs_fattr *fattr)
{ {
unsigned int type, major, minor; unsigned int type, major, minor;
int fmode; umode_t fmode;
type = ntohl(*p++); type = ntohl(*p++);
if (type >= NF3BAD) if (type > NF3FIFO)
type = NF3BAD; type = NF3NON;
fmode = nfs_type2fmt[type].mode; fmode = nfs_type2fmt[type];
fattr->type = nfs_type2fmt[type].nfs2type;
fattr->mode = (ntohl(*p++) & ~S_IFMT) | fmode; fattr->mode = (ntohl(*p++) & ~S_IFMT) | fmode;
fattr->nlink = ntohl(*p++); fattr->nlink = ntohl(*p++);
fattr->uid = ntohl(*p++); fattr->uid = ntohl(*p++);
......
...@@ -522,20 +522,17 @@ static int nfs4_stat_to_errno(int); ...@@ -522,20 +522,17 @@ static int nfs4_stat_to_errno(int);
decode_lookup_maxsz + \ decode_lookup_maxsz + \
decode_fs_locations_maxsz) decode_fs_locations_maxsz)
static struct { static const umode_t nfs_type2fmt[] = {
unsigned int mode; [NF4BAD] = 0,
unsigned int nfs2type; [NF4REG] = S_IFREG,
} nfs_type2fmt[] = { [NF4DIR] = S_IFDIR,
{ 0, NFNON }, [NF4BLK] = S_IFBLK,
{ S_IFREG, NFREG }, [NF4CHR] = S_IFCHR,
{ S_IFDIR, NFDIR }, [NF4LNK] = S_IFLNK,
{ S_IFBLK, NFBLK }, [NF4SOCK] = S_IFSOCK,
{ S_IFCHR, NFCHR }, [NF4FIFO] = S_IFIFO,
{ S_IFLNK, NFLNK }, [NF4ATTRDIR] = 0,
{ S_IFSOCK, NFSOCK }, [NF4NAMEDATTR] = 0,
{ S_IFIFO, NFFIFO },
{ 0, NFNON },
{ 0, NFNON },
}; };
struct compound_hdr { struct compound_hdr {
...@@ -2173,7 +2170,7 @@ static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t * ...@@ -2173,7 +2170,7 @@ static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *
} }
bitmap[0] &= ~FATTR4_WORD0_TYPE; bitmap[0] &= ~FATTR4_WORD0_TYPE;
} }
dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type].nfs2type); dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
return 0; return 0;
} }
...@@ -2580,8 +2577,9 @@ static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32 ...@@ -2580,8 +2577,9 @@ static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32
return status; return status;
} }
static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *mode) static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
{ {
uint32_t tmp;
__be32 *p; __be32 *p;
*mode = 0; *mode = 0;
...@@ -2589,8 +2587,8 @@ static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t * ...@@ -2589,8 +2587,8 @@ static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *
return -EIO; return -EIO;
if (likely(bitmap[1] & FATTR4_WORD1_MODE)) { if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
READ_BUF(4); READ_BUF(4);
READ32(*mode); READ32(tmp);
*mode &= ~S_IFMT; *mode = tmp & ~S_IFMT;
bitmap[1] &= ~FATTR4_WORD1_MODE; bitmap[1] &= ~FATTR4_WORD1_MODE;
} }
dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode); dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
...@@ -2994,7 +2992,8 @@ static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, cons ...@@ -2994,7 +2992,8 @@ static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, cons
uint32_t attrlen, uint32_t attrlen,
bitmap[2] = {0}, bitmap[2] = {0},
type; type;
int status, fmode = 0; int status;
umode_t fmode = 0;
uint64_t fileid; uint64_t fileid;
if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0) if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
...@@ -3008,8 +3007,7 @@ static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, cons ...@@ -3008,8 +3007,7 @@ static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, cons
if ((status = decode_attr_type(xdr, bitmap, &type)) != 0) if ((status = decode_attr_type(xdr, bitmap, &type)) != 0)
goto xdr_error; goto xdr_error;
fattr->type = nfs_type2fmt[type].nfs2type; fattr->mode = nfs_type2fmt[type];
fattr->mode = nfs_type2fmt[type].mode;
if ((status = decode_attr_change(xdr, bitmap, &fattr->change_attr)) != 0) if ((status = decode_attr_change(xdr, bitmap, &fattr->change_attr)) != 0)
goto xdr_error; goto xdr_error;
......
...@@ -28,8 +28,7 @@ static inline int nfs_fsid_equal(const struct nfs_fsid *a, const struct nfs_fsid ...@@ -28,8 +28,7 @@ static inline int nfs_fsid_equal(const struct nfs_fsid *a, const struct nfs_fsid
struct nfs_fattr { struct nfs_fattr {
unsigned int valid; /* which fields are valid */ unsigned int valid; /* which fields are valid */
enum nfs_ftype type; /* always use NFSv2 types */ umode_t mode;
__u32 mode;
__u32 nlink; __u32 nlink;
__u32 uid; __u32 uid;
__u32 gid; __u32 gid;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment