]>
Commit | Line | Data |
---|---|---|
558d2836 A |
1 | /* |
2 | * Copyright (c) 2014-2015 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 hfs_hfs_extents_test_h | |
30 | #define hfs_hfs_extents_test_h | |
31 | ||
32 | // Stuff that allow us to build hfs_extents.c for testing | |
33 | ||
34 | #define KERNEL 1 | |
35 | #define __APPLE_API_PRIVATE 1 | |
36 | #define HFS_EXTENTS_TEST 1 | |
37 | ||
38 | #include <stdint.h> | |
39 | #include <sys/errno.h> | |
40 | #include <stdio.h> | |
41 | #include <stdbool.h> | |
42 | #include <string.h> | |
43 | #include <stdlib.h> | |
44 | #include <sys/param.h> | |
45 | #include <assert.h> | |
46 | #include <unistd.h> | |
47 | #include <sys/queue.h> | |
48 | ||
49 | #include "../core/hfs_format.h" | |
50 | ||
51 | #define VTOF(v) (v)->ffork | |
52 | #define VTOHFS(v) (v)->mount | |
53 | #define VNODE_IS_RSRC(v) (v)->is_rsrc | |
54 | #define VTOC(v) (v)->cnode | |
55 | ||
56 | struct BTreeHint{ | |
57 | unsigned long writeCount; | |
58 | u_int32_t nodeNum; // node the key was last seen in | |
59 | u_int16_t index; // index then key was last seen at | |
60 | u_int16_t reserved1; | |
61 | u_int32_t reserved2; | |
62 | }; | |
63 | typedef struct BTreeHint BTreeHint; | |
64 | ||
65 | typedef struct BTreeIterator { | |
66 | BTreeHint hint; | |
67 | uint16_t version; | |
68 | uint16_t reserved; | |
69 | uint32_t hitCount; // Total number of leaf records hit | |
70 | uint32_t maxLeafRecs; // Max leaf records over iteration | |
71 | struct extent_group *group; | |
72 | HFSPlusExtentKey key; | |
73 | } BTreeIterator; | |
74 | ||
75 | typedef struct filefork { | |
76 | uint32_t ff_blocks, ff_unallocblocks; | |
77 | LIST_HEAD(extent_groups, extent_group) groups; | |
78 | } filefork_t; | |
79 | ||
80 | typedef struct cnode { | |
81 | uint32_t c_fileid; | |
82 | filefork_t *c_datafork; | |
83 | } cnode_t; | |
84 | ||
85 | typedef struct hfsmount { | |
86 | cnode_t *hfs_extents_cp; | |
87 | uint32_t blockSize; | |
88 | } hfsmount_t; | |
89 | ||
90 | typedef struct vnode { | |
91 | filefork_t *ffork; | |
92 | hfsmount_t *mount; | |
93 | bool is_rsrc; | |
94 | cnode_t *cnode; | |
95 | } *vnode_t; | |
96 | ||
97 | struct FSBufferDescriptor { | |
98 | void * bufferAddress; | |
99 | uint32_t itemSize; | |
100 | uint32_t itemCount; | |
101 | }; | |
102 | typedef struct FSBufferDescriptor FSBufferDescriptor; | |
103 | ||
104 | static inline int32_t | |
105 | BTSearchRecord (__unused filefork_t *filePtr, | |
106 | __unused BTreeIterator *searchIterator, | |
107 | __unused FSBufferDescriptor *record, | |
108 | __unused u_int16_t *recordLen, | |
109 | __unused BTreeIterator *resultIterator ) | |
110 | { | |
111 | return ENOTSUP; | |
112 | } | |
113 | ||
114 | /* Constants for HFS fork types */ | |
115 | enum { | |
116 | kHFSDataForkType = 0x0, /* data fork */ | |
117 | kHFSResourceForkType = 0xff /* resource fork */ | |
118 | }; | |
119 | ||
120 | static inline void *hfs_malloc(size_t size) | |
121 | { | |
122 | return malloc(size); | |
123 | } | |
124 | ||
125 | static inline void hfs_free(void *ptr, __unused size_t size) | |
126 | { | |
127 | return free(ptr); | |
128 | } | |
129 | ||
130 | static inline __attribute__((const)) | |
131 | uint64_t hfs_blk_to_bytes(uint32_t blk, uint32_t blk_size) | |
132 | { | |
133 | return (uint64_t)blk * blk_size; // Avoid the overflow | |
134 | } | |
135 | ||
136 | int32_t BTDeleteRecord(filefork_t *filePtr, | |
137 | BTreeIterator *iterator); | |
138 | ||
139 | #define HFS_ALLOC_ROLL_BACK 0x800 //Reallocate blocks that were just deallocated | |
140 | typedef uint32_t hfs_block_alloc_flags_t; | |
141 | ||
142 | typedef struct hfs_alloc_extra_args hfs_alloc_extra_args_t; | |
143 | ||
144 | static inline errno_t hfs_block_alloc(__unused hfsmount_t *hfsmp, | |
145 | __unused HFSPlusExtentDescriptor *extent, | |
146 | __unused hfs_block_alloc_flags_t flags, | |
147 | __unused hfs_alloc_extra_args_t *extra_args) | |
148 | { | |
149 | return ENOTSUP; | |
150 | } | |
151 | ||
152 | #define BlockDeallocate(m, b, c, f) (int16_t)0 | |
153 | #define BTFlushPath(ff) (int32_t)0 | |
154 | ||
155 | static inline int hfs_flushvolumeheader(__unused struct hfsmount *hfsmp, | |
156 | __unused int waitfor, | |
157 | __unused int altflush) | |
158 | { | |
159 | return 0; | |
160 | } | |
161 | ||
162 | #define hfs_mark_inconsistent(m, r) (void)0 | |
163 | ||
164 | static inline errno_t MacToVFSError(errno_t err) | |
165 | { | |
166 | return err; | |
167 | } | |
168 | ||
169 | struct hfs_ext_iter; | |
170 | ||
171 | uint32_t hfs_total_blocks(const HFSPlusExtentDescriptor *ext, int count); | |
172 | errno_t hfs_ext_iter_next_group(struct hfs_ext_iter *iter); | |
173 | errno_t hfs_ext_iter_update(struct hfs_ext_iter *iter, | |
174 | HFSPlusExtentDescriptor *extents, | |
175 | int count, | |
176 | HFSPlusExtentRecord cat_extents); | |
177 | errno_t hfs_ext_iter_check_group(struct hfs_ext_iter *iter); | |
178 | ||
179 | static inline uint32_t ff_allocblocks(filefork_t *ff) | |
180 | { | |
181 | return ff->ff_blocks - ff->ff_unallocblocks; | |
182 | } | |
183 | ||
184 | #endif |