+/* Checks if the given tape device is actually a holding disk file. We
+ accomplish this by stat()ing the file; if it is a regular file, we
+ assume (somewhat dangerously) that it's a holding disk file. If
+ it doesn't exist or is not a regular file, we assume it's a device
+ name.
+
+ Returns TRUE if we suspect the device is a holding disk, FALSE
+ otherwise. */
+static gboolean check_device_type(char * device_name) {
+ struct stat stat_buf;
+ int result;
+
+ result = stat(device_name, &stat_buf);
+
+ return !((result != 0 || !S_ISREG(stat_buf.st_mode)));
+}
+
+static void handle_holding_disk_restore(char * filename, rst_flags_t * flags,
+ GSList * dumpspecs) {
+ dumpfile_t this_header;
+ tapelist_t this_disk;
+
+ bzero(&this_disk, sizeof(this_disk));
+ this_disk.label = filename;
+
+ if (!restore_holding_disk(stderr, flags, NULL, &this_disk, NULL,
+ dumpspecs, &this_header, NULL)) {
+ g_fprintf(stderr, "%s did not match requested host.\n", filename);
+ return;
+ }
+}
+
+static void handle_tape_restore(char * device_name, rst_flags_t * flags,
+ GSList * dumpspecs, char * check_label) {
+ Device * device;
+ ReadLabelStatusFlags read_label_status;
+
+ dumpfile_t first_restored_file;
+
+ device_api_init();
+
+ fh_init(&first_restored_file);
+
+ device = device_open(device_name);
+ if (device == NULL) {
+ error("Could not open device.\n");
+ }
+
+ device_set_startup_properties_from_config(device);
+ read_label_status = device_read_label(device);
+ if (read_label_status != READ_LABEL_STATUS_SUCCESS) {
+ char * errstr =
+ g_english_strjoinv_and_free
+ (g_flags_nick_to_strv(read_label_status,
+ READ_LABEL_STATUS_FLAGS_TYPE), "or");
+ error("Error reading volume label: %s.\n", errstr);
+ }
+
+ g_assert(device->volume_label != NULL);
+
+ if (!device_start(device, ACCESS_READ, NULL, NULL)) {
+ error("Could not open device %s for reading.\n", device_name);
+ }
+
+ if (check_label != NULL && strcmp(check_label,
+ device->volume_label) != 0) {
+ error("Wrong label: Expected %s, found %s.\n",
+ check_label, device->volume_label);
+ }
+
+ search_a_tape(device, stderr, flags, NULL, NULL, dumpspecs,
+ NULL, &first_restored_file, 0, NULL);
+}