xref: /linux/fs/nfsd/vfs.h (revision d141ec2825b4d3ec52f27c43bdd864090159273a)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (C) 1995-1997 Olaf Kirch <okir@monad.swb.de>
4  */
5 
6 #ifndef LINUX_NFSD_VFS_H
7 #define LINUX_NFSD_VFS_H
8 
9 #include <linux/fs.h>
10 #include <linux/posix_acl.h>
11 #include "nfsfh.h"
12 
13 /*
14  * Flags for nfsd_permission
15  */
16 #define NFSD_MAY_NOP			0
17 #define NFSD_MAY_EXEC			0x001 /* == MAY_EXEC */
18 #define NFSD_MAY_WRITE			0x002 /* == MAY_WRITE */
19 #define NFSD_MAY_READ			0x004 /* == MAY_READ */
20 #define NFSD_MAY_SATTR			0x008
21 #define NFSD_MAY_TRUNC			0x010
22 #define NFSD_MAY_NLM			0x020 /* request is from lockd */
23 #define NFSD_MAY_MASK			0x03f
24 
25 /* extra hints to permission and open routines: */
26 #define NFSD_MAY_OWNER_OVERRIDE		0x040
27 #define NFSD_MAY_LOCAL_ACCESS		0x080 /* for device special files */
28 #define NFSD_MAY_BYPASS_GSS_ON_ROOT	0x100
29 #define NFSD_MAY_NOT_BREAK_LEASE	0x200
30 #define NFSD_MAY_BYPASS_GSS		0x400
31 #define NFSD_MAY_READ_IF_EXEC		0x800
32 
33 #define NFSD_MAY_64BIT_COOKIE		0x1000 /* 64 bit readdir cookies for >= NFSv3 */
34 
35 #define NFSD_MAY_LOCALIO		0x2000 /* for tracing, reflects when localio used */
36 
37 #define NFSD_MAY_CREATE		(NFSD_MAY_EXEC|NFSD_MAY_WRITE)
38 #define NFSD_MAY_REMOVE		(NFSD_MAY_EXEC|NFSD_MAY_WRITE|NFSD_MAY_TRUNC)
39 
40 struct nfsd_file;
41 
42 /*
43  * Callback function for readdir
44  */
45 typedef int (*nfsd_filldir_t)(void *, const char *, int, loff_t, u64, unsigned);
46 
47 struct readdir_cd {
48 	__be32			err;	/* nfs_ok, nfserr, or nfserr_eof */
49 };
50 
51 /* nfsd/vfs.c */
52 struct nfsd_attrs {
53 	struct iattr		*na_iattr;	/* input */
54 	struct xdr_netobj	*na_seclabel;	/* input */
55 	struct posix_acl	*na_pacl;	/* input */
56 	struct posix_acl	*na_dpacl;	/* input */
57 
58 	int			na_labelerr;	/* output */
59 	int			na_dpaclerr;	/* output */
60 	int			na_paclerr;	/* output */
61 };
62 
nfsd_attrs_free(struct nfsd_attrs * attrs)63 static inline void nfsd_attrs_free(struct nfsd_attrs *attrs)
64 {
65 	posix_acl_release(attrs->na_pacl);
66 	posix_acl_release(attrs->na_dpacl);
67 }
68 
nfsd_attrs_valid(struct nfsd_attrs * attrs)69 static inline bool nfsd_attrs_valid(struct nfsd_attrs *attrs)
70 {
71 	struct iattr *iap = attrs->na_iattr;
72 
73 	return (iap->ia_valid || (attrs->na_seclabel &&
74 		attrs->na_seclabel->len) ||
75 		attrs->na_pacl || attrs->na_dpacl);
76 }
77 
78 __be32		nfserrno (int errno);
79 int		nfsd_cross_mnt(struct svc_rqst *rqstp, struct dentry **dpp,
80 		                struct svc_export **expp);
81 __be32		nfsd_lookup(struct svc_rqst *, struct svc_fh *,
82 				const char *, unsigned int, struct svc_fh *);
83 __be32		 nfsd_lookup_dentry(struct svc_rqst *, struct svc_fh *,
84 				const char *, unsigned int,
85 				struct svc_export **, struct dentry **);
86 __be32		nfsd_setattr(struct svc_rqst *, struct svc_fh *,
87 			     struct nfsd_attrs *, const struct timespec64 *);
88 int nfsd_mountpoint(struct dentry *, struct svc_export *);
89 #ifdef CONFIG_NFSD_V4
90 __be32		nfsd4_vfs_fallocate(struct svc_rqst *, struct svc_fh *,
91 				    struct file *, loff_t, loff_t, int);
92 __be32		nfsd4_clone_file_range(struct svc_rqst *rqstp,
93 				       struct nfsd_file *nf_src, u64 src_pos,
94 				       struct nfsd_file *nf_dst, u64 dst_pos,
95 				       u64 count, bool sync);
96 #endif /* CONFIG_NFSD_V4 */
97 __be32		nfsd_create_locked(struct svc_rqst *, struct svc_fh *,
98 				struct nfsd_attrs *attrs, int type, dev_t rdev,
99 				struct svc_fh *res);
100 __be32		nfsd_create(struct svc_rqst *, struct svc_fh *,
101 				char *name, int len, struct nfsd_attrs *attrs,
102 				int type, dev_t rdev, struct svc_fh *res);
103 __be32		nfsd_access(struct svc_rqst *, struct svc_fh *, u32 *, u32 *);
104 __be32		nfsd_create_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
105 				struct svc_fh *resfhp, struct nfsd_attrs *iap);
106 __be32		nfsd_commit(struct svc_rqst *rqst, struct svc_fh *fhp,
107 				struct nfsd_file *nf, u64 offset, u32 count,
108 				__be32 *verf);
109 #ifdef CONFIG_NFSD_V4
110 __be32		nfsd_getxattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
111 			    char *name, void **bufp, int *lenp);
112 __be32		nfsd_listxattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
113 			    char **bufp, int *lenp);
114 __be32		nfsd_removexattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
115 			    char *name);
116 __be32		nfsd_setxattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
117 			    char *name, void *buf, u32 len, u32 flags);
118 #endif
119 int 		nfsd_open_break_lease(struct inode *, int);
120 __be32		nfsd_open(struct svc_rqst *, struct svc_fh *, umode_t,
121 				int, struct file **);
122 int		nfsd_open_verified(struct svc_fh *fhp, umode_t type, int may_flags,
123 				struct file **filp);
124 __be32		nfsd_splice_read(struct svc_rqst *rqstp, struct svc_fh *fhp,
125 				struct file *file, loff_t offset,
126 				unsigned long *count,
127 				u32 *eof);
128 __be32		nfsd_iter_read(struct svc_rqst *rqstp, struct svc_fh *fhp,
129 				struct nfsd_file *nf, loff_t offset,
130 				unsigned long *count, unsigned int base,
131 				u32 *eof);
132 bool		nfsd_read_splice_ok(struct svc_rqst *rqstp);
133 __be32		nfsd_read(struct svc_rqst *rqstp, struct svc_fh *fhp,
134 				loff_t offset, unsigned long *count,
135 				u32 *eof);
136 __be32		nfsd_write(struct svc_rqst *rqstp, struct svc_fh *fhp,
137 				loff_t offset, const struct xdr_buf *payload,
138 				unsigned long *cnt, int stable, __be32 *verf);
139 __be32		nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp,
140 				struct nfsd_file *nf, loff_t offset,
141 				const struct xdr_buf *payload,
142 				unsigned long *cnt, int stable, __be32 *verf);
143 __be32		nfsd_readlink(struct svc_rqst *, struct svc_fh *,
144 				char *, int *);
145 __be32		nfsd_symlink(struct svc_rqst *, struct svc_fh *,
146 			     char *name, int len, char *path,
147 			     struct nfsd_attrs *attrs,
148 			     struct svc_fh *res);
149 __be32		nfsd_link(struct svc_rqst *, struct svc_fh *,
150 				char *, int, struct svc_fh *);
151 ssize_t		nfsd_copy_file_range(struct file *, u64,
152 				     struct file *, u64, u64);
153 __be32		nfsd_rename(struct svc_rqst *,
154 				struct svc_fh *, char *, int,
155 				struct svc_fh *, char *, int);
156 __be32		nfsd_unlink(struct svc_rqst *, struct svc_fh *, int type,
157 				char *name, int len);
158 __be32		nfsd_readdir(struct svc_rqst *, struct svc_fh *,
159 			     loff_t *, struct readdir_cd *, nfsd_filldir_t);
160 __be32		nfsd_statfs(struct svc_rqst *, struct svc_fh *,
161 				struct kstatfs *, int access);
162 int		nfsd_get_case_info(struct dentry *dentry,
163 				   bool *case_insensitive,
164 				   bool *case_preserving);
165 
166 __be32		nfsd_permission(struct svc_cred *cred, struct svc_export *exp,
167 				struct dentry *dentry, int acc);
168 
169 void		nfsd_filp_close(struct file *fp);
170 
171 #endif /* LINUX_NFSD_VFS_H */
172