nfs.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* fs/fat/nfs.c
  2. *
  3. * This software is licensed under the terms of the GNU General Public
  4. * License version 2, as published by the Free Software Foundation, and
  5. * may be copied, distributed, and modified under those terms.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. */
  13. #include <linux/exportfs.h>
  14. #include "fat.h"
  15. /**
  16. * Look up a directory inode given its starting cluster.
  17. */
  18. static struct inode *fat_dget(struct super_block *sb, int i_logstart)
  19. {
  20. struct msdos_sb_info *sbi = MSDOS_SB(sb);
  21. struct hlist_head *head;
  22. struct msdos_inode_info *i;
  23. struct inode *inode = NULL;
  24. head = sbi->dir_hashtable + fat_dir_hash(i_logstart);
  25. spin_lock(&sbi->dir_hash_lock);
  26. hlist_for_each_entry(i, head, i_dir_hash) {
  27. BUG_ON(i->vfs_inode.i_sb != sb);
  28. if (i->i_logstart != i_logstart)
  29. continue;
  30. inode = igrab(&i->vfs_inode);
  31. if (inode)
  32. break;
  33. }
  34. spin_unlock(&sbi->dir_hash_lock);
  35. return inode;
  36. }
  37. static struct inode *fat_nfs_get_inode(struct super_block *sb,
  38. u64 ino, u32 generation)
  39. {
  40. struct inode *inode;
  41. if ((ino < MSDOS_ROOT_INO) || (ino == MSDOS_FSINFO_INO))
  42. return NULL;
  43. inode = ilookup(sb, ino);
  44. if (inode && generation && (inode->i_generation != generation)) {
  45. iput(inode);
  46. inode = NULL;
  47. }
  48. return inode;
  49. }
  50. /**
  51. * Map a NFS file handle to a corresponding dentry.
  52. * The dentry may or may not be connected to the filesystem root.
  53. */
  54. struct dentry *fat_fh_to_dentry(struct super_block *sb, struct fid *fid,
  55. int fh_len, int fh_type)
  56. {
  57. return generic_fh_to_dentry(sb, fid, fh_len, fh_type,
  58. fat_nfs_get_inode);
  59. }
  60. /*
  61. * Find the parent for a file specified by NFS handle.
  62. * This requires that the handle contain the i_ino of the parent.
  63. */
  64. struct dentry *fat_fh_to_parent(struct super_block *sb, struct fid *fid,
  65. int fh_len, int fh_type)
  66. {
  67. return generic_fh_to_parent(sb, fid, fh_len, fh_type,
  68. fat_nfs_get_inode);
  69. }
  70. /*
  71. * Find the parent for a directory that is not currently connected to
  72. * the filesystem root.
  73. *
  74. * On entry, the caller holds child_dir->d_inode->i_mutex.
  75. */
  76. struct dentry *fat_get_parent(struct dentry *child_dir)
  77. {
  78. struct super_block *sb = child_dir->d_sb;
  79. struct buffer_head *bh = NULL;
  80. struct msdos_dir_entry *de;
  81. struct inode *parent_inode = NULL;
  82. if (!fat_get_dotdot_entry(child_dir->d_inode, &bh, &de)) {
  83. int parent_logstart = fat_get_start(MSDOS_SB(sb), de);
  84. parent_inode = fat_dget(sb, parent_logstart);
  85. }
  86. brelse(bh);
  87. return d_obtain_alias(parent_inode);
  88. }