symlink.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * linux/fs/ext4/symlink.c
  3. *
  4. * Only fast symlinks left here - the rest is done by generic code. AV, 1999
  5. *
  6. * Copyright (C) 1992, 1993, 1994, 1995
  7. * Remy Card (card@masi.ibp.fr)
  8. * Laboratoire MASI - Institut Blaise Pascal
  9. * Universite Pierre et Marie Curie (Paris VI)
  10. *
  11. * from
  12. *
  13. * linux/fs/minix/symlink.c
  14. *
  15. * Copyright (C) 1991, 1992 Linus Torvalds
  16. *
  17. * ext4 symlink handling code
  18. */
  19. #include <linux/fs.h>
  20. #include <linux/namei.h>
  21. #include "ext4.h"
  22. #include "xattr.h"
  23. #ifdef CONFIG_EXT4_FS_ENCRYPTION
  24. static const char *ext4_encrypted_get_link(struct dentry *dentry,
  25. struct inode *inode,
  26. struct delayed_call *done)
  27. {
  28. struct page *cpage = NULL;
  29. char *caddr, *paddr = NULL;
  30. struct ext4_str cstr, pstr;
  31. struct ext4_encrypted_symlink_data *sd;
  32. loff_t size = min_t(loff_t, i_size_read(inode), PAGE_SIZE - 1);
  33. int res;
  34. u32 plen, max_size = inode->i_sb->s_blocksize;
  35. if (!dentry)
  36. return ERR_PTR(-ECHILD);
  37. res = ext4_get_encryption_info(inode);
  38. if (res)
  39. return ERR_PTR(res);
  40. if (ext4_inode_is_fast_symlink(inode)) {
  41. caddr = (char *) EXT4_I(inode)->i_data;
  42. max_size = sizeof(EXT4_I(inode)->i_data);
  43. } else {
  44. cpage = read_mapping_page(inode->i_mapping, 0, NULL);
  45. if (IS_ERR(cpage))
  46. return ERR_CAST(cpage);
  47. caddr = page_address(cpage);
  48. caddr[size] = 0;
  49. }
  50. /* Symlink is encrypted */
  51. sd = (struct ext4_encrypted_symlink_data *)caddr;
  52. cstr.name = sd->encrypted_path;
  53. cstr.len = le16_to_cpu(sd->len);
  54. if ((cstr.len +
  55. sizeof(struct ext4_encrypted_symlink_data) - 1) >
  56. max_size) {
  57. /* Symlink data on the disk is corrupted */
  58. res = -EFSCORRUPTED;
  59. goto errout;
  60. }
  61. plen = (cstr.len < EXT4_FNAME_CRYPTO_DIGEST_SIZE*2) ?
  62. EXT4_FNAME_CRYPTO_DIGEST_SIZE*2 : cstr.len;
  63. paddr = kmalloc(plen + 1, GFP_NOFS);
  64. if (!paddr) {
  65. res = -ENOMEM;
  66. goto errout;
  67. }
  68. pstr.name = paddr;
  69. pstr.len = plen;
  70. res = _ext4_fname_disk_to_usr(inode, NULL, &cstr, &pstr);
  71. if (res < 0)
  72. goto errout;
  73. /* Null-terminate the name */
  74. if (res <= plen)
  75. paddr[res] = '\0';
  76. if (cpage)
  77. page_cache_release(cpage);
  78. set_delayed_call(done, kfree_link, paddr);
  79. return paddr;
  80. errout:
  81. if (cpage)
  82. page_cache_release(cpage);
  83. kfree(paddr);
  84. return ERR_PTR(res);
  85. }
  86. const struct inode_operations ext4_encrypted_symlink_inode_operations = {
  87. .readlink = generic_readlink,
  88. .get_link = ext4_encrypted_get_link,
  89. .setattr = ext4_setattr,
  90. .setxattr = generic_setxattr,
  91. .getxattr = generic_getxattr,
  92. .listxattr = ext4_listxattr,
  93. .removexattr = generic_removexattr,
  94. };
  95. #endif
  96. const struct inode_operations ext4_symlink_inode_operations = {
  97. .readlink = generic_readlink,
  98. .get_link = page_get_link,
  99. .setattr = ext4_setattr,
  100. .setxattr = generic_setxattr,
  101. .getxattr = generic_getxattr,
  102. .listxattr = ext4_listxattr,
  103. .removexattr = generic_removexattr,
  104. };
  105. const struct inode_operations ext4_fast_symlink_inode_operations = {
  106. .readlink = generic_readlink,
  107. .get_link = simple_get_link,
  108. .setattr = ext4_setattr,
  109. .setxattr = generic_setxattr,
  110. .getxattr = generic_getxattr,
  111. .listxattr = ext4_listxattr,
  112. .removexattr = generic_removexattr,
  113. };