cnode.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. static int coda_fail_inode(struct inode *inode, void *data)
  50. {
  51. return -1;
  52. }
  53. struct inode * coda_iget(struct super_block * sb, struct CodaFid * fid,
  54. struct coda_vattr * attr)
  55. {
  56. struct inode *inode;
  57. struct coda_inode_info *cii;
  58. unsigned long hash = coda_f2i(fid);
  59. inode = iget5_locked(sb, hash, coda_test_inode, coda_set_inode, fid);
  60. if (!inode)
  61. return ERR_PTR(-ENOMEM);
  62. if (inode->i_state & I_NEW) {
  63. cii = ITOC(inode);
  64. /* we still need to set i_ino for things like stat(2) */
  65. inode->i_ino = hash;
  66. cii->c_mapcount = 0;
  67. unlock_new_inode(inode);
  68. }
  69. /* always replace the attributes, type might have changed */
  70. coda_fill_inode(inode, attr);
  71. return inode;
  72. }
  73. /* this is effectively coda_iget:
  74. - get attributes (might be cached)
  75. - get the inode for the fid using vfs iget
  76. - link the two up if this is needed
  77. - fill in the attributes
  78. */
  79. int coda_cnode_make(struct inode **inode, struct CodaFid *fid, struct super_block *sb)
  80. {
  81. struct coda_vattr attr;
  82. int error;
  83. /* We get inode numbers from Venus -- see venus source */
  84. error = venus_getattr(sb, fid, &attr);
  85. if ( error ) {
  86. *inode = NULL;
  87. return error;
  88. }
  89. *inode = coda_iget(sb, fid, &attr);
  90. if ( IS_ERR(*inode) ) {
  91. printk("coda_cnode_make: coda_iget failed\n");
  92. return PTR_ERR(*inode);
  93. }
  94. return 0;
  95. }
  96. void coda_replace_fid(struct inode *inode, struct CodaFid *oldfid,
  97. struct CodaFid *newfid)
  98. {
  99. struct coda_inode_info *cii;
  100. unsigned long hash = coda_f2i(newfid);
  101. cii = ITOC(inode);
  102. BUG_ON(!coda_fideq(&cii->c_fid, oldfid));
  103. /* replace fid and rehash inode */
  104. /* XXX we probably need to hold some lock here! */
  105. remove_inode_hash(inode);
  106. cii->c_fid = *newfid;
  107. inode->i_ino = hash;
  108. __insert_inode_hash(inode, hash);
  109. }
  110. /* convert a fid to an inode. */
  111. struct inode *coda_fid_to_inode(struct CodaFid *fid, struct super_block *sb)
  112. {
  113. struct inode *inode;
  114. unsigned long hash = coda_f2i(fid);
  115. if ( !sb ) {
  116. printk("coda_fid_to_inode: no sb!\n");
  117. return NULL;
  118. }
  119. inode = iget5_locked(sb, hash, coda_test_inode, coda_fail_inode, fid);
  120. if ( !inode )
  121. return NULL;
  122. /* we should never see newly created inodes because we intentionally
  123. * fail in the initialization callback */
  124. BUG_ON(inode->i_state & I_NEW);
  125. return inode;
  126. }
  127. /* the CONTROL inode is made without asking attributes from Venus */
  128. int coda_cnode_makectl(struct inode **inode, struct super_block *sb)
  129. {
  130. int error = -ENOMEM;
  131. *inode = new_inode(sb);
  132. if (*inode) {
  133. (*inode)->i_ino = CTL_INO;
  134. (*inode)->i_op = &coda_ioctl_inode_operations;
  135. (*inode)->i_fop = &coda_ioctl_operations;
  136. (*inode)->i_mode = 0444;
  137. error = 0;
  138. }
  139. return error;
  140. }