18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (C) 1995-1997 Olaf Kirch <okir@monad.swb.de> 48c2ecf20Sopenharmony_ci */ 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci#ifndef LINUX_NFSD_VFS_H 78c2ecf20Sopenharmony_ci#define LINUX_NFSD_VFS_H 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#include "nfsfh.h" 108c2ecf20Sopenharmony_ci#include "nfsd.h" 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci/* 138c2ecf20Sopenharmony_ci * Flags for nfsd_permission 148c2ecf20Sopenharmony_ci */ 158c2ecf20Sopenharmony_ci#define NFSD_MAY_NOP 0 168c2ecf20Sopenharmony_ci#define NFSD_MAY_EXEC 0x001 /* == MAY_EXEC */ 178c2ecf20Sopenharmony_ci#define NFSD_MAY_WRITE 0x002 /* == MAY_WRITE */ 188c2ecf20Sopenharmony_ci#define NFSD_MAY_READ 0x004 /* == MAY_READ */ 198c2ecf20Sopenharmony_ci#define NFSD_MAY_SATTR 0x008 208c2ecf20Sopenharmony_ci#define NFSD_MAY_TRUNC 0x010 218c2ecf20Sopenharmony_ci#define NFSD_MAY_LOCK 0x020 228c2ecf20Sopenharmony_ci#define NFSD_MAY_MASK 0x03f 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci/* extra hints to permission and open routines: */ 258c2ecf20Sopenharmony_ci#define NFSD_MAY_OWNER_OVERRIDE 0x040 268c2ecf20Sopenharmony_ci#define NFSD_MAY_LOCAL_ACCESS 0x080 /* for device special files */ 278c2ecf20Sopenharmony_ci#define NFSD_MAY_BYPASS_GSS_ON_ROOT 0x100 288c2ecf20Sopenharmony_ci#define NFSD_MAY_NOT_BREAK_LEASE 0x200 298c2ecf20Sopenharmony_ci#define NFSD_MAY_BYPASS_GSS 0x400 308c2ecf20Sopenharmony_ci#define NFSD_MAY_READ_IF_EXEC 0x800 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci#define NFSD_MAY_64BIT_COOKIE 0x1000 /* 64 bit readdir cookies for >= NFSv3 */ 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci#define NFSD_MAY_CREATE (NFSD_MAY_EXEC|NFSD_MAY_WRITE) 358c2ecf20Sopenharmony_ci#define NFSD_MAY_REMOVE (NFSD_MAY_EXEC|NFSD_MAY_WRITE|NFSD_MAY_TRUNC) 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_cistruct nfsd_file; 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci/* 408c2ecf20Sopenharmony_ci * Callback function for readdir 418c2ecf20Sopenharmony_ci */ 428c2ecf20Sopenharmony_citypedef int (*nfsd_filldir_t)(void *, const char *, int, loff_t, u64, unsigned); 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci/* nfsd/vfs.c */ 458c2ecf20Sopenharmony_ciint nfsd_cross_mnt(struct svc_rqst *rqstp, struct dentry **dpp, 468c2ecf20Sopenharmony_ci struct svc_export **expp); 478c2ecf20Sopenharmony_ci__be32 nfsd_lookup(struct svc_rqst *, struct svc_fh *, 488c2ecf20Sopenharmony_ci const char *, unsigned int, struct svc_fh *); 498c2ecf20Sopenharmony_ci__be32 nfsd_lookup_dentry(struct svc_rqst *, struct svc_fh *, 508c2ecf20Sopenharmony_ci const char *, unsigned int, 518c2ecf20Sopenharmony_ci struct svc_export **, struct dentry **); 528c2ecf20Sopenharmony_ci__be32 nfsd_setattr(struct svc_rqst *, struct svc_fh *, 538c2ecf20Sopenharmony_ci struct iattr *, int, time64_t); 548c2ecf20Sopenharmony_ciint nfsd_mountpoint(struct dentry *, struct svc_export *); 558c2ecf20Sopenharmony_ci#ifdef CONFIG_NFSD_V4 568c2ecf20Sopenharmony_ci__be32 nfsd4_set_nfs4_label(struct svc_rqst *, struct svc_fh *, 578c2ecf20Sopenharmony_ci struct xdr_netobj *); 588c2ecf20Sopenharmony_ci__be32 nfsd4_vfs_fallocate(struct svc_rqst *, struct svc_fh *, 598c2ecf20Sopenharmony_ci struct file *, loff_t, loff_t, int); 608c2ecf20Sopenharmony_ci__be32 nfsd4_clone_file_range(struct nfsd_file *nf_src, u64 src_pos, 618c2ecf20Sopenharmony_ci struct nfsd_file *nf_dst, u64 dst_pos, 628c2ecf20Sopenharmony_ci u64 count, bool sync); 638c2ecf20Sopenharmony_ci#endif /* CONFIG_NFSD_V4 */ 648c2ecf20Sopenharmony_ci__be32 nfsd_create_locked(struct svc_rqst *, struct svc_fh *, 658c2ecf20Sopenharmony_ci char *name, int len, struct iattr *attrs, 668c2ecf20Sopenharmony_ci int type, dev_t rdev, struct svc_fh *res); 678c2ecf20Sopenharmony_ci__be32 nfsd_create(struct svc_rqst *, struct svc_fh *, 688c2ecf20Sopenharmony_ci char *name, int len, struct iattr *attrs, 698c2ecf20Sopenharmony_ci int type, dev_t rdev, struct svc_fh *res); 708c2ecf20Sopenharmony_ci#ifdef CONFIG_NFSD_V3 718c2ecf20Sopenharmony_ci__be32 nfsd_access(struct svc_rqst *, struct svc_fh *, u32 *, u32 *); 728c2ecf20Sopenharmony_ci__be32 do_nfsd_create(struct svc_rqst *, struct svc_fh *, 738c2ecf20Sopenharmony_ci char *name, int len, struct iattr *attrs, 748c2ecf20Sopenharmony_ci struct svc_fh *res, int createmode, 758c2ecf20Sopenharmony_ci u32 *verifier, bool *truncp, bool *created); 768c2ecf20Sopenharmony_ci__be32 nfsd_commit(struct svc_rqst *, struct svc_fh *, 778c2ecf20Sopenharmony_ci loff_t, unsigned long, __be32 *verf); 788c2ecf20Sopenharmony_ci#endif /* CONFIG_NFSD_V3 */ 798c2ecf20Sopenharmony_ci#ifdef CONFIG_NFSD_V4 808c2ecf20Sopenharmony_ci__be32 nfsd_getxattr(struct svc_rqst *rqstp, struct svc_fh *fhp, 818c2ecf20Sopenharmony_ci char *name, void **bufp, int *lenp); 828c2ecf20Sopenharmony_ci__be32 nfsd_listxattr(struct svc_rqst *rqstp, struct svc_fh *fhp, 838c2ecf20Sopenharmony_ci char **bufp, int *lenp); 848c2ecf20Sopenharmony_ci__be32 nfsd_removexattr(struct svc_rqst *rqstp, struct svc_fh *fhp, 858c2ecf20Sopenharmony_ci char *name); 868c2ecf20Sopenharmony_ci__be32 nfsd_setxattr(struct svc_rqst *rqstp, struct svc_fh *fhp, 878c2ecf20Sopenharmony_ci char *name, void *buf, u32 len, u32 flags); 888c2ecf20Sopenharmony_ci#endif 898c2ecf20Sopenharmony_ciint nfsd_open_break_lease(struct inode *, int); 908c2ecf20Sopenharmony_ci__be32 nfsd_open(struct svc_rqst *, struct svc_fh *, umode_t, 918c2ecf20Sopenharmony_ci int, struct file **); 928c2ecf20Sopenharmony_ci__be32 nfsd_open_verified(struct svc_rqst *, struct svc_fh *, umode_t, 938c2ecf20Sopenharmony_ci int, struct file **); 948c2ecf20Sopenharmony_ci__be32 nfsd_splice_read(struct svc_rqst *rqstp, struct svc_fh *fhp, 958c2ecf20Sopenharmony_ci struct file *file, loff_t offset, 968c2ecf20Sopenharmony_ci unsigned long *count, 978c2ecf20Sopenharmony_ci u32 *eof); 988c2ecf20Sopenharmony_ci__be32 nfsd_readv(struct svc_rqst *rqstp, struct svc_fh *fhp, 998c2ecf20Sopenharmony_ci struct file *file, loff_t offset, 1008c2ecf20Sopenharmony_ci struct kvec *vec, int vlen, 1018c2ecf20Sopenharmony_ci unsigned long *count, 1028c2ecf20Sopenharmony_ci u32 *eof); 1038c2ecf20Sopenharmony_ci__be32 nfsd_read(struct svc_rqst *, struct svc_fh *, 1048c2ecf20Sopenharmony_ci loff_t, struct kvec *, int, unsigned long *, 1058c2ecf20Sopenharmony_ci u32 *eof); 1068c2ecf20Sopenharmony_ci__be32 nfsd_write(struct svc_rqst *, struct svc_fh *, loff_t, 1078c2ecf20Sopenharmony_ci struct kvec *, int, unsigned long *, 1088c2ecf20Sopenharmony_ci int stable, __be32 *verf); 1098c2ecf20Sopenharmony_ci__be32 nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, 1108c2ecf20Sopenharmony_ci struct nfsd_file *nf, loff_t offset, 1118c2ecf20Sopenharmony_ci struct kvec *vec, int vlen, unsigned long *cnt, 1128c2ecf20Sopenharmony_ci int stable, __be32 *verf); 1138c2ecf20Sopenharmony_ci__be32 nfsd_readlink(struct svc_rqst *, struct svc_fh *, 1148c2ecf20Sopenharmony_ci char *, int *); 1158c2ecf20Sopenharmony_ci__be32 nfsd_symlink(struct svc_rqst *, struct svc_fh *, 1168c2ecf20Sopenharmony_ci char *name, int len, char *path, 1178c2ecf20Sopenharmony_ci struct svc_fh *res); 1188c2ecf20Sopenharmony_ci__be32 nfsd_link(struct svc_rqst *, struct svc_fh *, 1198c2ecf20Sopenharmony_ci char *, int, struct svc_fh *); 1208c2ecf20Sopenharmony_cissize_t nfsd_copy_file_range(struct file *, u64, 1218c2ecf20Sopenharmony_ci struct file *, u64, u64); 1228c2ecf20Sopenharmony_ci__be32 nfsd_rename(struct svc_rqst *, 1238c2ecf20Sopenharmony_ci struct svc_fh *, char *, int, 1248c2ecf20Sopenharmony_ci struct svc_fh *, char *, int); 1258c2ecf20Sopenharmony_ci__be32 nfsd_unlink(struct svc_rqst *, struct svc_fh *, int type, 1268c2ecf20Sopenharmony_ci char *name, int len); 1278c2ecf20Sopenharmony_ci__be32 nfsd_readdir(struct svc_rqst *, struct svc_fh *, 1288c2ecf20Sopenharmony_ci loff_t *, struct readdir_cd *, nfsd_filldir_t); 1298c2ecf20Sopenharmony_ci__be32 nfsd_statfs(struct svc_rqst *, struct svc_fh *, 1308c2ecf20Sopenharmony_ci struct kstatfs *, int access); 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_ci__be32 nfsd_permission(struct svc_rqst *, struct svc_export *, 1338c2ecf20Sopenharmony_ci struct dentry *, int); 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_cistatic inline int fh_want_write(struct svc_fh *fh) 1368c2ecf20Sopenharmony_ci{ 1378c2ecf20Sopenharmony_ci int ret; 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_ci if (fh->fh_want_write) 1408c2ecf20Sopenharmony_ci return 0; 1418c2ecf20Sopenharmony_ci ret = mnt_want_write(fh->fh_export->ex_path.mnt); 1428c2ecf20Sopenharmony_ci if (!ret) 1438c2ecf20Sopenharmony_ci fh->fh_want_write = true; 1448c2ecf20Sopenharmony_ci return ret; 1458c2ecf20Sopenharmony_ci} 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_cistatic inline void fh_drop_write(struct svc_fh *fh) 1488c2ecf20Sopenharmony_ci{ 1498c2ecf20Sopenharmony_ci if (fh->fh_want_write) { 1508c2ecf20Sopenharmony_ci fh->fh_want_write = false; 1518c2ecf20Sopenharmony_ci mnt_drop_write(fh->fh_export->ex_path.mnt); 1528c2ecf20Sopenharmony_ci } 1538c2ecf20Sopenharmony_ci} 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_cistatic inline __be32 fh_getattr(struct svc_fh *fh, struct kstat *stat) 1568c2ecf20Sopenharmony_ci{ 1578c2ecf20Sopenharmony_ci struct path p = {.mnt = fh->fh_export->ex_path.mnt, 1588c2ecf20Sopenharmony_ci .dentry = fh->fh_dentry}; 1598c2ecf20Sopenharmony_ci return nfserrno(vfs_getattr(&p, stat, STATX_BASIC_STATS, 1608c2ecf20Sopenharmony_ci AT_STATX_SYNC_AS_STAT)); 1618c2ecf20Sopenharmony_ci} 1628c2ecf20Sopenharmony_ci 1638c2ecf20Sopenharmony_cistatic inline int nfsd_create_is_exclusive(int createmode) 1648c2ecf20Sopenharmony_ci{ 1658c2ecf20Sopenharmony_ci return createmode == NFS3_CREATE_EXCLUSIVE 1668c2ecf20Sopenharmony_ci || createmode == NFS4_CREATE_EXCLUSIVE4_1; 1678c2ecf20Sopenharmony_ci} 1688c2ecf20Sopenharmony_ci 1698c2ecf20Sopenharmony_ci#endif /* LINUX_NFSD_VFS_H */ 170