xref: /openbmc/linux/include/linux/nfs.h (revision e59fb674)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds  * NFS protocol definitions
41da177e4SLinus Torvalds  *
51da177e4SLinus Torvalds  * This file contains constants mostly for Version 2 of the protocol,
61da177e4SLinus Torvalds  * but also has a couple of NFSv3 bits in (notably the error codes).
71da177e4SLinus Torvalds  */
81da177e4SLinus Torvalds #ifndef _LINUX_NFS_H
91da177e4SLinus Torvalds #define _LINUX_NFS_H
101da177e4SLinus Torvalds 
11997b7af2SDavid Woodhouse #include <linux/sunrpc/msg_prot.h>
12997b7af2SDavid Woodhouse #include <linux/string.h>
13*e59fb674SJeff Layton #include <linux/crc32.h>
14607ca46eSDavid Howells #include <uapi/linux/nfs.h>
15997b7af2SDavid Woodhouse 
161da177e4SLinus Torvalds /*
171da177e4SLinus Torvalds  * This is the kernel NFS client file handle representation
181da177e4SLinus Torvalds  */
191da177e4SLinus Torvalds #define NFS_MAXFHSIZE		128
201da177e4SLinus Torvalds struct nfs_fh {
211da177e4SLinus Torvalds 	unsigned short		size;
221da177e4SLinus Torvalds 	unsigned char		data[NFS_MAXFHSIZE];
231da177e4SLinus Torvalds };
241da177e4SLinus Torvalds 
251da177e4SLinus Torvalds /*
261da177e4SLinus Torvalds  * Returns a zero iff the size and data fields match.
271da177e4SLinus Torvalds  * Checks only "size" bytes in the data field.
281da177e4SLinus Torvalds  */
nfs_compare_fh(const struct nfs_fh * a,const struct nfs_fh * b)291da177e4SLinus Torvalds static inline int nfs_compare_fh(const struct nfs_fh *a, const struct nfs_fh *b)
301da177e4SLinus Torvalds {
311da177e4SLinus Torvalds 	return a->size != b->size || memcmp(a->data, b->data, a->size) != 0;
321da177e4SLinus Torvalds }
331da177e4SLinus Torvalds 
nfs_copy_fh(struct nfs_fh * target,const struct nfs_fh * source)341da177e4SLinus Torvalds static inline void nfs_copy_fh(struct nfs_fh *target, const struct nfs_fh *source)
351da177e4SLinus Torvalds {
361da177e4SLinus Torvalds 	target->size = source->size;
371da177e4SLinus Torvalds 	memcpy(target->data, source->data, source->size);
381da177e4SLinus Torvalds }
391da177e4SLinus Torvalds 
401da177e4SLinus Torvalds enum nfs3_stable_how {
411da177e4SLinus Torvalds 	NFS_UNSTABLE = 0,
421da177e4SLinus Torvalds 	NFS_DATA_SYNC = 1,
435002c586SWeston Andros Adamson 	NFS_FILE_SYNC = 2,
445002c586SWeston Andros Adamson 
455002c586SWeston Andros Adamson 	/* used by direct.c to mark verf as invalid */
465002c586SWeston Andros Adamson 	NFS_INVALID_STABLE_HOW = -1
471da177e4SLinus Torvalds };
48*e59fb674SJeff Layton 
49*e59fb674SJeff Layton #ifdef CONFIG_CRC32
50*e59fb674SJeff Layton /**
51*e59fb674SJeff Layton  * nfs_fhandle_hash - calculate the crc32 hash for the filehandle
52*e59fb674SJeff Layton  * @fh - pointer to filehandle
53*e59fb674SJeff Layton  *
54*e59fb674SJeff Layton  * returns a crc32 hash for the filehandle that is compatible with
55*e59fb674SJeff Layton  * the one displayed by "wireshark".
56*e59fb674SJeff Layton  */
nfs_fhandle_hash(const struct nfs_fh * fh)57*e59fb674SJeff Layton static inline u32 nfs_fhandle_hash(const struct nfs_fh *fh)
58*e59fb674SJeff Layton {
59*e59fb674SJeff Layton 	return ~crc32_le(0xFFFFFFFF, &fh->data[0], fh->size);
60*e59fb674SJeff Layton }
61*e59fb674SJeff Layton #else /* CONFIG_CRC32 */
nfs_fhandle_hash(const struct nfs_fh * fh)62*e59fb674SJeff Layton static inline u32 nfs_fhandle_hash(const struct nfs_fh *fh)
63*e59fb674SJeff Layton {
64*e59fb674SJeff Layton 	return 0;
65*e59fb674SJeff Layton }
66*e59fb674SJeff Layton #endif /* CONFIG_CRC32 */
671da177e4SLinus Torvalds #endif /* _LINUX_NFS_H */
68