blob: 8b93d689c907e4b6325edd5b310cfc430c4d5fd3 [file] [log] [blame]
Jorgen Lundman9b4a1f92012-07-19 20:48:25 +00001/*
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
22#ifndef __ZFS_COMMON__
23#define __ZFS_COMMON__
24
Joel Johnson6600c122020-06-19 22:45:47 -060025#include <part.h>
26
Jorgen Lundman9b4a1f92012-07-19 20:48:25 +000027#define SECTOR_SIZE 0x200
28#define SECTOR_BITS 9
29
Jorgen Lundman9b4a1f92012-07-19 20:48:25 +000030typedef enum zfs_endian {
31 UNKNOWN_ENDIAN = -2,
32 LITTLE_ENDIAN = -1,
33 BIG_ENDIAN = 0
34} zfs_endian_t;
35
Jorgen Lundman9b4a1f92012-07-19 20:48:25 +000036/* Endian macros. */
37#define zfs_to_cpu16(x, a) (((a) == BIG_ENDIAN) ? be16_to_cpu(x) \
38 : le16_to_cpu(x))
39#define cpu_to_zfs16(x, a) (((a) == BIG_ENDIAN) ? cpu_to_be16(x) \
40 : cpu_to_le16(x))
41
42#define zfs_to_cpu32(x, a) (((a) == BIG_ENDIAN) ? be32_to_cpu(x) \
43 : le32_to_cpu(x))
44#define cpu_to_zfs32(x, a) (((a) == BIG_ENDIAN) ? cpu_to_be32(x) \
45 : cpu_to_le32(x))
46
47#define zfs_to_cpu64(x, a) (((a) == BIG_ENDIAN) ? be64_to_cpu(x) \
48 : le64_to_cpu(x))
49#define cpu_to_zfs64(x, a) (((a) == BIG_ENDIAN) ? cpu_to_be64(x) \
50 : cpu_to_le64(x))
51
Jorgen Lundman9b4a1f92012-07-19 20:48:25 +000052enum zfs_errors {
53 ZFS_ERR_NONE = 0,
54 ZFS_ERR_NOT_IMPLEMENTED_YET = -1,
55 ZFS_ERR_BAD_FS = -2,
56 ZFS_ERR_OUT_OF_MEMORY = -3,
57 ZFS_ERR_FILE_NOT_FOUND = -4,
58 ZFS_ERR_BAD_FILE_TYPE = -5,
59 ZFS_ERR_OUT_OF_RANGE = -6,
60};
61
62struct zfs_filesystem {
63
64 /* Block Device Descriptor */
Simon Glasse3394752016-02-29 15:25:34 -070065 struct blk_desc *dev_desc;
Jorgen Lundman9b4a1f92012-07-19 20:48:25 +000066};
67
Jorgen Lundman9b4a1f92012-07-19 20:48:25 +000068struct device_s {
69 uint64_t part_length;
70};
71typedef struct device_s *device_t;
72
73struct zfs_file {
74 device_t device;
75 uint64_t size;
76 void *data;
77 uint64_t offset;
78};
79
80typedef struct zfs_file *zfs_file_t;
81
82struct zfs_dirhook_info {
83 int dir;
84 int mtimeset;
85 time_t mtime;
86 time_t mtime2;
87};
88
Jorgen Lundman9b4a1f92012-07-19 20:48:25 +000089struct zfs_filesystem *zfsget_fs(void);
Jorgen Lundman9b4a1f92012-07-19 20:48:25 +000090int zfs_open(zfs_file_t, const char *filename);
91uint64_t zfs_read(zfs_file_t, char *buf, uint64_t len);
92struct zfs_data *zfs_mount(device_t);
93int zfs_close(zfs_file_t);
94int zfs_ls(device_t dev, const char *path,
95 int (*hook) (const char *, const struct zfs_dirhook_info *));
96int zfs_devread(int sector, int byte_offset, int byte_len, char *buf);
Simon Glassc1c4a8f2020-05-10 11:39:57 -060097void zfs_set_blk_dev(struct blk_desc *rbdd, struct disk_partition *info);
Jorgen Lundman9b4a1f92012-07-19 20:48:25 +000098void zfs_unmount(struct zfs_data *data);
99int lzjb_decompress(void *, void *, uint32_t, uint32_t);
100#endif