exportfs.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #ifndef LINUX_EXPORTFS_H
  2. #define LINUX_EXPORTFS_H 1
  3. #include <linux/types.h>
  4. struct dentry;
  5. struct super_block;
  6. struct vfsmount;
  7. /**
  8. * struct export_operations - for nfsd to communicate with file systems
  9. * @decode_fh: decode a file handle fragment and return a &struct dentry
  10. * @encode_fh: encode a file handle fragment from a dentry
  11. * @get_name: find the name for a given inode in a given directory
  12. * @get_parent: find the parent of a given directory
  13. * @get_dentry: find a dentry for the inode given a file handle sub-fragment
  14. * @find_exported_dentry:
  15. * set by the exporting module to a standard helper function.
  16. *
  17. * Description:
  18. * The export_operations structure provides a means for nfsd to communicate
  19. * with a particular exported file system - particularly enabling nfsd and
  20. * the filesystem to co-operate when dealing with file handles.
  21. *
  22. * export_operations contains two basic operation for dealing with file
  23. * handles, decode_fh() and encode_fh(), and allows for some other
  24. * operations to be defined which standard helper routines use to get
  25. * specific information from the filesystem.
  26. *
  27. * nfsd encodes information use to determine which filesystem a filehandle
  28. * applies to in the initial part of the file handle. The remainder, termed
  29. * a file handle fragment, is controlled completely by the filesystem. The
  30. * standard helper routines assume that this fragment will contain one or
  31. * two sub-fragments, one which identifies the file, and one which may be
  32. * used to identify the (a) directory containing the file.
  33. *
  34. * In some situations, nfsd needs to get a dentry which is connected into a
  35. * specific part of the file tree. To allow for this, it passes the
  36. * function acceptable() together with a @context which can be used to see
  37. * if the dentry is acceptable. As there can be multiple dentrys for a
  38. * given file, the filesystem should check each one for acceptability before
  39. * looking for the next. As soon as an acceptable one is found, it should
  40. * be returned.
  41. *
  42. * decode_fh:
  43. * @decode_fh is given a &struct super_block (@sb), a file handle fragment
  44. * (@fh, @fh_len) and an acceptability testing function (@acceptable,
  45. * @context). It should return a &struct dentry which refers to the same
  46. * file that the file handle fragment refers to, and which passes the
  47. * acceptability test. If it cannot, it should return a %NULL pointer if
  48. * the file was found but no acceptable &dentries were available, or a
  49. * %ERR_PTR error code indicating why it couldn't be found (e.g. %ENOENT or
  50. * %ENOMEM).
  51. *
  52. * encode_fh:
  53. * @encode_fh should store in the file handle fragment @fh (using at most
  54. * @max_len bytes) information that can be used by @decode_fh to recover the
  55. * file refered to by the &struct dentry @de. If the @connectable flag is
  56. * set, the encode_fh() should store sufficient information so that a good
  57. * attempt can be made to find not only the file but also it's place in the
  58. * filesystem. This typically means storing a reference to de->d_parent in
  59. * the filehandle fragment. encode_fh() should return the number of bytes
  60. * stored or a negative error code such as %-ENOSPC
  61. *
  62. * get_name:
  63. * @get_name should find a name for the given @child in the given @parent
  64. * directory. The name should be stored in the @name (with the
  65. * understanding that it is already pointing to a a %NAME_MAX+1 sized
  66. * buffer. get_name() should return %0 on success, a negative error code
  67. * or error. @get_name will be called without @parent->i_mutex held.
  68. *
  69. * get_parent:
  70. * @get_parent should find the parent directory for the given @child which
  71. * is also a directory. In the event that it cannot be found, or storage
  72. * space cannot be allocated, a %ERR_PTR should be returned.
  73. *
  74. * get_dentry:
  75. * Given a &super_block (@sb) and a pointer to a file-system specific inode
  76. * identifier, possibly an inode number, (@inump) get_dentry() should find
  77. * the identified inode and return a dentry for that inode. Any suitable
  78. * dentry can be returned including, if necessary, a new dentry created with
  79. * d_alloc_root. The caller can then find any other extant dentrys by
  80. * following the d_alias links. If a new dentry was created using
  81. * d_alloc_root, DCACHE_NFSD_DISCONNECTED should be set, and the dentry
  82. * should be d_rehash()ed.
  83. *
  84. * If the inode cannot be found, either a %NULL pointer or an %ERR_PTR code
  85. * can be returned. The @inump will be whatever was passed to
  86. * nfsd_find_fh_dentry() in either the @obj or @parent parameters.
  87. *
  88. * Locking rules:
  89. * get_parent is called with child->d_inode->i_mutex down
  90. * get_name is not (which is possibly inconsistent)
  91. */
  92. struct export_operations {
  93. struct dentry *(*decode_fh)(struct super_block *sb, __u32 *fh,
  94. int fh_len, int fh_type,
  95. int (*acceptable)(void *context, struct dentry *de),
  96. void *context);
  97. int (*encode_fh)(struct dentry *de, __u32 *fh, int *max_len,
  98. int connectable);
  99. int (*get_name)(struct dentry *parent, char *name,
  100. struct dentry *child);
  101. struct dentry * (*get_parent)(struct dentry *child);
  102. struct dentry * (*get_dentry)(struct super_block *sb, void *inump);
  103. /* This is set by the exporting module to a standard helper */
  104. struct dentry * (*find_exported_dentry)(
  105. struct super_block *sb, void *obj, void *parent,
  106. int (*acceptable)(void *context, struct dentry *de),
  107. void *context);
  108. };
  109. extern struct dentry *find_exported_dentry(struct super_block *sb, void *obj,
  110. void *parent, int (*acceptable)(void *context, struct dentry *de),
  111. void *context);
  112. extern int exportfs_encode_fh(struct dentry *dentry, __u32 *fh, int *max_len,
  113. int connectable);
  114. extern struct dentry *exportfs_decode_fh(struct vfsmount *mnt, __u32 *fh,
  115. int fh_len, int fileid_type, int (*acceptable)(void *, struct dentry *),
  116. void *context);
  117. #endif /* LINUX_EXPORTFS_H */