Пример #1
0
static void eject(GtkWidget *widget, gpointer data)
{
	res = 0;

	if (data) {
		eject_device(NULL, data, NULL);
	} else {
		g_hash_table_foreach(dev, eject_device, NULL);
	}

	if (res) {
        	gtk_widget_show(dialog);
		gtk_dialog_run(GTK_DIALOG(dialog));
        	gtk_widget_hide(dialog);
	}
}
/**
 * Close the global output file descriptor which Mondo has used to read
 * from buffer or dd, which read from the tape.
 * @param bkpinfo The backup information structure. Unused.
 * @return 0 for success, nonzero for failure.
 * @note This should be called by restore processes only.
 * @note This function also works for cdstreams for now, but don't count on this behavior.
 * @bug @p bkpinfo parameter is unused.
 */
int closein_tape(struct s_bkpinfo *bkpinfo)
{
	/*@ int's ******************************************************* */
	int retval = 0;
	int res = 0;
	int ctrl_chr = '\0';

	/*@ long long's ************************************************* */
	long long size;
	char *blk;
	int i;

	blk = (char *) malloc(256 * 1024);

	log_it("closein_tape() -- entering");
	res = read_header_block_from_stream(&size, NULL, &ctrl_chr);
	retval += res;
	if (ctrl_chr != BLK_END_OF_BACKUP) {
		wrong_marker(BLK_END_OF_BACKUP, ctrl_chr);
	}
	res = read_header_block_from_stream(&size, NULL, &ctrl_chr);
	retval += res;
	if (ctrl_chr != BLK_END_OF_TAPE) {
		wrong_marker(BLK_END_OF_TAPE, ctrl_chr);
	}
	for (i = 0; i < 8 && !feof(g_tape_stream); i++) {
		(void) fread(blk, 1, 256 * 1024, g_tape_stream);
	}
	sleep(1);
	sync();
	sleep(1);
	paranoid_pclose(g_tape_stream);
	log_it("closein_tape() -- leaving");
	if (!bkpinfo->please_dont_eject) {
		eject_device(bkpinfo->media_device);
	}
	paranoid_free(blk);
	paranoid_free(g_tapecatalog);
	return (retval);
}
/**
 * Verify the CD indicated by @c g_current_media_number.
 * @param bkpinfo The backup information structure. Fields used:
 * - @c bkpinfo->isodir
 * - @c bkpinfo->prefix
 * - @c bkpinfo->manual_cd_tray
 * - @c bkpinfo->media_device
 * - @c bkpinfo->nfs_remote_dir
 * - @c bkpinfo->tmpdir
 * - @c bkpinfo->verify_data
 *
 * @return 0 for success (even if differences are found), nonzero for failure.
 * @ingroup verifyGroup
 */
int verify_cd_image(struct s_bkpinfo *bkpinfo)
{

	/*@ int ************************************************************ */
	int retval = 0;

	/*@ buffers ******************************************************** */
	char *mountpoint;
	char *command;
	char *tmp;
	char *fname;
#ifdef __FreeBSD__
	char mdd[32];
	char *mddevice = mdd;
	int ret = 0;
	int vndev = 2;
#else
//skip
#endif

	command = malloc(2000);
	malloc_string(mountpoint);
	malloc_string(tmp);
	malloc_string(fname);

	assert(bkpinfo != NULL);

	sprintf(mountpoint, "%s/cdrom", bkpinfo->tmpdir);
	sprintf(fname, "%s/%s/%s-%d.iso", bkpinfo->nfs_remote_dir,
			bkpinfo->isodir, bkpinfo->prefix, g_current_media_number);

	mkdir(mountpoint, 1777);
	sync();
	if (!does_file_exist(fname)) {
		sprintf(tmp,
				"%s not found; assuming you backed up to CD; verifying CD...",
				fname);
		log_msg(2, tmp);
		if (bkpinfo->manual_cd_tray) {
			popup_and_OK("Please push CD tray closed.");
		}
		if (find_and_mount_actual_cd(bkpinfo, mountpoint)) {
			log_to_screen("failed to mount actual CD");
			return (1);
		}
	} else {
		sprintf(tmp, "%s found; verifying ISO...", fname);
#ifdef __FreeBSD__
		ret = 0;
		vndev = 2;
		mddevice = make_vn(fname);
		if (ret) {
			sprintf(tmp, "make_vn of %s failed; unable to verify ISO\n",
					fname);
			log_to_screen(tmp);
			return (1);
		}
		sprintf(command, "mount_cd9660 %s %s", mddevice, mountpoint);
#else
		sprintf(command, "mount -o loop,ro -t iso9660 %s %s", fname,
				mountpoint);
#endif
		if (run_program_and_log_output(command, FALSE)) {
			sprintf(tmp, "%s failed; unable to mount ISO image\n",
					command);
			log_to_screen(tmp);
			return (1);
		}
	}
	log_msg(2, "OK, I've mounted the ISO/CD\n");
	sprintf(tmp, "%s/archives/NOT-THE-LAST", mountpoint);
	if (!does_file_exist(tmp)) {
		log_msg
			(2,
			 "This is the last CD. I am therefore setting bkpinfo->verify_data to FALSE.");
		bkpinfo->verify_data = FALSE;
/*
   (a) It's an easy way to tell the calling subroutine that we've finished &
   there are no more CD's to be verified; (b) It stops the post-backup verifier
   from running after the per-CD verifier has run too.
*/
	}
	verify_afioballs_on_CD(bkpinfo, mountpoint);
	iamhere("before verify_all_slices");
	verify_all_slices_on_CD(bkpinfo, mountpoint);

#ifdef __FreeBSD__
	ret = 0;
	sprintf(command, "umount %s", mountpoint);
	ret += system(command);
	ret += kick_vn(mddevice);
	if (ret)
#else
	sprintf(command, "umount %s", mountpoint);
	if (system(command))
#endif
	{
		sprintf(tmp, "%s failed; unable to unmount ISO image\n", command);
		log_to_screen(tmp);
		retval++;
	} else {
		log_msg(2, "OK, I've unmounted the ISO file\n");
	}
	if (!does_file_exist(fname)) {
		sprintf(command, "umount %s", bkpinfo->media_device);
		run_program_and_log_output(command, 2);
		if (!bkpinfo->please_dont_eject
			&& eject_device(bkpinfo->media_device)) {
			log_msg(2, "Failed to eject CD-ROM drive");
		}
	}
	paranoid_free(command);
	paranoid_free(mountpoint);
	paranoid_free(tmp);
	paranoid_free(fname);
	return (retval);
}