symlink.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * symlink.c
  3. *
  4. * PURPOSE
  5. * Symlink handling routines for the OSTA-UDF(tm) filesystem.
  6. *
  7. * COPYRIGHT
  8. * This file is distributed under the terms of the GNU General Public
  9. * License (GPL). Copies of the GPL can be obtained from:
  10. * ftp://prep.ai.mit.edu/pub/gnu/GPL
  11. * Each contributing author retains all rights to their own work.
  12. *
  13. * (C) 1998-2001 Ben Fennema
  14. * (C) 1999 Stelias Computing Inc
  15. *
  16. * HISTORY
  17. *
  18. * 04/16/99 blf Created.
  19. *
  20. */
  21. #include "udfdecl.h"
  22. #include <asm/uaccess.h>
  23. #include <linux/errno.h>
  24. #include <linux/fs.h>
  25. #include <linux/time.h>
  26. #include <linux/mm.h>
  27. #include <linux/stat.h>
  28. #include <linux/pagemap.h>
  29. #include <linux/buffer_head.h>
  30. #include "udf_i.h"
  31. static void udf_pc_to_char(struct super_block *sb, unsigned char *from,
  32. int fromlen, unsigned char *to)
  33. {
  34. struct pathComponent *pc;
  35. int elen = 0;
  36. unsigned char *p = to;
  37. while (elen < fromlen) {
  38. pc = (struct pathComponent *)(from + elen);
  39. switch (pc->componentType) {
  40. case 1:
  41. /*
  42. * Symlink points to some place which should be agreed
  43. * upon between originator and receiver of the media. Ignore.
  44. */
  45. if (pc->lengthComponentIdent > 0)
  46. break;
  47. /* Fall through */
  48. case 2:
  49. p = to;
  50. *p++ = '/';
  51. break;
  52. case 3:
  53. memcpy(p, "../", 3);
  54. p += 3;
  55. break;
  56. case 4:
  57. memcpy(p, "./", 2);
  58. p += 2;
  59. /* that would be . - just ignore */
  60. break;
  61. case 5:
  62. p += udf_get_filename(sb, pc->componentIdent, p,
  63. pc->lengthComponentIdent);
  64. *p++ = '/';
  65. break;
  66. }
  67. elen += sizeof(struct pathComponent) + pc->lengthComponentIdent;
  68. }
  69. if (p > to + 1)
  70. p[-1] = '\0';
  71. else
  72. p[0] = '\0';
  73. }
  74. static int udf_symlink_filler(struct file *file, struct page *page)
  75. {
  76. struct inode *inode = page->mapping->host;
  77. struct buffer_head *bh = NULL;
  78. unsigned char *symlink;
  79. int err = -EIO;
  80. unsigned char *p = kmap(page);
  81. struct udf_inode_info *iinfo;
  82. uint32_t pos;
  83. iinfo = UDF_I(inode);
  84. pos = udf_block_map(inode, 0);
  85. down_read(&iinfo->i_data_sem);
  86. if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) {
  87. symlink = iinfo->i_ext.i_data + iinfo->i_lenEAttr;
  88. } else {
  89. bh = sb_bread(inode->i_sb, pos);
  90. if (!bh)
  91. goto out;
  92. symlink = bh->b_data;
  93. }
  94. udf_pc_to_char(inode->i_sb, symlink, inode->i_size, p);
  95. brelse(bh);
  96. up_read(&iinfo->i_data_sem);
  97. SetPageUptodate(page);
  98. kunmap(page);
  99. unlock_page(page);
  100. return 0;
  101. out:
  102. up_read(&iinfo->i_data_sem);
  103. SetPageError(page);
  104. kunmap(page);
  105. unlock_page(page);
  106. return err;
  107. }
  108. /*
  109. * symlinks can't do much...
  110. */
  111. const struct address_space_operations udf_symlink_aops = {
  112. .readpage = udf_symlink_filler,
  113. };