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