/* Device name to pass to register_chrdev(). */ #define DEVICE_NAME "xz_dec_test"
/* Dynamically allocated device major number */ staticint device_major;
/* * We reuse the same decoder state, and thus can decode only one * file at a time.
*/ staticbool device_is_open;
/* XZ decoder state */ staticstruct xz_dec *state;
/* * Return value of xz_dec_run(). We need to avoid calling xz_dec_run() after * it has returned XZ_STREAM_END, so we make this static.
*/ staticenum xz_ret ret;
/* * Input and output buffers. The input buffer is used as a temporary safe * place for the data coming from the userspace.
*/ static uint8_t buffer_in[1024]; static uint8_t buffer_out[1024];
/* * Structure to pass the input and output buffers to the XZ decoder. * A few of the fields are never modified so we initialize them here.
*/ staticstruct xz_buf buffers = {
.in = buffer_in,
.out = buffer_out,
.out_size = sizeof(buffer_out)
};
/* * CRC32 of uncompressed data. This is used to give the user a simple way * to check that the decoder produces correct output.
*/ static uint32_t crc;
/* * Decode the data given to us from the userspace. CRC32 of the uncompressed * data is calculated and is printed at the end of successful decoding. The * uncompressed data isn't stored anywhere for further use. * * The .xz file must have exactly one Stream and no Stream Padding. The data * after the first Stream is considered to be garbage.
*/ static ssize_t xz_dec_test_write(struct file *file, constchar __user *buf,
size_t size, loff_t *pos)
{
size_t remaining;
if (ret != XZ_OK) { if (size > 0)
printk(KERN_INFO DEVICE_NAME ": %zu bytes of " "garbage at the end of the file\n",
size);
return -ENOSPC;
}
printk(KERN_INFO DEVICE_NAME ": decoding %zu bytes of input\n",
size);
remaining = size; while ((remaining > 0 || buffers.out_pos == buffers.out_size)
&& ret == XZ_OK) { if (buffers.in_pos == buffers.in_size) {
buffers.in_pos = 0;
buffers.in_size = min(remaining, sizeof(buffer_in)); if (copy_from_user(buffer_in, buf, buffers.in_size)) return -EFAULT;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.