internal.h 4.5 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 nfs_destroy_nfspagecache(void);
  30. extern int __init nfs_init_readpagecache(void);
  31. extern void nfs_destroy_readpagecache(void);
  32. extern int __init nfs_init_writepagecache(void);
  33. extern void nfs_destroy_writepagecache(void);
  34. #ifdef CONFIG_NFS_DIRECTIO
  35. extern int __init nfs_init_directcache(void);
  36. extern void 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. extern struct rpc_stat nfs_rpcstat;
  72. extern int __init register_nfs_fs(void);
  73. extern void __exit unregister_nfs_fs(void);
  74. /* namespace.c */
  75. extern char *nfs_path(const char *base, const struct dentry *dentry,
  76. char *buffer, ssize_t buflen);
  77. /*
  78. * Determine the mount path as a string
  79. */
  80. static inline char *
  81. nfs4_path(const struct dentry *dentry, char *buffer, ssize_t buflen)
  82. {
  83. #ifdef CONFIG_NFS_V4
  84. return nfs_path(NFS_SB(dentry->d_sb)->mnt_path, dentry, buffer, buflen);
  85. #else
  86. return NULL;
  87. #endif
  88. }
  89. /*
  90. * Determine the device name as a string
  91. */
  92. static inline char *nfs_devname(const struct vfsmount *mnt_parent,
  93. const struct dentry *dentry,
  94. char *buffer, ssize_t buflen)
  95. {
  96. return nfs_path(mnt_parent->mnt_devname, dentry, buffer, buflen);
  97. }
  98. /*
  99. * Determine the actual block size (and log2 thereof)
  100. */
  101. static inline
  102. unsigned long nfs_block_bits(unsigned long bsize, unsigned char *nrbitsp)
  103. {
  104. /* make sure blocksize is a power of two */
  105. if ((bsize & (bsize - 1)) || nrbitsp) {
  106. unsigned char nrbits;
  107. for (nrbits = 31; nrbits && !(bsize & (1 << nrbits)); nrbits--)
  108. ;
  109. bsize = 1 << nrbits;
  110. if (nrbitsp)
  111. *nrbitsp = nrbits;
  112. }
  113. return bsize;
  114. }
  115. /*
  116. * Calculate the number of 512byte blocks used.
  117. */
  118. static inline unsigned long nfs_calc_block_size(u64 tsize)
  119. {
  120. loff_t used = (tsize + 511) >> 9;
  121. return (used > ULONG_MAX) ? ULONG_MAX : used;
  122. }
  123. /*
  124. * Compute and set NFS server blocksize
  125. */
  126. static inline
  127. unsigned long nfs_block_size(unsigned long bsize, unsigned char *nrbitsp)
  128. {
  129. if (bsize < NFS_MIN_FILE_IO_SIZE)
  130. bsize = NFS_DEF_FILE_IO_SIZE;
  131. else if (bsize >= NFS_MAX_FILE_IO_SIZE)
  132. bsize = NFS_MAX_FILE_IO_SIZE;
  133. return nfs_block_bits(bsize, nrbitsp);
  134. }
  135. /*
  136. * Determine the maximum file size for a superblock
  137. */
  138. static inline
  139. void nfs_super_set_maxbytes(struct super_block *sb, __u64 maxfilesize)
  140. {
  141. sb->s_maxbytes = (loff_t)maxfilesize;
  142. if (sb->s_maxbytes > MAX_LFS_FILESIZE || sb->s_maxbytes <= 0)
  143. sb->s_maxbytes = MAX_LFS_FILESIZE;
  144. }
  145. /*
  146. * Check if the string represents a "valid" IPv4 address
  147. */
  148. static inline int valid_ipaddr4(const char *buf)
  149. {
  150. int rc, count, in[4];
  151. rc = sscanf(buf, "%d.%d.%d.%d", &in[0], &in[1], &in[2], &in[3]);
  152. if (rc != 4)
  153. return -EINVAL;
  154. for (count = 0; count < 4; count++) {
  155. if (in[count] > 255)
  156. return -EINVAL;
  157. }
  158. return 0;
  159. }