xref: /openbmc/linux/fs/nfsd/vfs.h (revision b97d6790d03b763eca08847a9a5869a4291b9f9a)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
20a3adadeSJ. Bruce Fields /*
30a3adadeSJ. Bruce Fields  * Copyright (C) 1995-1997 Olaf Kirch <okir@monad.swb.de>
40a3adadeSJ. Bruce Fields  */
50a3adadeSJ. Bruce Fields 
60a3adadeSJ. Bruce Fields #ifndef LINUX_NFSD_VFS_H
70a3adadeSJ. Bruce Fields #define LINUX_NFSD_VFS_H
80a3adadeSJ. Bruce Fields 
9c0cbe707SNeilBrown #include <linux/fs.h>
10c0cbe707SNeilBrown #include <linux/posix_acl.h>
111557aca7SJ. Bruce Fields #include "nfsfh.h"
123dadecceSAl Viro #include "nfsd.h"
131557aca7SJ. Bruce Fields 
140a3adadeSJ. Bruce Fields /*
150a3adadeSJ. Bruce Fields  * Flags for nfsd_permission
160a3adadeSJ. Bruce Fields  */
170a3adadeSJ. Bruce Fields #define NFSD_MAY_NOP			0
188e82fa8fSJ. Bruce Fields #define NFSD_MAY_EXEC			0x001 /* == MAY_EXEC */
198e82fa8fSJ. Bruce Fields #define NFSD_MAY_WRITE			0x002 /* == MAY_WRITE */
208e82fa8fSJ. Bruce Fields #define NFSD_MAY_READ			0x004 /* == MAY_READ */
218e82fa8fSJ. Bruce Fields #define NFSD_MAY_SATTR			0x008
228e82fa8fSJ. Bruce Fields #define NFSD_MAY_TRUNC			0x010
238e82fa8fSJ. Bruce Fields #define NFSD_MAY_LOCK			0x020
248e82fa8fSJ. Bruce Fields #define NFSD_MAY_MASK			0x03f
25aea93397SJ. Bruce Fields 
26aea93397SJ. Bruce Fields /* extra hints to permission and open routines: */
278e82fa8fSJ. Bruce Fields #define NFSD_MAY_OWNER_OVERRIDE		0x040
288e82fa8fSJ. Bruce Fields #define NFSD_MAY_LOCAL_ACCESS		0x080 /* for device special files */
298e82fa8fSJ. Bruce Fields #define NFSD_MAY_BYPASS_GSS_ON_ROOT	0x100
308e82fa8fSJ. Bruce Fields #define NFSD_MAY_NOT_BREAK_LEASE	0x200
318e82fa8fSJ. Bruce Fields #define NFSD_MAY_BYPASS_GSS		0x400
328e82fa8fSJ. Bruce Fields #define NFSD_MAY_READ_IF_EXEC		0x800
330a3adadeSJ. Bruce Fields 
3406effdbbSBernd Schubert #define NFSD_MAY_64BIT_COOKIE		0x1000 /* 64 bit readdir cookies for >= NFSv3 */
3506effdbbSBernd Schubert 
360a3adadeSJ. Bruce Fields #define NFSD_MAY_CREATE		(NFSD_MAY_EXEC|NFSD_MAY_WRITE)
370a3adadeSJ. Bruce Fields #define NFSD_MAY_REMOVE		(NFSD_MAY_EXEC|NFSD_MAY_WRITE|NFSD_MAY_TRUNC)
380a3adadeSJ. Bruce Fields 
3916f8f894STrond Myklebust struct nfsd_file;
4016f8f894STrond Myklebust 
410a3adadeSJ. Bruce Fields /*
420a3adadeSJ. Bruce Fields  * Callback function for readdir
430a3adadeSJ. Bruce Fields  */
44ac7576f4SMiklos Szeredi typedef int (*nfsd_filldir_t)(void *, const char *, int, loff_t, u64, unsigned);
450a3adadeSJ. Bruce Fields 
460a3adadeSJ. Bruce Fields /* nfsd/vfs.c */
477fe2a71dSNeilBrown struct nfsd_attrs {
487fe2a71dSNeilBrown 	struct iattr		*na_iattr;	/* input */
49d6a97d3fSNeilBrown 	struct xdr_netobj	*na_seclabel;	/* input */
50c0cbe707SNeilBrown 	struct posix_acl	*na_pacl;	/* input */
51c0cbe707SNeilBrown 	struct posix_acl	*na_dpacl;	/* input */
52d6a97d3fSNeilBrown 
53d6a97d3fSNeilBrown 	int			na_labelerr;	/* output */
54c0cbe707SNeilBrown 	int			na_aclerr;	/* output */
557fe2a71dSNeilBrown };
567fe2a71dSNeilBrown 
nfsd_attrs_free(struct nfsd_attrs * attrs)57c0cbe707SNeilBrown static inline void nfsd_attrs_free(struct nfsd_attrs *attrs)
58c0cbe707SNeilBrown {
59c0cbe707SNeilBrown 	posix_acl_release(attrs->na_pacl);
60c0cbe707SNeilBrown 	posix_acl_release(attrs->na_dpacl);
61c0cbe707SNeilBrown }
62c0cbe707SNeilBrown 
63cb12fae1SJeff Layton __be32		nfserrno (int errno);
640a3adadeSJ. Bruce Fields int		nfsd_cross_mnt(struct svc_rqst *rqstp, struct dentry **dpp,
650a3adadeSJ. Bruce Fields 		                struct svc_export **expp);
660a3adadeSJ. Bruce Fields __be32		nfsd_lookup(struct svc_rqst *, struct svc_fh *,
670a3adadeSJ. Bruce Fields 				const char *, unsigned int, struct svc_fh *);
680a3adadeSJ. Bruce Fields __be32		 nfsd_lookup_dentry(struct svc_rqst *, struct svc_fh *,
690a3adadeSJ. Bruce Fields 				const char *, unsigned int,
700a3adadeSJ. Bruce Fields 				struct svc_export **, struct dentry **);
710a3adadeSJ. Bruce Fields __be32		nfsd_setattr(struct svc_rqst *, struct svc_fh *,
727fe2a71dSNeilBrown 				struct nfsd_attrs *, int, time64_t);
733227fa41SJ. Bruce Fields int nfsd_mountpoint(struct dentry *, struct svc_export *);
740a3adadeSJ. Bruce Fields #ifdef CONFIG_NFSD_V4
7595d871f0SAnna Schumaker __be32		nfsd4_vfs_fallocate(struct svc_rqst *, struct svc_fh *,
7695d871f0SAnna Schumaker 				    struct file *, loff_t, loff_t, int);
77a2f4c3faSTrond Myklebust __be32		nfsd4_clone_file_range(struct svc_rqst *rqstp,
78a2f4c3faSTrond Myklebust 				       struct nfsd_file *nf_src, u64 src_pos,
79b66ae6ddSTrond Myklebust 				       struct nfsd_file *nf_dst, u64 dst_pos,
80b66ae6ddSTrond Myklebust 				       u64 count, bool sync);
810a3adadeSJ. Bruce Fields #endif /* CONFIG_NFSD_V4 */
82b44061d0SJ. Bruce Fields __be32		nfsd_create_locked(struct svc_rqst *, struct svc_fh *,
839558f930SNeilBrown 				struct nfsd_attrs *attrs, int type, dev_t rdev,
849558f930SNeilBrown 				struct svc_fh *res);
850a3adadeSJ. Bruce Fields __be32		nfsd_create(struct svc_rqst *, struct svc_fh *,
867fe2a71dSNeilBrown 				char *name, int len, struct nfsd_attrs *attrs,
870a3adadeSJ. Bruce Fields 				int type, dev_t rdev, struct svc_fh *res);
880a3adadeSJ. Bruce Fields __be32		nfsd_access(struct svc_rqst *, struct svc_fh *, u32 *, u32 *);
895f46e950SChuck Lever __be32		nfsd_create_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
907fe2a71dSNeilBrown 				struct svc_fh *resfhp, struct nfsd_attrs *iap);
913f965021SChuck Lever __be32		nfsd_commit(struct svc_rqst *rqst, struct svc_fh *fhp,
92c2528490SChuck Lever 				struct nfsd_file *nf, u64 offset, u32 count,
93c2528490SChuck Lever 				__be32 *verf);
9432119446SFrank van der Linden #ifdef CONFIG_NFSD_V4
9532119446SFrank van der Linden __be32		nfsd_getxattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
9632119446SFrank van der Linden 			    char *name, void **bufp, int *lenp);
9732119446SFrank van der Linden __be32		nfsd_listxattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
9832119446SFrank van der Linden 			    char **bufp, int *lenp);
9932119446SFrank van der Linden __be32		nfsd_removexattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
10032119446SFrank van der Linden 			    char *name);
10132119446SFrank van der Linden __be32		nfsd_setxattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
10232119446SFrank van der Linden 			    char *name, void *buf, u32 len, u32 flags);
10332119446SFrank van der Linden #endif
10465294c1fSJeff Layton int 		nfsd_open_break_lease(struct inode *, int);
105175a4eb7SAl Viro __be32		nfsd_open(struct svc_rqst *, struct svc_fh *, umode_t,
1060a3adadeSJ. Bruce Fields 				int, struct file **);
107*83f8fc2cSTrond Myklebust int		nfsd_open_verified(struct svc_rqst *rqstp, struct svc_fh *fhp,
108*83f8fc2cSTrond Myklebust 				   int may_flags, struct file **filp);
10987c5942eSChuck Lever __be32		nfsd_splice_read(struct svc_rqst *rqstp, struct svc_fh *fhp,
11087c5942eSChuck Lever 				struct file *file, loff_t offset,
11183a63072STrond Myklebust 				unsigned long *count,
11283a63072STrond Myklebust 				u32 *eof);
113507df40eSChuck Lever __be32		nfsd_iter_read(struct svc_rqst *rqstp, struct svc_fh *fhp,
114507df40eSChuck Lever 				struct file *file, loff_t offset,
115507df40eSChuck Lever 				unsigned long *count, unsigned int base,
116507df40eSChuck Lever 				u32 *eof);
117507df40eSChuck Lever __be32		nfsd_read(struct svc_rqst *rqstp, struct svc_fh *fhp,
118507df40eSChuck Lever 				loff_t offset, unsigned long *count,
11983a63072STrond Myklebust 				u32 *eof);
12052e380e0SKinglong Mee __be32 		nfsd_write(struct svc_rqst *, struct svc_fh *, loff_t,
12119e0663fSTrond Myklebust 				struct kvec *, int, unsigned long *,
12219e0663fSTrond Myklebust 				int stable, __be32 *verf);
123af90f707SChristoph Hellwig __be32		nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp,
12416f8f894STrond Myklebust 				struct nfsd_file *nf, loff_t offset,
125af90f707SChristoph Hellwig 				struct kvec *vec, int vlen, unsigned long *cnt,
12619e0663fSTrond Myklebust 				int stable, __be32 *verf);
1270a3adadeSJ. Bruce Fields __be32		nfsd_readlink(struct svc_rqst *, struct svc_fh *,
1280a3adadeSJ. Bruce Fields 				char *, int *);
1290a3adadeSJ. Bruce Fields __be32		nfsd_symlink(struct svc_rqst *, struct svc_fh *,
13052ee0433SJ. Bruce Fields 			     char *name, int len, char *path,
13193adc1e3SNeilBrown 			     struct nfsd_attrs *attrs,
1321e444f5bSKinglong Mee 			     struct svc_fh *res);
1330a3adadeSJ. Bruce Fields __be32		nfsd_link(struct svc_rqst *, struct svc_fh *,
1340a3adadeSJ. Bruce Fields 				char *, int, struct svc_fh *);
13529ae7f9dSAnna Schumaker ssize_t		nfsd_copy_file_range(struct file *, u64,
13629ae7f9dSAnna Schumaker 				     struct file *, u64, u64);
1370a3adadeSJ. Bruce Fields __be32		nfsd_rename(struct svc_rqst *,
1380a3adadeSJ. Bruce Fields 				struct svc_fh *, char *, int,
1390a3adadeSJ. Bruce Fields 				struct svc_fh *, char *, int);
1400a3adadeSJ. Bruce Fields __be32		nfsd_unlink(struct svc_rqst *, struct svc_fh *, int type,
1410a3adadeSJ. Bruce Fields 				char *name, int len);
1420a3adadeSJ. Bruce Fields __be32		nfsd_readdir(struct svc_rqst *, struct svc_fh *,
143ac7576f4SMiklos Szeredi 			     loff_t *, struct readdir_cd *, nfsd_filldir_t);
1440a3adadeSJ. Bruce Fields __be32		nfsd_statfs(struct svc_rqst *, struct svc_fh *,
1450a3adadeSJ. Bruce Fields 				struct kstatfs *, int access);
1460a3adadeSJ. Bruce Fields 
1470a3adadeSJ. Bruce Fields __be32		nfsd_permission(struct svc_rqst *, struct svc_export *,
1480a3adadeSJ. Bruce Fields 				struct dentry *, int);
1490a3adadeSJ. Bruce Fields 
fh_want_write(struct svc_fh * fh)150bad0dcffSAl Viro static inline int fh_want_write(struct svc_fh *fh)
151bad0dcffSAl Viro {
1520b8f6262SJ. Bruce Fields 	int ret;
1534a55c101SJan Kara 
1540b8f6262SJ. Bruce Fields 	if (fh->fh_want_write)
1550b8f6262SJ. Bruce Fields 		return 0;
1560b8f6262SJ. Bruce Fields 	ret = mnt_want_write(fh->fh_export->ex_path.mnt);
1574a55c101SJan Kara 	if (!ret)
158aaf91ec1SJeff Layton 		fh->fh_want_write = true;
1594a55c101SJan Kara 	return ret;
160bad0dcffSAl Viro }
161bad0dcffSAl Viro 
fh_drop_write(struct svc_fh * fh)162bad0dcffSAl Viro static inline void fh_drop_write(struct svc_fh *fh)
163bad0dcffSAl Viro {
1644a55c101SJan Kara 	if (fh->fh_want_write) {
165aaf91ec1SJeff Layton 		fh->fh_want_write = false;
166bad0dcffSAl Viro 		mnt_drop_write(fh->fh_export->ex_path.mnt);
167bad0dcffSAl Viro 	}
1684a55c101SJan Kara }
169bad0dcffSAl Viro 
fh_getattr(const struct svc_fh * fh,struct kstat * stat)170907c3822SChuck Lever static inline __be32 fh_getattr(const struct svc_fh *fh, struct kstat *stat)
1713dadecceSAl Viro {
172638e3e7dSJeff Layton 	u32 request_mask = STATX_BASIC_STATS;
1733dadecceSAl Viro 	struct path p = {.mnt = fh->fh_export->ex_path.mnt,
1743dadecceSAl Viro 			 .dentry = fh->fh_dentry};
175638e3e7dSJeff Layton 
176638e3e7dSJeff Layton 	if (fh->fh_maxsize == NFS4_FHSIZE)
177638e3e7dSJeff Layton 		request_mask |= (STATX_BTIME | STATX_CHANGE_COOKIE);
178638e3e7dSJeff Layton 
179638e3e7dSJeff Layton 	return nfserrno(vfs_getattr(&p, stat, request_mask,
180a528d35eSDavid Howells 				    AT_STATX_SYNC_AS_STAT));
1813dadecceSAl Viro }
1823dadecceSAl Viro 
1830a3adadeSJ. Bruce Fields #endif /* LINUX_NFSD_VFS_H */
184