<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[fragmentiertes filesystem nachbilden]]></title><description><![CDATA[<p>hi,<br />
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?</p>
<p>hier mal meine funktion um einen filesystem tree zu erzeugen:</p>
<pre><code class="language-cpp">void createFATTree(const string &amp;path_current, int depth = 0, int maxdepth = 2, int subdircount = 2) {
	if(depth &gt; maxdepth)
		return;
	for(unsigned int i = 0; i &lt; subdircount; i++) {
		stringstream s, ast;
		s &lt;&lt; depth;
       		ast &lt;&lt; i;
		createDirectory(path_current + &quot;/FOO_&quot; + s.str() + &quot;_&quot; + ast.str());
		createFile(path_current + &quot;/FOO_&quot; + s.str() + &quot;_&quot; + ast.str());
       		createFATTree(path_current + &quot;/FOO_&quot; + s.str() + &quot;_&quot; + ast.str(), depth+1, maxdepth, subdircount);
	}
}

void createDirectory(const string &amp;dir_name) {
	fs::path dir_path(dir_name, fs::native);
	if(!fs::create_directory( dir_path ))
		throw fs::filesystem_error(&quot;mkdir failed&quot;, dir_path, errno);
        string tmp(dir_path.string());
	tmp.erase(0, root_str.length()); 
	config &lt;&lt; &quot;type=Directory &quot; &lt;&lt; &quot;name=&quot; &lt;&lt; tmp &lt;&lt; endl;
}

void createFile(const string &amp;file_name, const string &amp;content = &quot;&quot;) {
	string filename = file_name + &quot;.txt&quot;;
	ofstream file(filename.c_str());

        // if content == &quot;&quot; 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(&amp;buffer, 0, sizeof(buffer));

		ifstream random_data(&quot;/dev/urandom&quot;, 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();
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/173410/fragmentiertes-filesystem-nachbilden</link><generator>RSS for Node</generator><lastBuildDate>Fri, 18 Sep 2026 06:39:36 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/173410.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 14 Feb 2007 20:14:25 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to fragmentiertes filesystem nachbilden on Wed, 14 Feb 2007 20:14:25 GMT]]></title><description><![CDATA[<p>hi,<br />
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?</p>
<p>hier mal meine funktion um einen filesystem tree zu erzeugen:</p>
<pre><code class="language-cpp">void createFATTree(const string &amp;path_current, int depth = 0, int maxdepth = 2, int subdircount = 2) {
	if(depth &gt; maxdepth)
		return;
	for(unsigned int i = 0; i &lt; subdircount; i++) {
		stringstream s, ast;
		s &lt;&lt; depth;
       		ast &lt;&lt; i;
		createDirectory(path_current + &quot;/FOO_&quot; + s.str() + &quot;_&quot; + ast.str());
		createFile(path_current + &quot;/FOO_&quot; + s.str() + &quot;_&quot; + ast.str());
       		createFATTree(path_current + &quot;/FOO_&quot; + s.str() + &quot;_&quot; + ast.str(), depth+1, maxdepth, subdircount);
	}
}

void createDirectory(const string &amp;dir_name) {
	fs::path dir_path(dir_name, fs::native);
	if(!fs::create_directory( dir_path ))
		throw fs::filesystem_error(&quot;mkdir failed&quot;, dir_path, errno);
        string tmp(dir_path.string());
	tmp.erase(0, root_str.length()); 
	config &lt;&lt; &quot;type=Directory &quot; &lt;&lt; &quot;name=&quot; &lt;&lt; tmp &lt;&lt; endl;
}

void createFile(const string &amp;file_name, const string &amp;content = &quot;&quot;) {
	string filename = file_name + &quot;.txt&quot;;
	ofstream file(filename.c_str());

        // if content == &quot;&quot; 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(&amp;buffer, 0, sizeof(buffer));

		ifstream random_data(&quot;/dev/urandom&quot;, 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();
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1229066</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1229066</guid><dc:creator><![CDATA[cpp1]]></dc:creator><pubDate>Wed, 14 Feb 2007 20:14:25 GMT</pubDate></item><item><title><![CDATA[Reply to fragmentiertes filesystem nachbilden on Wed, 14 Feb 2007 22:19:57 GMT]]></title><description><![CDATA[<p>Was willst du denn damit erreichen?</p>
<p>BTW: ob du das mit boost filesystem machst oder mit native Funktionen ist vollkommen egal.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1229120</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1229120</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Wed, 14 Feb 2007 22:19:57 GMT</pubDate></item></channel></rss>