1f7b422b1SDavid Howells /* 2f7b422b1SDavid Howells * NFS internal definitions 3f7b422b1SDavid Howells */ 4f7b422b1SDavid Howells 5f7b422b1SDavid Howells #include <linux/mount.h> 6f7b422b1SDavid Howells 7f7b422b1SDavid Howells struct nfs_clone_mount { 8f7b422b1SDavid Howells const struct super_block *sb; 9f7b422b1SDavid Howells const struct dentry *dentry; 10f7b422b1SDavid Howells struct nfs_fh *fh; 11f7b422b1SDavid Howells struct nfs_fattr *fattr; 12f7b422b1SDavid Howells char *hostname; 13f7b422b1SDavid Howells char *mnt_path; 14f7b422b1SDavid Howells struct sockaddr_in *addr; 15f7b422b1SDavid Howells rpc_authflavor_t authflavor; 16f7b422b1SDavid Howells }; 17f7b422b1SDavid Howells 18f7b422b1SDavid Howells /* namespace-nfs4.c */ 19f7b422b1SDavid Howells #ifdef CONFIG_NFS_V4 20f7b422b1SDavid Howells extern struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry); 21f7b422b1SDavid Howells #else 22f7b422b1SDavid Howells static inline 23f7b422b1SDavid Howells struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry) 24f7b422b1SDavid Howells { 25f7b422b1SDavid Howells return ERR_PTR(-ENOENT); 26f7b422b1SDavid Howells } 27f7b422b1SDavid Howells #endif 28f7b422b1SDavid Howells 29f7b422b1SDavid Howells /* callback_xdr.c */ 30f7b422b1SDavid Howells extern struct svc_version nfs4_callback_version1; 31f7b422b1SDavid Howells 32f7b422b1SDavid Howells /* pagelist.c */ 33f7b422b1SDavid Howells extern int __init nfs_init_nfspagecache(void); 34266bee88SDavid Brownell extern void nfs_destroy_nfspagecache(void); 35f7b422b1SDavid Howells extern int __init nfs_init_readpagecache(void); 36266bee88SDavid Brownell extern void nfs_destroy_readpagecache(void); 37f7b422b1SDavid Howells extern int __init nfs_init_writepagecache(void); 38266bee88SDavid Brownell extern void nfs_destroy_writepagecache(void); 39f7b422b1SDavid Howells 40f7b422b1SDavid Howells #ifdef CONFIG_NFS_DIRECTIO 41f7b422b1SDavid Howells extern int __init nfs_init_directcache(void); 42266bee88SDavid Brownell extern void nfs_destroy_directcache(void); 43f7b422b1SDavid Howells #else 44f7b422b1SDavid Howells #define nfs_init_directcache() (0) 45f7b422b1SDavid Howells #define nfs_destroy_directcache() do {} while(0) 46f7b422b1SDavid Howells #endif 47f7b422b1SDavid Howells 48f7b422b1SDavid Howells /* nfs2xdr.c */ 49f7b422b1SDavid Howells extern struct rpc_procinfo nfs_procedures[]; 50f7b422b1SDavid Howells extern u32 * nfs_decode_dirent(u32 *, struct nfs_entry *, int); 51f7b422b1SDavid Howells 52f7b422b1SDavid Howells /* nfs3xdr.c */ 53f7b422b1SDavid Howells extern struct rpc_procinfo nfs3_procedures[]; 54f7b422b1SDavid Howells extern u32 *nfs3_decode_dirent(u32 *, struct nfs_entry *, int); 55f7b422b1SDavid Howells 56f7b422b1SDavid Howells /* nfs4xdr.c */ 57f7b422b1SDavid Howells extern int nfs_stat_to_errno(int); 58f7b422b1SDavid Howells extern u32 *nfs4_decode_dirent(u32 *p, struct nfs_entry *entry, int plus); 59f7b422b1SDavid Howells 60f7b422b1SDavid Howells /* nfs4proc.c */ 61d75d5414SAndrew Morton #ifdef CONFIG_NFS_V4 62f7b422b1SDavid Howells extern struct rpc_procinfo nfs4_procedures[]; 63f7b422b1SDavid Howells 64f7b422b1SDavid Howells extern int nfs4_proc_fs_locations(struct inode *dir, struct dentry *dentry, 65f7b422b1SDavid Howells struct nfs4_fs_locations *fs_locations, 66f7b422b1SDavid Howells struct page *page); 67d75d5414SAndrew Morton #endif 68f7b422b1SDavid Howells 69979df72eSTrond Myklebust /* dir.c */ 70979df72eSTrond Myklebust extern int nfs_access_cache_shrinker(int nr_to_scan, gfp_t gfp_mask); 71979df72eSTrond Myklebust 72f7b422b1SDavid Howells /* inode.c */ 73f7b422b1SDavid Howells extern struct inode *nfs_alloc_inode(struct super_block *sb); 74f7b422b1SDavid Howells extern void nfs_destroy_inode(struct inode *); 75f7b422b1SDavid Howells extern int nfs_write_inode(struct inode *,int); 76f7b422b1SDavid Howells extern void nfs_clear_inode(struct inode *); 77f7b422b1SDavid Howells #ifdef CONFIG_NFS_V4 78f7b422b1SDavid Howells extern void nfs4_clear_inode(struct inode *); 79f7b422b1SDavid Howells #endif 80f7b422b1SDavid Howells 81f7b422b1SDavid Howells /* super.c */ 82f7b422b1SDavid Howells extern struct file_system_type nfs_referral_nfs4_fs_type; 83f7b422b1SDavid Howells extern struct file_system_type clone_nfs_fs_type; 84f7b422b1SDavid Howells #ifdef CONFIG_NFS_V4 85f7b422b1SDavid Howells extern struct file_system_type clone_nfs4_fs_type; 86f7b422b1SDavid Howells #endif 874ebd9ab3SDominik Hackl 88f7b422b1SDavid Howells extern struct rpc_stat nfs_rpcstat; 894ebd9ab3SDominik Hackl 90f7b422b1SDavid Howells extern int __init register_nfs_fs(void); 91f7b422b1SDavid Howells extern void __exit unregister_nfs_fs(void); 92f7b422b1SDavid Howells 93f7b422b1SDavid Howells /* namespace.c */ 94f7b422b1SDavid Howells extern char *nfs_path(const char *base, const struct dentry *dentry, 95f7b422b1SDavid Howells char *buffer, ssize_t buflen); 96f7b422b1SDavid Howells 97f7b422b1SDavid Howells /* 98f7b422b1SDavid Howells * Determine the mount path as a string 99f7b422b1SDavid Howells */ 100d75d5414SAndrew Morton static inline char * 101d75d5414SAndrew Morton nfs4_path(const struct dentry *dentry, char *buffer, ssize_t buflen) 102f7b422b1SDavid Howells { 103d75d5414SAndrew Morton #ifdef CONFIG_NFS_V4 104f7b422b1SDavid Howells return nfs_path(NFS_SB(dentry->d_sb)->mnt_path, dentry, buffer, buflen); 105d75d5414SAndrew Morton #else 106d75d5414SAndrew Morton return NULL; 107d75d5414SAndrew Morton #endif 108f7b422b1SDavid Howells } 109f7b422b1SDavid Howells 110f7b422b1SDavid Howells /* 111f7b422b1SDavid Howells * Determine the device name as a string 112f7b422b1SDavid Howells */ 113f7b422b1SDavid Howells static inline char *nfs_devname(const struct vfsmount *mnt_parent, 114f7b422b1SDavid Howells const struct dentry *dentry, 115f7b422b1SDavid Howells char *buffer, ssize_t buflen) 116f7b422b1SDavid Howells { 117f7b422b1SDavid Howells return nfs_path(mnt_parent->mnt_devname, dentry, buffer, buflen); 118f7b422b1SDavid Howells } 119f7b422b1SDavid Howells 120f7b422b1SDavid Howells /* 121f7b422b1SDavid Howells * Determine the actual block size (and log2 thereof) 122f7b422b1SDavid Howells */ 123f7b422b1SDavid Howells static inline 124f7b422b1SDavid Howells unsigned long nfs_block_bits(unsigned long bsize, unsigned char *nrbitsp) 125f7b422b1SDavid Howells { 126f7b422b1SDavid Howells /* make sure blocksize is a power of two */ 127f7b422b1SDavid Howells if ((bsize & (bsize - 1)) || nrbitsp) { 128f7b422b1SDavid Howells unsigned char nrbits; 129f7b422b1SDavid Howells 130f7b422b1SDavid Howells for (nrbits = 31; nrbits && !(bsize & (1 << nrbits)); nrbits--) 131f7b422b1SDavid Howells ; 132f7b422b1SDavid Howells bsize = 1 << nrbits; 133f7b422b1SDavid Howells if (nrbitsp) 134f7b422b1SDavid Howells *nrbitsp = nrbits; 135f7b422b1SDavid Howells } 136f7b422b1SDavid Howells 137f7b422b1SDavid Howells return bsize; 138f7b422b1SDavid Howells } 139f7b422b1SDavid Howells 140f7b422b1SDavid Howells /* 141f7b422b1SDavid Howells * Calculate the number of 512byte blocks used. 142f7b422b1SDavid Howells */ 143f7b422b1SDavid Howells static inline unsigned long nfs_calc_block_size(u64 tsize) 144f7b422b1SDavid Howells { 145f7b422b1SDavid Howells loff_t used = (tsize + 511) >> 9; 146f7b422b1SDavid Howells return (used > ULONG_MAX) ? ULONG_MAX : used; 147f7b422b1SDavid Howells } 148f7b422b1SDavid Howells 149f7b422b1SDavid Howells /* 150f7b422b1SDavid Howells * Compute and set NFS server blocksize 151f7b422b1SDavid Howells */ 152f7b422b1SDavid Howells static inline 153f7b422b1SDavid Howells unsigned long nfs_block_size(unsigned long bsize, unsigned char *nrbitsp) 154f7b422b1SDavid Howells { 155f7b422b1SDavid Howells if (bsize < NFS_MIN_FILE_IO_SIZE) 156f7b422b1SDavid Howells bsize = NFS_DEF_FILE_IO_SIZE; 157f7b422b1SDavid Howells else if (bsize >= NFS_MAX_FILE_IO_SIZE) 158f7b422b1SDavid Howells bsize = NFS_MAX_FILE_IO_SIZE; 159f7b422b1SDavid Howells 160f7b422b1SDavid Howells return nfs_block_bits(bsize, nrbitsp); 161f7b422b1SDavid Howells } 162f7b422b1SDavid Howells 163f7b422b1SDavid Howells /* 164f7b422b1SDavid Howells * Determine the maximum file size for a superblock 165f7b422b1SDavid Howells */ 166f7b422b1SDavid Howells static inline 167f7b422b1SDavid Howells void nfs_super_set_maxbytes(struct super_block *sb, __u64 maxfilesize) 168f7b422b1SDavid Howells { 169f7b422b1SDavid Howells sb->s_maxbytes = (loff_t)maxfilesize; 170f7b422b1SDavid Howells if (sb->s_maxbytes > MAX_LFS_FILESIZE || sb->s_maxbytes <= 0) 171f7b422b1SDavid Howells sb->s_maxbytes = MAX_LFS_FILESIZE; 172f7b422b1SDavid Howells } 173f7b422b1SDavid Howells 174f7b422b1SDavid Howells /* 175f7b422b1SDavid Howells * Check if the string represents a "valid" IPv4 address 176f7b422b1SDavid Howells */ 177f7b422b1SDavid Howells static inline int valid_ipaddr4(const char *buf) 178f7b422b1SDavid Howells { 179f7b422b1SDavid Howells int rc, count, in[4]; 180f7b422b1SDavid Howells 181f7b422b1SDavid Howells rc = sscanf(buf, "%d.%d.%d.%d", &in[0], &in[1], &in[2], &in[3]); 182f7b422b1SDavid Howells if (rc != 4) 183f7b422b1SDavid Howells return -EINVAL; 184f7b422b1SDavid Howells for (count = 0; count < 4; count++) { 185f7b422b1SDavid Howells if (in[count] > 255) 186f7b422b1SDavid Howells return -EINVAL; 187f7b422b1SDavid Howells } 188f7b422b1SDavid Howells return 0; 189f7b422b1SDavid Howells } 190