示例#1
0
static int
execute_add_command(struct update_command_journal *j,
		    WIMStruct *wim,
		    const struct wimlib_update_command *add_cmd,
		    struct wim_inode_table *inode_table,
		    struct wim_sd_set *sd_set,
		    struct list_head *unhashed_streams)
{
	int ret;
	int add_flags;
	tchar *fs_source_path;
	tchar *wim_target_path;
	const tchar *config_file;
	struct capture_params params;
	struct capture_config config;
	capture_tree_t capture_tree = platform_default_capture_tree;
#ifdef WITH_NTFS_3G
	struct _ntfs_volume *ntfs_vol = NULL;
#endif
	void *extra_arg = NULL;
	struct wim_dentry *branch;

	add_flags = add_cmd->add.add_flags;
	fs_source_path = add_cmd->add.fs_source_path;
	wim_target_path = add_cmd->add.wim_target_path;
	config_file = add_cmd->add.config_file;

	DEBUG("fs_source_path=\"%"TS"\", wim_target_path=\"%"TS"\", add_flags=%#x",
	      fs_source_path, wim_target_path, add_flags);

	memset(&params, 0, sizeof(params));

#ifdef WITH_NTFS_3G
	if (add_flags & WIMLIB_ADD_FLAG_NTFS) {
		capture_tree = build_dentry_tree_ntfs;
		extra_arg = &ntfs_vol;
		if (wim_get_current_image_metadata(wim)->ntfs_vol != NULL) {
			ERROR("NTFS volume already set");
			ret = WIMLIB_ERR_INVALID_PARAM;
			goto out;
		}
	}
#endif

	ret = get_capture_config(config_file, &config,
				 add_flags, fs_source_path);
	if (ret)
		goto out;

	params.lookup_table = wim->lookup_table;
	params.unhashed_streams = unhashed_streams;
	params.inode_table = inode_table;
	params.sd_set = sd_set;
	params.config = &config;
	params.add_flags = add_flags;
	params.extra_arg = extra_arg;

	params.progfunc = wim->progfunc;
	params.progctx = wim->progctx;
	params.progress.scan.source = fs_source_path;
	params.progress.scan.wim_target_path = wim_target_path;
	ret = call_progress(params.progfunc, WIMLIB_PROGRESS_MSG_SCAN_BEGIN,
			    &params.progress, params.progctx);
	if (ret)
		goto out_destroy_config;

	if (WIMLIB_IS_WIM_ROOT_PATH(wim_target_path))
		params.add_flags |= WIMLIB_ADD_FLAG_ROOT;
	ret = (*capture_tree)(&branch, fs_source_path, &params);
	if (ret)
		goto out_destroy_config;

	ret = call_progress(params.progfunc, WIMLIB_PROGRESS_MSG_SCAN_END,
			    &params.progress, params.progctx);
	if (ret) {
		free_dentry_tree(branch, wim->lookup_table);
		goto out_cleanup_after_capture;
	}

	if (WIMLIB_IS_WIM_ROOT_PATH(wim_target_path) &&
	    branch && !dentry_is_directory(branch))
	{
		ERROR("\"%"TS"\" is not a directory!", fs_source_path);
		ret = WIMLIB_ERR_NOTDIR;
		free_dentry_tree(branch, wim->lookup_table);
		goto out_cleanup_after_capture;
	}

	ret = attach_branch(branch, wim_target_path, j,
			    add_flags, params.progfunc, params.progctx);
	if (ret)
		goto out_cleanup_after_capture;

	if (config_file && (add_flags & WIMLIB_ADD_FLAG_WIMBOOT) &&
	    WIMLIB_IS_WIM_ROOT_PATH(wim_target_path))
	{
		params.add_flags = 0;
		params.progfunc = NULL;
		params.config = NULL;

		/* If a capture configuration file was explicitly specified when
		 * capturing an image in WIMBoot mode, save it as
		 * /Windows/System32/WimBootCompress.ini in the WIM image. */
		ret = platform_default_capture_tree(&branch, config_file, &params);
		if (ret)
			goto out_cleanup_after_capture;

		ret = attach_branch(branch, wimboot_cfgfile, j, 0, NULL, NULL);
		if (ret)
			goto out_cleanup_after_capture;
	}

#ifdef WITH_NTFS_3G
	wim_get_current_image_metadata(wim)->ntfs_vol = ntfs_vol;
#endif
	ret = 0;
	goto out_destroy_config;
out_cleanup_after_capture:
#ifdef WITH_NTFS_3G
	if (ntfs_vol)
		do_ntfs_umount(ntfs_vol);
#endif
out_destroy_config:
	destroy_capture_config(&config);
out:
	return ret;
}
示例#2
0
int main ( int narg, char **argv ) {
	
	// parse command line ----------------------------------------------
	po::options_description general_opt ( "Allowed options are: " );
	general_opt.add_options()
		( "help,h", "display this message." )
		( "initial,i", po::value< std::string >(), "Initial skeleton pgm filename." )
		( "reduced,r", po::value< std::string >(), "Reduced skeleton pgm filename." )
		( "label,l", po::value< std::string >(), "(part of the) Reduced skeleton being labeled pgm filename." )
		( "selection,s", po::value< std::string >()->multitoken(), "Catch branch touching the given components\' labels of the reduced skeleton.")
		( "output,o", po::value< std::string >(), "Extended labeled skeleton pgm filename.");

	bool parseOK = true ;
	po::variables_map vm;
	try {
		po::store(po::parse_command_line(narg, argv, general_opt), vm);  
	} catch ( const std::exception& ex ) {
		parseOK = false ;
		std::cerr<< "Error checking program options: "<< ex.what()<< endl;
		return -1 ;
	}

	po::notify ( vm );
	if (!parseOK || vm.count ( "help" ) ||narg<=1 ) {
		errorAndHelp( general_opt ) ;
		return -1 ;
	}
	if ( ! vm.count("initial") ) missingParam( "initial" ) ;
	if ( ! vm.count("label") ) missingParam( "label" ) ;
	if ( ! vm.count("reduced") ) missingParam( "reduced" ) ;
	if ( ! vm.count("output") ) missingParam( "output" ) ;
	
	std::string initialSkelFile = vm["initial"].as<std::string>() ;
	std::string reducedSkelFile = vm["reduced"].as<std::string>() ;
	std::string reducedLabelSkelFile = vm["label"].as<std::string>() ;
	std::string outputSkelFile  = vm["output"].as<std::string>() ;
	
	QList< tlabel > Labels ;
	if ( vm.count( "selection" ) ) {
		QStringList selectedLabels = QString( "%1").arg( vm["selection"].as< std::string >().c_str() ).split( " ", QString::SkipEmptyParts) ;
		while ( !selectedLabels.isEmpty() )
			Labels.append( (tlabel)selectedLabels.takeAt(0).toInt() ) ;
		qSort( Labels.begin(), Labels.end(), qLess<tlabel>() ) ;
		
		std::cout<<"Selection : ";
		for ( QList< tlabel >::ConstIterator lbl = Labels.begin() ; lbl != Labels.end() ; lbl++ )
			std::cout<<"["<<(int) *lbl<<"] " ;
		std::cout<<std::endl;
	}
	
	BillonTpl< tlabel > *labelReducedSkel ;
	BillonTpl< arma::u8 > *initialSkel,
	                      *reducedSkel ;
	{
		Pgm3dFactory< tlabel > factory ;
		labelReducedSkel = factory.read( QString(reducedLabelSkelFile.c_str()) ) ;
	}
	{
		Pgm3dFactory< arma::u8 > factory ;
		initialSkel = factory.read( QString(initialSkelFile.c_str()) ) ;
		if ( initialSkel->max() > 1 ) *initialSkel /= initialSkel->max() ;
		reducedSkel = factory.read( QString(reducedSkelFile.c_str()) ) ;
		if ( reducedSkel->max() > 1 ) *reducedSkel /= reducedSkel->max() ;
	}
	
	QList< uint * > touching ;
	make_branch( initialSkel, reducedSkel, labelReducedSkel, touching ) ;
	delete reducedSkel ;
	
	ConnexComponentExtractor< arma::u8, tlabelbranch > CCE ;
	BillonTpl< tlabelbranch > * labelBranch = CCE.run( *initialSkel ) ;
	IOPgm3d< tlabelbranch, qtlabelbranch, false >::write( *labelBranch, "/tmp/whois429.pgm3d" ) ;
	delete initialSkel ;
	
	QMap< tlabelbranch, tlabel > NewLabelBranch ;
	QMap< tlabel, QList<tlabel> > edges ;
	set_branch( touching, labelReducedSkel, labelBranch, NewLabelBranch, Labels,edges ) ;
	attach_branch( labelReducedSkel, labelBranch, NewLabelBranch, Labels ) ;
	
	IOPgm3d< tlabel, qtlabel, false >::write( *labelReducedSkel, QString(outputSkelFile.c_str() ) ) ;
	
	while ( !touching.isEmpty() ) {
		delete [] touching.takeFirst() ;
	}
	delete labelReducedSkel ;
	delete labelBranch ;
	
	return 0 ;
}