symlink.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. if (pc->lengthComponentIdent == 0) {
  42. p = to;
  43. *p++ = '/';
  44. }
  45. break;
  46. case 3:
  47. memcpy(p, "../", 3);
  48. p += 3;
  49. break;
  50. case 4:
  51. memcpy(p, "./", 2);
  52. p += 2;
  53. /* that would be . - just ignore */
  54. break;
  55. case 5:
  56. p += udf_get_filename(sb, pc->componentIdent, p,
  57. pc->lengthComponentIdent);
  58. *p++ = '/';
  59. break;
  60. }
  61. elen += sizeof(struct pathComponent) + pc->lengthComponentIdent;
  62. }
  63. if (p > to + 1)
  64. p[-1] = '\0';
  65. else
  66. p[0] = '\0';
  67. }
  68. static int udf_symlink_filler(struct file *file, struct page *page)
  69. {
  70. struct inode *inode = page->mapping->host;
  71. struct buffer_head *bh = NULL;
  72. unsigned char *symlink;
  73. int err = -EIO;
  74. unsigned char *p = kmap(page);
  75. struct udf_inode_info *iinfo;
  76. uint32_t pos;
  77. iinfo = UDF_I(inode);
  78. pos = udf_block_map(inode, 0);
  79. down_read(&iinfo->i_data_sem);
  80. if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) {
  81. symlink = iinfo->i_ext.i_data + iinfo->i_lenEAttr;
  82. } else {
  83. bh = sb_bread(inode->i_sb, pos);
  84. if (!bh)
  85. goto out;
  86. symlink = bh->b_data;
  87. }
  88. udf_pc_to_char(inode->i_sb, symlink, inode->i_size, p);
  89. brelse(bh);
  90. up_read(&iinfo->i_data_sem);
  91. SetPageUptodate(page);
  92. kunmap(page);
  93. unlock_page(page);
  94. return 0;
  95. out:
  96. up_read(&iinfo->i_data_sem);
  97. SetPageError(page);
  98. kunmap(page);
  99. unlock_page(page);
  100. return err;
  101. }
  102. /*
  103. * symlinks can't do much...
  104. */
  105. const struct address_space_operations udf_symlink_aops = {
  106. .readpage = udf_symlink_filler,
  107. };