zfs_common.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * ZFS filesystem port for Uboot by
  3. * Jorgen Lundman <lundman at lundman.net>
  4. *
  5. * zfsfs support
  6. * made from existing GRUB Sources by Sun, GNU and others.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  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, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21. #ifndef __ZFS_COMMON__
  22. #define __ZFS_COMMON__
  23. #include <part.h>
  24. #define SECTOR_SIZE 0x200
  25. #define SECTOR_BITS 9
  26. typedef enum zfs_endian {
  27. UNKNOWN_ENDIAN = -2,
  28. LITTLE_ENDIAN = -1,
  29. BIG_ENDIAN = 0
  30. } zfs_endian_t;
  31. /* Endian macros. */
  32. #define zfs_to_cpu16(x, a) (((a) == BIG_ENDIAN) ? be16_to_cpu(x) \
  33. : le16_to_cpu(x))
  34. #define cpu_to_zfs16(x, a) (((a) == BIG_ENDIAN) ? cpu_to_be16(x) \
  35. : cpu_to_le16(x))
  36. #define zfs_to_cpu32(x, a) (((a) == BIG_ENDIAN) ? be32_to_cpu(x) \
  37. : le32_to_cpu(x))
  38. #define cpu_to_zfs32(x, a) (((a) == BIG_ENDIAN) ? cpu_to_be32(x) \
  39. : cpu_to_le32(x))
  40. #define zfs_to_cpu64(x, a) (((a) == BIG_ENDIAN) ? be64_to_cpu(x) \
  41. : le64_to_cpu(x))
  42. #define cpu_to_zfs64(x, a) (((a) == BIG_ENDIAN) ? cpu_to_be64(x) \
  43. : cpu_to_le64(x))
  44. enum zfs_errors {
  45. ZFS_ERR_NONE = 0,
  46. ZFS_ERR_NOT_IMPLEMENTED_YET = -1,
  47. ZFS_ERR_BAD_FS = -2,
  48. ZFS_ERR_OUT_OF_MEMORY = -3,
  49. ZFS_ERR_FILE_NOT_FOUND = -4,
  50. ZFS_ERR_BAD_FILE_TYPE = -5,
  51. ZFS_ERR_OUT_OF_RANGE = -6,
  52. };
  53. struct zfs_filesystem {
  54. /* Block Device Descriptor */
  55. struct blk_desc *dev_desc;
  56. };
  57. struct device_s {
  58. uint64_t part_length;
  59. };
  60. typedef struct device_s *device_t;
  61. struct zfs_file {
  62. device_t device;
  63. uint64_t size;
  64. void *data;
  65. uint64_t offset;
  66. };
  67. typedef struct zfs_file *zfs_file_t;
  68. struct zfs_dirhook_info {
  69. int dir;
  70. int mtimeset;
  71. time_t mtime;
  72. time_t mtime2;
  73. };
  74. struct zfs_filesystem *zfsget_fs(void);
  75. int zfs_open(zfs_file_t, const char *filename);
  76. uint64_t zfs_read(zfs_file_t, char *buf, uint64_t len);
  77. struct zfs_data *zfs_mount(device_t);
  78. int zfs_close(zfs_file_t);
  79. int zfs_ls(device_t dev, const char *path,
  80. int (*hook) (const char *, const struct zfs_dirhook_info *));
  81. int zfs_devread(int sector, int byte_offset, int byte_len, char *buf);
  82. void zfs_set_blk_dev(struct blk_desc *rbdd, struct disk_partition *info);
  83. void zfs_unmount(struct zfs_data *data);
  84. int lzjb_decompress(void *, void *, uint32_t, uint32_t);
  85. #endif