symlink.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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/udf_fs.h>
  26. #include <linux/time.h>
  27. #include <linux/mm.h>
  28. #include <linux/stat.h>
  29. #include <linux/slab.h>
  30. #include <linux/pagemap.h>
  31. #include <linux/smp_lock.h>
  32. #include <linux/buffer_head.h>
  33. #include "udf_i.h"
  34. static void udf_pc_to_char(struct super_block *sb, char *from, int fromlen,
  35. char *to)
  36. {
  37. struct pathComponent *pc;
  38. int elen = 0;
  39. char *p = to;
  40. while (elen < fromlen) {
  41. pc = (struct pathComponent *)(from + elen);
  42. switch (pc->componentType) {
  43. case 1:
  44. if (pc->lengthComponentIdent == 0) {
  45. p = to;
  46. *p++ = '/';
  47. }
  48. break;
  49. case 3:
  50. memcpy(p, "../", 3);
  51. p += 3;
  52. break;
  53. case 4:
  54. memcpy(p, "./", 2);
  55. p += 2;
  56. /* that would be . - just ignore */
  57. break;
  58. case 5:
  59. p += udf_get_filename(sb, pc->componentIdent, p,
  60. pc->lengthComponentIdent);
  61. *p++ = '/';
  62. break;
  63. }
  64. elen += sizeof(struct pathComponent) + pc->lengthComponentIdent;
  65. }
  66. if (p > to + 1)
  67. p[-1] = '\0';
  68. else
  69. p[0] = '\0';
  70. }
  71. static int udf_symlink_filler(struct file *file, struct page *page)
  72. {
  73. struct inode *inode = page->mapping->host;
  74. struct buffer_head *bh = NULL;
  75. char *symlink;
  76. int err = -EIO;
  77. char *p = kmap(page);
  78. struct udf_inode_info *iinfo;
  79. lock_kernel();
  80. iinfo = UDF_I(inode);
  81. if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) {
  82. symlink = iinfo->i_ext.i_data + iinfo->i_lenEAttr;
  83. } else {
  84. bh = sb_bread(inode->i_sb, udf_block_map(inode, 0));
  85. if (!bh)
  86. goto out;
  87. symlink = bh->b_data;
  88. }
  89. udf_pc_to_char(inode->i_sb, symlink, inode->i_size, p);
  90. brelse(bh);
  91. unlock_kernel();
  92. SetPageUptodate(page);
  93. kunmap(page);
  94. unlock_page(page);
  95. return 0;
  96. out:
  97. unlock_kernel();
  98. SetPageError(page);
  99. kunmap(page);
  100. unlock_page(page);
  101. return err;
  102. }
  103. /*
  104. * symlinks can't do much...
  105. */
  106. const struct address_space_operations udf_symlink_aops = {
  107. .readpage = udf_symlink_filler,
  108. };