cnode.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /* cnode related routines for the coda kernel code
  2. (C) 1996 Peter Braam
  3. */
  4. #include <linux/types.h>
  5. #include <linux/string.h>
  6. #include <linux/time.h>
  7. #include <linux/coda.h>
  8. #include <linux/coda_linux.h>
  9. #include <linux/coda_fs_i.h>
  10. #include <linux/coda_psdev.h>
  11. static inline int coda_fideq(struct CodaFid *fid1, struct CodaFid *fid2)
  12. {
  13. return memcmp(fid1, fid2, sizeof(*fid1)) == 0;
  14. }
  15. static const struct inode_operations coda_symlink_inode_operations = {
  16. .readlink = generic_readlink,
  17. .follow_link = page_follow_link_light,
  18. .put_link = page_put_link,
  19. .setattr = coda_setattr,
  20. };
  21. /* cnode.c */
  22. static void coda_fill_inode(struct inode *inode, struct coda_vattr *attr)
  23. {
  24. coda_vattr_to_iattr(inode, attr);
  25. if (S_ISREG(inode->i_mode)) {
  26. inode->i_op = &coda_file_inode_operations;
  27. inode->i_fop = &coda_file_operations;
  28. } else if (S_ISDIR(inode->i_mode)) {
  29. inode->i_op = &coda_dir_inode_operations;
  30. inode->i_fop = &coda_dir_operations;
  31. } else if (S_ISLNK(inode->i_mode)) {
  32. inode->i_op = &coda_symlink_inode_operations;
  33. inode->i_data.a_ops = &coda_symlink_aops;
  34. inode->i_mapping = &inode->i_data;
  35. } else
  36. init_special_inode(inode, inode->i_mode, huge_decode_dev(attr->va_rdev));
  37. }
  38. static int coda_test_inode(struct inode *inode, void *data)
  39. {
  40. struct CodaFid *fid = (struct CodaFid *)data;
  41. return coda_fideq(&(ITOC(inode)->c_fid), fid);
  42. }
  43. static int coda_set_inode(struct inode *inode, void *data)
  44. {
  45. struct CodaFid *fid = (struct CodaFid *)data;
  46. ITOC(inode)->c_fid = *fid;
  47. return 0;
  48. }
  49. struct inode * coda_iget(struct super_block * sb, struct CodaFid * fid,
  50. struct coda_vattr * attr)
  51. {
  52. struct inode *inode;
  53. struct coda_inode_info *cii;
  54. unsigned long hash = coda_f2i(fid);
  55. inode = iget5_locked(sb, hash, coda_test_inode, coda_set_inode, fid);
  56. if (!inode)
  57. return ERR_PTR(-ENOMEM);
  58. if (inode->i_state & I_NEW) {
  59. cii = ITOC(inode);
  60. /* we still need to set i_ino for things like stat(2) */
  61. inode->i_ino = hash;
  62. cii->c_mapcount = 0;
  63. unlock_new_inode(inode);
  64. }
  65. /* always replace the attributes, type might have changed */
  66. coda_fill_inode(inode, attr);
  67. return inode;
  68. }
  69. /* this is effectively coda_iget:
  70. - get attributes (might be cached)
  71. - get the inode for the fid using vfs iget
  72. - link the two up if this is needed
  73. - fill in the attributes
  74. */
  75. int coda_cnode_make(struct inode **inode, struct CodaFid *fid, struct super_block *sb)
  76. {
  77. struct coda_vattr attr;
  78. int error;
  79. /* We get inode numbers from Venus -- see venus source */
  80. error = venus_getattr(sb, fid, &attr);
  81. if ( error ) {
  82. *inode = NULL;
  83. return error;
  84. }
  85. *inode = coda_iget(sb, fid, &attr);
  86. if ( IS_ERR(*inode) ) {
  87. printk("coda_cnode_make: coda_iget failed\n");
  88. return PTR_ERR(*inode);
  89. }
  90. return 0;
  91. }
  92. void coda_replace_fid(struct inode *inode, struct CodaFid *oldfid,
  93. struct CodaFid *newfid)
  94. {
  95. struct coda_inode_info *cii;
  96. unsigned long hash = coda_f2i(newfid);
  97. cii = ITOC(inode);
  98. BUG_ON(!coda_fideq(&cii->c_fid, oldfid));
  99. /* replace fid and rehash inode */
  100. /* XXX we probably need to hold some lock here! */
  101. remove_inode_hash(inode);
  102. cii->c_fid = *newfid;
  103. inode->i_ino = hash;
  104. __insert_inode_hash(inode, hash);
  105. }
  106. /* convert a fid to an inode. */
  107. struct inode *coda_fid_to_inode(struct CodaFid *fid, struct super_block *sb)
  108. {
  109. struct inode *inode;
  110. unsigned long hash = coda_f2i(fid);
  111. if ( !sb ) {
  112. printk("coda_fid_to_inode: no sb!\n");
  113. return NULL;
  114. }
  115. inode = ilookup5(sb, hash, coda_test_inode, fid);
  116. if ( !inode )
  117. return NULL;
  118. /* we should never see newly created inodes because we intentionally
  119. * fail in the initialization callback */
  120. BUG_ON(inode->i_state & I_NEW);
  121. return inode;
  122. }
  123. /* the CONTROL inode is made without asking attributes from Venus */
  124. int coda_cnode_makectl(struct inode **inode, struct super_block *sb)
  125. {
  126. int error = -ENOMEM;
  127. *inode = new_inode(sb);
  128. if (*inode) {
  129. (*inode)->i_ino = CTL_INO;
  130. (*inode)->i_op = &coda_ioctl_inode_operations;
  131. (*inode)->i_fop = &coda_ioctl_operations;
  132. (*inode)->i_mode = 0444;
  133. error = 0;
  134. }
  135. return error;
  136. }