1N/A/*
1N/A libparted - a library for manipulating disk partitions
1N/A Copyright (C) 2004-2005, 2007, 2009-2010 Free Software Foundation,
1N/A Inc.
1N/A
1N/A This program is free software; you can redistribute it and/or modify
1N/A it under the terms of the GNU General Public License as published by
1N/A the Free Software Foundation; either version 3 of the License, or
1N/A (at your option) any later version.
1N/A
1N/A This program is distributed in the hope that it will be useful,
1N/A but WITHOUT ANY WARRANTY; without even the implied warranty of
1N/A MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1N/A GNU General Public License for more details.
1N/A
1N/A You should have received a copy of the GNU General Public License
1N/A along with this program. If not, see <http://www.gnu.org/licenses/>.
1N/A*/
1N/A
1N/A#ifndef _CACHE_H
1N/A#define _CACHE_H
1N/A
1N/A#include <parted/parted.h>
1N/A#include <parted/endian.h>
1N/A#include <parted/debug.h>
1N/A
1N/A#include "hfs.h"
1N/A
1N/A/* CR => CACHE REF */
1N/A#define CR_NULL 0 /* reserved */
1N/A#define CR_PRIM_CAT 1
1N/A#define CR_PRIM_EXT 2
1N/A#define CR_PRIM_ATTR 3
1N/A#define CR_PRIM_ALLOC 4
1N/A#define CR_PRIM_START 5
1N/A#define CR_BTREE_CAT 6
1N/A#define CR_BTREE_ATTR 7
1N/A#define CR_BTREE_EXT_0 8
1N/A#define CR_BTREE_EXT_CAT 9
1N/A#define CR_BTREE_EXT_EXT 10 /* should not happen ! */
1N/A#define CR_BTREE_EXT_ATTR 11
1N/A#define CR_BTREE_EXT_ALLOC 12
1N/A#define CR_BTREE_EXT_START 13 /* unneeded in current code */
1N/A#define CR_BTREE_CAT_JIB 14 /* journal info block */
1N/A#define CR_BTREE_CAT_JL 15 /* journal */
1N/A/* 16 -> 31 || high order bit */ /* reserved */
1N/A
1N/A/* tuning */
1N/A#define CR_SHIFT 8 /* number of bits to shift start_block by */
1N/A /* to get the index of the linked list */
1N/A#define CR_OVER_DIV 16 /* alloc a table for (1+1/CR_OVER_DIV) *
1N/A file_number + CR_ADD_CST */
1N/A#define CR_ADD_CST 16
1N/A#define CR_NEW_ALLOC_DIV 4 /* divide the size of the first alloc table
1N/A by this value to allocate next tables */
1N/A
1N/A/* See DOC for an explaination of this structure */
1N/A/* Access read only from outside cache.c */
1N/Astruct _HfsCPrivateExtent {
1N/A struct _HfsCPrivateExtent* next;
1N/A uint32_t ext_start;
1N/A uint32_t ext_length;
1N/A uint32_t ref_block;
1N/A uint16_t ref_offset;
1N/A uint8_t sect_by_block;
1N/A unsigned where : 5;
1N/A unsigned ref_index : 3; /* 0 -> 7 */
1N/A};
1N/Atypedef struct _HfsCPrivateExtent HfsCPrivateExtent;
1N/A
1N/A/* Internaly used by cache.c for custom memory managment only */
1N/Astruct _HfsCPrivateCacheTable {
1N/A struct _HfsCPrivateCacheTable* next_cache;
1N/A HfsCPrivateExtent* table;
1N/A unsigned int table_size;
1N/A unsigned int table_first_free;
1N/A /* first_elemt ? */
1N/A};
1N/Atypedef struct _HfsCPrivateCacheTable HfsCPrivateCacheTable;
1N/A
1N/A/* Internaly used by cache.c for custom memory managment
1N/A and cache handling only */
1N/Astruct _HfsCPrivateCache {
1N/A HfsCPrivateCacheTable* table_list;
1N/A HfsCPrivateCacheTable* last_table;
1N/A HfsCPrivateExtent** linked_ref;
1N/A unsigned int linked_ref_size;
1N/A unsigned int block_number;
1N/A unsigned int first_cachetable_size;
1N/A unsigned int needed_alloc_size;
1N/A};
1N/Atypedef struct _HfsCPrivateCache HfsCPrivateCache;
1N/A
1N/AHfsCPrivateCache*
1N/Ahfsc_new_cache(unsigned int block_number, unsigned int file_number);
1N/A
1N/Avoid
1N/Ahfsc_delete_cache(HfsCPrivateCache* cache);
1N/A
1N/AHfsCPrivateExtent*
1N/Ahfsc_cache_add_extent(HfsCPrivateCache* cache, uint32_t start, uint32_t length,
1N/A uint32_t block, uint16_t offset, uint8_t sbb,
1N/A uint8_t where, uint8_t index);
1N/A
1N/AHfsCPrivateExtent*
1N/Ahfsc_cache_search_extent(HfsCPrivateCache* cache, uint32_t start);
1N/A
1N/AHfsCPrivateExtent*
1N/Ahfsc_cache_move_extent(HfsCPrivateCache* cache, uint32_t old_start,
1N/A uint32_t new_start);
1N/A
1N/Astatic __inline__ unsigned int
1N/Ahfsc_cache_needed_buffer(HfsCPrivateCache* cache)
1N/A{
1N/A return cache->needed_alloc_size;
1N/A}
1N/A
1N/A#endif /* _CACHE_H */