zfs: Add ZFS filesystem support
U-Boot port is based on sources forked from GRUB-0.97 by Sun in 2004,
which can be found here:
http://src.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/grub/grub-0.97/stage2/zfs-include/zfs.h
Released by Sun for GRUB under the license:
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
GRUB official releases include ZFS in version:
ftp://alpha.gnu.org/gnu/grub/grub-1.99~rc1.tar.gz
And patched against GRUB Bazaar repository for ashift fixes (4KB HDDs)
more conveniently found at github:
e7b6ef3ac3
Signed-off-by: Jorgen Lundman <lundman@lundman.net>
This commit is contained in:
parent
753ac61088
commit
4d3c95f5ea
2
Makefile
2
Makefile
@ -247,7 +247,7 @@ endif
|
||||
LIBS += arch/$(ARCH)/lib/lib$(ARCH).o
|
||||
LIBS += fs/cramfs/libcramfs.o fs/fat/libfat.o fs/fdos/libfdos.o fs/jffs2/libjffs2.o \
|
||||
fs/reiserfs/libreiserfs.o fs/ext2/libext2fs.o fs/yaffs2/libyaffs2.o \
|
||||
fs/ubifs/libubifs.o
|
||||
fs/ubifs/libubifs.o fs/zfs/libzfs.o
|
||||
LIBS += net/libnet.o
|
||||
LIBS += disk/libdisk.o
|
||||
LIBS += drivers/bios_emulator/libatibiosemu.o
|
||||
|
@ -162,6 +162,7 @@ endif
|
||||
COBJS-$(CONFIG_CMD_XIMG) += cmd_ximg.o
|
||||
COBJS-$(CONFIG_YAFFS2) += cmd_yaffs2.o
|
||||
COBJS-$(CONFIG_CMD_SPL) += cmd_spl.o
|
||||
COBJS-$(CONFIG_CMD_ZFS) += cmd_zfs.o
|
||||
|
||||
# others
|
||||
ifdef CONFIG_DDR_SPD
|
||||
|
236
common/cmd_zfs.c
Normal file
236
common/cmd_zfs.c
Normal file
@ -0,0 +1,236 @@
|
||||
/*
|
||||
*
|
||||
* ZFS filesystem porting to Uboot by
|
||||
* Jorgen Lundman <lundman at lundman.net>
|
||||
*
|
||||
* zfsfs support
|
||||
* made from existing GRUB Sources by Sun, GNU and others.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include <common.h>
|
||||
#include <part.h>
|
||||
#include <config.h>
|
||||
#include <command.h>
|
||||
#include <image.h>
|
||||
#include <linux/ctype.h>
|
||||
#include <asm/byteorder.h>
|
||||
#include <zfs_common.h>
|
||||
#include <linux/stat.h>
|
||||
#include <malloc.h>
|
||||
|
||||
#if defined(CONFIG_CMD_USB) && defined(CONFIG_USB_STORAGE)
|
||||
#include <usb.h>
|
||||
#endif
|
||||
|
||||
#if !defined(CONFIG_DOS_PARTITION) && !defined(CONFIG_EFI_PARTITION)
|
||||
#error DOS or EFI partition support must be selected
|
||||
#endif
|
||||
|
||||
#define DOS_PART_MAGIC_OFFSET 0x1fe
|
||||
#define DOS_FS_TYPE_OFFSET 0x36
|
||||
#define DOS_FS32_TYPE_OFFSET 0x52
|
||||
|
||||
static int do_zfs_load(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
|
||||
{
|
||||
char *filename = NULL;
|
||||
char *ep;
|
||||
int dev;
|
||||
unsigned long part = 1;
|
||||
ulong addr = 0;
|
||||
ulong part_length;
|
||||
disk_partition_t info;
|
||||
char buf[12];
|
||||
unsigned long count;
|
||||
const char *addr_str;
|
||||
struct zfs_file zfile;
|
||||
struct device_s vdev;
|
||||
|
||||
if (argc < 3)
|
||||
return CMD_RET_USAGE;
|
||||
|
||||
count = 0;
|
||||
addr = simple_strtoul(argv[3], NULL, 16);
|
||||
filename = getenv("bootfile");
|
||||
switch (argc) {
|
||||
case 3:
|
||||
addr_str = getenv("loadaddr");
|
||||
if (addr_str != NULL)
|
||||
addr = simple_strtoul(addr_str, NULL, 16);
|
||||
else
|
||||
addr = CONFIG_SYS_LOAD_ADDR;
|
||||
|
||||
break;
|
||||
case 4:
|
||||
break;
|
||||
case 5:
|
||||
filename = argv[4];
|
||||
break;
|
||||
case 6:
|
||||
filename = argv[4];
|
||||
count = simple_strtoul(argv[5], NULL, 16);
|
||||
break;
|
||||
|
||||
default:
|
||||
return cmd_usage(cmdtp);
|
||||
}
|
||||
|
||||
if (!filename) {
|
||||
puts("** No boot file defined **\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
dev = (int)simple_strtoul(argv[2], &ep, 16);
|
||||
zfs_dev_desc = get_dev(argv[1], dev);
|
||||
if (zfs_dev_desc == NULL) {
|
||||
printf("** Block device %s %d not supported\n", argv[1], dev);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (*ep) {
|
||||
if (*ep != ':') {
|
||||
puts("** Invalid boot device, use `dev[:part]' **\n");
|
||||
return 1;
|
||||
}
|
||||
part = simple_strtoul(++ep, NULL, 16);
|
||||
}
|
||||
|
||||
if (part != 0) {
|
||||
if (get_partition_info(zfs_dev_desc, part, &info)) {
|
||||
printf("** Bad partition %lu **\n", part);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (strncmp((char *)info.type, BOOT_PART_TYPE,
|
||||
strlen(BOOT_PART_TYPE)) != 0) {
|
||||
printf("** Invalid partition type \"%s\" (expect \"" BOOT_PART_TYPE "\")\n",
|
||||
info.type);
|
||||
return 1;
|
||||
}
|
||||
printf("Loading file \"%s\" "
|
||||
"from %s device %d:%lu %s\n",
|
||||
filename, argv[1], dev, part, info.name);
|
||||
} else {
|
||||
printf("Loading file \"%s\" from %s device %d\n",
|
||||
filename, argv[1], dev);
|
||||
}
|
||||
|
||||
part_length = zfs_set_blk_dev(zfs_dev_desc, part);
|
||||
if (part_length == 0) {
|
||||
printf("**Bad partition - %s %d:%lu **\n", argv[1], dev, part);
|
||||
return 1;
|
||||
}
|
||||
|
||||
vdev.part_length = part_length;
|
||||
|
||||
memset(&zfile, 0, sizeof(zfile));
|
||||
zfile.device = &vdev;
|
||||
if (zfs_open(&zfile, filename)) {
|
||||
printf("** File not found %s\n", filename);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ((count < zfile.size) && (count != 0))
|
||||
zfile.size = (uint64_t)count;
|
||||
|
||||
if (zfs_read(&zfile, (char *)addr, zfile.size) != zfile.size) {
|
||||
printf("** Unable to read \"%s\" from %s %d:%lu **\n",
|
||||
filename, argv[1], dev, part);
|
||||
zfs_close(&zfile);
|
||||
return 1;
|
||||
}
|
||||
|
||||
zfs_close(&zfile);
|
||||
|
||||
/* Loading ok, update default load address */
|
||||
load_addr = addr;
|
||||
|
||||
printf("%llu bytes read\n", zfile.size);
|
||||
sprintf(buf, "%llX", zfile.size);
|
||||
setenv("filesize", buf);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int zfs_print(const char *entry, const struct zfs_dirhook_info *data)
|
||||
{
|
||||
printf("%s %s\n",
|
||||
data->dir ? "<DIR> " : " ",
|
||||
entry);
|
||||
return 0; /* 0 continue, 1 stop */
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int do_zfs_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
|
||||
{
|
||||
const char *filename = "/";
|
||||
int dev;
|
||||
unsigned long part = 1;
|
||||
char *ep;
|
||||
int part_length;
|
||||
struct device_s vdev;
|
||||
|
||||
if (argc < 3)
|
||||
return cmd_usage(cmdtp);
|
||||
|
||||
dev = (int)simple_strtoul(argv[2], &ep, 16);
|
||||
zfs_dev_desc = get_dev(argv[1], dev);
|
||||
|
||||
if (zfs_dev_desc == NULL) {
|
||||
printf("\n** Block device %s %d not supported\n", argv[1], dev);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (*ep) {
|
||||
if (*ep != ':') {
|
||||
puts("\n** Invalid boot device, use `dev[:part]' **\n");
|
||||
return 1;
|
||||
}
|
||||
part = simple_strtoul(++ep, NULL, 16);
|
||||
}
|
||||
|
||||
if (argc == 4)
|
||||
filename = argv[3];
|
||||
|
||||
part_length = zfs_set_blk_dev(zfs_dev_desc, part);
|
||||
if (part_length == 0) {
|
||||
printf("** Bad partition - %s %d:%lu **\n", argv[1], dev, part);
|
||||
return 1;
|
||||
}
|
||||
|
||||
vdev.part_length = part_length;
|
||||
|
||||
zfs_ls(&vdev, filename,
|
||||
zfs_print);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
U_BOOT_CMD(zfsls, 4, 1, do_zfs_ls,
|
||||
"list files in a directory (default /)",
|
||||
"<interface> <dev[:part]> [directory]\n"
|
||||
" - list files from 'dev' on 'interface' in a '/DATASET/@/$dir/'");
|
||||
|
||||
U_BOOT_CMD(zfsload, 6, 0, do_zfs_load,
|
||||
"load binary file from a ZFS filesystem",
|
||||
"<interface> <dev[:part]> [addr] [filename] [bytes]\n"
|
||||
" - load binary file '/DATASET/@/$dir/$file' from 'dev' on 'interface'\n"
|
||||
" to address 'addr' from ZFS filesystem");
|
29
doc/README.zfs
Normal file
29
doc/README.zfs
Normal file
@ -0,0 +1,29 @@
|
||||
This patch series adds support for ZFS listing and load to u-boot.
|
||||
|
||||
To Enable zfs ls and load commands, modify the board specific config file with
|
||||
#define CONFIG_CMD_ZFS
|
||||
|
||||
Steps to test:
|
||||
|
||||
1. After applying the patch, zfs specific commands can be seen
|
||||
in the boot loader prompt using
|
||||
UBOOT #help
|
||||
|
||||
zfsload- load binary file from a ZFS file system
|
||||
zfsls - list files in a directory (default /)
|
||||
|
||||
2. To list the files in zfs pool, device or partition, execute
|
||||
zfsls <interface> <dev[:part]> [POOL/@/dir/file]
|
||||
For example:
|
||||
UBOOT #zfsls mmc 0:5 /rpool/@/usr/bin/
|
||||
|
||||
3. To read and load a file from an ZFS formatted partition to RAM, execute
|
||||
zfsload <interface> <dev[:part]> [addr] [filename] [bytes]
|
||||
For example:
|
||||
UBOOT #zfsload mmc 2:2 0x30007fc0 /rpool/@/boot/uImage
|
||||
|
||||
References :
|
||||
-- ZFS GRUB sources from Solaris GRUB-0.97
|
||||
-- GRUB Bazaar repository
|
||||
|
||||
Jorgen Lundman <lundman at lundman.net> 2012.
|
@ -30,6 +30,7 @@ subdirs-$(CONFIG_CMD_JFFS2) += jffs2
|
||||
subdirs-$(CONFIG_CMD_REISER) += reiserfs
|
||||
subdirs-$(CONFIG_YAFFS2) += yaffs2
|
||||
subdirs-$(CONFIG_CMD_UBIFS) += ubifs
|
||||
subdirs-$(CONFIG_CMD_ZFS) += zfs
|
||||
|
||||
SUBDIRS := $(subdirs-y)
|
||||
|
||||
|
47
fs/zfs/Makefile
Normal file
47
fs/zfs/Makefile
Normal file
@ -0,0 +1,47 @@
|
||||
#
|
||||
# (C) Copyright 2012
|
||||
# Jorgen Lundman <lundman at lundman.net>
|
||||
#
|
||||
# See file CREDITS for list of people who contributed to this
|
||||
# project.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License as
|
||||
# published by the Free Software Foundation; either version 2 of
|
||||
# the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
# MA 02111-1307 USA
|
||||
#
|
||||
|
||||
include $(TOPDIR)/config.mk
|
||||
|
||||
LIB = $(obj)libzfs.o
|
||||
|
||||
AOBJS =
|
||||
COBJS-$(CONFIG_CMD_ZFS) := dev.o zfs.o zfs_fletcher.o zfs_sha256.o zfs_lzjb.o
|
||||
|
||||
SRCS := $(AOBJS:.o=.S) $(COBJS-y:.o=.c)
|
||||
OBJS := $(addprefix $(obj),$(AOBJS) $(COBJS-y))
|
||||
|
||||
|
||||
all: $(LIB) $(AOBJS)
|
||||
|
||||
$(LIB): $(obj).depend $(OBJS)
|
||||
$(call cmd_link_o_target, $(OBJS))
|
||||
|
||||
#########################################################################
|
||||
|
||||
# defines $(obj).depend target
|
||||
include $(SRCTREE)/rules.mk
|
||||
|
||||
sinclude $(obj).depend
|
||||
|
||||
#########################################################################
|
137
fs/zfs/dev.c
Normal file
137
fs/zfs/dev.c
Normal file
@ -0,0 +1,137 @@
|
||||
/*
|
||||
*
|
||||
* based on code of fs/reiserfs/dev.c by
|
||||
*
|
||||
* (C) Copyright 2003 - 2004
|
||||
* Sysgo AG, <www.elinos.com>, Pavel Bartusek <pba@sysgo.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
|
||||
#include <common.h>
|
||||
#include <config.h>
|
||||
#include <zfs_common.h>
|
||||
|
||||
static block_dev_desc_t *zfs_block_dev_desc;
|
||||
static disk_partition_t part_info;
|
||||
|
||||
int zfs_set_blk_dev(block_dev_desc_t *rbdd, int part)
|
||||
{
|
||||
zfs_block_dev_desc = rbdd;
|
||||
|
||||
if (part == 0) {
|
||||
/* disk doesn't use partition table */
|
||||
part_info.start = 0;
|
||||
part_info.size = rbdd->lba;
|
||||
part_info.blksz = rbdd->blksz;
|
||||
} else {
|
||||
if (get_partition_info(zfs_block_dev_desc, part, &part_info))
|
||||
return 0;
|
||||
}
|
||||
|
||||
return part_info.size;
|
||||
}
|
||||
|
||||
/* err */
|
||||
int zfs_devread(int sector, int byte_offset, int byte_len, char *buf)
|
||||
{
|
||||
short sec_buffer[SECTOR_SIZE/sizeof(short)];
|
||||
char *sec_buf = (char *)sec_buffer;
|
||||
unsigned block_len;
|
||||
|
||||
/*
|
||||
* Check partition boundaries
|
||||
*/
|
||||
if ((sector < 0) ||
|
||||
((sector + ((byte_offset + byte_len - 1) >> SECTOR_BITS)) >=
|
||||
part_info.size)) {
|
||||
/* errnum = ERR_OUTSIDE_PART; */
|
||||
printf(" ** zfs_devread() read outside partition sector %d\n", sector);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the read to the beginning of a partition.
|
||||
*/
|
||||
sector += byte_offset >> SECTOR_BITS;
|
||||
byte_offset &= SECTOR_SIZE - 1;
|
||||
|
||||
debug(" <%d, %d, %d>\n", sector, byte_offset, byte_len);
|
||||
|
||||
if (zfs_block_dev_desc == NULL) {
|
||||
printf("** Invalid Block Device Descriptor (NULL)\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (byte_offset != 0) {
|
||||
/* read first part which isn't aligned with start of sector */
|
||||
if (zfs_block_dev_desc->block_read(zfs_block_dev_desc->dev,
|
||||
part_info.start + sector, 1,
|
||||
(unsigned long *) sec_buf) != 1) {
|
||||
printf(" ** zfs_devread() read error **\n");
|
||||
return 1;
|
||||
}
|
||||
memcpy(buf, sec_buf + byte_offset,
|
||||
min(SECTOR_SIZE - byte_offset, byte_len));
|
||||
buf += min(SECTOR_SIZE - byte_offset, byte_len);
|
||||
byte_len -= min(SECTOR_SIZE - byte_offset, byte_len);
|
||||
sector++;
|
||||
}
|
||||
|
||||
if (byte_len == 0)
|
||||
return 0;
|
||||
|
||||
/* read sector aligned part */
|
||||
block_len = byte_len & ~(SECTOR_SIZE - 1);
|
||||
|
||||
if (block_len == 0) {
|
||||
u8 p[SECTOR_SIZE];
|
||||
|
||||
block_len = SECTOR_SIZE;
|
||||
zfs_block_dev_desc->block_read(zfs_block_dev_desc->dev,
|
||||
part_info.start + sector,
|
||||
1, (unsigned long *)p);
|
||||
memcpy(buf, p, byte_len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (zfs_block_dev_desc->block_read(zfs_block_dev_desc->dev,
|
||||
part_info.start + sector,
|
||||
block_len / SECTOR_SIZE,
|
||||
(unsigned long *) buf) !=
|
||||
block_len / SECTOR_SIZE) {
|
||||
printf(" ** zfs_devread() read error - block\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
block_len = byte_len & ~(SECTOR_SIZE - 1);
|
||||
buf += block_len;
|
||||
byte_len -= block_len;
|
||||
sector += block_len / SECTOR_SIZE;
|
||||
|
||||
if (byte_len != 0) {
|
||||
/* read rest of data which are not in whole sector */
|
||||
if (zfs_block_dev_desc->
|
||||
block_read(zfs_block_dev_desc->dev,
|
||||
part_info.start + sector, 1,
|
||||
(unsigned long *) sec_buf) != 1) {
|
||||
printf(" ** zfs_devread() read error - last part\n");
|
||||
return 1;
|
||||
}
|
||||
memcpy(buf, sec_buf, byte_len);
|
||||
}
|
||||
return 0;
|
||||
}
|
2395
fs/zfs/zfs.c
Normal file
2395
fs/zfs/zfs.c
Normal file
File diff suppressed because it is too large
Load Diff
87
fs/zfs/zfs_fletcher.c
Normal file
87
fs/zfs/zfs_fletcher.c
Normal file
@ -0,0 +1,87 @@
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
/*
|
||||
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
|
||||
* Use is subject to license terms.
|
||||
*/
|
||||
|
||||
#include <common.h>
|
||||
#include <malloc.h>
|
||||
#include <linux/stat.h>
|
||||
#include <linux/time.h>
|
||||
#include <linux/ctype.h>
|
||||
#include <asm/byteorder.h>
|
||||
#include "zfs_common.h"
|
||||
|
||||
#include <zfs/zfs.h>
|
||||
#include <zfs/zio.h>
|
||||
#include <zfs/dnode.h>
|
||||
#include <zfs/uberblock_impl.h>
|
||||
#include <zfs/vdev_impl.h>
|
||||
#include <zfs/zio_checksum.h>
|
||||
#include <zfs/zap_impl.h>
|
||||
#include <zfs/zap_leaf.h>
|
||||
#include <zfs/zfs_znode.h>
|
||||
#include <zfs/dmu.h>
|
||||
#include <zfs/dmu_objset.h>
|
||||
#include <zfs/dsl_dir.h>
|
||||
#include <zfs/dsl_dataset.h>
|
||||
|
||||
void
|
||||
fletcher_2_endian(const void *buf, uint64_t size,
|
||||
zfs_endian_t endian,
|
||||
zio_cksum_t *zcp)
|
||||
{
|
||||
const uint64_t *ip = buf;
|
||||
const uint64_t *ipend = ip + (size / sizeof(uint64_t));
|
||||
uint64_t a0, b0, a1, b1;
|
||||
|
||||
for (a0 = b0 = a1 = b1 = 0; ip < ipend; ip += 2) {
|
||||
a0 += zfs_to_cpu64(ip[0], endian);
|
||||
a1 += zfs_to_cpu64(ip[1], endian);
|
||||
b0 += a0;
|
||||
b1 += a1;
|
||||
}
|
||||
|
||||
zcp->zc_word[0] = cpu_to_zfs64(a0, endian);
|
||||
zcp->zc_word[1] = cpu_to_zfs64(a1, endian);
|
||||
zcp->zc_word[2] = cpu_to_zfs64(b0, endian);
|
||||
zcp->zc_word[3] = cpu_to_zfs64(b1, endian);
|
||||
}
|
||||
|
||||
void
|
||||
fletcher_4_endian(const void *buf, uint64_t size, zfs_endian_t endian,
|
||||
zio_cksum_t *zcp)
|
||||
{
|
||||
const uint32_t *ip = buf;
|
||||
const uint32_t *ipend = ip + (size / sizeof(uint32_t));
|
||||
uint64_t a, b, c, d;
|
||||
|
||||
for (a = b = c = d = 0; ip < ipend; ip++) {
|
||||
a += zfs_to_cpu32(ip[0], endian);
|
||||
b += a;
|
||||
c += b;
|
||||
d += c;
|
||||
}
|
||||
|
||||
zcp->zc_word[0] = cpu_to_zfs64(a, endian);
|
||||
zcp->zc_word[1] = cpu_to_zfs64(b, endian);
|
||||
zcp->zc_word[2] = cpu_to_zfs64(c, endian);
|
||||
zcp->zc_word[3] = cpu_to_zfs64(d, endian);
|
||||
}
|
97
fs/zfs/zfs_lzjb.c
Normal file
97
fs/zfs/zfs_lzjb.c
Normal file
@ -0,0 +1,97 @@
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
/*
|
||||
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
|
||||
* Use is subject to license terms.
|
||||
*/
|
||||
|
||||
#include <common.h>
|
||||
#include <malloc.h>
|
||||
#include <linux/stat.h>
|
||||
#include <linux/time.h>
|
||||
#include <linux/ctype.h>
|
||||
#include <asm/byteorder.h>
|
||||
#include "zfs_common.h"
|
||||
|
||||
#include <zfs/zfs.h>
|
||||
#include <zfs/zio.h>
|
||||
#include <zfs/dnode.h>
|
||||
#include <zfs/uberblock_impl.h>
|
||||
#include <zfs/vdev_impl.h>
|
||||
#include <zfs/zio_checksum.h>
|
||||
#include <zfs/zap_impl.h>
|
||||
#include <zfs/zap_leaf.h>
|
||||
#include <zfs/zfs_znode.h>
|
||||
#include <zfs/dmu.h>
|
||||
#include <zfs/dmu_objset.h>
|
||||
#include <zfs/dsl_dir.h>
|
||||
#include <zfs/dsl_dataset.h>
|
||||
|
||||
#define MATCH_BITS 6
|
||||
#define MATCH_MIN 3
|
||||
#define OFFSET_MASK ((1 << (16 - MATCH_BITS)) - 1)
|
||||
|
||||
/*
|
||||
* Decompression Entry - lzjb
|
||||
*/
|
||||
#ifndef NBBY
|
||||
#define NBBY 8
|
||||
#endif
|
||||
|
||||
int
|
||||
lzjb_decompress(void *s_start, void *d_start, uint32_t s_len,
|
||||
uint32_t d_len)
|
||||
{
|
||||
uint8_t *src = s_start;
|
||||
uint8_t *dst = d_start;
|
||||
uint8_t *d_end = (uint8_t *) d_start + d_len;
|
||||
uint8_t *s_end = (uint8_t *) s_start + s_len;
|
||||
uint8_t *cpy, copymap = 0;
|
||||
int copymask = 1 << (NBBY - 1);
|
||||
|
||||
while (dst < d_end && src < s_end) {
|
||||
if ((copymask <<= 1) == (1 << NBBY)) {
|
||||
copymask = 1;
|
||||
copymap = *src++;
|
||||
}
|
||||
if (src >= s_end) {
|
||||
printf("lzjb decompression failed\n");
|
||||
return ZFS_ERR_BAD_FS;
|
||||
}
|
||||
if (copymap & copymask) {
|
||||
int mlen = (src[0] >> (NBBY - MATCH_BITS)) + MATCH_MIN;
|
||||
int offset = ((src[0] << NBBY) | src[1]) & OFFSET_MASK;
|
||||
src += 2;
|
||||
cpy = dst - offset;
|
||||
if (src > s_end || cpy < (uint8_t *) d_start) {
|
||||
printf("lzjb decompression failed\n");
|
||||
return ZFS_ERR_BAD_FS;
|
||||
}
|
||||
while (--mlen >= 0 && dst < d_end)
|
||||
*dst++ = *cpy++;
|
||||
} else {
|
||||
*dst++ = *src++;
|
||||
}
|
||||
}
|
||||
if (dst < d_end) {
|
||||
printf("lzjb decompression failed\n");
|
||||
return ZFS_ERR_BAD_FS;
|
||||
}
|
||||
return ZFS_ERR_NONE;
|
||||
}
|
148
fs/zfs/zfs_sha256.c
Normal file
148
fs/zfs/zfs_sha256.c
Normal file
@ -0,0 +1,148 @@
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
/*
|
||||
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
|
||||
* Use is subject to license terms.
|
||||
*/
|
||||
|
||||
#include <common.h>
|
||||
#include <malloc.h>
|
||||
#include <linux/stat.h>
|
||||
#include <linux/time.h>
|
||||
#include <linux/ctype.h>
|
||||
#include <asm/byteorder.h>
|
||||
#include "zfs_common.h"
|
||||
|
||||
#include <zfs/zfs.h>
|
||||
#include <zfs/zio.h>
|
||||
#include <zfs/dnode.h>
|
||||
#include <zfs/uberblock_impl.h>
|
||||
#include <zfs/vdev_impl.h>
|
||||
#include <zfs/zio_checksum.h>
|
||||
#include <zfs/zap_impl.h>
|
||||
#include <zfs/zap_leaf.h>
|
||||
#include <zfs/zfs_znode.h>
|
||||
#include <zfs/dmu.h>
|
||||
#include <zfs/dmu_objset.h>
|
||||
#include <zfs/dsl_dir.h>
|
||||
#include <zfs/dsl_dataset.h>
|
||||
|
||||
/*
|
||||
* SHA-256 checksum, as specified in FIPS 180-2, available at:
|
||||
* http://csrc.nist.gov/cryptval
|
||||
*
|
||||
* This is a very compact implementation of SHA-256.
|
||||
* It is designed to be simple and portable, not to be fast.
|
||||
*/
|
||||
|
||||
/*
|
||||
* The literal definitions according to FIPS180-2 would be:
|
||||
*
|
||||
* Ch(x, y, z) (((x) & (y)) ^ ((~(x)) & (z)))
|
||||
* Maj(x, y, z) (((x) & (y)) | ((x) & (z)) | ((y) & (z)))
|
||||
*
|
||||
* We use logical equivalents which require one less op.
|
||||
*/
|
||||
#define Ch(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
|
||||
#define Maj(x, y, z) (((x) & (y)) ^ ((z) & ((x) ^ (y))))
|
||||
#define Rot32(x, s) (((x) >> s) | ((x) << (32 - s)))
|
||||
#define SIGMA0(x) (Rot32(x, 2) ^ Rot32(x, 13) ^ Rot32(x, 22))
|
||||
#define SIGMA1(x) (Rot32(x, 6) ^ Rot32(x, 11) ^ Rot32(x, 25))
|
||||
#define sigma0(x) (Rot32(x, 7) ^ Rot32(x, 18) ^ ((x) >> 3))
|
||||
#define sigma1(x) (Rot32(x, 17) ^ Rot32(x, 19) ^ ((x) >> 10))
|
||||
|
||||
static const uint32_t SHA256_K[64] = {
|
||||
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
|
||||
0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
||||
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
|
||||
0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
||||
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
|
||||
0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
||||
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
|
||||
0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
||||
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
|
||||
0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
||||
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
|
||||
0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
||||
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
|
||||
0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
||||
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
|
||||
0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
|
||||
};
|
||||
|
||||
static void
|
||||
SHA256Transform(uint32_t *H, const uint8_t *cp)
|
||||
{
|
||||
uint32_t a, b, c, d, e, f, g, h, t, T1, T2, W[64];
|
||||
|
||||
for (t = 0; t < 16; t++, cp += 4)
|
||||
W[t] = (cp[0] << 24) | (cp[1] << 16) | (cp[2] << 8) | cp[3];
|
||||
|
||||
for (t = 16; t < 64; t++)
|
||||
W[t] = sigma1(W[t - 2]) + W[t - 7] +
|
||||
sigma0(W[t - 15]) + W[t - 16];
|
||||
|
||||
a = H[0]; b = H[1]; c = H[2]; d = H[3];
|
||||
e = H[4]; f = H[5]; g = H[6]; h = H[7];
|
||||
|
||||
for (t = 0; t < 64; t++) {
|
||||
T1 = h + SIGMA1(e) + Ch(e, f, g) + SHA256_K[t] + W[t];
|
||||
T2 = SIGMA0(a) + Maj(a, b, c);
|
||||
h = g; g = f; f = e; e = d + T1;
|
||||
d = c; c = b; b = a; a = T1 + T2;
|
||||
}
|
||||
|
||||
H[0] += a; H[1] += b; H[2] += c; H[3] += d;
|
||||
H[4] += e; H[5] += f; H[6] += g; H[7] += h;
|
||||
}
|
||||
|
||||
void
|
||||
zio_checksum_SHA256(const void *buf, uint64_t size,
|
||||
zfs_endian_t endian, zio_cksum_t *zcp)
|
||||
{
|
||||
uint32_t H[8] = { 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
|
||||
0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19 };
|
||||
uint8_t pad[128];
|
||||
unsigned padsize = size & 63;
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < size - padsize; i += 64)
|
||||
SHA256Transform(H, (uint8_t *)buf + i);
|
||||
|
||||
for (i = 0; i < padsize; i++)
|
||||
pad[i] = ((uint8_t *)buf)[i];
|
||||
|
||||
for (pad[padsize++] = 0x80; (padsize & 63) != 56; padsize++)
|
||||
pad[padsize] = 0;
|
||||
|
||||
for (i = 0; i < 8; i++)
|
||||
pad[padsize++] = (size << 3) >> (56 - 8 * i);
|
||||
|
||||
for (i = 0; i < padsize; i += 64)
|
||||
SHA256Transform(H, pad + i);
|
||||
|
||||
zcp->zc_word[0] = cpu_to_zfs64((uint64_t)H[0] << 32 | H[1],
|
||||
endian);
|
||||
zcp->zc_word[1] = cpu_to_zfs64((uint64_t)H[2] << 32 | H[3],
|
||||
endian);
|
||||
zcp->zc_word[2] = cpu_to_zfs64((uint64_t)H[4] << 32 | H[5],
|
||||
endian);
|
||||
zcp->zc_word[3] = cpu_to_zfs64((uint64_t)H[6] << 32 | H[7],
|
||||
endian);
|
||||
}
|
@ -87,5 +87,6 @@
|
||||
#define CONFIG_CMD_UNZIP /* unzip from memory to memory */
|
||||
#define CONFIG_CMD_USB /* USB Support */
|
||||
#define CONFIG_CMD_XIMG /* Load part of Multi Image */
|
||||
#define CONFIG_CMD_ZFS /* ZFS Support */
|
||||
|
||||
#endif /* _CONFIG_CMD_ALL_H */
|
||||
|
120
include/zfs/dmu.h
Normal file
120
include/zfs/dmu.h
Normal file
@ -0,0 +1,120 @@
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
/*
|
||||
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
|
||||
* Use is subject to license terms.
|
||||
*/
|
||||
|
||||
#ifndef _SYS_DMU_H
|
||||
#define _SYS_DMU_H
|
||||
|
||||
/*
|
||||
* This file describes the interface that the DMU provides for its
|
||||
* consumers.
|
||||
*
|
||||
* The DMU also interacts with the SPA. That interface is described in
|
||||
* dmu_spa.h.
|
||||
*/
|
||||
typedef enum dmu_object_type {
|
||||
DMU_OT_NONE,
|
||||
/* general: */
|
||||
DMU_OT_OBJECT_DIRECTORY, /* ZAP */
|
||||
DMU_OT_OBJECT_ARRAY, /* UINT64 */
|
||||
DMU_OT_PACKED_NVLIST, /* UINT8 (XDR by nvlist_pack/unpack) */
|
||||
DMU_OT_PACKED_NVLIST_SIZE, /* UINT64 */
|
||||
DMU_OT_BPLIST, /* UINT64 */
|
||||
DMU_OT_BPLIST_HDR, /* UINT64 */
|
||||
/* spa: */
|
||||
DMU_OT_SPACE_MAP_HEADER, /* UINT64 */
|
||||
DMU_OT_SPACE_MAP, /* UINT64 */
|
||||
/* zil: */
|
||||
DMU_OT_INTENT_LOG, /* UINT64 */
|
||||
/* dmu: */
|
||||
DMU_OT_DNODE, /* DNODE */
|
||||
DMU_OT_OBJSET, /* OBJSET */
|
||||
/* dsl: */
|
||||
DMU_OT_DSL_DIR, /* UINT64 */
|
||||
DMU_OT_DSL_DIR_CHILD_MAP, /* ZAP */
|
||||
DMU_OT_DSL_DS_SNAP_MAP, /* ZAP */
|
||||
DMU_OT_DSL_PROPS, /* ZAP */
|
||||
DMU_OT_DSL_DATASET, /* UINT64 */
|
||||
/* zpl: */
|
||||
DMU_OT_ZNODE, /* ZNODE */
|
||||
DMU_OT_OLDACL, /* OLD ACL */
|
||||
DMU_OT_PLAIN_FILE_CONTENTS, /* UINT8 */
|
||||
DMU_OT_DIRECTORY_CONTENTS, /* ZAP */
|
||||
DMU_OT_MASTER_NODE, /* ZAP */
|
||||
DMU_OT_UNLINKED_SET, /* ZAP */
|
||||
/* zvol: */
|
||||
DMU_OT_ZVOL, /* UINT8 */
|
||||
DMU_OT_ZVOL_PROP, /* ZAP */
|
||||
/* other; for testing only! */
|
||||
DMU_OT_PLAIN_OTHER, /* UINT8 */
|
||||
DMU_OT_UINT64_OTHER, /* UINT64 */
|
||||
DMU_OT_ZAP_OTHER, /* ZAP */
|
||||
/* new object types: */
|
||||
DMU_OT_ERROR_LOG, /* ZAP */
|
||||
DMU_OT_SPA_HISTORY, /* UINT8 */
|
||||
DMU_OT_SPA_HISTORY_OFFSETS, /* spa_his_phys_t */
|
||||
DMU_OT_POOL_PROPS, /* ZAP */
|
||||
DMU_OT_DSL_PERMS, /* ZAP */
|
||||
DMU_OT_ACL, /* ACL */
|
||||
DMU_OT_SYSACL, /* SYSACL */
|
||||
DMU_OT_FUID, /* FUID table (Packed NVLIST UINT8) */
|
||||
DMU_OT_FUID_SIZE, /* FUID table size UINT64 */
|
||||
DMU_OT_NEXT_CLONES, /* ZAP */
|
||||
DMU_OT_SCRUB_QUEUE, /* ZAP */
|
||||
DMU_OT_USERGROUP_USED, /* ZAP */
|
||||
DMU_OT_USERGROUP_QUOTA, /* ZAP */
|
||||
DMU_OT_USERREFS, /* ZAP */
|
||||
DMU_OT_DDT_ZAP, /* ZAP */
|
||||
DMU_OT_DDT_STATS, /* ZAP */
|
||||
DMU_OT_SA, /* System attr */
|
||||
DMU_OT_SA_MASTER_NODE, /* ZAP */
|
||||
DMU_OT_SA_ATTR_REGISTRATION, /* ZAP */
|
||||
DMU_OT_SA_ATTR_LAYOUTS, /* ZAP */
|
||||
DMU_OT_NUMTYPES
|
||||
} dmu_object_type_t;
|
||||
|
||||
typedef enum dmu_objset_type {
|
||||
DMU_OST_NONE,
|
||||
DMU_OST_META,
|
||||
DMU_OST_ZFS,
|
||||
DMU_OST_ZVOL,
|
||||
DMU_OST_OTHER, /* For testing only! */
|
||||
DMU_OST_ANY, /* Be careful! */
|
||||
DMU_OST_NUMTYPES
|
||||
} dmu_objset_type_t;
|
||||
|
||||
/*
|
||||
* The names of zap entries in the DIRECTORY_OBJECT of the MOS.
|
||||
*/
|
||||
#define DMU_POOL_DIRECTORY_OBJECT 1
|
||||
#define DMU_POOL_CONFIG "config"
|
||||
#define DMU_POOL_ROOT_DATASET "root_dataset"
|
||||
#define DMU_POOL_SYNC_BPLIST "sync_bplist"
|
||||
#define DMU_POOL_ERRLOG_SCRUB "errlog_scrub"
|
||||
#define DMU_POOL_ERRLOG_LAST "errlog_last"
|
||||
#define DMU_POOL_SPARES "spares"
|
||||
#define DMU_POOL_DEFLATE "deflate"
|
||||
#define DMU_POOL_HISTORY "history"
|
||||
#define DMU_POOL_PROPS "pool_props"
|
||||
#define DMU_POOL_L2CACHE "l2cache"
|
||||
|
||||
#endif /* _SYS_DMU_H */
|
43
include/zfs/dmu_objset.h
Normal file
43
include/zfs/dmu_objset.h
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
/*
|
||||
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
|
||||
* Use is subject to license terms.
|
||||
*/
|
||||
|
||||
#ifndef _SYS_DMU_OBJSET_H
|
||||
#define _SYS_DMU_OBJSET_H
|
||||
|
||||
#include <zfs/zil.h>
|
||||
|
||||
#define OBJSET_PHYS_SIZE 2048
|
||||
#define OBJSET_PHYS_SIZE_V14 1024
|
||||
|
||||
typedef struct objset_phys {
|
||||
dnode_phys_t os_meta_dnode;
|
||||
zil_header_t os_zil_header;
|
||||
uint64_t os_type;
|
||||
uint64_t os_flags;
|
||||
char os_pad[OBJSET_PHYS_SIZE - sizeof(dnode_phys_t)*3 -
|
||||
sizeof(zil_header_t) - sizeof(uint64_t)*2];
|
||||
dnode_phys_t os_userused_dnode;
|
||||
dnode_phys_t os_groupused_dnode;
|
||||
} objset_phys_t;
|
||||
|
||||
#endif /* _SYS_DMU_OBJSET_H */
|
81
include/zfs/dnode.h
Normal file
81
include/zfs/dnode.h
Normal file
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
/*
|
||||
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
|
||||
* Use is subject to license terms.
|
||||
*/
|
||||
|
||||
#ifndef _SYS_DNODE_H
|
||||
#define _SYS_DNODE_H
|
||||
|
||||
#include <zfs/spa.h>
|
||||
|
||||
/*
|
||||
* Fixed constants.
|
||||
*/
|
||||
#define DNODE_SHIFT 9 /* 512 bytes */
|
||||
#define DN_MIN_INDBLKSHIFT 10 /* 1k */
|
||||
#define DN_MAX_INDBLKSHIFT 14 /* 16k */
|
||||
#define DNODE_BLOCK_SHIFT 14 /* 16k */
|
||||
#define DNODE_CORE_SIZE 64 /* 64 bytes for dnode sans blkptrs */
|
||||
#define DN_MAX_OBJECT_SHIFT 48 /* 256 trillion (zfs_fid_t limit) */
|
||||
#define DN_MAX_OFFSET_SHIFT 64 /* 2^64 bytes in a dnode */
|
||||
|
||||
/*
|
||||
* Derived constants.
|
||||
*/
|
||||
#define DNODE_SIZE (1 << DNODE_SHIFT)
|
||||
#define DN_MAX_NBLKPTR ((DNODE_SIZE - DNODE_CORE_SIZE) >> SPA_BLKPTRSHIFT)
|
||||
#define DN_MAX_BONUSLEN (DNODE_SIZE - DNODE_CORE_SIZE - (1 << SPA_BLKPTRSHIFT))
|
||||
#define DN_MAX_OBJECT (1ULL << DN_MAX_OBJECT_SHIFT)
|
||||
|
||||
#define DNODES_PER_BLOCK_SHIFT (DNODE_BLOCK_SHIFT - DNODE_SHIFT)
|
||||
#define DNODES_PER_BLOCK (1ULL << DNODES_PER_BLOCK_SHIFT)
|
||||
#define DNODES_PER_LEVEL_SHIFT (DN_MAX_INDBLKSHIFT - SPA_BLKPTRSHIFT)
|
||||
|
||||
#define DNODE_FLAG_SPILL_BLKPTR (1<<2)
|
||||
|
||||
#define DN_BONUS(dnp) ((void *)((dnp)->dn_bonus + \
|
||||
(((dnp)->dn_nblkptr - 1) * sizeof(blkptr_t))))
|
||||
|
||||
typedef struct dnode_phys {
|
||||
uint8_t dn_type; /* dmu_object_type_t */
|
||||
uint8_t dn_indblkshift; /* ln2(indirect block size) */
|
||||
uint8_t dn_nlevels; /* 1=dn_blkptr->data blocks */
|
||||
uint8_t dn_nblkptr; /* length of dn_blkptr */
|
||||
uint8_t dn_bonustype; /* type of data in bonus buffer */
|
||||
uint8_t dn_checksum; /* ZIO_CHECKSUM type */
|
||||
uint8_t dn_compress; /* ZIO_COMPRESS type */
|
||||
uint8_t dn_flags; /* DNODE_FLAG_* */
|
||||
uint16_t dn_datablkszsec; /* data block size in 512b sectors */
|
||||
uint16_t dn_bonuslen; /* length of dn_bonus */
|
||||
uint8_t dn_pad2[4];
|
||||
|
||||
/* accounting is protected by dn_dirty_mtx */
|
||||
uint64_t dn_maxblkid; /* largest allocated block ID */
|
||||
uint64_t dn_used; /* bytes (or sectors) of disk space */
|
||||
|
||||
uint64_t dn_pad3[4];
|
||||
|
||||
blkptr_t dn_blkptr[1];
|
||||
uint8_t dn_bonus[DN_MAX_BONUSLEN - sizeof(blkptr_t)];
|
||||
blkptr_t dn_spill;
|
||||
} dnode_phys_t;
|
||||
|
||||
#endif /* _SYS_DNODE_H */
|
53
include/zfs/dsl_dataset.h
Normal file
53
include/zfs/dsl_dataset.h
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
/*
|
||||
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
|
||||
* Use is subject to license terms.
|
||||
*/
|
||||
|
||||
#ifndef _SYS_DSL_DATASET_H
|
||||
#define _SYS_DSL_DATASET_H
|
||||
|
||||
typedef struct dsl_dataset_phys {
|
||||
uint64_t ds_dir_obj;
|
||||
uint64_t ds_prev_snap_obj;
|
||||
uint64_t ds_prev_snap_txg;
|
||||
uint64_t ds_next_snap_obj;
|
||||
uint64_t ds_snapnames_zapobj; /* zap obj of snaps; ==0 for snaps */
|
||||
uint64_t ds_num_children; /* clone/snap children; ==0 for head */
|
||||
uint64_t ds_creation_time; /* seconds since 1970 */
|
||||
uint64_t ds_creation_txg;
|
||||
uint64_t ds_deadlist_obj;
|
||||
uint64_t ds_used_bytes;
|
||||
uint64_t ds_compressed_bytes;
|
||||
uint64_t ds_uncompressed_bytes;
|
||||
uint64_t ds_unique_bytes; /* only relevant to snapshots */
|
||||
/*
|
||||
* The ds_fsid_guid is a 56-bit ID that can change to avoid
|
||||
* collisions. The ds_guid is a 64-bit ID that will never
|
||||
* change, so there is a small probability that it will collide.
|
||||
*/
|
||||
uint64_t ds_fsid_guid;
|
||||
uint64_t ds_guid;
|
||||
uint64_t ds_flags;
|
||||
blkptr_t ds_bp;
|
||||
uint64_t ds_pad[8]; /* pad out to 320 bytes for good measure */
|
||||
} dsl_dataset_phys_t;
|
||||
|
||||
#endif /* _SYS_DSL_DATASET_H */
|
49
include/zfs/dsl_dir.h
Normal file
49
include/zfs/dsl_dir.h
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
/*
|
||||
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
|
||||
* Use is subject to license terms.
|
||||
*/
|
||||
|
||||
#ifndef _SYS_DSL_DIR_H
|
||||
#define _SYS_DSL_DIR_H
|
||||
|
||||
typedef struct dsl_dir_phys {
|
||||
uint64_t dd_creation_time; /* not actually used */
|
||||
uint64_t dd_head_dataset_obj;
|
||||
uint64_t dd_parent_obj;
|
||||
uint64_t dd_clone_parent_obj;
|
||||
uint64_t dd_child_dir_zapobj;
|
||||
/*
|
||||
* how much space our children are accounting for; for leaf
|
||||
* datasets, == physical space used by fs + snaps
|
||||
*/
|
||||
uint64_t dd_used_bytes;
|
||||
uint64_t dd_compressed_bytes;
|
||||
uint64_t dd_uncompressed_bytes;
|
||||
/* Administrative quota setting */
|
||||
uint64_t dd_quota;
|
||||
/* Administrative reservation setting */
|
||||
uint64_t dd_reserved;
|
||||
uint64_t dd_props_zapobj;
|
||||
uint64_t dd_deleg_zapobj; /* dataset permissions */
|
||||
uint64_t dd_pad[20]; /* pad out to 256 bytes for good measure */
|
||||
} dsl_dir_phys_t;
|
||||
|
||||
#endif /* _SYS_DSL_DIR_H */
|
35
include/zfs/sa_impl.h
Normal file
35
include/zfs/sa_impl.h
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
/*
|
||||
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
|
||||
* Use is subject to license terms.
|
||||
*/
|
||||
#ifndef _SYS_SA_IMPL_H
|
||||
#define _SYS_SA_IMPL_H
|
||||
|
||||
typedef struct sa_hdr_phys {
|
||||
uint32_t sa_magic;
|
||||
uint16_t sa_layout_info;
|
||||
uint16_t sa_lengths[1];
|
||||
} sa_hdr_phys_t;
|
||||
|
||||
#define SA_HDR_SIZE(hdr) BF32_GET_SB(hdr->sa_layout_info, 10, 16, 3, 0)
|
||||
#define SA_SIZE_OFFSET 0x8
|
||||
|
||||
#endif /* _SYS_SA_IMPL_H */
|
292
include/zfs/spa.h
Normal file
292
include/zfs/spa.h
Normal file
@ -0,0 +1,292 @@
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
*/
|
||||
|
||||
#ifndef ZFS_SPA_HEADER
|
||||
#define ZFS_SPA_HEADER 1
|
||||
|
||||
|
||||
/*
|
||||
* General-purpose 32-bit and 64-bit bitfield encodings.
|
||||
*/
|
||||
#define BF32_DECODE(x, low, len) P2PHASE((x) >> (low), 1U << (len))
|
||||
#define BF64_DECODE(x, low, len) P2PHASE((x) >> (low), 1ULL << (len))
|
||||
#define BF32_ENCODE(x, low, len) (P2PHASE((x), 1U << (len)) << (low))
|
||||
#define BF64_ENCODE(x, low, len) (P2PHASE((x), 1ULL << (len)) << (low))
|
||||
|
||||
#define BF32_GET(x, low, len) BF32_DECODE(x, low, len)
|
||||
#define BF64_GET(x, low, len) BF64_DECODE(x, low, len)
|
||||
|
||||
#define BF32_SET(x, low, len, val) \
|
||||
((x) ^= BF32_ENCODE((x >> low) ^ (val), low, len))
|
||||
#define BF64_SET(x, low, len, val) \
|
||||
((x) ^= BF64_ENCODE((x >> low) ^ (val), low, len))
|
||||
|
||||
#define BF32_GET_SB(x, low, len, shift, bias) \
|
||||
((BF32_GET(x, low, len) + (bias)) << (shift))
|
||||
#define BF64_GET_SB(x, low, len, shift, bias) \
|
||||
((BF64_GET(x, low, len) + (bias)) << (shift))
|
||||
|
||||
#define BF32_SET_SB(x, low, len, shift, bias, val) \
|
||||
BF32_SET(x, low, len, ((val) >> (shift)) - (bias))
|
||||
#define BF64_SET_SB(x, low, len, shift, bias, val) \
|
||||
BF64_SET(x, low, len, ((val) >> (shift)) - (bias))
|
||||
|
||||
/*
|
||||
* We currently support nine block sizes, from 512 bytes to 128K.
|
||||
* We could go higher, but the benefits are near-zero and the cost
|
||||
* of COWing a giant block to modify one byte would become excessive.
|
||||
*/
|
||||
#define SPA_MINBLOCKSHIFT 9
|
||||
#define SPA_MAXBLOCKSHIFT 17
|
||||
#define SPA_MINBLOCKSIZE (1ULL << SPA_MINBLOCKSHIFT)
|
||||
#define SPA_MAXBLOCKSIZE (1ULL << SPA_MAXBLOCKSHIFT)
|
||||
|
||||
#define SPA_BLOCKSIZES (SPA_MAXBLOCKSHIFT - SPA_MINBLOCKSHIFT + 1)
|
||||
|
||||
/*
|
||||
* Size of block to hold the configuration data (a packed nvlist)
|
||||
*/
|
||||
#define SPA_CONFIG_BLOCKSIZE (1 << 14)
|
||||
|
||||
/*
|
||||
* The DVA size encodings for LSIZE and PSIZE support blocks up to 32MB.
|
||||
* The ASIZE encoding should be at least 64 times larger (6 more bits)
|
||||
* to support up to 4-way RAID-Z mirror mode with worst-case gang block
|
||||
* overhead, three DVAs per bp, plus one more bit in case we do anything
|
||||
* else that expands the ASIZE.
|
||||
*/
|
||||
#define SPA_LSIZEBITS 16 /* LSIZE up to 32M (2^16 * 512) */
|
||||
#define SPA_PSIZEBITS 16 /* PSIZE up to 32M (2^16 * 512) */
|
||||
#define SPA_ASIZEBITS 24 /* ASIZE up to 64 times larger */
|
||||
|
||||
/*
|
||||
* All SPA data is represented by 128-bit data virtual addresses (DVAs).
|
||||
* The members of the dva_t should be considered opaque outside the SPA.
|
||||
*/
|
||||
typedef struct dva {
|
||||
uint64_t dva_word[2];
|
||||
} dva_t;
|
||||
|
||||
/*
|
||||
* Each block has a 256-bit checksum -- strong enough for cryptographic hashes.
|
||||
*/
|
||||
typedef struct zio_cksum {
|
||||
uint64_t zc_word[4];
|
||||
} zio_cksum_t;
|
||||
|
||||
/*
|
||||
* Each block is described by its DVAs, time of birth, checksum, etc.
|
||||
* The word-by-word, bit-by-bit layout of the blkptr is as follows:
|
||||
*
|
||||
* 64 56 48 40 32 24 16 8 0
|
||||
* +-------+-------+-------+-------+-------+-------+-------+-------+
|
||||
* 0 | vdev1 | GRID | ASIZE |
|
||||
* +-------+-------+-------+-------+-------+-------+-------+-------+
|
||||
* 1 |G| offset1 |
|
||||
* +-------+-------+-------+-------+-------+-------+-------+-------+
|
||||
* 2 | vdev2 | GRID | ASIZE |
|
||||
* +-------+-------+-------+-------+-------+-------+-------+-------+
|
||||
* 3 |G| offset2 |
|
||||
* +-------+-------+-------+-------+-------+-------+-------+-------+
|
||||
* 4 | vdev3 | GRID | ASIZE |
|
||||
* +-------+-------+-------+-------+-------+-------+-------+-------+
|
||||
* 5 |G| offset3 |
|
||||
* +-------+-------+-------+-------+-------+-------+-------+-------+
|
||||
* 6 |BDX|lvl| type | cksum | comp | PSIZE | LSIZE |
|
||||
* +-------+-------+-------+-------+-------+-------+-------+-------+
|
||||
* 7 | padding |
|
||||
* +-------+-------+-------+-------+-------+-------+-------+-------+
|
||||
* 8 | padding |
|
||||
* +-------+-------+-------+-------+-------+-------+-------+-------+
|
||||
* 9 | physical birth txg |
|
||||
* +-------+-------+-------+-------+-------+-------+-------+-------+
|
||||
* a | logical birth txg |
|
||||
* +-------+-------+-------+-------+-------+-------+-------+-------+
|
||||
* b | fill count |
|
||||
* +-------+-------+-------+-------+-------+-------+-------+-------+
|
||||
* c | checksum[0] |
|
||||
* +-------+-------+-------+-------+-------+-------+-------+-------+
|
||||
* d | checksum[1] |
|
||||
* +-------+-------+-------+-------+-------+-------+-------+-------+
|
||||
* e | checksum[2] |
|
||||
* +-------+-------+-------+-------+-------+-------+-------+-------+
|
||||
* f | checksum[3] |
|
||||
* +-------+-------+-------+-------+-------+-------+-------+-------+
|
||||
*
|
||||
* Legend:
|
||||
*
|
||||
* vdev virtual device ID
|
||||
* offset offset into virtual device
|
||||
* LSIZE logical size
|
||||
* PSIZE physical size (after compression)
|
||||
* ASIZE allocated size (including RAID-Z parity and gang block headers)
|
||||
* GRID RAID-Z layout information (reserved for future use)
|
||||
* cksum checksum function
|
||||
* comp compression function
|
||||
* G gang block indicator
|
||||
* B byteorder (endianness)
|
||||
* D dedup
|
||||
* X unused
|
||||
* lvl level of indirection
|
||||
* type DMU object type
|
||||
* phys birth txg of block allocation; zero if same as logical birth txg
|
||||
* log. birth transaction group in which the block was logically born
|
||||
* fill count number of non-zero blocks under this bp
|
||||
* checksum[4] 256-bit checksum of the data this bp describes
|
||||
*/
|
||||
#define SPA_BLKPTRSHIFT 7 /* blkptr_t is 128 bytes */
|
||||
#define SPA_DVAS_PER_BP 3 /* Number of DVAs in a bp */
|
||||
|
||||
typedef struct blkptr {
|
||||
dva_t blk_dva[SPA_DVAS_PER_BP]; /* Data Virtual Addresses */
|
||||
uint64_t blk_prop; /* size, compression, type, etc */
|
||||
uint64_t blk_pad[2]; /* Extra space for the future */
|
||||
uint64_t blk_phys_birth; /* txg when block was allocated */
|
||||
uint64_t blk_birth; /* transaction group at birth */
|
||||
uint64_t blk_fill; /* fill count */
|
||||
zio_cksum_t blk_cksum; /* 256-bit checksum */
|
||||
} blkptr_t;
|
||||
|
||||
/*
|
||||
* Macros to get and set fields in a bp or DVA.
|
||||
*/
|
||||
#define DVA_GET_ASIZE(dva) \
|
||||
BF64_GET_SB((dva)->dva_word[0], 0, 24, SPA_MINBLOCKSHIFT, 0)
|
||||
#define DVA_SET_ASIZE(dva, x) \
|
||||
BF64_SET_SB((dva)->dva_word[0], 0, 24, SPA_MINBLOCKSHIFT, 0, x)
|
||||
|
||||
#define DVA_GET_GRID(dva) BF64_GET((dva)->dva_word[0], 24, 8)
|
||||
#define DVA_SET_GRID(dva, x) BF64_SET((dva)->dva_word[0], 24, 8, x)
|
||||
|
||||
#define DVA_GET_VDEV(dva) BF64_GET((dva)->dva_word[0], 32, 32)
|
||||
#define DVA_SET_VDEV(dva, x) BF64_SET((dva)->dva_word[0], 32, 32, x)
|
||||
|
||||
#define DVA_GET_GANG(dva) BF64_GET((dva)->dva_word[1], 63, 1)
|
||||
#define DVA_SET_GANG(dva, x) BF64_SET((dva)->dva_word[1], 63, 1, x)
|
||||
|
||||
#define BP_GET_LSIZE(bp) \
|
||||
BF64_GET_SB((bp)->blk_prop, 0, 16, SPA_MINBLOCKSHIFT, 1)
|
||||
#define BP_SET_LSIZE(bp, x) \
|
||||
BF64_SET_SB((bp)->blk_prop, 0, 16, SPA_MINBLOCKSHIFT, 1, x)
|
||||
|
||||
#define BP_GET_COMPRESS(bp) BF64_GET((bp)->blk_prop, 32, 8)
|
||||
#define BP_SET_COMPRESS(bp, x) BF64_SET((bp)->blk_prop, 32, 8, x)
|
||||
|
||||
#define BP_GET_CHECKSUM(bp) BF64_GET((bp)->blk_prop, 40, 8)
|
||||
#define BP_SET_CHECKSUM(bp, x) BF64_SET((bp)->blk_prop, 40, 8, x)
|
||||
|
||||
#define BP_GET_TYPE(bp) BF64_GET((bp)->blk_prop, 48, 8)
|
||||
#define BP_SET_TYPE(bp, x) BF64_SET((bp)->blk_prop, 48, 8, x)
|
||||
|
||||
#define BP_GET_LEVEL(bp) BF64_GET((bp)->blk_prop, 56, 5)
|
||||
#define BP_SET_LEVEL(bp, x) BF64_SET((bp)->blk_prop, 56, 5, x)
|
||||
|
||||
#define BP_GET_PROP_BIT_61(bp) BF64_GET((bp)->blk_prop, 61, 1)
|
||||
#define BP_SET_PROP_BIT_61(bp, x) BF64_SET((bp)->blk_prop, 61, 1, x)
|
||||
|
||||
#define BP_GET_DEDUP(bp) BF64_GET((bp)->blk_prop, 62, 1)
|
||||
#define BP_SET_DEDUP(bp, x) BF64_SET((bp)->blk_prop, 62, 1, x)
|
||||
|
||||
#define BP_GET_BYTEORDER(bp) (0 - BF64_GET((bp)->blk_prop, 63, 1))
|
||||
#define BP_SET_BYTEORDER(bp, x) BF64_SET((bp)->blk_prop, 63, 1, x)
|
||||
|
||||
#define BP_PHYSICAL_BIRTH(bp) \
|
||||
((bp)->blk_phys_birth ? (bp)->blk_phys_birth : (bp)->blk_birth)
|
||||
|
||||
#define BP_SET_BIRTH(bp, logical, physical) \
|
||||
{ \
|
||||
(bp)->blk_birth = (logical); \
|
||||
(bp)->blk_phys_birth = ((logical) == (physical) ? 0 : (physical)); \
|
||||
}
|
||||
|
||||
#define BP_GET_ASIZE(bp) \
|
||||
(DVA_GET_ASIZE(&(bp)->blk_dva[0]) + DVA_GET_ASIZE(&(bp)->blk_dva[1]) + \
|
||||
DVA_GET_ASIZE(&(bp)->blk_dva[2]))
|
||||
|
||||
#define BP_GET_UCSIZE(bp) \
|
||||
((BP_GET_LEVEL(bp) > 0 || dmu_ot[BP_GET_TYPE(bp)].ot_metadata) ? \
|
||||
BP_GET_PSIZE(bp) : BP_GET_LSIZE(bp));
|
||||
|
||||
#define BP_GET_NDVAS(bp) \
|
||||
(!!DVA_GET_ASIZE(&(bp)->blk_dva[0]) + \
|
||||
!!DVA_GET_ASIZE(&(bp)->blk_dva[1]) + \
|
||||
!!DVA_GET_ASIZE(&(bp)->blk_dva[2]))
|
||||
|
||||
#define BP_COUNT_GANG(bp) \
|
||||
(DVA_GET_GANG(&(bp)->blk_dva[0]) + \
|
||||
DVA_GET_GANG(&(bp)->blk_dva[1]) + \
|
||||
DVA_GET_GANG(&(bp)->blk_dva[2]))
|
||||
|
||||
#define DVA_EQUAL(dva1, dva2) \
|
||||
((dva1)->dva_word[1] == (dva2)->dva_word[1] && \
|
||||
(dva1)->dva_word[0] == (dva2)->dva_word[0])
|
||||
|
||||
#define BP_EQUAL(bp1, bp2) \
|
||||
(BP_PHYSICAL_BIRTH(bp1) == BP_PHYSICAL_BIRTH(bp2) && \
|
||||
DVA_EQUAL(&(bp1)->blk_dva[0], &(bp2)->blk_dva[0]) && \
|
||||
DVA_EQUAL(&(bp1)->blk_dva[1], &(bp2)->blk_dva[1]) && \
|
||||
DVA_EQUAL(&(bp1)->blk_dva[2], &(bp2)->blk_dva[2]))
|
||||
|
||||
#define ZIO_CHECKSUM_EQUAL(zc1, zc2) \
|
||||
(0 == (((zc1).zc_word[0] - (zc2).zc_word[0]) | \
|
||||
((zc1).zc_word[1] - (zc2).zc_word[1]) | \
|
||||
((zc1).zc_word[2] - (zc2).zc_word[2]) | \
|
||||
((zc1).zc_word[3] - (zc2).zc_word[3])))
|
||||
|
||||
#define DVA_IS_VALID(dva) (DVA_GET_ASIZE(dva) != 0)
|
||||
|
||||
#define ZIO_SET_CHECKSUM(zcp, w0, w1, w2, w3) \
|
||||
{ \
|
||||
(zcp)->zc_word[0] = w0; \
|
||||
(zcp)->zc_word[1] = w1; \
|
||||
(zcp)->zc_word[2] = w2; \
|
||||
(zcp)->zc_word[3] = w3; \
|
||||
}
|
||||
|
||||
#define BP_IDENTITY(bp) (&(bp)->blk_dva[0])
|
||||
#define BP_IS_GANG(bp) DVA_GET_GANG(BP_IDENTITY(bp))
|
||||
#define BP_IS_HOLE(bp) ((bp)->blk_birth == 0)
|
||||
|
||||
/* BP_IS_RAIDZ(bp) assumes no block compression */
|
||||
#define BP_IS_RAIDZ(bp) (DVA_GET_ASIZE(&(bp)->blk_dva[0]) > \
|
||||
BP_GET_PSIZE(bp))
|
||||
|
||||
#define BP_ZERO(bp) \
|
||||
{ \
|
||||
(bp)->blk_dva[0].dva_word[0] = 0; \
|
||||
(bp)->blk_dva[0].dva_word[1] = 0; \
|
||||
(bp)->blk_dva[1].dva_word[0] = 0; \
|
||||
(bp)->blk_dva[1].dva_word[1] = 0; \
|
||||
(bp)->blk_dva[2].dva_word[0] = 0; \
|
||||
(bp)->blk_dva[2].dva_word[1] = 0; \
|
||||
(bp)->blk_prop = 0; \
|
||||
(bp)->blk_pad[0] = 0; \
|
||||
(bp)->blk_pad[1] = 0; \
|
||||
(bp)->blk_phys_birth = 0; \
|
||||
(bp)->blk_birth = 0; \
|
||||
(bp)->blk_fill = 0; \
|
||||
ZIO_SET_CHECKSUM(&(bp)->blk_cksum, 0, 0, 0, 0); \
|
||||
}
|
||||
|
||||
#define BP_SPRINTF_LEN 320
|
||||
|
||||
#endif /* ! ZFS_SPA_HEADER */
|
57
include/zfs/uberblock_impl.h
Normal file
57
include/zfs/uberblock_impl.h
Normal file
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
/*
|
||||
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
|
||||
* Use is subject to license terms.
|
||||
*/
|
||||
|
||||
#ifndef _SYS_UBERBLOCK_IMPL_H
|
||||
#define _SYS_UBERBLOCK_IMPL_H
|
||||
|
||||
#define UBMAX(a, b) ((a) > (b) ? (a) : (b))
|
||||
|
||||
/*
|
||||
* The uberblock version is incremented whenever an incompatible on-disk
|
||||
* format change is made to the SPA, DMU, or ZAP.
|
||||
*
|
||||
* Note: the first two fields should never be moved. When a storage pool
|
||||
* is opened, the uberblock must be read off the disk before the version
|
||||
* can be checked. If the ub_version field is moved, we may not detect
|
||||
* version mismatch. If the ub_magic field is moved, applications that
|
||||
* expect the magic number in the first word won't work.
|
||||
*/
|
||||
#define UBERBLOCK_MAGIC 0x00bab10c /* oo-ba-bloc! */
|
||||
#define UBERBLOCK_SHIFT 10 /* up to 1K */
|
||||
|
||||
typedef struct uberblock {
|
||||
uint64_t ub_magic; /* UBERBLOCK_MAGIC */
|
||||
uint64_t ub_version; /* ZFS_VERSION */
|
||||
uint64_t ub_txg; /* txg of last sync */
|
||||
uint64_t ub_guid_sum; /* sum of all vdev guids */
|
||||
uint64_t ub_timestamp; /* UTC time of last sync */
|
||||
blkptr_t ub_rootbp; /* MOS objset_phys_t */
|
||||
} uberblock_t;
|
||||
|
||||
#define VDEV_UBERBLOCK_SHIFT(as) UBMAX(as, UBERBLOCK_SHIFT)
|
||||
#define UBERBLOCK_SIZE(as) (1ULL << VDEV_UBERBLOCK_SHIFT(as))
|
||||
|
||||
/* Number of uberblocks that can fit in the ring at a given ashift */
|
||||
#define UBERBLOCK_COUNT(as) (VDEV_UBERBLOCK_RING >> VDEV_UBERBLOCK_SHIFT(as))
|
||||
|
||||
#endif /* _SYS_UBERBLOCK_IMPL_H */
|
70
include/zfs/vdev_impl.h
Normal file
70
include/zfs/vdev_impl.h
Normal file
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
/*
|
||||
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
|
||||
* Use is subject to license terms.
|
||||
*/
|
||||
|
||||
#ifndef _SYS_VDEV_IMPL_H
|
||||
#define _SYS_VDEV_IMPL_H
|
||||
|
||||
#define VDEV_SKIP_SIZE (8 << 10)
|
||||
#define VDEV_BOOT_HEADER_SIZE (8 << 10)
|
||||
#define VDEV_PHYS_SIZE (112 << 10)
|
||||
#define VDEV_UBERBLOCK_RING (128 << 10)
|
||||
|
||||
/* ZFS boot block */
|
||||
#define VDEV_BOOT_MAGIC 0x2f5b007b10cULL
|
||||
#define VDEV_BOOT_VERSION 1 /* version number */
|
||||
|
||||
typedef struct vdev_boot_header {
|
||||
uint64_t vb_magic; /* VDEV_BOOT_MAGIC */
|
||||
uint64_t vb_version; /* VDEV_BOOT_VERSION */
|
||||
uint64_t vb_offset; /* start offset (bytes) */
|
||||
uint64_t vb_size; /* size (bytes) */
|
||||
char vb_pad[VDEV_BOOT_HEADER_SIZE - 4 * sizeof(uint64_t)];
|
||||
} vdev_boot_header_t;
|
||||
|
||||
typedef struct vdev_phys {
|
||||
char vp_nvlist[VDEV_PHYS_SIZE - sizeof(zio_eck_t)];
|
||||
zio_eck_t vp_zbt;
|
||||
} vdev_phys_t;
|
||||
|
||||
typedef struct vdev_label {
|
||||
char vl_pad[VDEV_SKIP_SIZE]; /* 8K */
|
||||
vdev_boot_header_t vl_boot_header; /* 8K */
|
||||
vdev_phys_t vl_vdev_phys; /* 112K */
|
||||
char vl_uberblock[VDEV_UBERBLOCK_RING]; /* 128K */
|
||||
} vdev_label_t; /* 256K total */
|
||||
|
||||
/*
|
||||
* Size and offset of embedded boot loader region on each label.
|
||||
* The total size of the first two labels plus the boot area is 4MB.
|
||||
*/
|
||||
#define VDEV_BOOT_OFFSET (2 * sizeof(vdev_label_t))
|
||||
#define VDEV_BOOT_SIZE (7ULL << 19) /* 3.5M */
|
||||
|
||||
/*
|
||||
* Size of label regions at the start and end of each leaf device.
|
||||
*/
|
||||
#define VDEV_LABEL_START_SIZE (2 * sizeof(vdev_label_t) + VDEV_BOOT_SIZE)
|
||||
#define VDEV_LABEL_END_SIZE (2 * sizeof(vdev_label_t))
|
||||
#define VDEV_LABELS 4
|
||||
|
||||
#endif /* _SYS_VDEV_IMPL_H */
|
111
include/zfs/zap_impl.h
Normal file
111
include/zfs/zap_impl.h
Normal file
@ -0,0 +1,111 @@
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
*/
|
||||
|
||||
#ifndef _SYS_ZAP_IMPL_H
|
||||
#define _SYS_ZAP_IMPL_H
|
||||
|
||||
#define ZAP_MAGIC 0x2F52AB2ABULL
|
||||
|
||||
#define ZAP_HASHBITS 28
|
||||
#define MZAP_ENT_LEN 64
|
||||
#define MZAP_NAME_LEN (MZAP_ENT_LEN - 8 - 4 - 2)
|
||||
#define MZAP_MAX_BLKSHIFT SPA_MAXBLOCKSHIFT
|
||||
#define MZAP_MAX_BLKSZ (1 << MZAP_MAX_BLKSHIFT)
|
||||
|
||||
typedef struct mzap_ent_phys {
|
||||
uint64_t mze_value;
|
||||
uint32_t mze_cd;
|
||||
uint16_t mze_pad; /* in case we want to chain them someday */
|
||||
char mze_name[MZAP_NAME_LEN];
|
||||
} mzap_ent_phys_t;
|
||||
|
||||
typedef struct mzap_phys {
|
||||
uint64_t mz_block_type; /* ZBT_MICRO */
|
||||
uint64_t mz_salt;
|
||||
uint64_t mz_pad[6];
|
||||
mzap_ent_phys_t mz_chunk[1];
|
||||
/* actually variable size depending on block size */
|
||||
} mzap_phys_t;
|
||||
|
||||
/*
|
||||
* The (fat) zap is stored in one object. It is an array of
|
||||
* 1<<FZAP_BLOCK_SHIFT byte blocks. The layout looks like one of:
|
||||
*
|
||||
* ptrtbl fits in first block:
|
||||
* [zap_phys_t zap_ptrtbl_shift < 6] [zap_leaf_t] ...
|
||||
*
|
||||
* ptrtbl too big for first block:
|
||||
* [zap_phys_t zap_ptrtbl_shift >= 6] [zap_leaf_t] [ptrtbl] ...
|
||||
*
|
||||
*/
|
||||
|
||||
#define ZBT_LEAF ((1ULL << 63) + 0)
|
||||
#define ZBT_HEADER ((1ULL << 63) + 1)
|
||||
#define ZBT_MICRO ((1ULL << 63) + 3)
|
||||
/* any other values are ptrtbl blocks */
|
||||
|
||||
/*
|
||||
* the embedded pointer table takes up half a block:
|
||||
* block size / entry size (2^3) / 2
|
||||
*/
|
||||
#define ZAP_EMBEDDED_PTRTBL_SHIFT(zap) (FZAP_BLOCK_SHIFT(zap) - 3 - 1)
|
||||
|
||||
/*
|
||||
* The embedded pointer table starts half-way through the block. Since
|
||||
* the pointer table itself is half the block, it starts at (64-bit)
|
||||
* word number (1<<ZAP_EMBEDDED_PTRTBL_SHIFT(zap)).
|
||||
*/
|
||||
#define ZAP_EMBEDDED_PTRTBL_ENT(zap, idx) \
|
||||
((uint64_t *)(zap)->zap_f.zap_phys) \
|
||||
[(idx) + (1<<ZAP_EMBEDDED_PTRTBL_SHIFT(zap))]
|
||||
|
||||
/*
|
||||
* TAKE NOTE:
|
||||
* If zap_phys_t is modified, zap_byteswap() must be modified.
|
||||
*/
|
||||
typedef struct zap_phys {
|
||||
uint64_t zap_block_type; /* ZBT_HEADER */
|
||||
uint64_t zap_magic; /* ZAP_MAGIC */
|
||||
|
||||
struct zap_table_phys {
|
||||
uint64_t zt_blk; /* starting block number */
|
||||
uint64_t zt_numblks; /* number of blocks */
|
||||
uint64_t zt_shift; /* bits to index it */
|
||||
uint64_t zt_nextblk; /* next (larger) copy start block */
|
||||
uint64_t zt_blks_copied; /* number source blocks copied */
|
||||
} zap_ptrtbl;
|
||||
|
||||
uint64_t zap_freeblk; /* the next free block */
|
||||
uint64_t zap_num_leafs; /* number of leafs */
|
||||
uint64_t zap_num_entries; /* number of entries */
|
||||
uint64_t zap_salt; /* salt to stir into hash function */
|
||||
uint64_t zap_normflags; /* flags for u8_textprep_str() */
|
||||
uint64_t zap_flags; /* zap_flag_t */
|
||||
/*
|
||||
* This structure is followed by padding, and then the embedded
|
||||
* pointer table. The embedded pointer table takes up second
|
||||
* half of the block. It is accessed using the
|
||||
* ZAP_EMBEDDED_PTRTBL_ENT() macro.
|
||||
*/
|
||||
} zap_phys_t;
|
||||
|
||||
#endif /* _SYS_ZAP_IMPL_H */
|
103
include/zfs/zap_leaf.h
Normal file
103
include/zfs/zap_leaf.h
Normal file
@ -0,0 +1,103 @@
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
/*
|
||||
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
|
||||
* Use is subject to license terms.
|
||||
*/
|
||||
|
||||
#ifndef _SYS_ZAP_LEAF_H
|
||||
#define _SYS_ZAP_LEAF_H
|
||||
|
||||
#define ZAP_LEAF_MAGIC 0x2AB1EAF
|
||||
|
||||
/* chunk size = 24 bytes */
|
||||
#define ZAP_LEAF_CHUNKSIZE 24
|
||||
|
||||
/*
|
||||
* The amount of space within the chunk available for the array is:
|
||||
* chunk size - space for type (1) - space for next pointer (2)
|
||||
*/
|
||||
#define ZAP_LEAF_ARRAY_BYTES (ZAP_LEAF_CHUNKSIZE - 3)
|
||||
|
||||
typedef enum zap_chunk_type {
|
||||
ZAP_CHUNK_FREE = 253,
|
||||
ZAP_CHUNK_ENTRY = 252,
|
||||
ZAP_CHUNK_ARRAY = 251,
|
||||
ZAP_CHUNK_TYPE_MAX = 250
|
||||
} zap_chunk_type_t;
|
||||
|
||||
/*
|
||||
* TAKE NOTE:
|
||||
* If zap_leaf_phys_t is modified, zap_leaf_byteswap() must be modified.
|
||||
*/
|
||||
typedef struct zap_leaf_phys {
|
||||
struct zap_leaf_header {
|
||||
uint64_t lh_block_type; /* ZBT_LEAF */
|
||||
uint64_t lh_pad1;
|
||||
uint64_t lh_prefix; /* hash prefix of this leaf */
|
||||
uint32_t lh_magic; /* ZAP_LEAF_MAGIC */
|
||||
uint16_t lh_nfree; /* number free chunks */
|
||||
uint16_t lh_nentries; /* number of entries */
|
||||
uint16_t lh_prefix_len; /* num bits used to id this */
|
||||
|
||||
/* above is accessable to zap, below is zap_leaf private */
|
||||
|
||||
uint16_t lh_freelist; /* chunk head of free list */
|
||||
uint8_t lh_pad2[12];
|
||||
} l_hdr; /* 2 24-byte chunks */
|
||||
|
||||
/*
|
||||
* The header is followed by a hash table with
|
||||
* ZAP_LEAF_HASH_NUMENTRIES(zap) entries. The hash table is
|
||||
* followed by an array of ZAP_LEAF_NUMCHUNKS(zap)
|
||||
* zap_leaf_chunk structures. These structures are accessed
|
||||
* with the ZAP_LEAF_CHUNK() macro.
|
||||
*/
|
||||
|
||||
uint16_t l_hash[1];
|
||||
} zap_leaf_phys_t;
|
||||
|
||||
typedef union zap_leaf_chunk {
|
||||
struct zap_leaf_entry {
|
||||
uint8_t le_type; /* always ZAP_CHUNK_ENTRY */
|
||||
uint8_t le_int_size; /* size of ints */
|
||||
uint16_t le_next; /* next entry in hash chain */
|
||||
uint16_t le_name_chunk; /* first chunk of the name */
|
||||
uint16_t le_name_length; /* bytes in name, incl null */
|
||||
uint16_t le_value_chunk; /* first chunk of the value */
|
||||
uint16_t le_value_length; /* value length in ints */
|
||||
uint32_t le_cd; /* collision differentiator */
|
||||
uint64_t le_hash; /* hash value of the name */
|
||||
} l_entry;
|
||||
struct zap_leaf_array {
|
||||
uint8_t la_type; /* always ZAP_CHUNK_ARRAY */
|
||||
union {
|
||||
uint8_t la_array[ZAP_LEAF_ARRAY_BYTES];
|
||||
uint64_t la_array64;
|
||||
} __attribute__ ((packed));
|
||||
uint16_t la_next; /* next blk or CHAIN_END */
|
||||
} l_array;
|
||||
struct zap_leaf_free {
|
||||
uint8_t lf_type; /* always ZAP_CHUNK_FREE */
|
||||
uint8_t lf_pad[ZAP_LEAF_ARRAY_BYTES];
|
||||
uint16_t lf_next; /* next in free list, or CHAIN_END */
|
||||
} l_free;
|
||||
} zap_leaf_chunk_t;
|
||||
|
||||
#endif /* _SYS_ZAP_LEAF_H */
|
122
include/zfs/zfs.h
Normal file
122
include/zfs/zfs.h
Normal file
@ -0,0 +1,122 @@
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
*/
|
||||
|
||||
#ifndef GRUB_ZFS_HEADER
|
||||
#define GRUB_ZFS_HEADER 1
|
||||
|
||||
|
||||
/*
|
||||
* On-disk version number.
|
||||
*/
|
||||
#define SPA_VERSION 28ULL
|
||||
|
||||
/*
|
||||
* The following are configuration names used in the nvlist describing a pool's
|
||||
* configuration.
|
||||
*/
|
||||
#define ZPOOL_CONFIG_VERSION "version"
|
||||
#define ZPOOL_CONFIG_POOL_NAME "name"
|
||||
#define ZPOOL_CONFIG_POOL_STATE "state"
|
||||
#define ZPOOL_CONFIG_POOL_TXG "txg"
|
||||
#define ZPOOL_CONFIG_POOL_GUID "pool_guid"
|
||||
#define ZPOOL_CONFIG_CREATE_TXG "create_txg"
|
||||
#define ZPOOL_CONFIG_TOP_GUID "top_guid"
|
||||
#define ZPOOL_CONFIG_VDEV_TREE "vdev_tree"
|
||||
#define ZPOOL_CONFIG_TYPE "type"
|
||||
#define ZPOOL_CONFIG_CHILDREN "children"
|
||||
#define ZPOOL_CONFIG_ID "id"
|
||||
#define ZPOOL_CONFIG_GUID "guid"
|
||||
#define ZPOOL_CONFIG_PATH "path"
|
||||
#define ZPOOL_CONFIG_DEVID "devid"
|
||||
#define ZPOOL_CONFIG_METASLAB_ARRAY "metaslab_array"
|
||||
#define ZPOOL_CONFIG_METASLAB_SHIFT "metaslab_shift"
|
||||
#define ZPOOL_CONFIG_ASHIFT "ashift"
|
||||
#define ZPOOL_CONFIG_ASIZE "asize"
|
||||
#define ZPOOL_CONFIG_DTL "DTL"
|
||||
#define ZPOOL_CONFIG_STATS "stats"
|
||||
#define ZPOOL_CONFIG_WHOLE_DISK "whole_disk"
|
||||
#define ZPOOL_CONFIG_ERRCOUNT "error_count"
|
||||
#define ZPOOL_CONFIG_NOT_PRESENT "not_present"
|
||||
#define ZPOOL_CONFIG_SPARES "spares"
|
||||
#define ZPOOL_CONFIG_IS_SPARE "is_spare"
|
||||
#define ZPOOL_CONFIG_NPARITY "nparity"
|
||||
#define ZPOOL_CONFIG_PHYS_PATH "phys_path"
|
||||
#define ZPOOL_CONFIG_L2CACHE "l2cache"
|
||||
#define ZPOOL_CONFIG_HOLE_ARRAY "hole_array"
|
||||
#define ZPOOL_CONFIG_VDEV_CHILDREN "vdev_children"
|
||||
#define ZPOOL_CONFIG_IS_HOLE "is_hole"
|
||||
#define ZPOOL_CONFIG_DDT_HISTOGRAM "ddt_histogram"
|
||||
#define ZPOOL_CONFIG_DDT_OBJ_STATS "ddt_object_stats"
|
||||
#define ZPOOL_CONFIG_DDT_STATS "ddt_stats"
|
||||
/*
|
||||
* The persistent vdev state is stored as separate values rather than a single
|
||||
* 'vdev_state' entry. This is because a device can be in multiple states, such
|
||||
* as offline and degraded.
|
||||
*/
|
||||
#define ZPOOL_CONFIG_OFFLINE "offline"
|
||||
#define ZPOOL_CONFIG_FAULTED "faulted"
|
||||
#define ZPOOL_CONFIG_DEGRADED "degraded"
|
||||
#define ZPOOL_CONFIG_REMOVED "removed"
|
||||
|
||||
#define VDEV_TYPE_ROOT "root"
|
||||
#define VDEV_TYPE_MIRROR "mirror"
|
||||
#define VDEV_TYPE_REPLACING "replacing"
|
||||
#define VDEV_TYPE_RAIDZ "raidz"
|
||||
#define VDEV_TYPE_DISK "disk"
|
||||
#define VDEV_TYPE_FILE "file"
|
||||
#define VDEV_TYPE_MISSING "missing"
|
||||
#define VDEV_TYPE_HOLE "hole"
|
||||
#define VDEV_TYPE_SPARE "spare"
|
||||
#define VDEV_TYPE_L2CACHE "l2cache"
|
||||
|
||||
/*
|
||||
* pool state. The following states are written to disk as part of the normal
|
||||
* SPA lifecycle: ACTIVE, EXPORTED, DESTROYED, SPARE, L2CACHE. The remaining
|
||||
* states are software abstractions used at various levels to communicate pool
|
||||
* state.
|
||||
*/
|
||||
typedef enum pool_state {
|
||||
POOL_STATE_ACTIVE = 0, /* In active use */
|
||||
POOL_STATE_EXPORTED, /* Explicitly exported */
|
||||
POOL_STATE_DESTROYED, /* Explicitly destroyed */
|
||||
POOL_STATE_SPARE, /* Reserved for hot spare use */
|
||||
POOL_STATE_L2CACHE, /* Level 2 ARC device */
|
||||
POOL_STATE_UNINITIALIZED, /* Internal spa_t state */
|
||||
POOL_STATE_UNAVAIL, /* Internal libzfs state */
|
||||
POOL_STATE_POTENTIALLY_ACTIVE /* Internal libzfs state */
|
||||
} pool_state_t;
|
||||
|
||||
struct zfs_data;
|
||||
|
||||
int zfs_fetch_nvlist(device_t dev, char **nvlist);
|
||||
int zfs_getmdnobj(device_t dev, const char *fsfilename,
|
||||
uint64_t *mdnobj);
|
||||
|
||||
char *zfs_nvlist_lookup_string(char *nvlist, char *name);
|
||||
char *zfs_nvlist_lookup_nvlist(char *nvlist, char *name);
|
||||
int zfs_nvlist_lookup_uint64(char *nvlist, char *name,
|
||||
uint64_t *out);
|
||||
char *zfs_nvlist_lookup_nvlist_array(char *nvlist, char *name,
|
||||
size_t index);
|
||||
int zfs_nvlist_lookup_nvlist_array_get_nelm(char *nvlist, char *name);
|
||||
|
||||
#endif /* ! GRUB_ZFS_HEADER */
|
55
include/zfs/zfs_acl.h
Normal file
55
include/zfs/zfs_acl.h
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
/*
|
||||
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
|
||||
* Use is subject to license terms.
|
||||
*/
|
||||
|
||||
#ifndef _SYS_FS_ZFS_ACL_H
|
||||
#define _SYS_FS_ZFS_ACL_H
|
||||
|
||||
typedef struct zfs_oldace {
|
||||
uint32_t z_fuid; /* "who" */
|
||||
uint32_t z_access_mask; /* access mask */
|
||||
uint16_t z_flags; /* flags, i.e inheritance */
|
||||
uint16_t z_type; /* type of entry allow/deny */
|
||||
} zfs_oldace_t;
|
||||
|
||||
#define ACE_SLOT_CNT 6
|
||||
|
||||
typedef struct zfs_znode_acl_v0 {
|
||||
uint64_t z_acl_extern_obj; /* ext acl pieces */
|
||||
uint32_t z_acl_count; /* Number of ACEs */
|
||||
uint16_t z_acl_version; /* acl version */
|
||||
uint16_t z_acl_pad; /* pad */
|
||||
zfs_oldace_t z_ace_data[ACE_SLOT_CNT]; /* 6 standard ACEs */
|
||||
} zfs_znode_acl_v0_t;
|
||||
|
||||
#define ZFS_ACE_SPACE (sizeof(zfs_oldace_t) * ACE_SLOT_CNT)
|
||||
|
||||
typedef struct zfs_znode_acl {
|
||||
uint64_t z_acl_extern_obj; /* ext acl pieces */
|
||||
uint32_t z_acl_size; /* Number of bytes in ACL */
|
||||
uint16_t z_acl_version; /* acl version */
|
||||
uint16_t z_acl_count; /* ace count */
|
||||
uint8_t z_ace_data[ZFS_ACE_SPACE]; /* space for embedded ACEs */
|
||||
} zfs_znode_acl_t;
|
||||
|
||||
|
||||
#endif /* _SYS_FS_ZFS_ACL_H */
|
71
include/zfs/zfs_znode.h
Normal file
71
include/zfs/zfs_znode.h
Normal file
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
/*
|
||||
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
|
||||
* Use is subject to license terms.
|
||||
*/
|
||||
|
||||
#ifndef _SYS_FS_ZFS_ZNODE_H
|
||||
#define _SYS_FS_ZFS_ZNODE_H
|
||||
|
||||
#include <zfs/zfs_acl.h>
|
||||
|
||||
#define MASTER_NODE_OBJ 1
|
||||
#define ZFS_ROOT_OBJ "ROOT"
|
||||
#define ZPL_VERSION_STR "VERSION"
|
||||
#define ZFS_SA_ATTRS "SA_ATTRS"
|
||||
|
||||
#define ZPL_VERSION 5ULL
|
||||
|
||||
#define ZFS_DIRENT_OBJ(de) BF64_GET(de, 0, 48)
|
||||
|
||||
/*
|
||||
* This is the persistent portion of the znode. It is stored
|
||||
* in the "bonus buffer" of the file. Short symbolic links
|
||||
* are also stored in the bonus buffer.
|
||||
*/
|
||||
typedef struct znode_phys {
|
||||
uint64_t zp_atime[2]; /* 0 - last file access time */
|
||||
uint64_t zp_mtime[2]; /* 16 - last file modification time */
|
||||
uint64_t zp_ctime[2]; /* 32 - last file change time */
|
||||
uint64_t zp_crtime[2]; /* 48 - creation time */
|
||||
uint64_t zp_gen; /* 64 - generation (txg of creation) */
|
||||
uint64_t zp_mode; /* 72 - file mode bits */
|
||||
uint64_t zp_size; /* 80 - size of file */
|
||||
uint64_t zp_parent; /* 88 - directory parent (`..') */
|
||||
uint64_t zp_links; /* 96 - number of links to file */
|
||||
uint64_t zp_xattr; /* 104 - DMU object for xattrs */
|
||||
uint64_t zp_rdev; /* 112 - dev_t for VBLK & VCHR files */
|
||||
uint64_t zp_flags; /* 120 - persistent flags */
|
||||
uint64_t zp_uid; /* 128 - file owner */
|
||||
uint64_t zp_gid; /* 136 - owning group */
|
||||
uint64_t zp_pad[4]; /* 144 - future */
|
||||
zfs_znode_acl_t zp_acl; /* 176 - 263 ACL */
|
||||
/*
|
||||
* Data may pad out any remaining bytes in the znode buffer, eg:
|
||||
*
|
||||
* |<---------------------- dnode_phys (512) ------------------------>|
|
||||
* |<-- dnode (192) --->|<----------- "bonus" buffer (320) ---------->|
|
||||
* |<---- znode (264) ---->|<---- data (56) ---->|
|
||||
*
|
||||
* At present, we only use this space to store symbolic links.
|
||||
*/
|
||||
} znode_phys_t;
|
||||
|
||||
#endif /* _SYS_FS_ZFS_ZNODE_H */
|
57
include/zfs/zil.h
Normal file
57
include/zfs/zil.h
Normal file
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
/*
|
||||
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
|
||||
* Use is subject to license terms.
|
||||
*/
|
||||
|
||||
#ifndef _SYS_ZIL_H
|
||||
#define _SYS_ZIL_H
|
||||
|
||||
/*
|
||||
* Intent log format:
|
||||
*
|
||||
* Each objset has its own intent log. The log header (zil_header_t)
|
||||
* for objset N's intent log is kept in the Nth object of the SPA's
|
||||
* intent_log objset. The log header points to a chain of log blocks,
|
||||
* each of which contains log records (i.e., transactions) followed by
|
||||
* a log block trailer (zil_trailer_t). The format of a log record
|
||||
* depends on the record (or transaction) type, but all records begin
|
||||
* with a common structure that defines the type, length, and txg.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Intent log header - this on disk structure holds fields to manage
|
||||
* the log. All fields are 64 bit to easily handle cross architectures.
|
||||
*/
|
||||
typedef struct zil_header {
|
||||
uint64_t zh_claim_txg; /* txg in which log blocks were claimed */
|
||||
uint64_t zh_replay_seq; /* highest replayed sequence number */
|
||||
blkptr_t zh_log; /* log chain */
|
||||
uint64_t zh_claim_seq; /* highest claimed sequence number */
|
||||
uint64_t zh_flags; /* header flags */
|
||||
uint64_t zh_pad[4];
|
||||
} zil_header_t;
|
||||
|
||||
/*
|
||||
* zh_flags bit settings
|
||||
*/
|
||||
#define ZIL_REPLAY_NEEDED 0x1 /* replay needed - internal only */
|
||||
|
||||
#endif /* _SYS_ZIL_H */
|
92
include/zfs/zio.h
Normal file
92
include/zfs/zio.h
Normal file
@ -0,0 +1,92 @@
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
*/
|
||||
|
||||
#ifndef _ZIO_H
|
||||
#define _ZIO_H
|
||||
|
||||
#include <zfs/spa.h>
|
||||
|
||||
#define ZEC_MAGIC 0x210da7ab10c7a11ULL /* zio data bloc tail */
|
||||
|
||||
typedef struct zio_eck {
|
||||
uint64_t zec_magic; /* for validation, endianness */
|
||||
zio_cksum_t zec_cksum; /* 256-bit checksum */
|
||||
} zio_eck_t;
|
||||
|
||||
/*
|
||||
* Gang block headers are self-checksumming and contain an array
|
||||
* of block pointers.
|
||||
*/
|
||||
#define SPA_GANGBLOCKSIZE SPA_MINBLOCKSIZE
|
||||
#define SPA_GBH_NBLKPTRS ((SPA_GANGBLOCKSIZE - \
|
||||
sizeof(zio_eck_t)) / sizeof(blkptr_t))
|
||||
#define SPA_GBH_FILLER ((SPA_GANGBLOCKSIZE - \
|
||||
sizeof(zio_eck_t) - \
|
||||
(SPA_GBH_NBLKPTRS * sizeof(blkptr_t))) /\
|
||||
sizeof(uint64_t))
|
||||
|
||||
#define ZIO_GET_IOSIZE(zio) \
|
||||
(BP_IS_GANG((zio)->io_bp) ? \
|
||||
SPA_GANGBLOCKSIZE : BP_GET_PSIZE((zio)->io_bp))
|
||||
|
||||
typedef struct zio_gbh {
|
||||
blkptr_t zg_blkptr[SPA_GBH_NBLKPTRS];
|
||||
uint64_t zg_filler[SPA_GBH_FILLER];
|
||||
zio_eck_t zg_tail;
|
||||
} zio_gbh_phys_t;
|
||||
|
||||
enum zio_checksum {
|
||||
ZIO_CHECKSUM_INHERIT = 0,
|
||||
ZIO_CHECKSUM_ON,
|
||||
ZIO_CHECKSUM_OFF,
|
||||
ZIO_CHECKSUM_LABEL,
|
||||
ZIO_CHECKSUM_GANG_HEADER,
|
||||
ZIO_CHECKSUM_ZILOG,
|
||||
ZIO_CHECKSUM_FLETCHER_2,
|
||||
ZIO_CHECKSUM_FLETCHER_4,
|
||||
ZIO_CHECKSUM_SHA256,
|
||||
ZIO_CHECKSUM_ZILOG2,
|
||||
ZIO_CHECKSUM_FUNCTIONS
|
||||
};
|
||||
|
||||
#define ZIO_CHECKSUM_ON_VALUE ZIO_CHECKSUM_FLETCHER_2
|
||||
#define ZIO_CHECKSUM_DEFAULT ZIO_CHECKSUM_ON
|
||||
|
||||
enum zio_compress {
|
||||
ZIO_COMPRESS_INHERIT = 0,
|
||||
ZIO_COMPRESS_ON,
|
||||
ZIO_COMPRESS_OFF,
|
||||
ZIO_COMPRESS_LZJB,
|
||||
ZIO_COMPRESS_EMPTY,
|
||||
ZIO_COMPRESS_GZIP1,
|
||||
ZIO_COMPRESS_GZIP2,
|
||||
ZIO_COMPRESS_GZIP3,
|
||||
ZIO_COMPRESS_GZIP4,
|
||||
ZIO_COMPRESS_GZIP5,
|
||||
ZIO_COMPRESS_GZIP6,
|
||||
ZIO_COMPRESS_GZIP7,
|
||||
ZIO_COMPRESS_GZIP8,
|
||||
ZIO_COMPRESS_GZIP9,
|
||||
ZIO_COMPRESS_FUNCTIONS
|
||||
};
|
||||
|
||||
#endif /* _ZIO_H */
|
50
include/zfs/zio_checksum.h
Normal file
50
include/zfs/zio_checksum.h
Normal file
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
/*
|
||||
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
|
||||
* Use is subject to license terms.
|
||||
*/
|
||||
|
||||
#ifndef _SYS_ZIO_CHECKSUM_H
|
||||
#define _SYS_ZIO_CHECKSUM_H
|
||||
|
||||
/*
|
||||
* Signature for checksum functions.
|
||||
*/
|
||||
typedef void zio_checksum_t(const void *data, uint64_t size,
|
||||
zfs_endian_t endian, zio_cksum_t *zcp);
|
||||
|
||||
/*
|
||||
* Information about each checksum function.
|
||||
*/
|
||||
typedef struct zio_checksum_info {
|
||||
zio_checksum_t *ci_func; /* checksum function for each byteorder */
|
||||
int ci_correctable; /* number of correctable bits */
|
||||
int ci_eck; /* uses zio embedded checksum? */
|
||||
char *ci_name; /* descriptive name */
|
||||
} zio_checksum_info_t;
|
||||
|
||||
extern void zio_checksum_SHA256(const void *, uint64_t,
|
||||
zfs_endian_t endian, zio_cksum_t *);
|
||||
extern void fletcher_2_endian(const void *, uint64_t, zfs_endian_t endian,
|
||||
zio_cksum_t *);
|
||||
extern void fletcher_4_endian(const void *, uint64_t, zfs_endian_t endian,
|
||||
zio_cksum_t *);
|
||||
|
||||
#endif /* _SYS_ZIO_CHECKSUM_H */
|
109
include/zfs_common.h
Normal file
109
include/zfs_common.h
Normal file
@ -0,0 +1,109 @@
|
||||
/*
|
||||
* ZFS filesystem port for Uboot by
|
||||
* Jorgen Lundman <lundman at lundman.net>
|
||||
*
|
||||
* zfsfs support
|
||||
* made from existing GRUB Sources by Sun, GNU and others.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifndef __ZFS_COMMON__
|
||||
#define __ZFS_COMMON__
|
||||
|
||||
#define SECTOR_SIZE 0x200
|
||||
#define SECTOR_BITS 9
|
||||
|
||||
|
||||
typedef enum zfs_endian {
|
||||
UNKNOWN_ENDIAN = -2,
|
||||
LITTLE_ENDIAN = -1,
|
||||
BIG_ENDIAN = 0
|
||||
} zfs_endian_t;
|
||||
|
||||
|
||||
/* Endian macros. */
|
||||
#define zfs_to_cpu16(x, a) (((a) == BIG_ENDIAN) ? be16_to_cpu(x) \
|
||||
: le16_to_cpu(x))
|
||||
#define cpu_to_zfs16(x, a) (((a) == BIG_ENDIAN) ? cpu_to_be16(x) \
|
||||
: cpu_to_le16(x))
|
||||
|
||||
#define zfs_to_cpu32(x, a) (((a) == BIG_ENDIAN) ? be32_to_cpu(x) \
|
||||
: le32_to_cpu(x))
|
||||
#define cpu_to_zfs32(x, a) (((a) == BIG_ENDIAN) ? cpu_to_be32(x) \
|
||||
: cpu_to_le32(x))
|
||||
|
||||
#define zfs_to_cpu64(x, a) (((a) == BIG_ENDIAN) ? be64_to_cpu(x) \
|
||||
: le64_to_cpu(x))
|
||||
#define cpu_to_zfs64(x, a) (((a) == BIG_ENDIAN) ? cpu_to_be64(x) \
|
||||
: cpu_to_le64(x))
|
||||
|
||||
|
||||
enum zfs_errors {
|
||||
ZFS_ERR_NONE = 0,
|
||||
ZFS_ERR_NOT_IMPLEMENTED_YET = -1,
|
||||
ZFS_ERR_BAD_FS = -2,
|
||||
ZFS_ERR_OUT_OF_MEMORY = -3,
|
||||
ZFS_ERR_FILE_NOT_FOUND = -4,
|
||||
ZFS_ERR_BAD_FILE_TYPE = -5,
|
||||
ZFS_ERR_OUT_OF_RANGE = -6,
|
||||
};
|
||||
|
||||
struct zfs_filesystem {
|
||||
|
||||
/* Block Device Descriptor */
|
||||
block_dev_desc_t *dev_desc;
|
||||
};
|
||||
|
||||
|
||||
extern block_dev_desc_t *zfs_dev_desc;
|
||||
|
||||
struct device_s {
|
||||
uint64_t part_length;
|
||||
};
|
||||
typedef struct device_s *device_t;
|
||||
|
||||
struct zfs_file {
|
||||
device_t device;
|
||||
uint64_t size;
|
||||
void *data;
|
||||
uint64_t offset;
|
||||
};
|
||||
|
||||
typedef struct zfs_file *zfs_file_t;
|
||||
|
||||
struct zfs_dirhook_info {
|
||||
int dir;
|
||||
int mtimeset;
|
||||
time_t mtime;
|
||||
time_t mtime2;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
struct zfs_filesystem *zfsget_fs(void);
|
||||
int init_fs(block_dev_desc_t *dev_desc);
|
||||
void deinit_fs(block_dev_desc_t *dev_desc);
|
||||
int zfs_open(zfs_file_t, const char *filename);
|
||||
uint64_t zfs_read(zfs_file_t, char *buf, uint64_t len);
|
||||
struct zfs_data *zfs_mount(device_t);
|
||||
int zfs_close(zfs_file_t);
|
||||
int zfs_ls(device_t dev, const char *path,
|
||||
int (*hook) (const char *, const struct zfs_dirhook_info *));
|
||||
int zfs_devread(int sector, int byte_offset, int byte_len, char *buf);
|
||||
int zfs_set_blk_dev(block_dev_desc_t *rbdd, int part);
|
||||
void zfs_unmount(struct zfs_data *data);
|
||||
int lzjb_decompress(void *, void *, uint32_t, uint32_t);
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user