symlink.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * linux/fs/affs/symlink.c
  3. *
  4. * 1995 Hans-Joachim Widmaier - Modified for affs.
  5. *
  6. * Copyright (C) 1991, 1992 Linus Torvalds
  7. *
  8. * affs symlink handling code
  9. */
  10. #include "affs.h"
  11. static int affs_symlink_readpage(struct file *file, struct page *page)
  12. {
  13. struct buffer_head *bh;
  14. struct inode *inode = page->mapping->host;
  15. char *link = kmap(page);
  16. struct slink_front *lf;
  17. int err;
  18. int i, j;
  19. char c;
  20. char lc;
  21. pr_debug("AFFS: follow_link(ino=%lu)\n",inode->i_ino);
  22. err = -EIO;
  23. bh = affs_bread(inode->i_sb, inode->i_ino);
  24. if (!bh)
  25. goto fail;
  26. i = 0;
  27. j = 0;
  28. lf = (struct slink_front *)bh->b_data;
  29. lc = 0;
  30. if (strchr(lf->symname,':')) { /* Handle assign or volume name */
  31. struct affs_sb_info *sbi = AFFS_SB(inode->i_sb);
  32. char *pf;
  33. spin_lock(&sbi->symlink_lock);
  34. pf = sbi->s_prefix ? sbi->s_prefix : "/";
  35. while (i < 1023 && (c = pf[i]))
  36. link[i++] = c;
  37. spin_unlock(&sbi->symlink_lock);
  38. while (i < 1023 && lf->symname[j] != ':')
  39. link[i++] = lf->symname[j++];
  40. if (i < 1023)
  41. link[i++] = '/';
  42. j++;
  43. lc = '/';
  44. }
  45. while (i < 1023 && (c = lf->symname[j])) {
  46. if (c == '/' && lc == '/' && i < 1020) { /* parent dir */
  47. link[i++] = '.';
  48. link[i++] = '.';
  49. }
  50. link[i++] = c;
  51. lc = c;
  52. j++;
  53. }
  54. link[i] = '\0';
  55. affs_brelse(bh);
  56. SetPageUptodate(page);
  57. kunmap(page);
  58. unlock_page(page);
  59. return 0;
  60. fail:
  61. SetPageError(page);
  62. kunmap(page);
  63. unlock_page(page);
  64. return err;
  65. }
  66. const struct address_space_operations affs_symlink_aops = {
  67. .readpage = affs_symlink_readpage,
  68. };
  69. const struct inode_operations affs_symlink_inode_operations = {
  70. .readlink = generic_readlink,
  71. .follow_link = page_follow_link_light,
  72. .put_link = page_put_link,
  73. .setattr = affs_notify_change,
  74. };