Note that there are some explanatory texts on larger screens.

plurals
  1. POC: write file from kernel-module correct this way?
    text
    copied!<p>I try to copy/write pcm-bytes (from ALSA-buffer) from the kernel-space into a file within a kernel-module (LKM).</p> <p>The file got's written and the size looks ok for me, but because it's PCM-data I can't see if it's correct (raw audio data, not readable).</p> <p>My audio-players (MPlayer="Invalid seek to negative position ffffffffffffffff!", VLC, Foobar2000) fail to play my written file so I think I have a mistake in my code.</p> <p>When I open the file via SCITE I see many many "NUL" and other cryted stuff (bytes ;).</p> <p>Maybe one of you find a bug?</p> <p>I have this script:</p> <pre><code>unsigned char *dma_area; // this is the source, an mmapped-area int pcm_offset_bytes; // the actual offset in the dma_area int size_bytes; // the amount of bytes to copy struct file *target_file; // the target-file int ret; // used in write-process below int wrote = 0; // used in write-process below mm_segment_t fs; void *data; // dma_area + pcm_offset_bytes // (..) calculate offset and size // open the target file target_file = filp_open("/dev/snd/pcmC0D0p_output", (O_CREAT | O_TRUNC | O_WRONLY), (S_IRWXU | S_IRWXG | S_IRWXO)); data = dma_area + pcm_offset_bytes fs = get_fs(); set_fs (get_ds ()); if (!target_file || !target_file-&gt;f_op || !target_file-&gt;f_op-&gt;write) { LOGI("something's missing\n"); return -EIO; } // loop until every byte is written while (size_bytes &gt; 0) { ret = target_file-&gt;f_op-&gt;write(target_file, (char *)data, size_bytes, &amp;target_file-&gt;f_pos); LOGI ("wrote %d bytes to target_file@%p, return %d\n", size_bytes, target_file, ret); if (ret &lt;= 0) goto done; size_bytes -= ret; data += ret; wrote += ret; } ret = wrote; done: set_fs(fs); LOGI("result %d\n", ret); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload