- my $dev = $self->{'dst_dev'} =
- Amanda::Device->new($res->{'device_name'});
- if ($dev->status() != $DEVICE_STATUS_SUCCESS) {
- fail ("Could not open device $res->{device_name}: " .
- $dev->error_or_status());
- }
-
- # for now, we only overwrite absolutely empty volumes. This will need
- # to change when we introduce use of a taperscan algorithm.
-
- my $status = $dev->read_label();
- if (!($status & $DEVICE_STATUS_VOLUME_UNLABELED)) {
- # if UNLABELED is only one possibility, give a device error msg
- if ($status & ~$DEVICE_STATUS_VOLUME_UNLABELED) {
- fail ("Could not read label from $res->{device_name}: " .
- $dev->error_or_status());
+ my $dev = $self->{'dst_dev'} = $res->{'device'};
+ my $device_name = $dev->device_name;
+
+ # characterize the device/volume status, and then check if we can
+ # automatically relabel it.
+
+use Data::Dumper;
+debug("". Dumper($dev->volume_header));
+ my $status = $dev->status;
+ my $volstate = '';
+ if ($status & $DEVICE_STATUS_VOLUME_UNLABELED and
+ $dev->volume_header and
+ $dev->volume_header->{'type'} == $F_EMPTY) {
+ $volstate = 'empty';
+ } elsif ($status & $DEVICE_STATUS_VOLUME_UNLABELED and
+ !$dev->volume_header) {
+ $volstate = 'empty';
+ } elsif ($status & $DEVICE_STATUS_VOLUME_UNLABELED and
+ $dev->volume_header and
+ $dev->volume_header->{'type'} != $F_WEIRD) {
+ $volstate = 'non_amanda';
+ } elsif ($status & $DEVICE_STATUS_VOLUME_ERROR) {
+ $volstate = 'volume_error';
+ } elsif ($status == $DEVICE_STATUS_SUCCESS) {
+ # OK, the label was read successfully
+ if (!$dev->volume_header) {
+ $volstate = 'empty';
+ } elsif ($dev->volume_header->{'type'} != $F_TAPESTART) {
+ $volstate = 'non_amanda';