xref: /linux/fs/nfsd/xdr.h (revision d141ec2825b4d3ec52f27c43bdd864090159273a)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* XDR types for nfsd. This is mainly a typing exercise. */
3 
4 #ifndef LINUX_NFSD_H
5 #define LINUX_NFSD_H
6 
7 #include <linux/vfs.h>
8 #include "nfsd.h"
9 #include "nfsfh.h"
10 #include "vfs.h"
11 
12 struct nfsd_fhandle {
13 	struct svc_fh		fh;
14 };
15 
16 struct nfsd_sattrargs {
17 	struct svc_fh		fh;
18 	struct iattr		attrs;
19 };
20 
21 struct nfsd_diropargs {
22 	struct svc_fh		fh;
23 	char *			name;
24 	unsigned int		len;
25 };
26 
27 struct nfsd_readargs {
28 	struct svc_fh		fh;
29 	__u32			offset;
30 	__u32			count;
31 };
32 
33 struct nfsd_writeargs {
34 	svc_fh			fh;
35 	__u32			offset;
36 	__u32			len;
37 	struct xdr_buf		payload;
38 };
39 
40 struct nfsd_createargs {
41 	struct svc_fh		fh;
42 	char *			name;
43 	unsigned int		len;
44 	struct iattr		attrs;
45 };
46 
47 struct nfsd_renameargs {
48 	struct svc_fh		ffh;
49 	char *			fname;
50 	unsigned int		flen;
51 	struct svc_fh		tfh;
52 	char *			tname;
53 	unsigned int		tlen;
54 };
55 
56 struct nfsd_linkargs {
57 	struct svc_fh		ffh;
58 	struct svc_fh		tfh;
59 	char *			tname;
60 	unsigned int		tlen;
61 };
62 
63 struct nfsd_symlinkargs {
64 	struct svc_fh		ffh;
65 	char *			fname;
66 	unsigned int		flen;
67 	char *			tname;
68 	unsigned int		tlen;
69 	struct iattr		attrs;
70 	struct kvec		first;
71 };
72 
73 struct nfsd_readdirargs {
74 	struct svc_fh		fh;
75 	__u32			cookie;
76 	__u32			count;
77 };
78 
79 struct nfsd_stat {
80 	__be32			status;
81 };
82 
83 struct nfsd_attrstat {
84 	__be32			status;
85 	struct svc_fh		fh;
86 	struct kstat		stat;
87 };
88 
89 struct nfsd_diropres  {
90 	__be32			status;
91 	struct svc_fh		fh;
92 	struct kstat		stat;
93 };
94 
95 struct nfsd_readlinkres {
96 	__be32			status;
97 	int			len;
98 	struct page		*page;
99 };
100 
101 struct nfsd_readres {
102 	__be32			status;
103 	struct svc_fh		fh;
104 	unsigned long		count;
105 	struct kstat		stat;
106 	struct page		**pages;
107 };
108 
109 struct nfsd_readdirres {
110 	/* Components of the reply */
111 	__be32			status;
112 
113 	int			count;
114 
115 	/* Used to encode the reply's entry list */
116 	struct xdr_stream	xdr;
117 	struct xdr_buf		dirlist;
118 	struct readdir_cd	common;
119 	unsigned int		cookie_offset;
120 };
121 
122 struct nfsd_statfsres {
123 	__be32			status;
124 	struct kstatfs		stats;
125 };
126 
127 /*
128  * Storage requirements for XDR arguments and results.
129  */
130 union nfsd_xdrstore {
131 	struct nfsd_sattrargs	sattr;
132 	struct nfsd_diropargs	dirop;
133 	struct nfsd_readargs	read;
134 	struct nfsd_writeargs	write;
135 	struct nfsd_createargs	create;
136 	struct nfsd_renameargs	rename;
137 	struct nfsd_linkargs	link;
138 	struct nfsd_symlinkargs	symlink;
139 	struct nfsd_readdirargs	readdir;
140 };
141 
142 #define NFS2_SVC_XDRSIZE	sizeof(union nfsd_xdrstore)
143 
144 
145 bool nfssvc_decode_fhandleargs(struct svc_rqst *rqstp, struct xdr_stream *xdr);
146 bool nfssvc_decode_sattrargs(struct svc_rqst *rqstp, struct xdr_stream *xdr);
147 bool nfssvc_decode_diropargs(struct svc_rqst *rqstp, struct xdr_stream *xdr);
148 bool nfssvc_decode_readargs(struct svc_rqst *rqstp, struct xdr_stream *xdr);
149 bool nfssvc_decode_writeargs(struct svc_rqst *rqstp, struct xdr_stream *xdr);
150 bool nfssvc_decode_createargs(struct svc_rqst *rqstp, struct xdr_stream *xdr);
151 bool nfssvc_decode_renameargs(struct svc_rqst *rqstp, struct xdr_stream *xdr);
152 bool nfssvc_decode_linkargs(struct svc_rqst *rqstp, struct xdr_stream *xdr);
153 bool nfssvc_decode_symlinkargs(struct svc_rqst *rqstp, struct xdr_stream *xdr);
154 bool nfssvc_decode_readdirargs(struct svc_rqst *rqstp, struct xdr_stream *xdr);
155 
156 bool nfssvc_encode_statres(struct svc_rqst *rqstp, struct xdr_stream *xdr);
157 bool nfssvc_encode_attrstatres(struct svc_rqst *rqstp, struct xdr_stream *xdr);
158 bool nfssvc_encode_diropres(struct svc_rqst *rqstp, struct xdr_stream *xdr);
159 bool nfssvc_encode_readlinkres(struct svc_rqst *rqstp, struct xdr_stream *xdr);
160 bool nfssvc_encode_readres(struct svc_rqst *rqstp, struct xdr_stream *xdr);
161 bool nfssvc_encode_statfsres(struct svc_rqst *rqstp, struct xdr_stream *xdr);
162 bool nfssvc_encode_readdirres(struct svc_rqst *rqstp, struct xdr_stream *xdr);
163 
164 void nfssvc_encode_nfscookie(struct nfsd_readdirres *resp, u32 offset);
165 int nfssvc_encode_entry(void *data, const char *name, int namlen,
166 			loff_t offset, u64 ino, unsigned int d_type);
167 
168 void nfssvc_release_attrstat(struct svc_rqst *rqstp);
169 void nfssvc_release_diropres(struct svc_rqst *rqstp);
170 void nfssvc_release_readres(struct svc_rqst *rqstp);
171 
172 /* Helper functions for NFSv2 ACL code */
173 bool svcxdr_decode_fhandle(struct xdr_stream *xdr, struct svc_fh *fhp);
174 bool svcxdr_encode_stat(struct xdr_stream *xdr, __be32 status);
175 bool svcxdr_encode_fattr(struct svc_rqst *rqstp, struct xdr_stream *xdr,
176 			 const struct svc_fh *fhp, const struct kstat *stat);
177 
178 #endif /* LINUX_NFSD_H */
179