@@ -166,23 +166,28 @@ out_overflow:
}
/*
- * 2.3.2. ftype
- *
- * enum ftype {
- * NFNON = 0,
- * NFREG = 1,
- * NFDIR = 2,
- * NFBLK = 3,
- * NFCHR = 4,
- * NFLNK = 5
- * };
- *
+ * Map file type to S_IFMT bits
*/
-static __be32 *xdr_decode_ftype(__be32 *p, u32 *type)
+static const umode_t nfs2_type2fmt[] = {
+ [NFNON] = 0,
+ [NFREG] = S_IFREG,
+ [NFDIR] = S_IFDIR,
+ [NFBLK] = S_IFBLK,
+ [NFCHR] = S_IFCHR,
+ [NFLNK] = S_IFLNK,
+ [NFSOCK] = S_IFSOCK,
+ [NFBAD] = 0,
+ [NFFIFO] = S_IFIFO,
+};
+
+static __be32 *xdr_decode_ftype(__be32 *p, umode_t *mode)
{
- *type = be32_to_cpup(p++);
- if (unlikely(*type > NF2FIFO))
- *type = NFBAD;
+ u32 type;
+
+ type = be32_to_cpup(p++);
+ if (unlikely(type > NF2FIFO))
+ type = NFBAD;
+ *mode = nfs2_type2fmt[type];
return p;
}
@@ -277,7 +282,8 @@ static __be32 *xdr_decode_time(__be32 *p, struct timespec *timep)
*/
static int decode_fattr(struct xdr_stream *xdr, struct nfs_fattr *fattr)
{
- u32 rdev, type;
+ umode_t fmode;
+ u32 rdev;
__be32 *p;
p = xdr_inline_decode(xdr, NFS_fattr_sz << 2);
@@ -286,9 +292,9 @@ static int decode_fattr(struct xdr_stream *xdr, struct nfs_fattr *fattr)
fattr->valid |= NFS_ATTR_FATTR_V2;
- p = xdr_decode_ftype(p, &type);
+ p = xdr_decode_ftype(p, &fmode);
- fattr->mode = be32_to_cpup(p++);
+ fattr->mode = (be32_to_cpup(p++) & ~S_IFMT) | fmode;
fattr->nlink = be32_to_cpup(p++);
fattr->uid = make_kuid(&init_user_ns, be32_to_cpup(p++));
if (!uid_valid(fattr->uid))
@@ -302,7 +308,7 @@ static int decode_fattr(struct xdr_stream *xdr, struct nfs_fattr *fattr)
rdev = be32_to_cpup(p++);
fattr->rdev = new_decode_dev(rdev);
- if (type == (u32)NFCHR && rdev == (u32)NFS2_FIFO_DEV) {
+ if (fmode == S_IFCHR && rdev == (u32)NFS2_FIFO_DEV) {
fattr->mode = (fattr->mode & ~S_IFMT) | S_IFIFO;
fattr->rdev = 0;
}