internal.h 4.6 KB

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