return $self->{digest}->(@_);
}
-#XXX Parameterize the staleness counter stuff here
+sub _add_free_blist_sector { shift->_add_free_sector( 0, @_ ) }
+sub _add_free_data_sector { shift->_add_free_sector( 1, @_ ) }
+sub _add_free_index_sector { shift->_add_free_sector( 2, @_ ) }
+
sub _add_free_sector {
my $self = shift;
- my ($offset, $size) = @_;
+ my ($multiple, $offset, $size) = @_;
- my $chains_offset;
- # Data sector
- if ( $size == 256 ) {
- $chains_offset = $self->byte_size;
- }
- # Blist sector
- else {
- $chains_offset = 0;
- }
+ my $chains_offset = $multiple * $self->byte_size;
my $storage = $self->storage;
# Increment staleness.
+ # XXX Can this increment+modulo be done by "&= 0x1" ?
my $staleness = unpack( $StP{STALE_SIZE()}, $storage->read_at( $offset + SIG_SIZE, STALE_SIZE ) );
$staleness = ($staleness + 1 ) % ( 2 ** ( 8 * STALE_SIZE ) );
$storage->print_at( $offset + SIG_SIZE, pack( $StP{STALE_SIZE()}, $staleness ) );
$storage->print_at( $offset + SIG_SIZE + STALE_SIZE, $old_head );
}
+sub _request_blist_sector { shift->_request_sector( 0, @_ ) }
+sub _request_data_sector { shift->_request_sector( 1, @_ ) }
+sub _request_index_sector { shift->_request_sector( 2, @_ ) }
+
sub _request_sector {
my $self = shift;
- my ($size) = @_;
+ my ($multiple, $size) = @_;
- my $chains_offset;
- # Data sector
- if ( $size == 256 ) {
- $chains_offset = $self->byte_size;
- }
- # Blist sector
- else {
- $chains_offset = 0;
- }
+ my $chains_offset = $multiple * $self->byte_size;
my $old_head = $self->storage->read_at( $self->chains_loc + $chains_offset, $self->byte_size );
my $loc = unpack( $StP{$self->byte_size}, $old_head );
chr(0) x ($self->size - $self->base_size),
);
- $e->_add_free_sector(
- $self->offset, $self->size,
- );
+ my $free_meth = $self->free_meth;
+ $e->$free_meth( $self->offset, $self->size );
return;
}
# This is in bytes
sub size { return 256 }
+sub free_meth { return '_add_free_data_sector' }
sub clone {
my $self = shift;
unless ( $self->offset ) {
my $data_section = $self->size - $self->base_size - 1 * $engine->byte_size - 1;
- $self->{offset} = $engine->_request_sector( $self->size );
+ $self->{offset} = $engine->_request_data_sector( $self->size );
my $data = delete $self->{data};
my $dlen = length $data;
$chunk = substr( $data, 0, $this_len );
$dlen -= $data_section;
- $next_offset = $engine->_request_sector( $self->size );
+ $next_offset = $engine->_request_data_sector( $self->size );
$data = substr( $data, $this_len );
}
else {
unless ( $self->offset ) {
my $leftover = $self->size - $self->base_size - 1 * $engine->byte_size - 1;
- $self->{offset} = $engine->_request_sector( $self->size );
+ $self->{offset} = $engine->_request_data_sector( $self->size );
$engine->storage->print_at( $self->offset, $self->type ); # Sector type
# Skip staleness counter
$engine->storage->print_at( $self->offset + $self->base_size,
$class_offset = $class_sector->offset;
}
- $self->{offset} = $e->_request_sector( $self->size );
+ $self->{offset} = $e->_request_data_sector( $self->size );
$e->storage->print_at( $self->offset, $self->type ); # Sector type
# Skip staleness counter
$e->storage->print_at( $self->offset + $self->base_size,
pack( $StP{$e->byte_size}, 0 ), # Index/BList loc
pack( $StP{$e->byte_size}, $class_offset ), # Classname loc
- chr(0) x $leftover, # Zero-fill the rest
+ chr(0) x $leftover, # Zero-fill the rest
);
}
else {
unless ( $self->offset ) {
my $leftover = $self->size - $self->base_size;
- $self->{offset} = $engine->_request_sector( $self->size );
+ $self->{offset} = $engine->_request_blist_sector( $self->size );
$engine->storage->print_at( $self->offset, $engine->SIG_BLIST ); # Sector type
# Skip staleness counter
$engine->storage->print_at( $self->offset + $self->base_size,
return $self->{size};
}
+sub free_meth { return '_add_free_blist_sector' }
+
sub bucket_size {
my $self = shift;
unless ( $self->{bucket_size} ) {
unless ( $self->offset ) {
my $leftover = $self->size - $self->base_size;
- $self->{offset} = $engine->_request_sector( $self->size );
+ $self->{offset} = $engine->_request_index_sector( $self->size );
$engine->storage->print_at( $self->offset, $engine->SIG_BLIST ); # Sector type
# Skip staleness counter
$engine->storage->print_at( $self->offset + $self->base_size,
return $self->{size};
}
+sub free_meth { return '_add_free_index_sector' }
+
1;
__END__