symlink.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. char *pf;
  22. pr_debug("AFFS: follow_link(ino=%lu)\n",inode->i_ino);
  23. err = -EIO;
  24. bh = affs_bread(inode->i_sb, inode->i_ino);
  25. if (!bh)
  26. goto fail;
  27. i = 0;
  28. j = 0;
  29. lf = (struct slink_front *)bh->b_data;
  30. lc = 0;
  31. pf = AFFS_SB(inode->i_sb)->s_prefix ? AFFS_SB(inode->i_sb)->s_prefix : "/";
  32. if (strchr(lf->symname,':')) { /* Handle assign or volume name */
  33. while (i < 1023 && (c = pf[i]))
  34. link[i++] = c;
  35. while (i < 1023 && lf->symname[j] != ':')
  36. link[i++] = lf->symname[j++];
  37. if (i < 1023)
  38. link[i++] = '/';
  39. j++;
  40. lc = '/';
  41. }
  42. while (i < 1023 && (c = lf->symname[j])) {
  43. if (c == '/' && lc == '/' && i < 1020) { /* parent dir */
  44. link[i++] = '.';
  45. link[i++] = '.';
  46. }
  47. link[i++] = c;
  48. lc = c;
  49. j++;
  50. }
  51. link[i] = '\0';
  52. affs_brelse(bh);
  53. SetPageUptodate(page);
  54. kunmap(page);
  55. unlock_page(page);
  56. return 0;
  57. fail:
  58. SetPageError(page);
  59. kunmap(page);
  60. unlock_page(page);
  61. return err;
  62. }
  63. const struct address_space_operations affs_symlink_aops = {
  64. .readpage = affs_symlink_readpage,
  65. };
  66. const struct inode_operations affs_symlink_inode_operations = {
  67. .readlink = generic_readlink,
  68. .follow_link = page_follow_link_light,
  69. .put_link = page_put_link,
  70. .setattr = affs_notify_change,
  71. };