]>
Commit | Line | Data |
---|---|---|
b4c24cb9 A |
1 | |
2 | /* | |
3 | * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved. | |
4 | * | |
5 | * @APPLE_LICENSE_HEADER_START@ | |
6 | * | |
de355530 A |
7 | * The contents of this file constitute Original Code as defined in and |
8 | * are subject to the Apple Public Source License Version 1.1 (the | |
9 | * "License"). You may not use this file except in compliance with the | |
10 | * License. Please obtain a copy of the License at | |
11 | * http://www.apple.com/publicsource and read it before using this file. | |
b4c24cb9 | 12 | * |
de355530 A |
13 | * This Original Code and all software distributed under the License are |
14 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
b4c24cb9 A |
15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
de355530 A |
17 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the |
18 | * License for the specific language governing rights and limitations | |
19 | * under the License. | |
b4c24cb9 A |
20 | * |
21 | * @APPLE_LICENSE_HEADER_END@ | |
22 | */ | |
23 | /* | |
24 | * This header contains the structures and function prototypes | |
25 | * for the vfs journaling code. The data types are not meant | |
26 | * to be modified by user code. Just use the functions and do | |
27 | * not mess around with the structs. | |
28 | */ | |
29 | #ifndef _SYS_VFS_JOURNAL_H_ | |
30 | #define _SYS_VFS_JOURNAL_H_ | |
31 | ||
32 | #include <sys/appleapiopts.h> | |
33 | ||
34 | #ifdef __APPLE_API_UNSTABLE | |
35 | ||
36 | #include <sys/types.h> | |
37 | ||
38 | typedef struct block_info { | |
39 | off_t bnum; // block # on the file system device | |
40 | size_t bsize; // in bytes | |
41 | struct buf *bp; | |
42 | } block_info; | |
43 | ||
44 | typedef struct block_list_header { | |
45 | u_int16_t max_blocks; // max number of blocks in this chunk | |
46 | u_int16_t num_blocks; // number of valid block numbers in block_nums | |
47 | int32_t bytes_used; // how many bytes of this tbuffer are used | |
48 | int32_t checksum; // on-disk: checksum of this header and binfo[0] | |
49 | int32_t pad; // pad out to 16 bytes | |
50 | block_info binfo[1]; // so we can reference them by name | |
51 | } block_list_header; | |
52 | ||
53 | ||
54 | struct journal; | |
55 | ||
56 | typedef struct transaction { | |
57 | int tbuffer_size; // in bytes | |
58 | char *tbuffer; // memory copy of the transaction | |
59 | block_list_header *blhdr; // points to the first byte of tbuffer | |
60 | int num_blhdrs; // how many buffers we've allocated | |
61 | int total_bytes; // total # of bytes in transaction | |
62 | int num_flushed; // how many bytes have been flushed | |
63 | int num_killed; // how many bytes were "killed" | |
64 | off_t journal_start; // where in the journal this transaction starts | |
65 | off_t journal_end; // where in the journal this transaction ends | |
66 | struct journal *jnl; // ptr back to the journal structure | |
67 | struct transaction *next; // list of tr's (either completed or to be free'd) | |
68 | } transaction; | |
69 | ||
70 | ||
71 | /* | |
72 | * This is written to block zero of the journal and it | |
73 | * maintains overall state about the journal. | |
74 | */ | |
75 | typedef struct journal_header { | |
76 | int32_t magic; | |
77 | int32_t endian; | |
78 | volatile off_t start; // zero-based byte offset of the start of the first transaction | |
79 | volatile off_t end; // zero-based byte offset of where free space begins | |
80 | off_t size; // size in bytes of the entire journal | |
81 | int32_t blhdr_size; // size in bytes of each block_list_header in the journal | |
82 | int32_t checksum; | |
83 | int32_t jhdr_size; // block size (in bytes) of the journal header | |
84 | } journal_header; | |
85 | ||
86 | #define JOURNAL_HEADER_MAGIC 0x4a4e4c78 // 'JNLx' | |
87 | #define ENDIAN_MAGIC 0x12345678 | |
88 | ||
89 | #define OLD_JOURNAL_HEADER_MAGIC 0x4a484452 // 'JHDR' | |
90 | ||
91 | ||
92 | /* | |
93 | * In memory structure about the journal. | |
94 | */ | |
95 | typedef struct journal { | |
96 | struct vnode *jdev; // vnode of the device where the journal lives | |
97 | off_t jdev_offset; // byte offset to the start of the journal | |
98 | ||
99 | struct vnode *fsdev; // vnode of the file system device | |
100 | ||
101 | void (*flush)(void *arg); // fs callback to flush meta data blocks | |
102 | void *flush_arg; // arg that's passed to flush() | |
103 | ||
104 | int32_t flags; | |
105 | int32_t tbuffer_size; // default transaction buffer size | |
106 | ||
107 | char *header_buf; // in-memory copy of the journal header | |
108 | journal_header *jhdr; // points to the first byte of header_buf | |
109 | ||
110 | transaction *cur_tr; // for group-commit | |
111 | transaction *completed_trs; // out-of-order transactions that completed | |
112 | transaction *active_tr; // for nested transactions | |
113 | int32_t nested_count; // for nested transactions | |
114 | void *owner; // a ptr that's unique to the calling process | |
115 | ||
116 | transaction *tr_freeme; // transaction structs that need to be free'd | |
117 | ||
118 | volatile off_t active_start; // the active start that we only keep in memory | |
119 | simple_lock_data_t old_start_lock; // guard access | |
120 | volatile off_t old_start[16]; // this is how we do lazy start update | |
121 | ||
122 | semaphore_t jsem; | |
123 | } journal; | |
124 | ||
125 | /* internal-only journal flags (top 16 bits) */ | |
126 | #define JOURNAL_CLOSE_PENDING 0x00010000 | |
127 | #define JOURNAL_INVALID 0x00020000 | |
128 | ||
129 | /* journal_open/create options are always in the low-16 bits */ | |
130 | #define JOURNAL_OPTION_FLAGS_MASK 0x0000ffff | |
131 | ||
132 | /* | |
133 | * Prototypes. | |
134 | */ | |
135 | ||
136 | /* | |
137 | * Call journal_create() to create a new journal. You only | |
138 | * call this once, typically at file system creation time. | |
139 | * | |
140 | * The "jvp" argument is the vnode where the journal is written. | |
141 | * The journal starts at "offset" and is "journal_size" bytes long. | |
142 | * | |
143 | * The "fsvp" argument is the vnode of your file system. It may be | |
144 | * the same as "jvp". | |
145 | * | |
146 | * The "min_fs_block_size" argument is the minimum block size | |
147 | * (in bytes) that the file system will ever write. Typically | |
148 | * this is the block size of the file system (1k, 4k, etc) but | |
149 | * on HFS+ it is the minimum block size of the underlying device. | |
150 | * | |
151 | * The flags argument lets you disable group commit if you | |
152 | * want tighter guarantees on transactions (in exchange for | |
153 | * lower performance). | |
154 | * | |
155 | * The tbuffer_size is the size of the transaction buffer | |
156 | * used by the journal. If you specify zero, the journal code | |
157 | * will use a reasonable defaults. The tbuffer_size should | |
158 | * be an integer multiple of the min_fs_block_size. | |
159 | * | |
160 | * Returns a valid journal pointer or NULL if one could not | |
161 | * be created. | |
162 | */ | |
163 | journal *journal_create(struct vnode *jvp, | |
164 | off_t offset, | |
165 | off_t journal_size, | |
166 | struct vnode *fsvp, | |
167 | size_t min_fs_block_size, | |
168 | int32_t flags, | |
169 | int32_t tbuffer_size, | |
170 | void (*flush)(void *arg), | |
171 | void *arg); | |
172 | ||
173 | /* | |
174 | * Call journal_open() when mounting an existing file system | |
175 | * that has a previously created journal. It will take care | |
176 | * of validating the journal and replaying it if necessary. | |
177 | * | |
178 | * See journal_create() for a description of the arguments. | |
179 | * | |
180 | * Returns a valid journal pointer of NULL if it runs into | |
181 | * trouble reading/playing back the journal. | |
182 | */ | |
183 | journal *journal_open(struct vnode *jvp, | |
184 | off_t offset, | |
185 | off_t journal_size, | |
186 | struct vnode *fsvp, | |
187 | size_t min_fs_block_size, | |
188 | int32_t flags, | |
189 | int32_t tbuffer_size, | |
190 | void (*flush)(void *arg), | |
191 | void *arg); | |
192 | ||
193 | /* | |
194 | * Call journal_close() just before your file system is unmounted. | |
195 | * It flushes any outstanding transactions and makes sure the | |
196 | * journal is in a consistent state. | |
197 | */ | |
198 | void journal_close(journal *journal); | |
199 | ||
200 | /* | |
201 | * flags for journal_create/open. only can use | |
202 | * the low 16 bits for flags because internal | |
203 | * bits go in the high 16. | |
204 | */ | |
205 | #define JOURNAL_NO_GROUP_COMMIT 0x00000001 | |
206 | #define JOURNAL_RESET 0x00000002 | |
207 | ||
208 | /* | |
209 | * Transaction related functions. | |
210 | * | |
211 | * Before you start modifying file system meta data, you | |
212 | * should call journal_start_transaction(). Then before | |
213 | * you modify each block, call journal_modify_block_start() | |
214 | * and when you're done, journal_modify_block_end(). When | |
215 | * you've modified the last block as part of a transaction, | |
216 | * call journal_end_transaction() to commit the changes. | |
217 | * | |
218 | * If you decide to abort the modifications to a block you | |
219 | * should call journal_modify_block_abort(). | |
220 | * | |
221 | * If as part of a transaction you need want to throw out | |
222 | * any previous copies of a block (because it got deleted) | |
223 | * then call journal_kill_block(). This will mark it so | |
224 | * that the journal does not play it back (effectively | |
225 | * dropping it). | |
226 | */ | |
227 | int journal_start_transaction(journal *jnl); | |
228 | int journal_modify_block_start(journal *jnl, struct buf *bp); | |
229 | int journal_modify_block_abort(journal *jnl, struct buf *bp); | |
230 | int journal_modify_block_end(journal *jnl, struct buf *bp); | |
231 | int journal_kill_block(journal *jnl, struct buf *bp); | |
232 | int journal_end_transaction(journal *jnl); | |
233 | ||
234 | int journal_active(journal *jnl); | |
235 | int journal_flush(journal *jnl); | |
236 | ||
237 | #endif /* __APPLE_API_UNSTABLE */ | |
238 | #endif /* !_SYS_VFS_JOURNAL_H_ */ |