symlink.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * symlink.c
  3. *
  4. * PURPOSE
  5. * Symlink handling routines for the OSTA-UDF(tm) filesystem.
  6. *
  7. * CONTACTS
  8. * E-mail regarding any portion of the Linux UDF file system should be
  9. * directed to the development team mailing list (run by majordomo):
  10. * linux_udf@hpesjro.fc.hp.com
  11. *
  12. * COPYRIGHT
  13. * This file is distributed under the terms of the GNU General Public
  14. * License (GPL). Copies of the GPL can be obtained from:
  15. * ftp://prep.ai.mit.edu/pub/gnu/GPL
  16. * Each contributing author retains all rights to their own work.
  17. *
  18. * (C) 1998-2001 Ben Fennema
  19. * (C) 1999 Stelias Computing Inc
  20. *
  21. * HISTORY
  22. *
  23. * 04/16/99 blf Created.
  24. *
  25. */
  26. #include "udfdecl.h"
  27. #include <asm/uaccess.h>
  28. #include <linux/errno.h>
  29. #include <linux/fs.h>
  30. #include <linux/udf_fs.h>
  31. #include <linux/time.h>
  32. #include <linux/mm.h>
  33. #include <linux/stat.h>
  34. #include <linux/slab.h>
  35. #include <linux/pagemap.h>
  36. #include <linux/smp_lock.h>
  37. #include <linux/buffer_head.h>
  38. #include "udf_i.h"
  39. static void udf_pc_to_char(struct super_block *sb, char *from, int fromlen, char *to)
  40. {
  41. struct pathComponent *pc;
  42. int elen = 0;
  43. char *p = to;
  44. while (elen < fromlen)
  45. {
  46. pc = (struct pathComponent *)(from + elen);
  47. switch (pc->componentType)
  48. {
  49. case 1:
  50. if (pc->lengthComponentIdent == 0)
  51. {
  52. p = to;
  53. *p++ = '/';
  54. }
  55. break;
  56. case 3:
  57. memcpy(p, "../", 3);
  58. p += 3;
  59. break;
  60. case 4:
  61. memcpy(p, "./", 2);
  62. p += 2;
  63. /* that would be . - just ignore */
  64. break;
  65. case 5:
  66. p += udf_get_filename(sb, pc->componentIdent, p, pc->lengthComponentIdent);
  67. *p++ = '/';
  68. break;
  69. }
  70. elen += sizeof(struct pathComponent) + pc->lengthComponentIdent;
  71. }
  72. if (p > to+1)
  73. p[-1] = '\0';
  74. else
  75. p[0] = '\0';
  76. }
  77. static int udf_symlink_filler(struct file *file, struct page *page)
  78. {
  79. struct inode *inode = page->mapping->host;
  80. struct buffer_head *bh = NULL;
  81. char *symlink;
  82. int err = -EIO;
  83. char *p = kmap(page);
  84. lock_kernel();
  85. if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB)
  86. symlink = UDF_I_DATA(inode) + UDF_I_LENEATTR(inode);
  87. else
  88. {
  89. bh = sb_bread(inode->i_sb, udf_block_map(inode, 0));
  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. udf_release_data(bh);
  96. unlock_kernel();
  97. SetPageUptodate(page);
  98. kunmap(page);
  99. unlock_page(page);
  100. return 0;
  101. out:
  102. unlock_kernel();
  103. SetPageError(page);
  104. kunmap(page);
  105. unlock_page(page);
  106. return err;
  107. }
  108. /*
  109. * symlinks can't do much...
  110. */
  111. struct address_space_operations udf_symlink_aops = {
  112. .readpage = udf_symlink_filler,
  113. };