fragmentiertes filesystem nachbilden



  • hi,
    wie kann ich mit boost::filesystem eine fragmentiertes filesystem nachbilden? viele kleine files erzeugen dann alle x files loeschen und groessere files erzeugen usw? wie kann man dann den fragmentierungsgrad bestimmen?

    hier mal meine funktion um einen filesystem tree zu erzeugen:

    void createFATTree(const string &path_current, int depth = 0, int maxdepth = 2, int subdircount = 2) {
    	if(depth > maxdepth)
    		return;
    	for(unsigned int i = 0; i < subdircount; i++) {
    		stringstream s, ast;
    		s << depth;
           		ast << i;
    		createDirectory(path_current + "/FOO_" + s.str() + "_" + ast.str());
    		createFile(path_current + "/FOO_" + s.str() + "_" + ast.str());
           		createFATTree(path_current + "/FOO_" + s.str() + "_" + ast.str(), depth+1, maxdepth, subdircount);
    	}
    }
    
    void createDirectory(const string &dir_name) {
    	fs::path dir_path(dir_name, fs::native);
    	if(!fs::create_directory( dir_path ))
    		throw fs::filesystem_error("mkdir failed", dir_path, errno);
            string tmp(dir_path.string());
    	tmp.erase(0, root_str.length()); 
    	config << "type=Directory " << "name=" << tmp << endl;
    }
    
    void createFile(const string &file_name, const string &content = "") {
    	string filename = file_name + ".txt";
    	ofstream file(filename.c_str());
    
            // if content == "" fill file with random data
    	if(content.length() == 0) {
    		unsigned int random_integer = (rand()%file_size_max)+file_size_min;
    
    		char buffer[random_integer*SIZE];
    		memset(&buffer, 0, sizeof(buffer));
    
    		ifstream random_data("/dev/urandom", ios::in | ios::binary);
    		random_data.read(buffer, random_integer*SIZE);
    		random_data.close();
    
    		file.write(buffer, random_integer*SIZE);
    	}
    	else {
    		file.write(content.c_str(), content.length());
    	}
    	file.close();
    }
    


  • Was willst du denn damit erreichen?

    BTW: ob du das mit boost filesystem machst oder mit native Funktionen ist vollkommen egal.


Anmelden zum Antworten