<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://criu.org/index.php?action=history&amp;feed=atom&amp;title=How_hard_is_it_to_open_a_file</id>
	<title>How hard is it to open a file - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://criu.org/index.php?action=history&amp;feed=atom&amp;title=How_hard_is_it_to_open_a_file"/>
	<link rel="alternate" type="text/html" href="https://criu.org/index.php?title=How_hard_is_it_to_open_a_file&amp;action=history"/>
	<updated>2026-05-13T14:50:31Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.6</generator>
	<entry>
		<id>https://criu.org/index.php?title=How_hard_is_it_to_open_a_file&amp;diff=3587&amp;oldid=prev</id>
		<title>Kir: Intro added</title>
		<link rel="alternate" type="text/html" href="https://criu.org/index.php?title=How_hard_is_it_to_open_a_file&amp;diff=3587&amp;oldid=prev"/>
		<updated>2016-09-24T02:57:19Z</updated>

		<summary type="html">&lt;p&gt;Intro added&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left diff-editfont-monospace&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 02:57, 24 September 2016&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot; &gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;This article outlines what CRIU restore needs to take care of when re-creating an open file descriptor.&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Let's imagine we have an information about a file we want to open.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Let's imagine we have an information about a file we want to open.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;What should it contain? Apparently, access mode and path:&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;What should it contain? Apparently, access mode and path:&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key criuwikidb:diff::1.12:old-3474:rev-3587 --&gt;
&lt;/table&gt;</summary>
		<author><name>Kir</name></author>
	</entry>
	<entry>
		<id>https://criu.org/index.php?title=How_hard_is_it_to_open_a_file&amp;diff=3474&amp;oldid=prev</id>
		<title>Kir: use source highlighting; fixes and improvements in English</title>
		<link rel="alternate" type="text/html" href="https://criu.org/index.php?title=How_hard_is_it_to_open_a_file&amp;diff=3474&amp;oldid=prev"/>
		<updated>2016-09-20T23:42:23Z</updated>

		<summary type="html">&lt;p&gt;use source highlighting; fixes and improvements in English&lt;/p&gt;
&lt;a href=&quot;https://criu.org/index.php?title=How_hard_is_it_to_open_a_file&amp;amp;diff=3474&amp;amp;oldid=2133&quot;&gt;Show changes&lt;/a&gt;</summary>
		<author><name>Kir</name></author>
	</entry>
	<entry>
		<id>https://criu.org/index.php?title=How_hard_is_it_to_open_a_file&amp;diff=2133&amp;oldid=prev</id>
		<title>Xemul: cat files</title>
		<link rel="alternate" type="text/html" href="https://criu.org/index.php?title=How_hard_is_it_to_open_a_file&amp;diff=2133&amp;oldid=prev"/>
		<updated>2015-02-26T15:45:42Z</updated>

		<summary type="html">&lt;p&gt;cat files&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left diff-editfont-monospace&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 15:45, 26 February 2015&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l289&quot; &gt;Line 289:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 289:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Under the hood]]&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Under the hood]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[Category:Files]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Xemul</name></author>
	</entry>
	<entry>
		<id>https://criu.org/index.php?title=How_hard_is_it_to_open_a_file&amp;diff=1844&amp;oldid=prev</id>
		<title>Xemul at 08:46, 3 December 2014</title>
		<link rel="alternate" type="text/html" href="https://criu.org/index.php?title=How_hard_is_it_to_open_a_file&amp;diff=1844&amp;oldid=prev"/>
		<updated>2014-12-03T08:46:15Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left diff-editfont-monospace&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 08:46, 3 December 2014&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l39&quot; &gt;Line 39:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 39:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Now this seems to be OK, but it's actually not. In Linux file can be&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Now this seems to be OK, but it's actually not. In Linux file can be&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;unlinked while being opened. In that case what was formerly pointed by&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;unlinked while being opened &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;(these [[invisible files]] are treated carefully&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;on dump)&lt;/ins&gt;. In that case what was formerly pointed by&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;path may be kept in some temporary location. And we have to create a&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;path may be kept in some temporary location. And we have to create a&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;temp name for it and unlink one afterwards. So we need to extend the&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;temp name for it and unlink one afterwards. So we need to extend the&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Xemul</name></author>
	</entry>
	<entry>
		<id>https://criu.org/index.php?title=How_hard_is_it_to_open_a_file&amp;diff=1614&amp;oldid=prev</id>
		<title>Xemul at 11:24, 5 August 2014</title>
		<link rel="alternate" type="text/html" href="https://criu.org/index.php?title=How_hard_is_it_to_open_a_file&amp;diff=1614&amp;oldid=prev"/>
		<updated>2014-08-05T11:24:30Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left diff-editfont-monospace&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 11:24, 5 August 2014&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l285&quot; &gt;Line 285:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 285:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;but it's not. &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;We&lt;/del&gt;'&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;ll get back &lt;/del&gt;to &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;it in the next series.&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;but it's not. &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;Here&lt;/ins&gt;'&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;s [[how &lt;/ins&gt;to &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;assign needed file descriptor to a file]] :)&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Under the hood]]&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Under the hood]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Xemul</name></author>
	</entry>
	<entry>
		<id>https://criu.org/index.php?title=How_hard_is_it_to_open_a_file&amp;diff=1572&amp;oldid=prev</id>
		<title>Xemul: Categorized</title>
		<link rel="alternate" type="text/html" href="https://criu.org/index.php?title=How_hard_is_it_to_open_a_file&amp;diff=1572&amp;oldid=prev"/>
		<updated>2014-07-16T13:26:10Z</updated>

		<summary type="html">&lt;p&gt;Categorized&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left diff-editfont-monospace&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 13:26, 16 July 2014&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l286&quot; &gt;Line 286:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 286:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;but it's not. We'll get back to it in the next series.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;but it's not. We'll get back to it in the next series.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[Category:Under the hood]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key criuwikidb:diff::1.12:old-1571:rev-1572 --&gt;
&lt;/table&gt;</summary>
		<author><name>Xemul</name></author>
	</entry>
	<entry>
		<id>https://criu.org/index.php?title=How_hard_is_it_to_open_a_file&amp;diff=1571&amp;oldid=prev</id>
		<title>Xemul: Created page with &quot;OK, let's imagine we have an information about a file we want to open. What should it contain? Apparently access mode and path  &lt;pre&gt; 	struct file { 		char *path; 		unsigned m...&quot;</title>
		<link rel="alternate" type="text/html" href="https://criu.org/index.php?title=How_hard_is_it_to_open_a_file&amp;diff=1571&amp;oldid=prev"/>
		<updated>2014-07-16T11:55:24Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;OK, let&amp;#039;s imagine we have an information about a file we want to open. What should it contain? Apparently access mode and path  &amp;lt;pre&amp;gt; 	struct file { 		char *path; 		unsigned m...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;OK, let's imagine we have an information about a file we want to open.&lt;br /&gt;
What should it contain? Apparently access mode and path&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	struct file {&lt;br /&gt;
		char *path;&lt;br /&gt;
		unsigned mode;&lt;br /&gt;
	} *f;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and we'd like to have that path being opened by a process.  We would&lt;br /&gt;
do it like below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	int fd;&lt;br /&gt;
&lt;br /&gt;
	fd = open(f-&amp;gt;path, f-&amp;gt;mode);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
right? Right, but it's not all. We all know, that not only regular&lt;br /&gt;
files might be opened via paths, but also such things as FIFO-s. And&lt;br /&gt;
plain open with the flags we want it to have may just hang. So we need&lt;br /&gt;
to change that code to look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	int fd, tfd = -1;&lt;br /&gt;
&lt;br /&gt;
	if (S_ISFIFO(f-&amp;gt;mode))&lt;br /&gt;
		tfd = open(f-&amp;gt;path, O_RDWR);&lt;br /&gt;
&lt;br /&gt;
	fd = open(f-&amp;gt;path, f-&amp;gt;mode);&lt;br /&gt;
&lt;br /&gt;
	if (tfd &amp;gt;= 0)&lt;br /&gt;
		close(tfd);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The tfd keeps FIFO read-write opened while we open it with any flags&lt;br /&gt;
we want. Then we close it.&lt;br /&gt;
&lt;br /&gt;
Now this seems to be OK, but it's actually not. In Linux file can be&lt;br /&gt;
unlinked while being opened. In that case what was formerly pointed by&lt;br /&gt;
path may be kept in some temporary location. And we have to create a&lt;br /&gt;
temp name for it and unlink one afterwards. So we need to extend the&lt;br /&gt;
info about file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	struct file {&lt;br /&gt;
		char *path;&lt;br /&gt;
		unsigned mode;&lt;br /&gt;
		char *temp_path;&lt;br /&gt;
	} *f;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and the opening code to take care of that temorary location&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	int fd, tfd = -1;&lt;br /&gt;
&lt;br /&gt;
	if (f-&amp;gt;temp_path)&lt;br /&gt;
		link(f-&amp;gt;temp_path, f-&amp;gt;path);&lt;br /&gt;
&lt;br /&gt;
	if (S_ISFIFO(f-&amp;gt;mode))&lt;br /&gt;
		tfd = open(f-&amp;gt;path, O_RDWR);&lt;br /&gt;
&lt;br /&gt;
	fd = open(f-&amp;gt;path, f-&amp;gt;mode);&lt;br /&gt;
&lt;br /&gt;
	if (tfd &amp;gt;= 0)&lt;br /&gt;
		close(tfd);&lt;br /&gt;
&lt;br /&gt;
	if (f-&amp;gt;temp_path)&lt;br /&gt;
		unlink(f-&amp;gt;path);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And we haven't seen all the code we need to manage what is pointed by&lt;br /&gt;
the temp_path, but let's proceed.&lt;br /&gt;
&lt;br /&gt;
We have forgotten, that opened and unl^w removed can also be a&lt;br /&gt;
directory. On directories link and unlink do not work and we have to&lt;br /&gt;
slightly fix the code to at least try to make things work OK:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	int fd, tfd = -1;&lt;br /&gt;
&lt;br /&gt;
	if (f-&amp;gt;temp_path) {&lt;br /&gt;
		if (S_ISDIR(f-&amp;gt;mode))&lt;br /&gt;
			mkdir(f-&amp;gt;path);&lt;br /&gt;
		else&lt;br /&gt;
			link(f-&amp;gt;temp_path, f-&amp;gt;path);&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	if (S_ISFIFO(f-&amp;gt;mode))&lt;br /&gt;
		tfd = open(f-&amp;gt;path, O_RDWR);&lt;br /&gt;
&lt;br /&gt;
	fd = open(f-&amp;gt;path, f-&amp;gt;mode);&lt;br /&gt;
&lt;br /&gt;
	if (tfd &amp;gt;= 0)&lt;br /&gt;
		close(tfd);&lt;br /&gt;
&lt;br /&gt;
	if (f-&amp;gt;temp_path) {&lt;br /&gt;
		if (S_ISDIR(f-&amp;gt;mode))&lt;br /&gt;
			rmdir(f-&amp;gt;mode);&lt;br /&gt;
		else&lt;br /&gt;
			unlink(f-&amp;gt;path);&lt;br /&gt;
	}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Done. But, we also should take care of hard links. If a file has such&lt;br /&gt;
and both were opened and removed, we cannot after opening just go&lt;br /&gt;
ahead and kill the temp_path -- it can be waiting for some other&lt;br /&gt;
struct file to open one. A little bit more information should be added&lt;br /&gt;
to the struct file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	struct temp_file {&lt;br /&gt;
		char *path;&lt;br /&gt;
		unsigned users;&lt;br /&gt;
	};&lt;br /&gt;
&lt;br /&gt;
	struct file {&lt;br /&gt;
		char *path;&lt;br /&gt;
		unsigned mode;&lt;br /&gt;
		struct temp_file *temp;&lt;br /&gt;
	} *f;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and to the code that opens one now looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	int fd, tfd = -1;&lt;br /&gt;
&lt;br /&gt;
	if (f-&amp;gt;temp) {&lt;br /&gt;
		if (S_ISDIR(f-&amp;gt;mode))&lt;br /&gt;
			mkdir(f-&amp;gt;path);&lt;br /&gt;
		else&lt;br /&gt;
			link(f-&amp;gt;temp-&amp;gt;path, f-&amp;gt;path);&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	if (S_ISFIFO(f-&amp;gt;mode))&lt;br /&gt;
		tfd = open(f-&amp;gt;path, O_RDWR);&lt;br /&gt;
&lt;br /&gt;
	fd = open(f-&amp;gt;path, f-&amp;gt;mode);&lt;br /&gt;
&lt;br /&gt;
	if (tfd &amp;gt;= 0)&lt;br /&gt;
		close(tfd);&lt;br /&gt;
&lt;br /&gt;
	if (f-&amp;gt;temp) {&lt;br /&gt;
		if (--f-&amp;gt;temp-&amp;gt;users == 0) {&lt;br /&gt;
			if (S_ISDIR(f-&amp;gt;mode))&lt;br /&gt;
				rmdir(f-&amp;gt;mode);&lt;br /&gt;
			else&lt;br /&gt;
				unlink(f-&amp;gt;temp-&amp;gt;path);&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By the way, we've left behind the scenes all the code required to make&lt;br /&gt;
the temp_file data be shared between processes that need one and to&lt;br /&gt;
make the decrement of f-&amp;gt;temp-&amp;gt;users be smp-safe.&lt;br /&gt;
&lt;br /&gt;
Also note, that we don't handle the case when the file/directory is&lt;br /&gt;
removed and some other file/directory is created under the same name.&lt;br /&gt;
It's rare case.&lt;br /&gt;
&lt;br /&gt;
Now, is that all? No, sorry. A couple of things left. First, Linux has&lt;br /&gt;
a thing called mount namespace. And two files with the same path may&lt;br /&gt;
have been opened in different mount namespaces. So we also need the&lt;br /&gt;
info about what mount point the file belongs to like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	struct file {&lt;br /&gt;
		char *path;&lt;br /&gt;
		unsigned mode;&lt;br /&gt;
		struct temp_file *temp;&lt;br /&gt;
		unsigned mnt_id;&lt;br /&gt;
	} *f;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and the code to open file would now look like&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	int fd, tfd = -1, ns_fd;&lt;br /&gt;
	char *rel_path = f-&amp;gt;path + 1;&lt;br /&gt;
&lt;br /&gt;
	ns_fd = open_ns_root(f-&amp;gt;mnt_id);&lt;br /&gt;
&lt;br /&gt;
	if (f-&amp;gt;temp) {&lt;br /&gt;
		if (S_ISDIR(f-&amp;gt;mode))&lt;br /&gt;
			mkdirat(ns_fd, rel_path);&lt;br /&gt;
		else&lt;br /&gt;
			linkat(ns_fd, f-&amp;gt;temp-&amp;gt;path, ns_fd, rel_path);&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	if (S_ISFIFO(f-&amp;gt;mode))&lt;br /&gt;
		tfd = openat(ns_fd, rel_path, O_RDWR);&lt;br /&gt;
&lt;br /&gt;
	fd = openat(ns_fd, rel_path, f-&amp;gt;mode);&lt;br /&gt;
&lt;br /&gt;
	if (tfd &amp;gt;= 0)&lt;br /&gt;
		close(tfd);&lt;br /&gt;
&lt;br /&gt;
	if (f-&amp;gt;temp_path) {&lt;br /&gt;
		if (--f-&amp;gt;temp-&amp;gt;users == 0) {&lt;br /&gt;
			if (S_ISDIR(f-&amp;gt;mode))&lt;br /&gt;
				unlinkat(ns_fd, f-&amp;gt;mode, AT_REMOVEDIR);&lt;br /&gt;
			else&lt;br /&gt;
				unlinkat(ns_fd, f-&amp;gt;temp-&amp;gt;path);&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	close(ns_fd);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let me not dive into the details of how the open_ns_root looks like.&lt;br /&gt;
Just know, that it opens a file descriptor, that refers to the root&lt;br /&gt;
of the mount namespace that contains a mount point with the id mnt_id&lt;br /&gt;
(they cannot be shared, and that's great).&lt;br /&gt;
&lt;br /&gt;
Pretty complex already, isn't it? Just a couple of final touches left.&lt;br /&gt;
First, opened files typically have a position. Flags we get need to be&lt;br /&gt;
sanitated not to container those that only make sense during open,&lt;br /&gt;
like O_TRUNC or O_CREAT. And file may have a thing called fown managed&lt;br /&gt;
by the F_SETSIG and F_SETOWN fcntls. All this results in&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	struct file {&lt;br /&gt;
		char *path;&lt;br /&gt;
		unsigned mode;&lt;br /&gt;
		struct temp_file *temp;&lt;br /&gt;
		unsigned mnt_id;&lt;br /&gt;
		unsigned long pos;&lt;br /&gt;
		struct fown fown;&lt;br /&gt;
	} *f;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	int fd, tfd = -1, ns_fd, open_flags;&lt;br /&gt;
	char *rel_path = f-&amp;gt;path + 1;&lt;br /&gt;
&lt;br /&gt;
	ns_fd = open_ns_root(f-&amp;gt;mnt_id);&lt;br /&gt;
&lt;br /&gt;
	if (f-&amp;gt;temp) {&lt;br /&gt;
		if (S_ISDIR(f-&amp;gt;mode))&lt;br /&gt;
			mkdirat(ns_fd, rel_path);&lt;br /&gt;
		else&lt;br /&gt;
			linkat(ns_fd, f-&amp;gt;temp-&amp;gt;path, ns_fd, rel_path);&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	if (S_ISFIFO(f-&amp;gt;mode))&lt;br /&gt;
		tfd = openat(ns_fd, rel_path, O_RDWR);&lt;br /&gt;
&lt;br /&gt;
	open_flags = sanitize_open_mode(f-&amp;gt;mode);&lt;br /&gt;
	fd = openat(ns_fd, rel_path, open_flags);&lt;br /&gt;
&lt;br /&gt;
	if (tfd &amp;gt;= 0)&lt;br /&gt;
		close(tfd);&lt;br /&gt;
&lt;br /&gt;
	if (f-&amp;gt;temp_path) {&lt;br /&gt;
		if (--f-&amp;gt;temp-&amp;gt;users == 0) {&lt;br /&gt;
			if (S_ISDIR(f-&amp;gt;mode))&lt;br /&gt;
				unlinkat(ns_fd, f-&amp;gt;mode, AT_REMOVEDIR);&lt;br /&gt;
			else&lt;br /&gt;
				unlinkat(ns_fd, f-&amp;gt;temp-&amp;gt;path);&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	close(ns_fd);&lt;br /&gt;
&lt;br /&gt;
	fcntl(fd, F_SETSIG, f-&amp;gt;fown-&amp;gt;sig);&lt;br /&gt;
	fcntl(fd, F_SETOWN, &amp;amp;f-&amp;gt;fown-&amp;gt;owner);&lt;br /&gt;
	lseek(fd, SEEK_SET, f-&amp;gt;pos);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And don't ask for details of the f-&amp;gt;fown thing. It's tricky, but just&lt;br /&gt;
follows the ABI and thus boring.&lt;br /&gt;
&lt;br /&gt;
OK, we've finished with the top of the iceberg -- opening a file. Why&lt;br /&gt;
top? Becase when opened file should be planted into a process' file&lt;br /&gt;
descriptors table under desired number. You might thing, that it's as&lt;br /&gt;
simple as&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	dup2(fd, desired_fd);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
but it's not. We'll get back to it in the next series.&lt;/div&gt;</summary>
		<author><name>Xemul</name></author>
	</entry>
</feed>