symlink.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. static const char *ext4_encrypted_get_link(struct dentry *dentry,
  24. struct inode *inode,
  25. struct delayed_call *done)
  26. {
  27. struct page *cpage = NULL;
  28. char *caddr, *paddr = NULL;
  29. struct fscrypt_str cstr, pstr;
  30. struct fscrypt_symlink_data *sd;
  31. int res;
  32. u32 max_size = inode->i_sb->s_blocksize;
  33. if (!dentry)
  34. return ERR_PTR(-ECHILD);
  35. res = fscrypt_get_encryption_info(inode);
  36. if (res)
  37. return ERR_PTR(res);
  38. if (ext4_inode_is_fast_symlink(inode)) {
  39. caddr = (char *) EXT4_I(inode)->i_data;
  40. max_size = sizeof(EXT4_I(inode)->i_data);
  41. } else {
  42. cpage = read_mapping_page(inode->i_mapping, 0, NULL);
  43. if (IS_ERR(cpage))
  44. return ERR_CAST(cpage);
  45. caddr = page_address(cpage);
  46. }
  47. /* Symlink is encrypted */
  48. sd = (struct fscrypt_symlink_data *)caddr;
  49. cstr.name = sd->encrypted_path;
  50. cstr.len = le16_to_cpu(sd->len);
  51. if ((cstr.len + sizeof(struct fscrypt_symlink_data) - 1) > max_size) {
  52. /* Symlink data on the disk is corrupted */
  53. res = -EFSCORRUPTED;
  54. goto errout;
  55. }
  56. res = fscrypt_fname_alloc_buffer(inode, cstr.len, &pstr);
  57. if (res)
  58. goto errout;
  59. paddr = pstr.name;
  60. res = fscrypt_fname_disk_to_usr(inode, 0, 0, &cstr, &pstr);
  61. if (res)
  62. goto errout;
  63. /* Null-terminate the name */
  64. paddr[pstr.len] = '\0';
  65. if (cpage)
  66. put_page(cpage);
  67. set_delayed_call(done, kfree_link, paddr);
  68. return paddr;
  69. errout:
  70. if (cpage)
  71. put_page(cpage);
  72. kfree(paddr);
  73. return ERR_PTR(res);
  74. }
  75. const struct inode_operations ext4_encrypted_symlink_inode_operations = {
  76. .readlink = generic_readlink,
  77. .get_link = ext4_encrypted_get_link,
  78. .setattr = ext4_setattr,
  79. .listxattr = ext4_listxattr,
  80. };
  81. const struct inode_operations ext4_symlink_inode_operations = {
  82. .readlink = generic_readlink,
  83. .get_link = page_get_link,
  84. .setattr = ext4_setattr,
  85. .listxattr = ext4_listxattr,
  86. };
  87. const struct inode_operations ext4_fast_symlink_inode_operations = {
  88. .readlink = generic_readlink,
  89. .get_link = simple_get_link,
  90. .setattr = ext4_setattr,
  91. .listxattr = ext4_listxattr,
  92. };