1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 * NFS protocol definitions
4 *
5 * This file contains constants mostly for Version 2 of the protocol,
6 * but also has a couple of NFSv3 bits in (notably the error codes).
7 */
8 #ifndef _LINUX_NFS_H
9 #define _LINUX_NFS_H
10
11 #include <linux/cred.h>
12 #include <linux/sunrpc/auth.h>
13 #include <linux/sunrpc/msg_prot.h>
14 #include <linux/string.h>
15 #include <linux/crc32.h>
16 #include <uapi/linux/nfs.h>
17
18 /* The LOCALIO program is entirely private to Linux and is
19 * NOT part of the uapi.
20 */
21 #define NFS_LOCALIO_PROGRAM 400122
22 #define LOCALIOPROC_NULL 0
23 #define LOCALIOPROC_UUID_IS_LOCAL 1
24
25 /*
26 * This is the kernel NFS client file handle representation
27 */
28 #define NFS_MAXFHSIZE 128
29 struct nfs_fh {
30 unsigned short size;
31 unsigned char data[NFS_MAXFHSIZE];
32 };
33
34 /*
35 * Returns a zero iff the size and data fields match.
36 * Checks only "size" bytes in the data field.
37 */
nfs_compare_fh(const struct nfs_fh * a,const struct nfs_fh * b)38 static inline int nfs_compare_fh(const struct nfs_fh *a, const struct nfs_fh *b)
39 {
40 return a->size != b->size || memcmp(a->data, b->data, a->size) != 0;
41 }
42
nfs_copy_fh(struct nfs_fh * target,const struct nfs_fh * source)43 static inline void nfs_copy_fh(struct nfs_fh *target, const struct nfs_fh *source)
44 {
45 target->size = source->size;
46 memcpy(target->data, source->data, source->size);
47 }
48
49 enum nfs3_stable_how {
50 NFS_UNSTABLE = 0,
51 NFS_DATA_SYNC = 1,
52 NFS_FILE_SYNC = 2,
53
54 /* used by direct.c to mark verf as invalid */
55 NFS_INVALID_STABLE_HOW = -1
56 };
57
58 #ifdef CONFIG_CRC32
59 /**
60 * nfs_fhandle_hash - calculate the crc32 hash for the filehandle
61 * @fh - pointer to filehandle
62 *
63 * returns a crc32 hash for the filehandle that is compatible with
64 * the one displayed by "wireshark".
65 */
nfs_fhandle_hash(const struct nfs_fh * fh)66 static inline u32 nfs_fhandle_hash(const struct nfs_fh *fh)
67 {
68 return ~crc32_le(0xFFFFFFFF, &fh->data[0], fh->size);
69 }
70 #else /* CONFIG_CRC32 */
nfs_fhandle_hash(const struct nfs_fh * fh)71 static inline u32 nfs_fhandle_hash(const struct nfs_fh *fh)
72 {
73 return 0;
74 }
75 #endif /* CONFIG_CRC32 */
76 #endif /* _LINUX_NFS_H */
77