This commit is contained in:
Ciro Santilli
2025-05-10 07:50:53 +01:00
parent 3450d7b5b4
commit 0a2a05fe28
957 changed files with 10219 additions and 2068 deletions

View File

@@ -5,7 +5,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="Asciidoctor 2.0.11">
<meta name="description" content="The perfect emulation setup to study and develop the &lt;&lt;linux-kernel&gt;&gt; v5.9.2, kernel modules, &lt;&lt;qemu-buildroot-setup,QEMU&gt;&gt;, &lt;&lt;gem5-buildroot-setup,gem5&gt;&gt; and x86_64, ARMv7 and ARMv8 &lt;&lt;userland-assembly,userland&gt;&gt; and &lt;&lt;baremetal-setup,baremetal&gt;&gt; assembly, &lt;&lt;c,ANSI C&gt;&gt;, &lt;&lt;cpp,C++&gt;&gt; and &lt;&lt;posix,POSIX&gt;&gt;. &lt;&lt;gdb&gt;&gt; and &lt;&lt;kgdb&gt;&gt; just work. Powered by &lt;&lt;about-the-qemu-buildroot-setup,Buildroot&gt;&gt; and &lt;&lt;about-the-baremetal-setup,crosstool-NG&gt;&gt;. Highly automated. Thoroughly documented. Automated &lt;&lt;test-this-repo,tests&gt;&gt;. "Tested" in an Ubuntu 20.04 host.">
<meta name="description" content="The perfect emulation setup to study and develop the &lt;&lt;linux-kernel&gt;&gt; v5.9.2, kernel modules, &lt;&lt;qemu-buildroot-setup,QEMU&gt;&gt;, &lt;&lt;gem5-buildroot-setup,gem5&gt;&gt; and x86_64, ARMv7 and ARMv8 &lt;&lt;userland-assembly,userland&gt;&gt; and &lt;&lt;baremetal-setup,baremetal&gt;&gt; assembly, &lt;&lt;c,ANSI C&gt;&gt;, &lt;&lt;cpp,C++&gt;&gt; and &lt;&lt;posix,POSIX&gt;&gt;. EVERYTHING is built from source. &lt;&lt;gdb&gt;&gt; and &lt;&lt;kgdb&gt;&gt; just work. Powered by &lt;&lt;about-the-qemu-buildroot-setup,Buildroot&gt;&gt; and &lt;&lt;about-the-baremetal-setup,crosstool-NG&gt;&gt;. Highly automated. Thoroughly documented. Automated &lt;&lt;test-this-repo,tests&gt;&gt;. "Tested" in an Ubuntu 20.04 host.">
<title>Linux Kernel Module Cheat</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:300,300italic,400,400italic,600,600italic%7CNoto+Serif:400,400italic,700,700italic%7CDroid+Sans+Mono:400,700">
<style>
@@ -459,66 +459,24 @@ pre{ white-space:pre }
<div class="sect3">
<h4 id="file-operations"><a class="anchor" href="#file-operations"></a><a class="link" href="#file-operations">17.8.1. File operations</a></h4>
<div class="paragraph">
<p>File operations are the main method of userland driver communication.</p>
<p>File operations are the main method of userland driver communication that uses common file system calls such as read and write.</p>
</div>
<div class="paragraph">
<p><code>struct file_operations</code> determines what the kernel will do on filesystem system calls of <a href="pseudo-filesystems.html">Pseudo filesystems</a>.</p>
</div>
<div class="paragraph">
<p>This example illustrates the most basic system calls: <code>open</code>, <code>read</code>, <code>write</code>, <code>close</code> and <code>lseek</code>:</p>
</div>
<div class="literalblock">
<div class="content">
<pre>./fops.sh
echo $?</pre>
</div>
</div>
<div class="paragraph">
<p>Outcome: the test passes:</p>
</div>
<div class="literalblock">
<div class="content">
<pre>0</pre>
</div>
</div>
<div class="paragraph">
<p>Sources:</p>
<p>Through <code>struct file_operations</code> drivers tell the kernel what it should do on filesystem system calls of <a href="pseudo-filesystems.html">Pseudo filesystems</a>.</p>
</div>
<div class="ulist">
<ul>
<li>
<p><a href="https://github.com/cirosantilli/linux-kernel-module-cheat/blob/master/kernel_modules/fops.c">kernel_modules/fops.c</a></p>
<p><a href="fops.html">fops.c</a></p>
</li>
<li>
<p><a href="https://github.com/cirosantilli/linux-kernel-module-cheat/blob/master/rootfs_overlay/lkmc/fops.sh">rootfs_overlay/lkmc/fops.sh</a></p>
</li>
</ul>
</div>
<div class="paragraph">
<p>Then give this a try:</p>
</div>
<div class="literalblock">
<div class="content">
<pre>sh -x ./fops.sh</pre>
</div>
</div>
<div class="paragraph">
<p>We have put printks on each fop, so this allows you to see which system calls are being made for each command.</p>
</div>
<div class="paragraph">
<p>No, there no official documentation: <a href="https://stackoverflow.com/questions/15213932/what-are-the-struct-file-operations-arguments" class="bare">https://stackoverflow.com/questions/15213932/what-are-the-struct-file-operations-arguments</a></p>
</div>
<div class="ulist">
<ul>
</ul>
</div>
</div>
<div class="paragraph nav-footer">
<p> Up: <a href="pseudo-files.html">Pseudo files</a> | ⌂ Home: <a href="README.html">Linux Kernel Module Cheat</a> | Next: <a href="seq-file.html">seq_file</a> →</p>
<p> Up: <a href="pseudo-files.html">Pseudo files</a> | ⌂ Home: <a href="README.html">Linux Kernel Module Cheat</a> | Next: <a href="fops.html">fops.c</a> →</p>
</div>
</div>
<script>
<!-- Google Analytics, AKA selling my soul to Google for some backlinks. -->
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
@@ -526,5 +484,12 @@ m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
ga('create', 'UA-47867706-1', 'auto');
ga('send', 'pageview');
</script>
<script async src="https://www.googletagmanager.com/gtag/js?id=G-DEE2HEJW9X"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-DEE2HEJW9X');
</script>
</body>
</html>