1/*
2 * Copyright (c) 2000-2012 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29#ifndef _FSCK_JOURNAL_H
30#define _FSCK_JOURNAL_H
31
32#include <sys/cdefs.h>
33
34#include <sys/types.h>
35
36/*
37 * The guts of the journal:  a descriptor for which
38 * block number on the data disk is to be written.
39 */
40typedef struct block_info {
41	uint64_t	bnum;
42	uint32_t	bsize;
43	uint32_t	next;
44} __attribute__((__packed__)) block_info;
45
46/*
47 * A "transaction," for want of a better word.
48 * This contains a series of block_info, in the
49 * binfo array, which are used to modify the
50 * filesystem.
51 */
52typedef struct block_list_header {
53	uint16_t	max_blocks;
54	uint16_t	num_blocks;
55	uint32_t	bytes_used;
56	uint32_t	checksum;
57	uint32_t	pad;
58	block_info	binfo[1];
59} __attribute__((__packed__)) block_list_header;
60
61/*
62 * This is written to block zero of the journal and it
63 * maintains overall state about the journal.
64 */
65typedef struct journal_header {
66    int32_t        magic;
67    int32_t        endian;
68    off_t	 start;         // zero-based byte offset of the start of the first transaction
69    off_t	end;           // zero-based byte offset of where free space begins
70    off_t          size;          // size in bytes of the entire journal
71    int32_t        blhdr_size;    // size in bytes of each block_list_header in the journal
72    int32_t        checksum;
73    int32_t        jhdr_size;     // block size (in bytes) of the journal header
74    uint32_t       sequence_num;  // NEW FIELD: a monotonically increasing value assigned to all txn's
75} __attribute__((__packed__)) journal_header;
76
77#define JOURNAL_HEADER_MAGIC	0x4a4e4c78   // 'JNLx'
78#define	OLD_JOURNAL_HEADER_MAGIC	0x4a484452   // 'JHDR'
79#define ENDIAN_MAGIC	0x12345678
80
81//
82// we only checksum the original size of the journal_header to remain
83// backwards compatible.  the size of the original journal_header is
84// everything up to the the sequence_num field, hence we use the
85// offsetof macro to calculate the size.
86//
87#define JOURNAL_HEADER_CKSUM_SIZE  (offsetof(struct journal_header, sequence_num))
88
89#define OLD_JOURNAL_HEADER_MAGIC  0x4a484452   // 'JHDR'
90
91/*
92 * The function used by fsck_hfs to replay the journal.
93 * It's modeled on the kernel function.
94 *
95 * For the do_write_b block, the offset argument is in bytes --
96 * the journal replay code will convert from journal block to
97 * bytes.
98 */
99
100int	journal_open(int jdev,
101		     off_t         offset,
102		     off_t         journal_size,
103		     size_t        min_fs_block_size,
104		     uint32_t       flags,
105		     const char	*jdev_name,
106		     int (^do_write_b)(off_t, void *, size_t));
107
108#endif /* !_FSCK_JOURNAL_H */
109