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
29struct 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 */
38static 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
43static inline void nfs_copy_fh(struct nfs_fh *target, const struct nfs_fh *source)
44{
45 target->size = source->size;
46 memcpy(to: target->data, from: source->data, len: source->size);
47}
48
49enum 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/**
59 * nfs_fhandle_hash - calculate the crc32 hash for the filehandle
60 * @fh - pointer to filehandle
61 *
62 * returns a crc32 hash for the filehandle that is compatible with
63 * the one displayed by "wireshark".
64 */
65static inline u32 nfs_fhandle_hash(const struct nfs_fh *fh)
66{
67 return ~crc32_le(crc: 0xFFFFFFFF, p: &fh->data[0], len: fh->size);
68}
69#endif /* _LINUX_NFS_H */
70