1 /* 2 libparted - a library for manipulating disk partitions 3 Copyright (C) 2004, 2005, 2007 Free Software Foundation, Inc. 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; either version 3 of the License, or 8 (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program. If not, see <http://www.gnu.org/licenses/>. 17 */ 18 19 #ifndef _CACHE_H 20 #define _CACHE_H 21 22 #include <parted/parted.h> 23 #include <parted/endian.h> 24 #include <parted/debug.h> 25 26 #include "hfs.h" 27 28 /* CR => CACHE REF */ 29 #define CR_NULL 0 /* reserved */ 30 #define CR_PRIM_CAT 1 31 #define CR_PRIM_EXT 2 32 #define CR_PRIM_ATTR 3 33 #define CR_PRIM_ALLOC 4 34 #define CR_PRIM_START 5 35 #define CR_BTREE_CAT 6 36 #define CR_BTREE_ATTR 7 37 #define CR_BTREE_EXT_0 8 38 #define CR_BTREE_EXT_CAT 9 39 #define CR_BTREE_EXT_EXT 10 /* should not happen ! */ 40 #define CR_BTREE_EXT_ATTR 11 41 #define CR_BTREE_EXT_ALLOC 12 42 #define CR_BTREE_EXT_START 13 /* unneeded in current code */ 43 #define CR_BTREE_CAT_JIB 14 /* journal info block */ 44 #define CR_BTREE_CAT_JL 15 /* journal */ 45 /* 16 -> 31 || high order bit */ /* reserved */ 46 47 /* tuning */ 48 #define CR_SHIFT 8 /* number of bits to shift start_block by */ 49 /* to get the index of the linked list */ 50 #define CR_OVER_DIV 16 /* alloc a table for (1+1/CR_OVER_DIV) * 51 file_number + CR_ADD_CST */ 52 #define CR_ADD_CST 16 53 #define CR_NEW_ALLOC_DIV 4 /* divide the size of the first alloc table 54 by this value to allocate next tables */ 55 56 /* See DOC for an explaination of this structure */ 57 /* Access read only from outside cache.c */ 58 struct _HfsCPrivateExtent { 59 struct _HfsCPrivateExtent* next; 60 uint32_t ext_start; 61 uint32_t ext_length; 62 uint32_t ref_block; 63 uint16_t ref_offset; 64 uint8_t sect_by_block; 65 unsigned where : 5; 66 unsigned ref_index : 3; /* 0 -> 7 */ 67 }; 68 typedef struct _HfsCPrivateExtent HfsCPrivateExtent; 69 70 /* Internaly used by cache.c for custom memory managment only */ 71 struct _HfsCPrivateCacheTable { 72 struct _HfsCPrivateCacheTable* next_cache; 73 HfsCPrivateExtent* table; 74 unsigned int table_size; 75 unsigned int table_first_free; 76 /* first_elemt ? */ 77 }; 78 typedef struct _HfsCPrivateCacheTable HfsCPrivateCacheTable; 79 80 /* Internaly used by cache.c for custom memory managment 81 and cache handling only */ 82 struct _HfsCPrivateCache { 83 HfsCPrivateCacheTable* table_list; 84 HfsCPrivateCacheTable* last_table; 85 HfsCPrivateExtent** linked_ref; 86 unsigned int linked_ref_size; 87 unsigned int block_number; 88 unsigned int first_cachetable_size; 89 unsigned int needed_alloc_size; 90 }; 91 typedef struct _HfsCPrivateCache HfsCPrivateCache; 92 93 HfsCPrivateCache* 94 hfsc_new_cache(unsigned int block_number, unsigned int file_number); 95 96 void 97 hfsc_delete_cache(HfsCPrivateCache* cache); 98 99 HfsCPrivateExtent* 100 hfsc_cache_add_extent(HfsCPrivateCache* cache, uint32_t start, uint32_t length, 101 uint32_t block, uint16_t offset, uint8_t sbb, 102 uint8_t where, uint8_t index); 103 104 HfsCPrivateExtent* 105 hfsc_cache_search_extent(HfsCPrivateCache* cache, uint32_t start); 106 107 HfsCPrivateExtent* 108 hfsc_cache_move_extent(HfsCPrivateCache* cache, uint32_t old_start, 109 uint32_t new_start); 110 111 static __inline__ unsigned int 112 hfsc_cache_needed_buffer(HfsCPrivateCache* cache) 113 { 114 return cache->needed_alloc_size; 115 } 116 117 #endif /* _CACHE_H */