exportfs.h 6.7 KB

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