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