- printf(", writing label %s", label); fflush(stdout);
-
-#ifdef HAVE_LINUX_ZFTAPE_H
- if (isa_zftape) {
- errstr = tapefd_wrlabel(fd, "X", label,
- (tt_blocksize_kb * 1024));
- if(errstr != NULL) {
- putchar('\n');
- error(errstr);
- /*NOTREACHED*/
- }
- }
- else
-#endif /* HAVE_LINUX_ZFTAPE_H */
- errstr = tape_wrlabel(tapename, "X", label,
- (tt_blocksize_kb * 1024));
- if(errstr != NULL) {
- putchar('\n');
- error(errstr);
- /*NOTREACHED*/
- }
-
-#ifdef HAVE_LINUX_ZFTAPE_H
- if (isa_zftape) {
- tapefd_weof(fd, (off_t)1);
- }
-#endif /* HAVE_LINUX_ZFTAPE_H */
-
-#ifdef HAVE_LINUX_ZFTAPE_H
- if (isa_zftape) {
- errstr = tapefd_wrendmark(fd, "X",
- (tt_blocksize_kb * 1024));
- if(errstr != NULL) {
- putchar('\n');
- error(errstr);
- /*NOTREACHED*/
- }
- }
- else
-#endif /* HAVE_LINUX_ZFTAPE_H */
- errstr = tape_wrendmark(tapename, "X",
- (tt_blocksize_kb * 1024));
- if(errstr != NULL) {
- putchar('\n');
- error(errstr);
- /*NOTREACHED*/
- }
-
-#ifdef HAVE_LINUX_ZFTAPE_H
- if (isa_zftape) {
- tapefd_weof(fd, (off_t)1);
-
- printf(",\nrewinding"); fflush(stdout);
-
- if(tapefd_rewind(fd) == -1) {
- putchar('\n');
- error(strerror(errno));
- /*NOTREACHED*/
- }
- close(fd);
-#ifdef HAVE_LIBVTBLC
- /* update volume table */
- printf(", updating volume table"); fflush(stdout);
-
- if ((fd = raw_tape_open(rawtapedev, O_RDWR)) == -1) {
- if(errno == EACCES) {
- errstr = newstralloc(errstr,
- "updating volume table: raw tape device is write protected");
- } else {
- errstr = newstralloc2(errstr,
- "updating volume table: ", strerror(errno));
- }
- putchar('\n');
- error(errstr);
- /*NOTREACHED*/
- }
- /* read volume table */
- if ((num_volumes = read_vtbl(fd, volumes, vtbl_buffer,
- &first_seg, &last_seg)) == -1 ) {
- errstr = newstralloc2(errstr,
- "reading volume table: ", strerror(errno));
- putchar('\n');
- error(errstr);
- /*NOTREACHED*/
- }
- /* set date and volume label for first entry */
- vtbl_no = 0;
- datestr = NULL;
- if (set_date(datestr, volumes, num_volumes, vtbl_no)){
- errstr = newstralloc2(errstr,
- "setting date for entry 1: ", strerror(errno));
- putchar('\n');
- error(errstr);
- /*NOTREACHED*/
- }
- if(set_label(label, volumes, num_volumes, vtbl_no)){
- errstr = newstralloc2(errstr,
- "setting label for entry 1: ", strerror(errno));
- putchar('\n');
- error(errstr);
- /*NOTREACHED*/
- }
- /* set date and volume label for last entry */
- vtbl_no = 1;
- datestr = NULL;
- if (set_date(datestr, volumes, num_volumes, vtbl_no)){
- errstr = newstralloc2(errstr,
- "setting date for entry 2: ", strerror(errno));
- putchar('\n');
- error(errstr);
- /*NOTREACHED*/
- }
- if(set_label("AMANDA Tape End", volumes, num_volumes, vtbl_no)){
- errstr = newstralloc2(errstr,
- "setting label for entry 2: ", strerror(errno));
- putchar('\n');
- error(errstr);
- /*NOTREACHED*/
- }
- /* write volume table back */
- if (write_vtbl(fd, volumes, vtbl_buffer, num_volumes, first_seg,
- op_mode == trunc)) {
- errstr = newstralloc2(errstr,
- "writing volume table: ", strerror(errno));
- putchar('\n');
- error(errstr);
- /*NOTREACHED*/
- }
- close(fd);
-#endif /* HAVE_LIBVTBLC */
- }
-#endif /* HAVE_LINUX_ZFTAPE_H */
-
- if (tape_ok) {
- printf(", checking label"); fflush(stdout);
-
- if((errstr = tape_rdlabel(tapename, &olddatestamp, &oldlabel)) != NULL) {
- putchar('\n');
- if (strcmp(errstr, "not an amanda tape") != 0) {
- error(errstr);
- /*NOTREACHED*/
- }
- error("no label found, are you sure %s is non-rewinding?",
- tapename);
- /*NOTREACHED*/
- }
-
- if (strcmp("X", olddatestamp) != 0 ||
- (strcmp(oldlabel, FAKE_LABEL) != 0
- && strcmp(label, oldlabel) != 0)) {
- putchar('\n');
- error("read label %s back, timestamp %s (expected X), what now?",
- oldlabel, olddatestamp);
- /*NOTREACHED*/
- }
- amfree(oldlabel);
- amfree(olddatestamp);
-
- /* write tape list */
-
- /* make a copy */
- conf_tapelist_old = stralloc2(conf_tapelist, ".amlabel");
- if(write_tapelist(conf_tapelist_old)) {
- error("couldn't write tapelist: %s", strerror(errno));
- /*NOTREACHED*/
- }
- amfree(conf_tapelist_old);
-
- /* XXX add cur_tape number to tape list structure */
- remove_tapelabel(label);
- add_tapelabel("0", label);
- if(write_tapelist(conf_tapelist)) {
- error("couldn't write tapelist: %s", strerror(errno));
- /*NOTREACHED*/
- }
- } /* write tape list */
- printf(", done.\n");
+ char *timestamp = NULL;
+
+ g_printf(_("Writing label %s..\n"), label); fflush(stdout);
+
+ timestamp = get_undef_timestamp();
+ if (!device_start(device, ACCESS_WRITE, label, timestamp)) {
+ error(_("Error writing label.\n"));
+ g_assert_not_reached();
+ } else if (!device_finish(device)) {
+ error(_("Error closing device.\n"));
+ g_assert_not_reached();
+ }
+ amfree(timestamp);
+
+ g_printf(_("Checking label...\n")); fflush(stdout);
+
+ label_status = device_read_label(device);
+ if (label_status != READ_LABEL_STATUS_SUCCESS) {
+ g_printf("Checking the tape label failed: \n ");
+ print_read_label_status_error(label_status);
+ exit(EXIT_FAILURE);
+ } else if (device->volume_label == NULL) {
+ error(_("no label found.\n"));
+ g_assert_not_reached();
+ } else if (strcmp(device->volume_label, label) != 0) {
+ error(_("Read back a different label: Got %s, but expected %s\n"),
+ device->volume_label, label);
+ g_assert_not_reached();
+ } else if (get_timestamp_state(device->volume_time) !=
+ TIME_STATE_UNDEF) {
+ error(_("Read the right label, but the wrong timestamp: "
+ "Got %s, expected X.\n"), device->volume_time);
+ g_assert_not_reached();
+ }
+
+ /* write tape list */
+
+ /* make a copy */
+ conf_tapelist_old = stralloc2(conf_tapelist, ".amlabel");
+ if(write_tapelist(conf_tapelist_old)) {
+ error(_("couldn't write tapelist: %s"), strerror(errno));
+ /*NOTREACHED*/
+ }
+ amfree(conf_tapelist_old);
+
+ /* XXX add cur_tape number to tape list structure */
+ remove_tapelabel(label);
+ add_tapelabel("0", label);
+ if(write_tapelist(conf_tapelist)) {
+ error(_("couldn't write tapelist: %s"), strerror(errno));
+ /*NOTREACHED*/
+ }
+
+ g_printf(_("Success!\n"));