예제 #1
0
파일: vj-misc.c 프로젝트: flv0/veejay
static int	find_files( filelist_t *filelist, const char *path )
{
	struct dirent **files = NULL;
	int N = scandir ( path, &files, dir_selector,alphasort );
	int n;
	if( N < 0 ) {
		return 0;
	}

	for( n = 0; n < N; n ++ )
	{
		char tmp[PATH_MAX];
		if( strcmp( files[n]->d_name, "." ) == 0 ||
		    strcmp( files[n]->d_name, ".." ) == 0 ) {
			continue;
		}

		snprintf(tmp,sizeof(tmp), "%s/%s", path,files[n]->d_name );
		if(is_usable_file( filelist, tmp, files[n]->d_name ) ) { //@recurse
			find_files( filelist, tmp );
		}
	}

	for( n = 0; n < N; n ++ )  {
		if( files[n])
	 	 free(files[n]);
	}
	free(files);
	return 1;
}
예제 #2
0
void CVFSHandler::FindArchives(const string& pattern, const string& path)
{
	fs::path fn(path);
	std::vector<fs::path> found = find_files(fn,pattern, false);
	for (std::vector<fs::path>::iterator it = found.begin(); it != found.end(); it++)
		AddArchive(it->string().c_str(),false);
}
예제 #3
0
파일: vj-misc.c 프로젝트: flv0/veejay
filelist_t *find_media_files( veejay_t *info )
{
	char working_dir[PATH_MAX];
	char *wd = getcwd( working_dir, sizeof(working_dir));

	if( wd == NULL ) {
		return NULL;
	}

	filelist_t *fl = (filelist_t*) vj_malloc(sizeof(filelist_t));
	fl->files      = (char**) vj_calloc(sizeof(char*) * 1024 ); 
	fl->max_files  = 1024;
	fl->num_files  = 0;	
	fl->working_dir = vj_strdup(working_dir);

	int res = find_files( fl, wd );

	if( res == 0 ) {
		veejay_msg(VEEJAY_MSG_DEBUG, "No files found in %s", wd );
		free( fl->files );
		free( fl->working_dir );
		free( fl );
		fl = NULL;
	}

	return fl;
}
예제 #4
0
/*! This function reads initial conditions, in one of the three possible file
 *  formats currently supported by Gadget.  Note: When a snapshot file is
 *  started from initial conditions (start-option 0), not all the information
 *  in the header is used, in particular, the STARTING TIME needs to be set in
 *  the parameterfile.  Also, for gas particles, only the internal energy is
 *  read, the density and mean molecular weight will be recomputed by the
 *  code.  When InitGasTemp>0 is given, the gas temperature will be initialzed
 *  to this value assuming a mean colecular weight either corresponding to
 *  complete neutrality, or full ionization.
 *
 *  However, when the code is started with start-option 2, then all the this
 *  data in the snapshot files is preserved, i.e. this is also the way to
 *  resume a simulation from a snapshot file in case a regular restart file is
 *  not available.
 */
void read_ic(char *fname)
{
  int i, num_files, rest_files, ngroups, gr, filenr, masterTask, lastTask, groupMaster;
#ifndef POLYTROPE
  double u_init;
#endif
  char buf[500];

#ifndef ISOTHERM_EQS
#ifndef POLYTROPE
  double molecular_weight;
#endif
#ifdef CHEMCOOL
  double gamm1;
#endif /* CHEMCOOL */
#endif /* ISOTHERM_EQS */
#ifdef SFR
  double original_gas_mass, mass, masstot;
#endif

  NumPart = 0;
  N_gas = 0;
  N_sinks = 0;
  All.TotNumPart = 0;

  num_files = find_files(fname);
  fill_Tab_IO_Labels();

  sprintf(buf, "%s.hdf5", fname);
  read_file(buf, ThisTask, ThisTask);
  

  /* this makes sure that masses are initialized in the case that the mass-block
     is completely empty */
  for(i = 0; i < NumPart; i++)
    {
      if(All.MassTable[P[i].Type] != 0)
	P[i].Mass = All.MassTable[P[i].Type];
    }


#ifndef POLYTROPE
  for(i = 0; i < N_gas; i++)
    SphP[i].Entropy = dmax(All.MinEgySpec, SphP[i].Entropy);
#endif

  if(ThisTask == 0)
    {
      printf("reading done.\n");
      fflush(stdout);
    }

  if(ThisTask == 0)
    {
      printf("Total number of particles :  %d%09d\n\n",
	     (int) (All.TotNumPart / 1000000000), (int) (All.TotNumPart % 1000000000));
      fflush(stdout);
    }
}
예제 #5
0
void FileMgr::search(){	
	if (flag_fm == 1){											//For directory file search
		if (flip == 0 && path_ != "."){
			FileSystem::Directory::setCurrentDirectory(path_);
			flip = 1;
		}
		find_files(path_); 
		find_dir(path_);
	}
	else{														//non  directory file search
		if (flip == 0 && path_ != "."){
			FileSystem::Directory::setCurrentDirectory(path_);
			flip = 1;
		}
		find_files(path_);
	}
}
예제 #6
0
파일: lean_path.cpp 프로젝트: avigad/lean
void find_imports_core(std::string const & base, optional<unsigned> const & k,
                       std::vector<pair<std::string, std::string>> & imports) {
    std::vector<std::string> files;
    find_files(base, ".lean", files);
    find_files(base, ".olean", files);

    for (auto const & file : files) {
        auto import = file.substr(base.size() + 1, file.rfind('.') - (base.size() + 1));
        std::replace(import.begin(), import.end(), get_dir_sep_ch(), '.');
        if (k)
            import = std::string(*k + 1, '.') + import;
        auto n = import.rfind(".default");
        if (n != static_cast<unsigned>(-1) && n == import.size() - std::string(".default").size())
            import = import.substr(0, n);
        imports.push_back({import, file});
    }
}
예제 #7
0
static bool find_files(std::string pathname, const std::string &filename, string_array &files, bool recursive)
{
   if (!pathname.empty())
   {
      char c = pathname[pathname.size() - 1];
      if ((c != ':') && (c != '\\') && (c != '/'))
         pathname += "/";
   }

   DIR *dp = opendir(pathname.c_str());

   if (!dp)
      return false;

   string_array paths;

   for ( ; ; )
   {
      struct dirent *ep = readdir(dp);
      if (!ep)
         break;

      const bool is_directory = (ep->d_type & DT_DIR) != 0;
      const bool is_file =  (ep->d_type & DT_REG) != 0;

      if (ep->d_name[0] == '.')
         continue;

      std::string filename(ep->d_name);

      if (is_directory)
      {
         if (recursive)
            paths.push_back(filename);
      }
      else if (is_file)
         files.push_back(pathname + filename);
   }

   closedir(dp);
   dp = NULL;

   if (recursive)
   {
      for (uint i = 0; i < paths.size(); i++)
      {
         const std::string &path = paths[i];
         if (!find_files(pathname + path, filename, files, true))
            return false;
      }
   }

   return true;
}
예제 #8
0
파일: main.cpp 프로젝트: keitee/kb
int main()
{
   auto dir = fs::temp_directory_path();
   auto pattern = R"(wct[0-9a-zA-Z]{3}\.tmp)";
   auto result = find_files(dir, pattern);

   for (auto const & entry : result)
   {
      std::cout << entry.path().string() << std::endl;
   }
}
예제 #9
0
파일: Misc.cpp 프로젝트: vinceplusplus/z3D
		vector<wcs> find_files_recursive(const wcs& dir, const wcs& pattern)
		{
			vector<wcs> array_files = find_files(dir, pattern);
			vector<wcs> array_directories = find_directories(dir + L"/*.*");
			for(size_t i = 0; i < array_directories.size(); ++i)
			{
				vector<wcs> files = find_files_recursive(dir + L"/" + array_directories[i], pattern);
				array_files.insert(array_files.end(), files.begin(), files.end());
			}
			return array_files;
		}
예제 #10
0
파일: estimate.c 프로젝트: halgandd/bacula
/*
 * Find all the requested files and count them.
 */
int make_estimate(JCR *jcr)
{
   int stat;

   set_jcr_job_status(jcr, JS_Running);

   set_find_options((FF_PKT *)jcr->ff, jcr->incremental, jcr->mtime);
   stat = find_files(jcr, (FF_PKT *)jcr->ff, tally_file, NULL);

   return stat;
}
예제 #11
0
void build_flist(WBROWSER *wb)
{
  BROWSE_FILES browse_files ;
  int          i, trouve ;
  char         *slash ;

  memset( &browse_files, 0, sizeof(browse_files) ) ;
  strcpy( wb->base_path, wb->nom ) ;
  slash = strrchr( wb->base_path, '\\' ) ;
  if ( slash ) *slash = 0 ;

  find_files( config.flags & FLG_LONGFNAME, wb->base_path, "*.*", prepare_list, &browse_files ) ;
  wb->fimg_list = calloc( browse_files.nb_files, sizeof(char *) ) ;

  if ( wb->fimg_list )
  {
    browse_files.nfile = 0 ;
    wb->buffer_list = calloc( 1, browse_files.nb_bytes_for_names + 500 ) ; /* +500 si jamais des fichiers nouveaux sont apparus ... */
    browse_files.last_ptname = wb->buffer_list ;
    if ( wb->buffer_list )
    {
      browse_files.fimg_list = wb->fimg_list ;
      find_files( config.flags & FLG_LONGFNAME, wb->base_path, "*.*", add_file_to_list, &browse_files ) ;
      wb->nb_files = browse_files.nfile ;

      /* Trier le dossier */
      qsort( wb->fimg_list, wb->nb_files, sizeof(char**), cmp_file ) ;

      /* Recherche de la position du fichier courant */
      trouve = 0 ;
      for ( i = 0; !trouve && ( i < wb->nb_files ) ; i++ )
        if ( strcmpi( wb->fimg_list[i], 1 + slash ) == 0 ) trouve = 1 ;

      if ( trouve ) wb->pos = i-1 ;
      else          wb->pos = 0 ;
    }
  }
}
예제 #12
0
파일: estimate.c 프로젝트: AlD/bareos
/*
 * Find all the requested files and count them.
 */
int make_estimate(JCR *jcr)
{
   int status;

   jcr->setJobStatus(JS_Running);

   set_find_options((FF_PKT *)jcr->ff, jcr->incremental, jcr->mtime);
   /* in accurate mode, we overwrite the find_one check function */
   if (jcr->accurate) {
      set_find_changed_function((FF_PKT *)jcr->ff, accurate_check_file);
   }

   status = find_files(jcr, (FF_PKT *)jcr->ff, tally_file, plugin_estimate);
   accurate_free(jcr);
   return status;
}
예제 #13
0
int find_files(char *filespec)
{
	long            h, err;
	struct _finddata_t data;
	char           *filename, *prevname;
	unsigned int    failID;
	int             failpos;

	filename = malloc(520);
	if(!filename)
		return 0;
	prevname = filename + 260;

	err = h = _findfirst(filespec, &data);
	if(err == -1)
	{
		printf("No files found: '%s'\n", filespec);
		return 0;
	}

	while(err != -1)
	{
		if((data.attrib & _A_SUBDIR) && data.name[0] != '.')
		{
			make_filespec(filespec, data.name, filename);
			find_files(filename);
		}
		if(!(data.attrib & _A_SUBDIR))
		{
			make_filename(filespec, data.name, filename);
			if(!strcmp(filename, prevname))
				break;
			strcpy(prevname, filename);
			printf("%s\n", filename);
			failID = failpos = 0;
			if(!testload(filename, &failID, &failpos))
			{
				printf("%s\nLoading failed near byte %d\n\n", filename, failpos);
			}
		}
		err = _findnext(h, &data);
	}

	_findclose(h);
	free(filename);
	return 1;
}
예제 #14
0
		int load_jsonfiles_from_dir( const std::string& files_path,json_file_vec& vec )
		{
			LogS << "load json files form:" << files_path << LogEnd;

			vector<path> v;
			path dir;
			dir /= files_path;
			find_files(dir,"*.json",v);
			if(v.size()==0) return 0;
			for (vector<path>::iterator i = v.begin();i!=v.end();++i)
			{
				path& p = *i;
				LogS << "filename:" << p.generic_string() << LogEnd;
				vec.push_back(load_jsonfile(p.generic_string()));
			}
			return 1;
		}
예제 #15
0
static int find_ordered_chapter_sources(struct MPContext *mpctx,
                                        struct demuxer **sources,
                                        int num_sources,
                                        unsigned char uid_map[][16])
{
    int num_filenames = 0;
    char **filenames = NULL;
    if (num_sources > 1) {
        char *main_filename = mpctx->demuxer->filename;
        mp_msg(MSGT_CPLAYER, MSGL_INFO, "This file references data from "
               "other sources.\n");
        if (mpctx->demuxer->stream->uncached_type != STREAMTYPE_FILE) {
            mp_msg(MSGT_CPLAYER, MSGL_WARN, "Playback source is not a "
                   "normal disk file. Will not search for related files.\n");
        } else {
            mp_msg(MSGT_CPLAYER, MSGL_INFO, "Will scan other files in the "
                   "same directory to find referenced sources.\n");
            filenames = find_files(main_filename, ".mkv");
            num_filenames = MP_TALLOC_ELEMS(filenames);
        }
        // Possibly get further segments appended to the first segment
        check_file(mpctx, sources, num_sources, uid_map, main_filename, 1);
    }

    for (int i = 0; i < num_filenames; i++) {
        if (!missing(sources, num_sources))
            break;
        mp_msg(MSGT_CPLAYER, MSGL_INFO, "Checking file %s\n", filenames[i]);
        check_file(mpctx, sources, num_sources, uid_map, filenames[i], 0);
    }

    talloc_free(filenames);
    if (missing(sources, num_sources)) {
        mp_msg(MSGT_CPLAYER, MSGL_ERR, "Failed to find ordered chapter part!\n"
               "There will be parts MISSING from the video!\n");
        int j = 1;
        for (int i = 1; i < num_sources; i++)
            if (sources[i]) {
                sources[j] = sources[i];
                memcpy(uid_map[j], uid_map[i], 16);
                j++;
            }
        num_sources = j;
    }
    return num_sources;
}
예제 #16
0
void CPreGame::ShowMapList(void)
{
	CglList* list=new CglList("Select map",SelectMap);
	fs::path fn("maps/");
	std::vector<fs::path> found = find_files(fn,"*.smf");
	std::vector<std::string> arFound = archiveScanner->GetMaps();
	if (found.begin() == found.end() && arFound.begin() == arFound.end()
			) {
		handleerror(0,"Couldnt find any map files","PreGame error",0);
		return;
	}
	for (std::vector<fs::path>::iterator it = found.begin(); it != found.end(); it++)
		list->AddItem(it->leaf().c_str(),it->leaf().c_str());
	for (std::vector<std::string>::iterator it = arFound.begin(); it != arFound.end(); it++)
		list->AddItem((*it).c_str(), (*it).c_str());

	showList=list;
}
예제 #17
0
void			completion(t_cursor *cursor, t_hist **hist)
{
	t_info		info;
	int			i;

	(void)hist;
	g_shell->comp = 1;
	g_shell->info = &info;
	i = cursor->cur_col - 3 + cursor->max_col * (cursor->cur_line - 1);
	if (cursor->line[i] == ' ' || cursor->line[i] == '\0')
	{
		find_files(cursor, &info, i);
		if (info.arg)
			ft_select(&info, cursor);
		ft_strdel(&info.file);
		free(info.dir);
	}
	g_shell->comp = 0;
}
예제 #18
0
		int load_jsonfiles_from_dir( const std::string& files_path,json_value_vec& vec )
		{
			LogS << "load json files form:" << files_path << LogEnd;

			vector<path> v;
			path dir;
			dir /= files_path;
			find_files(dir,"*.json",v);
			if(v.size()==0) return 0;
			for (vector<path>::iterator i = v.begin();i!=v.end();++i)
			{
				path& p = *i;
				string s = load_jsonfile(p.generic_string());
				Json::Value val;
				Json::Reader reader;
				reader.parse(s, val);
				vec.push_back(val);
			}
			return 1;
		}
예제 #19
0
파일: verify.c 프로젝트: rustyangel/bareos
/*
 * Find all the requested files and send attributes
 * to the Director.
 *
 */
void do_verify(JCR *jcr)
{
   jcr->setJobStatus(JS_Running);
   jcr->buf_size = DEFAULT_NETWORK_BUFFER_SIZE;
   if ((jcr->big_buf = (char *) malloc(jcr->buf_size)) == NULL) {
      Jmsg1(jcr, M_ABORT, 0, _("Cannot malloc %d network read buffer\n"),
         DEFAULT_NETWORK_BUFFER_SIZE);
   }
   set_find_options((FF_PKT *)jcr->ff, jcr->incremental, jcr->mtime);
   Dmsg0(10, "Start find files\n");
   /* Subroutine verify_file() is called for each file */
   find_files(jcr, (FF_PKT *)jcr->ff, verify_file, NULL);
   Dmsg0(10, "End find files\n");

   if (jcr->big_buf) {
      free(jcr->big_buf);
      jcr->big_buf = NULL;
   }
   jcr->setJobStatus(JS_Terminated);
}
예제 #20
0
		int load_jsonfiles_from_dir( const std::string& files_path,json_value_map& m, string item_id)
		{
			LogS << "load json files form:" << files_path << LogEnd;

			vector<path> v;
			path dir;
			dir /= files_path;
			find_files(dir,"*.json",v);
			if(v.size()==0) return 0;
			for (vector<path>::iterator i = v.begin();i!=v.end();++i)
			{
				path& p = *i;
				string s = load_jsonfile(p.generic_string());
				Json::Value val;
				Json::Reader reader;
				reader.parse(s, val);
				m.insert(make_pair(val[item_id].asInt(),val));
			}
			return 1;
		}
예제 #21
0
파일: main.cpp 프로젝트: jdelgad/ssfi
int main(int argc, char *argv[])
{
    int number_of_threads{0};
    std::string directory;

    ssfi::parse_args(argc, argv, number_of_threads, directory);

    boost::filesystem::path path(directory);

    ssfi::check_directory(path);

    BOOST_LOG_TRIVIAL(info) << "Finding text files under " << directory;
    BOOST_LOG_TRIVIAL(info) << "Number of worker threads to read in text "
                            << "files: " << number_of_threads;

    //std::shared_ptr<WorkerQueue> worker_queue_ptr =
    auto worker_queue_ptr =
            std::make_shared<ssfi::BoostAsIOQueue>(number_of_threads);
    worker_queue_ptr->spawn_threads();

    ssfi::FileLocator file_locator{".txt", worker_queue_ptr};

    // Requirement 2: start up a thread to find all of the files passed in via
    // a command line argument
    boost::thread find_files(&ssfi::FileLocator::recursively_find_files,
            &file_locator, path);

    find_files.join();
    worker_queue_ptr->clear();
    worker_queue_ptr->join();

    BOOST_LOG_TRIVIAL(trace) << "Worker queue finished";

    const auto count_word_map = file_locator.get_parser().get_count_word_map();

    BOOST_LOG_TRIVIAL(trace) << "length of map = " << count_word_map.size();

    ssfi::print_top_words(10, count_word_map);

    return 0;
}
예제 #22
0
/**
 * @brief Performs a volume analysis.
 * @return Zero for success, negative value otherwise.
 */
int analyze(udefrag_job_parameters *jp)
{
    ULONGLONG time;
    int result;
    
    time = start_timing("analysis",jp);
    jp->pi.current_operation = VOLUME_ANALYSIS;
    
    /* update volume information */
    result = get_volume_information(jp);
    if(result < 0)
        return result;
    
    /* scan volume for free space areas */
    if(get_free_space_layout(jp) < 0)
        return (-1);
    
    /* redraw mft zone in light magenta */
    get_mft_zones_layout(jp);
    
    /* search for files */
    if(find_files(jp) < 0)
        return (-1);
    
    /* redraw well known locked files in green */
    redraw_well_known_locked_files(jp);

    /* produce list of fragmented files */
    produce_list_of_fragmented_files(jp);
    (void)check_fragmentation_level(jp); /* for debugging */

    result = check_requested_action(jp);
    if(result < 0)
        return result;
    
    jp->p_counters.analysis_time = winx_xtime() - time;
    stop_timing("analysis",time,jp);
    return 0;
}
예제 #23
0
파일: main.c 프로젝트: mark711/Cafu
void main( int argc, char *argv[] )
{
   float t1, t2;

   if ( argc != 2 ) {
      printf( "Usage:  %s <filespec>\n", argv[ 0 ] );
      exit( 0 );
   }

   t1 = ( float ) clock() / CLOCKS_PER_SEC;
   find_files( argv[ 1 ] );
   t2 = ( float ) clock() / CLOCKS_PER_SEC - t1;

   printf( "\n%8d objects\n", nobjects );
   printf( "%8d layers\n", nlayers );
   printf( "%8d surfaces\n", nsurfs );
   printf( "%8d envelopes\n", nenvs );
   printf( "%8d clips\n", nclips );
   printf( "%8d points\n", npoints );
   printf( "%8d polygons\n\n", npolygons );
   printf( "%g seconds\n\n", t2 );
}
예제 #24
0
파일: puppack.c 프로젝트: Arikado/SCEkrit
int main(int argc, char *argv[])
{
	if (argc < 3)
		fail("usage: puppack filename.pup directory");

	if (key_get_simple("pup-hmac", pup_hmac, sizeof pup_hmac) < 0)
		fail("pup hmac key not available");

	fp = fopen(argv[1], "wb");
	if (fp == NULL)
		fail("fopen(%s)", argv[1]);

	if (chdir(argv[2]) < 0)
		fail("chdir(%s)", argv[1]);

	find_files();
	build_header();
	write_pup();

	fclose(fp);

	return 0;
}
예제 #25
0
/*
 * The chain command to display the cluster
 * chain of a directory entry.
 */
void cmd_chain(int argc, char *argv[])
{
     entlist_t *list, *ent;
     
     if (argc < 2) {
          display(NORMAL, "Usage: chain [file] ...\n");
          return;
     }
     
     /* get a list of files the user specified */
     if (!(list = find_files(argc - 1, &argv[1]))) {
          display(NORMAL, "No files found\n");
          return;
     }

     /* loop through the list of files, displaying 
      * cluster chains for each */
     for (ent = list; ent; ent = ent->next) {
          unsigned long clust = 0;
          dirent_t *dent = ent->ent;
          char *fn = dent->lfn ? dent->lfn : dent->filename;
          display(NORMAL, "cluster chain for \"%s\"\n", fn);
          do {
               clust = clust ? clusts[clust].fat_entry : dent->cluster;
               display(NORMAL, "%10lu", clust);
          } while (clust >= 2 &&
                   !clust_is_end(&clusts[clust]) &&
                   !clust_is_bad(&clusts[clust]));
          display(NORMAL, "\n");
     }
     ent = list;
     while (ent) {
          entlist_t *tmp = ent->next;
          free(ent);
          ent = tmp;
     }
}
예제 #26
0
void find_tree
(const Filename& fn_where, const std::string& what, DoStr dostr, void* from)
{
    std::string where = fn_where.get_rootful();
    // Nach Verzeichnissen suchen
    al_ffblk info;
    if (where[where.size()-1] != '/') where += '/';
    std::string search_for = where + '*';
    if (al_findfirst(search_for.c_str(), &info,
     FA_RDONLY | FA_HIDDEN | FA_LABEL | FA_DIREC | FA_ARCH) == 0) {
        do {
            // Dies nur f�r jedes Verzeichnis au�er . und .. ausf�hren:
            // Neue Suche mit gleichem Vektor im gefundenen Verzeichnis
            if ((info.attrib & FA_DIREC) == FA_DIREC && info.name[0] != '.') {
                Filename fn_recurs(where + info.name + '/');
                find_tree(fn_recurs, what, dostr, from);
            }
        } while (al_findnext(&info) == 0);
        al_findclose(&info);
    }
    // Nach Dateien suchen, die dem Suchkriterium entsprechen
    Filename fn_where_with_slash(where);
    find_files(fn_where_with_slash, what, dostr, from);
}
예제 #27
0
bool camera_directory<Tdata>::read_directory(const char *dir)
{
    out << "Image search pattern: " << file_pattern << " in "
        << dir << std::endl;
    std::string directory = dir;
    if (directory[directory.length() - 1] != '/')
        directory += '/';
    indir = directory;
    // // first count number of images, to allocate list and speed up
    // uint n = count_files(directory, file_pattern);
    // if (fl) delete fl;
    // fl = new files_list(n);
    // get all file names
    if (fl) delete fl;
    fl = find_files(directory, file_pattern, NULL,
                    randomize ? false : true, true, randomize);
    if (!fl)
    {
        err << "invalid directory: " << dir << std::endl;
        eblerror("invalid directory");
        return false;
    }
    return true;
}
예제 #28
0
파일: backup.c 프로젝트: tuxmux/bareos
/**
 * Find all the requested files and send them
 * to the Storage daemon.
 *
 * Note, we normally carry on a one-way
 * conversation from this point on with the SD, simply blasting
 * data to him.  To properly know what is going on, we
 * also run a "heartbeat" monitor which reads the socket and
 * reacts accordingly (at the moment it has nothing to do
 * except echo the heartbeat to the Director).
 */
bool blast_data_to_storage_daemon(JCR *jcr, char *addr, crypto_cipher_t cipher)
{
   BSOCK *sd;
   bool ok = true;

   sd = jcr->store_bsock;

   jcr->setJobStatus(JS_Running);

   Dmsg1(300, "filed: opened data connection %d to stored\n", sd->m_fd);

   LockRes();
   CLIENTRES *client = (CLIENTRES *)GetNextRes(R_CLIENT, NULL);
   UnlockRes();
   uint32_t buf_size;
   if (client) {
      buf_size = client->max_network_buffer_size;
   } else {
      buf_size = 0;                   /* use default */
   }
   if (!sd->set_buffer_size(buf_size, BNET_SETBUF_WRITE)) {
      jcr->setJobStatus(JS_ErrorTerminated);
      Jmsg(jcr, M_FATAL, 0, _("Cannot set buffer size FD->SD.\n"));
      return false;
   }

   jcr->buf_size = sd->msglen;

   if (!adjust_compression_buffers(jcr)) {
      return false;
   }

   if (!crypto_session_start(jcr, cipher)) {
      return false;
   }

   set_find_options((FF_PKT *)jcr->ff, jcr->incremental, jcr->mtime);

   /**
    * In accurate mode, we overload the find_one check function
    */
   if (jcr->accurate) {
      set_find_changed_function((FF_PKT *)jcr->ff, accurate_check_file);
   }

   start_heartbeat_monitor(jcr);

   if (have_acl) {
      jcr->acl_data = (acl_data_t *)malloc(sizeof(acl_data_t));
      memset(jcr->acl_data, 0, sizeof(acl_data_t));
      jcr->acl_data->u.build = (acl_build_data_t *)malloc(sizeof(acl_build_data_t));
      memset(jcr->acl_data->u.build, 0, sizeof(acl_build_data_t));
      jcr->acl_data->u.build->content = get_pool_memory(PM_MESSAGE);
   }

   if (have_xattr) {
      jcr->xattr_data = (xattr_data_t *)malloc(sizeof(xattr_data_t));
      memset(jcr->xattr_data, 0, sizeof(xattr_data_t));
      jcr->xattr_data->u.build = (xattr_build_data_t *)malloc(sizeof(xattr_build_data_t));
      memset(jcr->xattr_data->u.build, 0, sizeof(xattr_build_data_t));
      jcr->xattr_data->u.build->content = get_pool_memory(PM_MESSAGE);
   }

   /**
    * Subroutine save_file() is called for each file
    */
   if (!find_files(jcr, (FF_PKT *)jcr->ff, save_file, plugin_save)) {
      ok = false;                     /* error */
      jcr->setJobStatus(JS_ErrorTerminated);
   }

   if (have_acl && jcr->acl_data->u.build->nr_errors > 0) {
      Jmsg(jcr, M_WARNING, 0, _("Encountered %ld acl errors while doing backup\n"),
           jcr->acl_data->u.build->nr_errors);
   }
   if (have_xattr && jcr->xattr_data->u.build->nr_errors > 0) {
      Jmsg(jcr, M_WARNING, 0, _("Encountered %ld xattr errors while doing backup\n"),
           jcr->xattr_data->u.build->nr_errors);
   }

   close_vss_backup_session(jcr);

   accurate_finish(jcr);              /* send deleted or base file list to SD */

   stop_heartbeat_monitor(jcr);

   sd->signal(BNET_EOD);            /* end of sending data */

   if (have_acl && jcr->acl_data) {
      free_pool_memory(jcr->acl_data->u.build->content);
      free(jcr->acl_data->u.build);
      free(jcr->acl_data);
      jcr->acl_data = NULL;
   }

   if (have_xattr && jcr->xattr_data) {
      free_pool_memory(jcr->xattr_data->u.build->content);
      free(jcr->xattr_data->u.build);
      free(jcr->xattr_data);
      jcr->xattr_data = NULL;
   }

   if (jcr->big_buf) {
      free(jcr->big_buf);
      jcr->big_buf = NULL;
   }

   cleanup_compression(jcr);
   crypto_session_end(jcr);

   Dmsg1(100, "end blast_data ok=%d\n", ok);
   return ok;
}
예제 #29
0
/*! This function reads initial conditions, in one of the three possible file
 *  formats currently supported by Gadget.  Note: When a snapshot file is
 *  started from initial conditions (start-option 0), not all the information
 *  in the header is used, in particular, the STARTING TIME needs to be set in
 *  the parameterfile.  Also, for gas particles, only the internal energy is
 *  read, the density and mean molecular weight will be recomputed by the
 *  code.  When InitGasTemp>0 is given, the gas temperature will be initialzed
 *  to this value assuming a mean colecular weight either corresponding to
 *  complete neutrality, or full ionization.
 *
 *  However, when the code is started with start-option 2, then all the this
 *  data in the snapshot files is preserved, i.e. this is also the way to
 *  resume a simulation from a snapshot file in case a regular restart file is
 *  not available.
 */
void read_ic(char *fname)
{
  int i, num_files, rest_files, ngroups, gr, filenr, masterTask, lastTask, groupMaster;
  double u_init;
  char buf[500];

#ifndef ISOTHERM_EQS
  double molecular_weight;
#endif
#ifdef SFR
  double original_gas_mass, mass, masstot;
#endif

  NumPart = 0;
  N_gas = 0;
  All.TotNumPart = 0;

  num_files = find_files(fname);

  rest_files = num_files;

  fill_Tab_IO_Labels();

  while(rest_files > NTask)
    {
      sprintf(buf, "%s.%d", fname, ThisTask + (rest_files - NTask));
      if(All.ICFormat == 3)
	sprintf(buf, "%s.%d.hdf5", fname, ThisTask + (rest_files - NTask));

      ngroups = NTask / All.NumFilesWrittenInParallel;
      if((NTask % All.NumFilesWrittenInParallel))
	ngroups++;
      groupMaster = (ThisTask / ngroups) * ngroups;

      for(gr = 0; gr < ngroups; gr++)
	{
	  if(ThisTask == (groupMaster + gr))	/* ok, it's this processor's turn */
	    read_file(buf, ThisTask, ThisTask);
	  MPI_Barrier(MPI_COMM_WORLD);
	}

      rest_files -= NTask;
    }


  if(rest_files > 0)
    {
      distribute_file(rest_files, 0, 0, NTask - 1, &filenr, &masterTask, &lastTask);

      if(num_files > 1)
	{
	  sprintf(buf, "%s.%d", fname, filenr);
	  if(All.ICFormat == 3)
	    sprintf(buf, "%s.%d.hdf5", fname, filenr);
	}
      else
	{
	  sprintf(buf, "%s", fname);
	  if(All.ICFormat == 3)
	    sprintf(buf, "%s.hdf5", fname);
	}

      ngroups = rest_files / All.NumFilesWrittenInParallel;
      if((rest_files % All.NumFilesWrittenInParallel))
	ngroups++;

      for(gr = 0; gr < ngroups; gr++)
	{
	  if((filenr / All.NumFilesWrittenInParallel) == gr)	/* ok, it's this processor's turn */
	    read_file(buf, masterTask, lastTask);
	  MPI_Barrier(MPI_COMM_WORLD);
	}
    }


  /* this makes sure that masses are initialized in the case that the mass-block
     is completely empty */
  for(i = 0; i < NumPart; i++)
    {
      if(All.MassTable[P[i].Type] != 0)
	P[i].Mass = All.MassTable[P[i].Type];
    }

  if(RestartFlag == 0)
    {
#ifdef NEUTRINO_FLUID
       /* Initial sound velocity = 3.6e-5 c (94.1 Omega_Nu * h^2)^-2 * (1+z)^2 */
       u_init  = (BOLTZMANN / PROTONMASS) * 10000.;
       u_init *= All.UnitMass_in_g / All.UnitEnergy_in_cgs;	/* unit conversion */
       if (ThisTask == 0) printf("U_init 10000K :  %f\n\n",u_init);

       u_init = 0.2 * 2.02e-7 * (29979245800. / All.UnitVelocity_in_cm_per_s)        

                * (29979245800. / All.UnitVelocity_in_cm_per_s)

                / (94.1 * All.OmegaNeutrino * All.HubbleParam * All.HubbleParam)
                / (94.1 * All.OmegaNeutrino * All.HubbleParam * All.HubbleParam)
                / (All.Time * All.Time);
       if (ThisTask == 0) printf("U_init Neutrinos :  %f\n\n",u_init);
       All.InitGasTemp = u_init; 

       for(i = 0; i < N_gas; i++)
         {
           SphP[i].Entropy = u_init;
           /* Note: the coversion to entropy will be done in the function init(),
              after the densities have been computed */
         }
#else 
      if(All.InitGasTemp > 0)
	{
	  u_init = (BOLTZMANN / PROTONMASS) * All.InitGasTemp;
	  u_init *= All.UnitMass_in_g / All.UnitEnergy_in_cgs;	/* unit conversion */

#ifdef ISOTHERM_EQS
	  u_init *= 1.0;
#else
	  u_init *= (1.0 / GAMMA_MINUS1);

	  if(All.InitGasTemp > 1.0e4)	/* assuming FULL ionization */
	    molecular_weight = 4 / (8 - 5 * (1 - HYDROGEN_MASSFRAC));
	  else			/* assuming NEUTRAL GAS */
	    molecular_weight = 4 / (1 + 3 * HYDROGEN_MASSFRAC);

	  u_init /= molecular_weight;
#endif

	  for(i = 0; i < N_gas; i++)
	    {
	      if(SphP[i].Entropy == 0)
		SphP[i].Entropy = u_init;

	      /* Note: the coversion to entropy will be done in the function init(),
	         after the densities have been computed */
	    }
	}
#endif
    }

  for(i = 0; i < N_gas; i++)
    SphP[i].Entropy = dmax(All.MinEgySpec, SphP[i].Entropy);

  MPI_Barrier(MPI_COMM_WORLD);

  if(ThisTask == 0)
    {
      printf("reading done.\n");
      fflush(stdout);
    }

  if(ThisTask == 0)
    {
      printf("Total number of particles :  %d%09d\n\n",
	     (int) (All.TotNumPart / 1000000000), (int) (All.TotNumPart % 1000000000));
      fflush(stdout);
    }
}
예제 #30
0
파일: find.c 프로젝트: Sherlock221B/burp
int find_files_begin(struct asfd *asfd,
	FF_PKT *ff_pkt, struct conf *conf, char *fname)
{
	return find_files(asfd, ff_pkt,
		conf, fname, (dev_t)-1, 1 /* top_level */);
}