]> git.openfabrics.org - ~shefty/rdma-dev.git/commitdiff
nfsd4: clean up S_IS -> NF4 file type mapping
authorJ. Bruce Fields <bfields@redhat.com>
Mon, 15 Aug 2011 15:49:30 +0000 (11:49 -0400)
committerJ. Bruce Fields <bfields@redhat.com>
Fri, 26 Aug 2011 22:22:47 +0000 (18:22 -0400)
A slightly unconventional approach to make the code more compact I could
live with, but let's give the poor reader *some* chance.

Signed-off-by: J. Bruce Fields <bfields@redhat.com>
fs/nfsd/nfs4xdr.c

index f81099605256fdac4b3249a4d10cb93eaf507b46..51ec1f2745010bc6521708325b2b5774685566ec 100644 (file)
@@ -1772,12 +1772,19 @@ static __be32 nfsd4_encode_fs_locations(struct svc_rqst *rqstp,
        return 0;
 }
 
-static u32 nfs4_ftypes[16] = {
-        NF4BAD,  NF4FIFO, NF4CHR, NF4BAD,
-        NF4DIR,  NF4BAD,  NF4BLK, NF4BAD,
-        NF4REG,  NF4BAD,  NF4LNK, NF4BAD,
-        NF4SOCK, NF4BAD,  NF4LNK, NF4BAD,
-};
+static u32 nfs4_file_type(umode_t mode)
+{
+       switch (mode & S_IFMT) {
+       case S_IFIFO:   return NF4FIFO;
+       case S_IFCHR:   return NF4CHR;
+       case S_IFDIR:   return NF4DIR;
+       case S_IFBLK:   return NF4BLK;
+       case S_IFLNK:   return NF4LNK;
+       case S_IFREG:   return NF4REG;
+       case S_IFSOCK:  return NF4SOCK;
+       default:        return NF4BAD;
+       };
+}
 
 static __be32
 nfsd4_encode_name(struct svc_rqst *rqstp, int whotype, uid_t id, int group,
@@ -1966,7 +1973,7 @@ nfsd4_encode_fattr(struct svc_fh *fhp, struct svc_export *exp,
        if (bmval0 & FATTR4_WORD0_TYPE) {
                if ((buflen -= 4) < 0)
                        goto out_resource;
-               dummy = nfs4_ftypes[(stat.mode & S_IFMT) >> 12];
+               dummy = nfs4_file_type(stat.mode);
                if (dummy == NF4BAD)
                        goto out_serverfault;
                WRITE32(dummy);