Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Copyright (C) 1995-1997 Olaf Kirch <okir@monad.swb.de>
0004  */
0005 
0006 #ifndef LINUX_NFSD_VFS_H
0007 #define LINUX_NFSD_VFS_H
0008 
0009 #include <linux/fs.h>
0010 #include <linux/posix_acl.h>
0011 #include "nfsfh.h"
0012 #include "nfsd.h"
0013 
0014 /*
0015  * Flags for nfsd_permission
0016  */
0017 #define NFSD_MAY_NOP            0
0018 #define NFSD_MAY_EXEC           0x001 /* == MAY_EXEC */
0019 #define NFSD_MAY_WRITE          0x002 /* == MAY_WRITE */
0020 #define NFSD_MAY_READ           0x004 /* == MAY_READ */
0021 #define NFSD_MAY_SATTR          0x008
0022 #define NFSD_MAY_TRUNC          0x010
0023 #define NFSD_MAY_LOCK           0x020
0024 #define NFSD_MAY_MASK           0x03f
0025 
0026 /* extra hints to permission and open routines: */
0027 #define NFSD_MAY_OWNER_OVERRIDE     0x040
0028 #define NFSD_MAY_LOCAL_ACCESS       0x080 /* for device special files */
0029 #define NFSD_MAY_BYPASS_GSS_ON_ROOT 0x100
0030 #define NFSD_MAY_NOT_BREAK_LEASE    0x200
0031 #define NFSD_MAY_BYPASS_GSS     0x400
0032 #define NFSD_MAY_READ_IF_EXEC       0x800
0033 
0034 #define NFSD_MAY_64BIT_COOKIE       0x1000 /* 64 bit readdir cookies for >= NFSv3 */
0035 
0036 #define NFSD_MAY_CREATE     (NFSD_MAY_EXEC|NFSD_MAY_WRITE)
0037 #define NFSD_MAY_REMOVE     (NFSD_MAY_EXEC|NFSD_MAY_WRITE|NFSD_MAY_TRUNC)
0038 
0039 struct nfsd_file;
0040 
0041 /*
0042  * Callback function for readdir
0043  */
0044 typedef int (*nfsd_filldir_t)(void *, const char *, int, loff_t, u64, unsigned);
0045 
0046 /* nfsd/vfs.c */
0047 struct nfsd_attrs {
0048     struct iattr        *na_iattr;  /* input */
0049     struct xdr_netobj   *na_seclabel;   /* input */
0050     struct posix_acl    *na_pacl;   /* input */
0051     struct posix_acl    *na_dpacl;  /* input */
0052 
0053     int         na_labelerr;    /* output */
0054     int         na_aclerr;  /* output */
0055 };
0056 
0057 static inline void nfsd_attrs_free(struct nfsd_attrs *attrs)
0058 {
0059     posix_acl_release(attrs->na_pacl);
0060     posix_acl_release(attrs->na_dpacl);
0061 }
0062 
0063 int     nfsd_cross_mnt(struct svc_rqst *rqstp, struct dentry **dpp,
0064                         struct svc_export **expp);
0065 __be32      nfsd_lookup(struct svc_rqst *, struct svc_fh *,
0066                 const char *, unsigned int, struct svc_fh *);
0067 __be32       nfsd_lookup_dentry(struct svc_rqst *, struct svc_fh *,
0068                 const char *, unsigned int,
0069                 struct svc_export **, struct dentry **);
0070 __be32      nfsd_setattr(struct svc_rqst *, struct svc_fh *,
0071                 struct nfsd_attrs *, int, time64_t);
0072 int nfsd_mountpoint(struct dentry *, struct svc_export *);
0073 #ifdef CONFIG_NFSD_V4
0074 __be32      nfsd4_vfs_fallocate(struct svc_rqst *, struct svc_fh *,
0075                     struct file *, loff_t, loff_t, int);
0076 __be32      nfsd4_clone_file_range(struct svc_rqst *rqstp,
0077                        struct nfsd_file *nf_src, u64 src_pos,
0078                        struct nfsd_file *nf_dst, u64 dst_pos,
0079                        u64 count, bool sync);
0080 #endif /* CONFIG_NFSD_V4 */
0081 __be32      nfsd_create_locked(struct svc_rqst *, struct svc_fh *,
0082                 char *name, int len, struct nfsd_attrs *attrs,
0083                 int type, dev_t rdev, struct svc_fh *res);
0084 __be32      nfsd_create(struct svc_rqst *, struct svc_fh *,
0085                 char *name, int len, struct nfsd_attrs *attrs,
0086                 int type, dev_t rdev, struct svc_fh *res);
0087 __be32      nfsd_access(struct svc_rqst *, struct svc_fh *, u32 *, u32 *);
0088 __be32      nfsd_create_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
0089                 struct svc_fh *resfhp, struct nfsd_attrs *iap);
0090 __be32      nfsd_commit(struct svc_rqst *rqst, struct svc_fh *fhp,
0091                 u64 offset, u32 count, __be32 *verf);
0092 #ifdef CONFIG_NFSD_V4
0093 __be32      nfsd_getxattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
0094                 char *name, void **bufp, int *lenp);
0095 __be32      nfsd_listxattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
0096                 char **bufp, int *lenp);
0097 __be32      nfsd_removexattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
0098                 char *name);
0099 __be32      nfsd_setxattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
0100                 char *name, void *buf, u32 len, u32 flags);
0101 #endif
0102 int         nfsd_open_break_lease(struct inode *, int);
0103 __be32      nfsd_open(struct svc_rqst *, struct svc_fh *, umode_t,
0104                 int, struct file **);
0105 __be32      nfsd_open_verified(struct svc_rqst *, struct svc_fh *,
0106                 int, struct file **);
0107 __be32      nfsd_splice_read(struct svc_rqst *rqstp, struct svc_fh *fhp,
0108                 struct file *file, loff_t offset,
0109                 unsigned long *count,
0110                 u32 *eof);
0111 __be32      nfsd_readv(struct svc_rqst *rqstp, struct svc_fh *fhp,
0112                 struct file *file, loff_t offset,
0113                 struct kvec *vec, int vlen,
0114                 unsigned long *count,
0115                 u32 *eof);
0116 __be32      nfsd_read(struct svc_rqst *, struct svc_fh *,
0117                 loff_t, struct kvec *, int, unsigned long *,
0118                 u32 *eof);
0119 __be32      nfsd_write(struct svc_rqst *, struct svc_fh *, loff_t,
0120                 struct kvec *, int, unsigned long *,
0121                 int stable, __be32 *verf);
0122 __be32      nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp,
0123                 struct nfsd_file *nf, loff_t offset,
0124                 struct kvec *vec, int vlen, unsigned long *cnt,
0125                 int stable, __be32 *verf);
0126 __be32      nfsd_readlink(struct svc_rqst *, struct svc_fh *,
0127                 char *, int *);
0128 __be32      nfsd_symlink(struct svc_rqst *, struct svc_fh *,
0129                  char *name, int len, char *path,
0130                  struct nfsd_attrs *attrs,
0131                  struct svc_fh *res);
0132 __be32      nfsd_link(struct svc_rqst *, struct svc_fh *,
0133                 char *, int, struct svc_fh *);
0134 ssize_t     nfsd_copy_file_range(struct file *, u64,
0135                      struct file *, u64, u64);
0136 __be32      nfsd_rename(struct svc_rqst *,
0137                 struct svc_fh *, char *, int,
0138                 struct svc_fh *, char *, int);
0139 __be32      nfsd_unlink(struct svc_rqst *, struct svc_fh *, int type,
0140                 char *name, int len);
0141 __be32      nfsd_readdir(struct svc_rqst *, struct svc_fh *,
0142                  loff_t *, struct readdir_cd *, nfsd_filldir_t);
0143 __be32      nfsd_statfs(struct svc_rqst *, struct svc_fh *,
0144                 struct kstatfs *, int access);
0145 
0146 __be32      nfsd_permission(struct svc_rqst *, struct svc_export *,
0147                 struct dentry *, int);
0148 
0149 static inline int fh_want_write(struct svc_fh *fh)
0150 {
0151     int ret;
0152 
0153     if (fh->fh_want_write)
0154         return 0;
0155     ret = mnt_want_write(fh->fh_export->ex_path.mnt);
0156     if (!ret)
0157         fh->fh_want_write = true;
0158     return ret;
0159 }
0160 
0161 static inline void fh_drop_write(struct svc_fh *fh)
0162 {
0163     if (fh->fh_want_write) {
0164         fh->fh_want_write = false;
0165         mnt_drop_write(fh->fh_export->ex_path.mnt);
0166     }
0167 }
0168 
0169 static inline __be32 fh_getattr(const struct svc_fh *fh, struct kstat *stat)
0170 {
0171     struct path p = {.mnt = fh->fh_export->ex_path.mnt,
0172              .dentry = fh->fh_dentry};
0173     return nfserrno(vfs_getattr(&p, stat, STATX_BASIC_STATS,
0174                     AT_STATX_SYNC_AS_STAT));
0175 }
0176 
0177 #endif /* LINUX_NFSD_VFS_H */