xattr_id.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Squashfs - a compressed read only filesystem for Linux
  3. *
  4. * Copyright (c) 2010
  5. * Phillip Lougher <phillip@squashfs.org.uk>
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2,
  10. * or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  20. *
  21. * xattr_id.c
  22. */
  23. /*
  24. * This file implements code to map the 32-bit xattr id stored in the inode
  25. * into the on disk location of the xattr data.
  26. */
  27. #include <linux/fs.h>
  28. #include <linux/vfs.h>
  29. #include <linux/slab.h>
  30. #include "squashfs_fs.h"
  31. #include "squashfs_fs_sb.h"
  32. #include "squashfs.h"
  33. #include "xattr.h"
  34. /*
  35. * Map xattr id using the xattr id look up table
  36. */
  37. int squashfs_xattr_lookup(struct super_block *sb, unsigned int index,
  38. int *count, unsigned int *size, unsigned long long *xattr)
  39. {
  40. struct squashfs_sb_info *msblk = sb->s_fs_info;
  41. int block = SQUASHFS_XATTR_BLOCK(index);
  42. int offset = SQUASHFS_XATTR_BLOCK_OFFSET(index);
  43. u64 start_block = le64_to_cpu(msblk->xattr_id_table[block]);
  44. struct squashfs_xattr_id id;
  45. int err;
  46. err = squashfs_read_metadata(sb, &id, &start_block, &offset,
  47. sizeof(id));
  48. if (err < 0)
  49. return err;
  50. *xattr = le64_to_cpu(id.xattr);
  51. *size = le32_to_cpu(id.size);
  52. *count = le32_to_cpu(id.count);
  53. return 0;
  54. }
  55. /*
  56. * Read uncompressed xattr id lookup table indexes from disk into memory
  57. */
  58. __le64 *squashfs_read_xattr_id_table(struct super_block *sb, u64 start,
  59. u64 *xattr_table_start, int *xattr_ids)
  60. {
  61. unsigned int len;
  62. struct squashfs_xattr_id_table *id_table;
  63. id_table = squashfs_read_table(sb, start, sizeof(*id_table));
  64. if (IS_ERR(id_table))
  65. return (__le64 *) id_table;
  66. *xattr_table_start = le64_to_cpu(id_table->xattr_table_start);
  67. *xattr_ids = le32_to_cpu(id_table->xattr_ids);
  68. kfree(id_table);
  69. /* Sanity check values */
  70. /* there is always at least one xattr id */
  71. if (*xattr_ids == 0)
  72. return ERR_PTR(-EINVAL);
  73. /* xattr_table should be less than start */
  74. if (*xattr_table_start >= start)
  75. return ERR_PTR(-EINVAL);
  76. len = SQUASHFS_XATTR_BLOCK_BYTES(*xattr_ids);
  77. TRACE("In read_xattr_index_table, length %d\n", len);
  78. return squashfs_read_table(sb, start + sizeof(*id_table), len);
  79. }