+sub data_to_null {
+ my ($device) = @_;
+ my $got_error = 0;
+
+ my $xfer = Amanda::Xfer->new([
+ Amanda::Xfer::Source::Device->new($device),
+ Amanda::Xfer::Dest::Null->new(0),
+ ]);
+
+ $xfer->get_source()->set_callback(sub {
+ my ($src, $xmsg, $xfer) = @_;
+ if ($xmsg->{type} == $Amanda::Xfer::XMSG_ERROR) {
+ $got_error = $xmsg->{message};
+ }
+ if ($xfer->get_status() == $Amanda::Xfer::XFER_DONE) {
+ Amanda::MainLoop::quit();
+ }
+ });
+ $xfer->start();
+
+ Amanda::MainLoop::run();
+}
+
+sub check_property {
+ my ($device) = @_;
+
+ my $fsf_after_filemark = $device->property_get("FSF_AFTER_FILEMARK");
+
+ # not a 'tape:' device
+ return if !defined $fsf_after_filemark;
+
+ $device->start($ACCESS_WRITE, "TEST-001", "20080706050403");
+
+ my $hdr = Amanda::Types::dumpfile_t->new();
+
+ $hdr->{type} = $Amanda::Types::F_DUMPFILE;
+ $hdr->{name} = "localhost";
+ $hdr->{disk} = "/test1";
+ $hdr->{datestamp} = "20080706050403";
+ $device->start_file($hdr);
+ $device->finish_file();
+
+ $hdr->{type} = $Amanda::Types::F_DUMPFILE;
+ $hdr->{name} = "localhost";
+ $hdr->{disk} = "/test2";
+ $hdr->{datestamp} = "20080706050403";
+ $device->start_file($hdr);
+ $device->finish_file();
+
+ $hdr->{type} = $Amanda::Types::F_DUMPFILE;
+ $hdr->{name} = "localhost";
+ $hdr->{disk} = "/test3";
+ $hdr->{datestamp} = "20080706050403";
+ $device->start_file($hdr);
+ $device->finish_file();
+
+ $device->finish();
+
+ #set fsf_after_filemark to false
+ $device->property_set('FSF_AFTER_FILEMARK', 0)
+ or die "Error setting FSF_AFTER_FILEMARK: " . $device->error_or_status();
+
+ my $need_fsf_after_filemark = 0;
+
+ if ($device->read_label() != $DEVICE_STATUS_SUCCESS) {
+ die ("Could not read label from: " . $device->error_or_status());
+ }
+ if ($device->volume_label != "TEST-001") {
+ die ("wrong label: ", $device->volume_label);
+ }
+ $device->start($ACCESS_READ, undef, undef)
+ or die ("Could not start device: " . $device->error_or_status());
+
+ $hdr = $device->seek_file(1);
+ if ($device->status() != $DEVICE_STATUS_SUCCESS) {
+ die ("seek_file(1) failed");
+ }
+ if ($hdr->{disk} ne "/test1") {
+ die ("Wrong disk: " . $hdr->{disk} . " expected /test1");
+ }
+ data_to_null($device);
+
+ $hdr = $device->seek_file(2);
+ if ($device->status() == $DEVICE_STATUS_SUCCESS) {
+ if ($hdr->{disk} ne "/test2") {
+ die ("Wrong disk: " . $hdr->{disk} . " expected /test2");
+ }
+ data_to_null($device);
+
+ $hdr = $device->seek_file(3);
+ if ($device->status() != $DEVICE_STATUS_SUCCESS) {
+ die("seek_file(3) failed");
+ }
+ if ($hdr->{disk} ne "/test3") {
+ die ("Wrong disk: " . $hdr->{disk} . " expected /test3");
+ }
+ data_to_null($device);
+ } else {
+ $need_fsf_after_filemark = 1;
+ }
+
+ $device->finish();
+
+ #verify need_fsf_after_filemark
+ my $fsf_after_filemark_works = 0;
+ if ($need_fsf_after_filemark) {
+ #set fsf_after_filemark to true
+ $device->property_set('FSF_AFTER_FILEMARK', 1)
+ or die "Error setting FSF_AFTER_FILEMARK: " . $device->error_or_status();
+
+ if ($device->read_label() != $DEVICE_STATUS_SUCCESS) {
+ die ("Could not read label from: " . $device->error_or_status());
+ }
+ if ($device->volume_label != "TEST-001") {
+ die ("wrong label: ", $device->volume_label);
+ }
+ $device->start($ACCESS_READ, undef, undef)
+ or die ("Could not start device: " . $device->error_or_status());
+
+ $hdr = $device->seek_file(1);
+ if ($device->status() != $DEVICE_STATUS_SUCCESS) {
+ die ("seek_file(1) failed");
+ }
+ if ($hdr->{disk} ne "/test1") {
+ die ("Wrong disk: " . $hdr->{disk} . " expected /test1");
+ }
+ data_to_null($device);
+
+ $hdr = $device->seek_file(2);
+ if ($device->status() == $DEVICE_STATUS_SUCCESS) {
+ if ($hdr->{disk} ne "/test2") {
+ die ("Wrong disk: " . $hdr->{disk} . " expected /test2");
+ }
+ data_to_null($device);
+
+ $hdr = $device->seek_file(3);
+ if ($device->status() != $DEVICE_STATUS_SUCCESS) {
+ die("seek_file(3) failed");
+ }
+ if ($hdr->{disk} ne "/test3") {
+ die ("Wrong disk: " . $hdr->{disk} . " expected /test3");
+ }
+ data_to_null($device);
+ $fsf_after_filemark_works = 1;
+ } else {
+ die("seek_file(2) failed");
+ }
+ $device->finish();
+ }
+
+ if ($need_fsf_after_filemark == 0 && $fsf_after_filemark_works == 0) {
+ if (defined $opt_property || $fsf_after_filemark) {
+ print STDOUT "device_property \"FSF_AFTER_FILEMARK\" \"false\"\n";
+ }
+ $device->property_set('FSF_AFTER_FILEMARK', 0);
+ } elsif ($need_fsf_after_filemark == 1 && $fsf_after_filemark_works == 1) {
+ if (defined $opt_property || !$fsf_after_filemark) {
+ print STDOUT "device_property \"FSF_AFTER_FILEMARK\" \"true\"\n";
+ }
+ $device->property_set('FSF_AFTER_FILEMARK', 1);
+ } else {
+ die ("Broken seek_file");
+ }
+
+ #Check seek to file 1 from header
+ if ($device->read_label() != $DEVICE_STATUS_SUCCESS) {
+ die ("Could not read label from: " . $device->error_or_status());
+ }
+ if ($device->volume_label != "TEST-001") {
+ die ("wrong label: ", $device->volume_label);
+ }
+ $device->start($ACCESS_READ, undef, undef)
+ or die ("Could not start device: " . $device->error_or_status());
+
+ $hdr = $device->seek_file(1);
+ if ($device->status() != $DEVICE_STATUS_SUCCESS) {
+ die ("seek_file(1) failed");
+ }
+ if ($hdr->{disk} ne "/test1") {
+ die ("Wrong disk: " . $hdr->{disk} . " expected /test1");
+ }
+ $device->finish();
+
+ #Check seek to file 2 from header
+ if ($device->read_label() != $DEVICE_STATUS_SUCCESS) {
+ die ("Could not read label from: " . $device->error_or_status());
+ }
+ if ($device->volume_label != "TEST-001") {
+ die ("wrong label: ", $device->volume_label);
+ }
+ $device->start($ACCESS_READ, undef, undef)
+ or die ("Could not start device: " . $device->error_or_status());
+
+ $hdr = $device->seek_file(2);
+ if ($device->status() != $DEVICE_STATUS_SUCCESS) {
+ die ("seek_file(2) failed");
+ }
+ if ($hdr->{disk} ne "/test2") {
+ die ("Wrong disk: " . $hdr->{disk} . " expected /test1");
+ }
+ $device->finish();
+
+ #Check seek to file 3 from header
+ if ($device->read_label() != $DEVICE_STATUS_SUCCESS) {
+ die ("Could not read label from: " . $device->error_or_status());
+ }
+ if ($device->volume_label != "TEST-001") {
+ die ("wrong label: ", $device->volume_label);
+ }
+ $device->start($ACCESS_READ, undef, undef)
+ or die ("Could not start device: " . $device->error_or_status());
+
+ $hdr = $device->seek_file(3);
+ if ($device->status() != $DEVICE_STATUS_SUCCESS) {
+ die ("seek_file(3) failed");
+ }
+ if ($hdr->{disk} ne "/test3") {
+ die ("Wrong disk: " . $hdr->{disk} . " expected /test1");
+ }
+ $device->finish();
+
+ #Check seek to file 3 from eof of 1
+ if ($device->read_label() != $DEVICE_STATUS_SUCCESS) {
+ die ("Could not read label from: " . $device->error_or_status());
+ }
+ if ($device->volume_label != "TEST-001") {
+ die ("wrong label: ", $device->volume_label);
+ }
+ $device->start($ACCESS_READ, undef, undef)
+ or die ("Could not start device: " . $device->error_or_status());
+
+ $hdr = $device->seek_file(1);
+ if ($device->status() != $DEVICE_STATUS_SUCCESS) {
+ die ("seek_file(1) failed");
+ }
+ data_to_null($device);
+ $hdr = $device->seek_file(3);
+ if ($device->status() != $DEVICE_STATUS_SUCCESS) {
+ die ("seek_file(3) failed");
+ }
+ if ($hdr->{disk} ne "/test3") {
+ die ("Wrong disk: " . $hdr->{disk} . " expected /test3");
+ }
+ $device->finish();
+}
+