1b1b8ab3lling/*
2b1b8ab3lling *  GRUB  --  GRand Unified Bootloader
3b1b8ab3lling *  Copyright (C) 1999,2000,2001,2002,2003,2004  Free Software Foundation, Inc.
4b1b8ab3lling *
5b1b8ab3lling *  This program is free software; you can redistribute it and/or modify
6b1b8ab3lling *  it under the terms of the GNU General Public License as published by
7b1b8ab3lling *  the Free Software Foundation; either version 2 of the License, or
8b1b8ab3lling *  (at your option) any later version.
9b1b8ab3lling *
10b1b8ab3lling *  This program is distributed in the hope that it will be useful,
11b1b8ab3lling *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12b1b8ab3lling *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13b1b8ab3lling *  GNU General Public License for more details.
14b1b8ab3lling *
15b1b8ab3lling *  You should have received a copy of the GNU General Public License
16b1b8ab3lling *  along with this program; if not, write to the Free Software
17b1b8ab3lling *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18b1b8ab3lling */
19b1b8ab3lling/*
200a586ceMark Shellenbaum * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
21b1b8ab3lling * Use is subject to license terms.
22b1b8ab3lling */
23e94f268Matthew Ahrens/*
24e94f268Matthew Ahrens * Copyright (c) 2014 by Delphix. All rights reserved.
25e94f268Matthew Ahrens */
26b1b8ab3lling
27b1b8ab3lling#ifndef	_SYS_DNODE_H
28b1b8ab3lling#define	_SYS_DNODE_H
29b1b8ab3lling
30b1b8ab3lling/*
31b1b8ab3lling * Fixed constants.
32b1b8ab3lling */
33b1b8ab3lling#define	DNODE_SHIFT		9	/* 512 bytes */
34e94f268Matthew Ahrens#define	DN_MIN_INDBLKSHIFT	12	/* 4k */
35b1b8ab3lling#define	DN_MAX_INDBLKSHIFT	14	/* 16k */
36b1b8ab3lling#define	DNODE_BLOCK_SHIFT	14	/* 16k */
37b1b8ab3lling#define	DNODE_CORE_SIZE		64	/* 64 bytes for dnode sans blkptrs */
38b1b8ab3lling#define	DN_MAX_OBJECT_SHIFT	48	/* 256 trillion (zfs_fid_t limit) */
39b1b8ab3lling#define	DN_MAX_OFFSET_SHIFT	64	/* 2^64 bytes in a dnode */
40b1b8ab3lling
41b1b8ab3lling/*
42b1b8ab3lling * Derived constants.
43b1b8ab3lling */
44b1b8ab3lling#define	DNODE_SIZE	(1 << DNODE_SHIFT)
45b1b8ab3lling#define	DN_MAX_NBLKPTR	((DNODE_SIZE - DNODE_CORE_SIZE) >> SPA_BLKPTRSHIFT)
46b1b8ab3lling#define	DN_MAX_BONUSLEN	(DNODE_SIZE - DNODE_CORE_SIZE - (1 << SPA_BLKPTRSHIFT))
47b1b8ab3lling#define	DN_MAX_OBJECT	(1ULL << DN_MAX_OBJECT_SHIFT)
48b1b8ab3lling
49b1b8ab3lling#define	DNODES_PER_BLOCK_SHIFT	(DNODE_BLOCK_SHIFT - DNODE_SHIFT)
50b1b8ab3lling#define	DNODES_PER_BLOCK	(1ULL << DNODES_PER_BLOCK_SHIFT)
51b1b8ab3lling#define	DNODES_PER_LEVEL_SHIFT	(DN_MAX_INDBLKSHIFT - SPA_BLKPTRSHIFT)
52b1b8ab3lling
530a586ceMark Shellenbaum#define	DNODE_FLAG_SPILL_BLKPTR (1<<2)
540a586ceMark Shellenbaum
55b1b8ab3lling#define	DN_BONUS(dnp)	((void*)((dnp)->dn_bonus + \
56b1b8ab3lling	(((dnp)->dn_nblkptr - 1) * sizeof (blkptr_t))))
57b1b8ab3lling
58b1b8ab3llingtypedef struct dnode_phys {
59b1b8ab3lling	uint8_t dn_type;		/* dmu_object_type_t */
60b1b8ab3lling	uint8_t dn_indblkshift;		/* ln2(indirect block size) */
61b1b8ab3lling	uint8_t dn_nlevels;		/* 1=dn_blkptr->data blocks */
62b1b8ab3lling	uint8_t dn_nblkptr;		/* length of dn_blkptr */
63b1b8ab3lling	uint8_t dn_bonustype;		/* type of data in bonus buffer */
64b1b8ab3lling	uint8_t	dn_checksum;		/* ZIO_CHECKSUM type */
65b1b8ab3lling	uint8_t	dn_compress;		/* ZIO_COMPRESS type */
66b1b8ab3lling	uint8_t dn_flags;		/* DNODE_FLAG_* */
67b1b8ab3lling	uint16_t dn_datablkszsec;	/* data block size in 512b sectors */
68b1b8ab3lling	uint16_t dn_bonuslen;		/* length of dn_bonus */
69b1b8ab3lling	uint8_t dn_pad2[4];
70b1b8ab3lling
71b1b8ab3lling	/* accounting is protected by dn_dirty_mtx */
72b1b8ab3lling	uint64_t dn_maxblkid;		/* largest allocated block ID */
73b1b8ab3lling	uint64_t dn_used;		/* bytes (or sectors) of disk space */
74b1b8ab3lling
75b1b8ab3lling	uint64_t dn_pad3[4];
76b1b8ab3lling
77b1b8ab3lling	blkptr_t dn_blkptr[1];
780a586ceMark Shellenbaum	uint8_t dn_bonus[DN_MAX_BONUSLEN - sizeof (blkptr_t)];
790a586ceMark Shellenbaum	blkptr_t dn_spill;
80b1b8ab3lling} dnode_phys_t;
81b1b8ab3lling
82b1b8ab3lling#endif	/* _SYS_DNODE_H */
83