<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
					xmlns:content="http://purl.org/rss/1.0/modules/content/"
					xmlns:wfw="http://wellformedweb.org/CommentAPI/"
					xmlns:atom="http://www.w3.org/2005/Atom"
				  >
<channel>
<atom:link rel="self"  type="application/rss+xml"  href="http://rulinux.net/rss_from_sect_4_subsect_6_thread_35156"  />
<title>rulinux.net - Форум - Development - /dev/0xff</title>
<link>http://rulinux.net/</link>
<description><![CDATA[Портал о GNU/Linux и не только]]></description>
<image><title>rulinux.net - Форум - Development - /dev/0xff</title>
<link>http://rulinux.net/</link>
<url>http://rulinux.net/rss_icon.png</url>
</image>
<item>
<title>Re:/dev/0xff</title>
<link>https://rulinux.net/message.php?newsid=35156&amp;page=1#113583</link>
<guid>https://rulinux.net/message.php?newsid=35156&amp;page=1#113583</guid>
<pubDate>Wed, 09 Nov 2011 11:30:17 +0400</pubDate>
<description><![CDATA[<p><i>>а подручными средствами сделать из нуля 0xFF я не осилил</i><br> <fieldset><legend>bash</legend><code><br />
<span style="color: #c20cb9; font-weight: bold;">mkfifo</span> 0xff<br />
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #c20cb9; font-weight: bold;">true</span>; <span style="color: #000000; font-weight: bold;">do</span> <span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #c20cb9; font-weight: bold;">file</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> 0xff; <span style="color: #000000; font-weight: bold;">done</span> <span style="color: #000000; font-weight: bold;">&amp;</span><br />
&nbsp;</code></fieldset><br><br>а в file собственно только 0xFF.</p>]]></description>
</item>
<item>
<title>/dev/0xff</title>
<link>https://rulinux.net/message.php?newsid=35156&amp;page=1#113575</link>
<guid>https://rulinux.net/message.php?newsid=35156&amp;page=1#113575</guid>
<pubDate>Wed, 09 Nov 2011 10:02:18 +0400</pubDate>
<description><![CDATA[<p>Вот, во время бана анонимусов и по статье с оттеняющего сайта [1] написал драйвер устройства, которое возвращает поток 0xff (по аналогии с /dev/zero). Не знаю как вам, а мне показалось странным отсутствие подобного устройства ранее, а подручными средствами сделать из нуля 0xFF я не осилил.<br><br>Итак, код [2]: <fieldset><legend>c</legend><code><br />
<span style="color: #666666; font-style: italic;">// файл 0xff_dev.c</span><br />
<span style="color: #339933;">#include &lt;linux/fs.h&gt;</span><br />
<span style="color: #339933;">#include &lt;linux/miscdevice.h&gt;</span><br />
<span style="color: #339933;">#include &lt;linux/init.h&gt;</span><br />
<span style="color: #339933;">#include &lt;linux/module.h&gt;</span><br />
<span style="color: #339933;">#include &lt;asm/uaccess.h&gt;</span><br />
<span style="color: #339933;">#include &lt;linux/sched.h&gt;</span><br />
<br />
MODULE_LICENSE<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;PROHIBITED&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
MODULE_AUTHOR<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Anonymous &lt;anonymous@rulinux.net&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
MODULE_VERSION<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;0.1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #993333;">static</span> ssize_t OxFF_read <span style="color: #009900;">&#40;</span><span style="color: #993333;">struct</span> file <span style="color: #339933;">*</span>file<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> __user <span style="color: #339933;">*</span>buf<span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; size_t count<span style="color: #339933;">,</span> loff_t <span style="color: #339933;">*</span>ppos<span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; size_t written <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>count <span style="color: #339933;">==</span> 0<span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>access_ok<span style="color: #009900;">&#40;</span>VERIFY_WRITE<span style="color: #339933;">,</span> buf<span style="color: #339933;">,</span> count<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> 0<span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #339933;">-</span>EFAULT<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span>count<span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>__put_user<span style="color: #009900;">&#40;</span>0xFF<span style="color: #339933;">,</span> buf<span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> 0<span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #339933;">-</span>EFAULT<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; count<span style="color: #339933;">--;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; written<span style="color: #339933;">++;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; buf<span style="color: #339933;">++;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cond_resched<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> written <span style="color: #339933;">?</span> written <span style="color: #339933;">:</span> <span style="color: #339933;">-</span>EFAULT<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #993333;">static</span> <span style="color: #993333;">const</span> <span style="color: #993333;">struct</span> file_operations OxFF_fops <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; .<span style="color: #202020;">owner</span> <span style="color: #339933;">=</span> THIS_MODULE<span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; .<span style="color: #202020;">read</span> <span style="color: #339933;">=</span> OxFF_read<span style="color: #339933;">,</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #993333;">static</span> <span style="color: #993333;">struct</span> miscdevice OxFF_dev <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; MISC_DYNAMIC_MINOR<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;0xff&quot;</span><span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>OxFF_fops<br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span> <br />
<br />
<span style="color: #993333;">static</span> <span style="color: #993333;">int</span> __init OxFF_init <span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333;">int</span> ret <span style="color: #339933;">=</span> misc_register <span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>OxFF_dev<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>ret<span style="color: #009900;">&#41;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printk<span style="color: #009900;">&#40;</span>KERN_ERR <span style="color: #ff0000;">&quot;unable to register misc device<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; printk<span style="color: #009900;">&#40;</span>KERN_INFO <span style="color: #ff0000;">&quot;0xff_mod loaded successful.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> ret<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #993333;">static</span> <span style="color: #993333;">void</span> __exit OxFF_exit <span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; misc_deregister <span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>OxFF_dev<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; printk<span style="color: #009900;">&#40;</span>KERN_INFO <span style="color: #ff0000;">&quot;0xff_mod unloaded successful.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
module_init<span style="color: #009900;">&#40;</span>OxFF_init<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
module_exit<span style="color: #009900;">&#40;</span>OxFF_exit<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp;</code></fieldset><br><br>Makefile [3]: <fieldset><legend>make</legend><code><br />
<span style="color: #339900; font-style: italic;"># Файл Makefile</span><br />
CURRENT<span style="color: #004400;">=$</span><span style="color: #004400;">&#40;</span><span style="color: #0000CC; font-weight: bold;">shell</span> uname <span style="color: #004400;">-</span>r<span style="color: #004400;">&#41;</span><br />
KDIR<span style="color: #004400;">=/</span>lib<span style="color: #004400;">/</span>modules<span style="color: #004400;">/$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">CURRENT</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">/</span>build<br />
PWD<span style="color: #004400;">=$</span><span style="color: #004400;">&#40;</span><span style="color: #0000CC; font-weight: bold;">shell</span> pwd<span style="color: #004400;">&#41;</span><br />
DEST<span style="color: #004400;">=/</span>lib<span style="color: #004400;">/</span>modules<span style="color: #004400;">/$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">CURRENT</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">/</span>misc<br />
<br />
TARGET <span style="color: #004400;">=</span> 0xff_dev<br />
obj<span style="color: #004400;">-</span>m &nbsp; &nbsp; &nbsp;<span style="color: #004400;">:=</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">TARGET</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">.</span>o<br />
<br />
default<span style="color: #004400;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">MAKE</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">-</span>C <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">KDIR</span><span style="color: #004400;">&#41;</span> M<span style="color: #004400;">=$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">PWD</span><span style="color: #004400;">&#41;</span> modules<br />
<br />
clean<span style="color: #004400;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004400;">@</span>rm <span style="color: #004400;">-</span>f <span style="color: #004400;">*.</span>o <span style="color: #004400;">.*.</span>cmd <span style="color: #004400;">.*.</span>flags <span style="color: #004400;">*.</span>mod<span style="color: #004400;">.</span>c <span style="color: #004400;">*.</span>order<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004400;">@</span>rm <span style="color: #004400;">-</span>f <span style="color: #004400;">.*.*.</span>cmd <span style="color: #004400;">*.</span>symvers <span style="color: #004400;">*</span>~ <span style="color: #004400;">*.*</span>~ TODO<span style="color: #004400;">.*</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004400;">@</span>rm <span style="color: #004400;">-</span>fR <span style="color: #004400;">.</span>tmp<span style="color: #004400;">*</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004400;">@</span>rm <span style="color: #004400;">-</span>rf <span style="color: #004400;">.</span>tmp_versions<br />
&nbsp;</code></fieldset><br><br>Сборка заключается просто в выполнении make в текущей директории (при условии установленных сборочных файлах ядра (kernel-devel для Fedora)):<br><br><fieldset><legend>text</legend><code><br />
&gt;make<br />
make -C /lib/modules/2.6.35.13-92.fc14.i686/build M=/tmp/0xff_module modules<br />
make[1]: Вход в каталог `/usr/src/kernels/2.6.35.13-92.fc14.i686'<br />
&nbsp; CC [M] &nbsp;/tmp/0xff_module/0xff_dev.o<br />
&nbsp; Building modules, stage 2.<br />
&nbsp; MODPOST 1 modules<br />
&nbsp; CC &nbsp; &nbsp; &nbsp;/tmp/0xff_module/0xff_dev.mod.o<br />
&nbsp; LD [M] &nbsp;/tmp/0xff_module/0xff_dev.ko<br />
make[1]: Выход из каталога `/usr/src/kernels/2.6.35.13-92.fc14.i686'<br />
&nbsp;</code></fieldset><br><br>Загрузка модуля (от root-а): <fieldset><legend>text</legend><code><br />
&gt; insmod 0xff_dev.ko<br />
&gt; tail -n1 /var/log/messages<br />
Jan 1 00:01:00 rulinux.net kernel: 0xff_mod loaded successful.<br />
&gt; ls -l /dev/0xff<br />
crw------- 1 root root 10, 56 Jan 1 00:01 /dev/0xff<br />
&gt; chmod 666 /dev/0xff<br />
&gt; ls -l /dev/0xff<br />
crw-rw-rw- 1 root root 10, 56 Jan 1 00:01 /dev/0xff<br />
&nbsp;</code></fieldset><br><br>Проверяем от пользователя: <fieldset><legend>text</legend><code><br />
&gt; dd if=/dev/0xff bs=13 count=3 | hexdump<br />
0000000 ffff ffff ffff ffff ffff ffff ffff ffff<br />
*<br />
0000020 ffff ffff ffff 00ff &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
0000027<br />
3+0 записей считано<br />
3+0 записей написано<br />
&nbsp;скопировано 39 байт (39 B), 0,000383714 c, 102 kB/c<br />
&nbsp;</code></fieldset><br><br>Замечания к выпуску: ядро малость офигивает от подобной не ГПЛ-угодной лицензии и потому материться в лог при первой загрузке модуля <fieldset><legend>text</legend><code><br />
Jan 1 00:01:00 rulinux.net kernel: 0xff_dev: module license 'PROHIBITED' taints kernel.<br />
Jan 1 00:01:00 rulinux.net kernel: Disabling lock debugging due to kernel taint<br />
&nbsp;</code></fieldset><br><br>[1] http://rus-linux.net/MyLDP/BOOKS/Moduli-yadra-Linux/kern-mod-index.html<br><br>[2] http://pastebin.com/pddir8z3<br><br>[3] http://pastebin.com/VhPhwgVL</p>]]></description>
</item>
</channel>
</rss>