/* * This module shows how to create a variable sized record fifo.
*/
/* fifo size in elements (bytes) */ #define FIFO_SIZE 128
/* name of the proc entry */ #define PROC_FIFO "record-fifo"
/* lock for procfs read access */ static DEFINE_MUTEX(read_access);
/* lock for procfs write access */ static DEFINE_MUTEX(write_access);
/* * define DYNAMIC in this example for a dynamically allocated fifo. * * Otherwise the fifo storage will be a part of the fifo structure.
*/ #if 0 #define DYNAMIC #endif
/* * struct kfifo_rec_ptr_1 and STRUCT_KFIFO_REC_1 can handle records of a * length between 0 and 255 bytes. * * struct kfifo_rec_ptr_2 and STRUCT_KFIFO_REC_2 can handle records of a * length between 0 and 65535 bytes.
*/
/* show the first record without removing from the fifo */
ret = kfifo_out_peek(&test, buf, sizeof(buf)); if (ret)
printk(KERN_INFO "%.*s\n", ret, buf);
/* check the correctness of all values in the fifo */
i = 0; while (!kfifo_is_empty(&test)) {
ret = kfifo_out(&test, buf, sizeof(buf));
buf[ret] = '\0';
printk(KERN_INFO "item = %.*s\n", ret, buf); if (strcmp(buf, expected_result[i++])) {
printk(KERN_WARNING "value mismatch: test failed\n"); return -EIO;
}
} if (i != ARRAY_SIZE(expected_result)) {
printk(KERN_WARNING "size mismatch: test failed\n"); return -EIO;
}
printk(KERN_INFO "test passed\n");
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.