symlink.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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_follow_link(struct dentry *dentry, void **cookie)
  25. {
  26. struct page *cpage = NULL;
  27. char *caddr, *paddr = NULL;
  28. struct ext4_str cstr, pstr;
  29. struct inode *inode = d_inode(dentry);
  30. struct ext4_encrypted_symlink_data *sd;
  31. loff_t size = min_t(loff_t, i_size_read(inode), PAGE_SIZE - 1);
  32. int res;
  33. u32 plen, max_size = inode->i_sb->s_blocksize;
  34. res = ext4_get_encryption_info(inode);
  35. if (res)
  36. return ERR_PTR(res);
  37. if (ext4_inode_is_fast_symlink(inode)) {
  38. caddr = (char *) EXT4_I(inode)->i_data;
  39. max_size = sizeof(EXT4_I(inode)->i_data);
  40. } else {
  41. cpage = read_mapping_page(inode->i_mapping, 0, NULL);
  42. if (IS_ERR(cpage))
  43. return ERR_CAST(cpage);
  44. caddr = page_address(cpage);
  45. caddr[size] = 0;
  46. }
  47. /* Symlink is encrypted */
  48. sd = (struct ext4_encrypted_symlink_data *)caddr;
  49. cstr.name = sd->encrypted_path;
  50. cstr.len = le16_to_cpu(sd->len);
  51. if ((cstr.len +
  52. sizeof(struct ext4_encrypted_symlink_data) - 1) >
  53. max_size) {
  54. /* Symlink data on the disk is corrupted */
  55. res = -EFSCORRUPTED;
  56. goto errout;
  57. }
  58. plen = (cstr.len < EXT4_FNAME_CRYPTO_DIGEST_SIZE*2) ?
  59. EXT4_FNAME_CRYPTO_DIGEST_SIZE*2 : cstr.len;
  60. paddr = kmalloc(plen + 1, GFP_NOFS);
  61. if (!paddr) {
  62. res = -ENOMEM;
  63. goto errout;
  64. }
  65. pstr.name = paddr;
  66. pstr.len = plen;
  67. res = _ext4_fname_disk_to_usr(inode, NULL, &cstr, &pstr);
  68. if (res < 0)
  69. goto errout;
  70. /* Null-terminate the name */
  71. if (res <= plen)
  72. paddr[res] = '\0';
  73. if (cpage)
  74. page_cache_release(cpage);
  75. return *cookie = paddr;
  76. errout:
  77. if (cpage)
  78. page_cache_release(cpage);
  79. kfree(paddr);
  80. return ERR_PTR(res);
  81. }
  82. const struct inode_operations ext4_encrypted_symlink_inode_operations = {
  83. .readlink = generic_readlink,
  84. .follow_link = ext4_encrypted_follow_link,
  85. .put_link = kfree_put_link,
  86. .setattr = ext4_setattr,
  87. .setxattr = generic_setxattr,
  88. .getxattr = generic_getxattr,
  89. .listxattr = ext4_listxattr,
  90. .removexattr = generic_removexattr,
  91. };
  92. #endif
  93. const struct inode_operations ext4_symlink_inode_operations = {
  94. .readlink = generic_readlink,
  95. .follow_link = page_follow_link_light,
  96. .put_link = page_put_link,
  97. .setattr = ext4_setattr,
  98. .setxattr = generic_setxattr,
  99. .getxattr = generic_getxattr,
  100. .listxattr = ext4_listxattr,
  101. .removexattr = generic_removexattr,
  102. };
  103. const struct inode_operations ext4_fast_symlink_inode_operations = {
  104. .readlink = generic_readlink,
  105. .follow_link = simple_follow_link,
  106. .setattr = ext4_setattr,
  107. .setxattr = generic_setxattr,
  108. .getxattr = generic_getxattr,
  109. .listxattr = ext4_listxattr,
  110. .removexattr = generic_removexattr,
  111. };