Commit da12f304 authored by Leigh B Stoller's avatar Leigh B Stoller
Browse files

Couple of routines to compute PartitionSize and Chunks() for an

image descriptor.
parent 0fb5397d
......@@ -1860,6 +1860,40 @@ sub SetRange($$$;$$)
return $self->Update($argref);
}
#
# Compute a rough approximation of the partition size needed for an image.
# Return megabytes.
#
sub PartitionSize($)
{
my ($self) = @_;
my $lba_size = $self->lba_size();
my $lba_low = $self->lba_low();
my $lba_high = $self->lba_high();
return undef
if (!(defined($lba_size) && defined($lba_low) && defined($lba_high)));
return (($lba_high - $lba_low + 1) / (1024 / $lba_size)) / 1024;
}
#
# Chunks, the amount of space needed to store the image, say in an LVM.
# Return megabytes.
#
sub Chunks($)
{
my ($self) = @_;
my $size = $self->size();
return undef
if (!defined($size));
# XXX assumes chunksize of 1MB
my $chunks = int((($size + 1024 * 1024 - 1) / (1024 * 1024)) + 0.5);
return $chunks;
}
#
# Lock and Unlock. We lock the entire chain (all versions) of the
# image.
......
......@@ -632,6 +632,19 @@ sub GetDiskOffset($)
return $self->image()->GetDiskOffset();
}
sub PartitionSize($)
{
my ($self) = @_;
return $self->image()->PartitionSize();
}
sub Chunks($)
{
my ($self) = @_;
return $self->image()->Chunks();
}
#
# Return updated time for image as a UNIX timestamp via the passed ref.
# Return 0 on success, non-zero otherwise.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment