Loading...
Searching...
No Matches
cache.h
Go to the documentation of this file.
/*
libparted - a library for manipulating disk partitions
Copyright (C) 2004-2005, 2007, 2009-2014, 2019-2023, 2026 Free Software
Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _CACHE_H
#define _CACHE_H
#include <parted/parted.h>
#include <parted/endian.h>
#include <parted/debug.h>
#include "hfs.h"
/* CR => CACHE REF */
#define CR_NULL 0 /* reserved */
#define CR_PRIM_CAT 1
#define CR_PRIM_EXT 2
#define CR_PRIM_ATTR 3
#define CR_PRIM_ALLOC 4
#define CR_PRIM_START 5
#define CR_BTREE_CAT 6
#define CR_BTREE_ATTR 7
#define CR_BTREE_EXT_0 8
#define CR_BTREE_EXT_CAT 9
#define CR_BTREE_EXT_EXT 10 /* should not happen ! */
#define CR_BTREE_EXT_ATTR 11
#define CR_BTREE_EXT_ALLOC 12
#define CR_BTREE_EXT_START 13 /* unneeded in current code */
#define CR_BTREE_CAT_JIB 14 /* journal info block */
#define CR_BTREE_CAT_JL 15 /* journal */
/* 16 -> 31 || high order bit */ /* reserved */
/* tuning */
#define CR_SHIFT 8 /* number of bits to shift start_block by */
/* to get the index of the linked list */
#define CR_OVER_DIV 16 /* alloc a table for (1+1/CR_OVER_DIV) *
file_number + CR_ADD_CST */
#define CR_ADD_CST 16
#define CR_NEW_ALLOC_DIV 4 /* divide the size of the first alloc table
by this value to allocate next tables */
/* See DOC for an explaination of this structure */
/* Access read only from outside cache.c */
struct _HfsCPrivateExtent {
struct _HfsCPrivateExtent* next;
uint32_t ext_start;
uint32_t ext_length;
uint32_t ref_block;
uint16_t ref_offset;
uint8_t sect_by_block;
unsigned where : 5;
unsigned ref_index : 3; /* 0 -> 7 */
};
typedef struct _HfsCPrivateExtent HfsCPrivateExtent;
/* Internaly used by cache.c for custom memory managment only */
struct _HfsCPrivateCacheTable {
struct _HfsCPrivateCacheTable* next_cache;
HfsCPrivateExtent* table;
unsigned int table_size;
unsigned int table_first_free;
/* first_elemt ? */
};
typedef struct _HfsCPrivateCacheTable HfsCPrivateCacheTable;
/* Internaly used by cache.c for custom memory managment
and cache handling only */
struct _HfsCPrivateCache {
HfsCPrivateCacheTable* table_list;
HfsCPrivateCacheTable* last_table;
HfsCPrivateExtent** linked_ref;
unsigned int linked_ref_size;
unsigned int block_number;
unsigned int first_cachetable_size;
unsigned int needed_alloc_size;
};
typedef struct _HfsCPrivateCache HfsCPrivateCache;
HfsCPrivateCache*
hfsc_new_cache(unsigned int block_number, unsigned int file_number);
void
hfsc_delete_cache(HfsCPrivateCache* cache);
HfsCPrivateExtent*
hfsc_cache_add_extent(HfsCPrivateCache* cache, uint32_t start, uint32_t length,
uint32_t block, uint16_t offset, uint8_t sbb,
uint8_t where, uint8_t index);
HfsCPrivateExtent*
hfsc_cache_search_extent(HfsCPrivateCache* cache, uint32_t start);
HfsCPrivateExtent*
hfsc_cache_move_extent(HfsCPrivateCache* cache, uint32_t old_start,
uint32_t new_start);
static __inline__ unsigned int
hfsc_cache_needed_buffer(HfsCPrivateCache* cache)
{
return cache->needed_alloc_size;
}
#endif /* _CACHE_H */
hfsc_delete_cache
void hfsc_delete_cache(HfsCPrivateCache *cache)
Definition cache.c:112
hfsc_cache_search_extent
HfsCPrivateExtent * hfsc_cache_search_extent(HfsCPrivateCache *cache, uint32_t start)
Definition cache.c:177
HfsCPrivateExtent
struct _HfsCPrivateExtent HfsCPrivateExtent
Definition cache.h:67
hfsc_cache_move_extent
HfsCPrivateExtent * hfsc_cache_move_extent(HfsCPrivateCache *cache, uint32_t old_start, uint32_t new_start)
Definition cache.c:194
HfsCPrivateCacheTable
struct _HfsCPrivateCacheTable HfsCPrivateCacheTable
Definition cache.h:77
hfsc_cache_add_extent
HfsCPrivateExtent * hfsc_cache_add_extent(HfsCPrivateCache *cache, uint32_t start, uint32_t length, uint32_t block, uint16_t offset, uint8_t sbb, uint8_t where, uint8_t index)
Definition cache.c:120
HfsCPrivateCache
struct _HfsCPrivateCache HfsCPrivateCache
Definition cache.h:90
hfsc_new_cache
HfsCPrivateCache * hfsc_new_cache(unsigned int block_number, unsigned int file_number)
Definition cache.c:60
debug.h
start
uint32_t start
Definition dos.c:4
length
uint32_t length
Definition dos.c:5
endian.h
offset
offset
Definition fdasd.h:264
cache
unsigned char cache
Definition fdasd.h:13
parted.h
hfs.h
_HfsCPrivateCacheTable
Definition cache.h:70
_HfsCPrivateCacheTable::table
HfsCPrivateExtent * table
Definition cache.h:72
_HfsCPrivateCacheTable::table_first_free
unsigned int table_first_free
Definition cache.h:74
_HfsCPrivateCacheTable::table_size
unsigned int table_size
Definition cache.h:73
_HfsCPrivateCacheTable::next_cache
struct _HfsCPrivateCacheTable * next_cache
Definition cache.h:71
_HfsCPrivateCache
Definition cache.h:81
_HfsCPrivateCache::linked_ref_size
unsigned int linked_ref_size
Definition cache.h:85
_HfsCPrivateCache::last_table
HfsCPrivateCacheTable * last_table
Definition cache.h:83
_HfsCPrivateCache::needed_alloc_size
unsigned int needed_alloc_size
Definition cache.h:88
_HfsCPrivateCache::block_number
unsigned int block_number
Definition cache.h:86
_HfsCPrivateCache::first_cachetable_size
unsigned int first_cachetable_size
Definition cache.h:87
_HfsCPrivateCache::table_list
HfsCPrivateCacheTable * table_list
Definition cache.h:82
_HfsCPrivateCache::linked_ref
HfsCPrivateExtent ** linked_ref
Definition cache.h:84
_HfsCPrivateExtent
Definition cache.h:57
_HfsCPrivateExtent::ref_block
uint32_t ref_block
Definition cache.h:61
_HfsCPrivateExtent::where
unsigned where
Definition cache.h:64
_HfsCPrivateExtent::ref_index
unsigned ref_index
Definition cache.h:65
_HfsCPrivateExtent::ext_start
uint32_t ext_start
Definition cache.h:59
_HfsCPrivateExtent::ref_offset
uint16_t ref_offset
Definition cache.h:62
_HfsCPrivateExtent::ext_length
uint32_t ext_length
Definition cache.h:60
_HfsCPrivateExtent::sect_by_block
uint8_t sect_by_block
Definition cache.h:63
_HfsCPrivateExtent::next
struct _HfsCPrivateExtent * next
Definition cache.h:58