2 * Copyright (c) 2014-2015 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 #ifndef hfs_hfs_extents_test_h
30 #define hfs_hfs_extents_test_h
32 // Stuff that allow us to build hfs_extents.c for testing
35 #define __APPLE_API_PRIVATE 1
36 #define HFS_EXTENTS_TEST 1
39 #include <sys/errno.h>
44 #include <sys/param.h>
47 #include <sys/queue.h>
49 #include "../core/hfs_format.h"
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
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
63 typedef struct BTreeHint BTreeHint
;
65 typedef struct BTreeIterator
{
69 uint32_t hitCount
; // Total number of leaf records hit
70 uint32_t maxLeafRecs
; // Max leaf records over iteration
71 struct extent_group
*group
;
75 typedef struct filefork
{
76 uint32_t ff_blocks
, ff_unallocblocks
;
77 LIST_HEAD(extent_groups
, extent_group
) groups
;
80 typedef struct cnode
{
82 filefork_t
*c_datafork
;
85 typedef struct hfsmount
{
86 cnode_t
*hfs_extents_cp
;
90 typedef struct vnode
{
97 struct FSBufferDescriptor
{
102 typedef struct FSBufferDescriptor FSBufferDescriptor
;
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
)
114 /* Constants for HFS fork types */
116 kHFSDataForkType
= 0x0, /* data fork */
117 kHFSResourceForkType
= 0xff /* resource fork */
120 static inline void *hfs_malloc(size_t size
)
125 static inline void hfs_free(void *ptr
, __unused
size_t size
)
130 static inline __attribute__((const))
131 uint64_t hfs_blk_to_bytes(uint32_t blk
, uint32_t blk_size
)
133 return (uint64_t)blk
* blk_size
; // Avoid the overflow
136 int32_t BTDeleteRecord(filefork_t
*filePtr
,
137 BTreeIterator
*iterator
);
139 #define HFS_ALLOC_ROLL_BACK 0x800 //Reallocate blocks that were just deallocated
140 typedef uint32_t hfs_block_alloc_flags_t
;
142 typedef struct hfs_alloc_extra_args hfs_alloc_extra_args_t
;
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
)
152 #define BlockDeallocate(m, b, c, f) (int16_t)0
153 #define BTFlushPath(ff) (int32_t)0
155 static inline int hfs_flushvolumeheader(__unused
struct hfsmount
*hfsmp
,
156 __unused
int waitfor
,
157 __unused
int altflush
)
162 #define hfs_mark_inconsistent(m, r) (void)0
164 static inline errno_t
MacToVFSError(errno_t err
)
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
,
176 HFSPlusExtentRecord cat_extents
);
177 errno_t
hfs_ext_iter_check_group(struct hfs_ext_iter
*iter
);
179 static inline uint32_t ff_allocblocks(filefork_t
*ff
)
181 return ff
->ff_blocks
- ff
->ff_unallocblocks
;