added misc driver log output

Signed-off-by: Jolan Rathelot <jrathelo@student.42nice.fr>
This commit is contained in:
Jolan Rathelot
2024-03-15 15:24:42 +01:00
parent bf5d9ed83b
commit 2f8b9a1e37
2 changed files with 52 additions and 8 deletions

10
.idea/workspace.xml generated
View File

@ -16,9 +16,7 @@
<configurations />
</component>
<component name="ChangeListManager">
<list default="true" id="2686ebbf-1c6c-4484-bb57-dec59a208d53" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/99-Hotload-Keyboard.rules" beforeDir="false" afterPath="$PROJECT_DIR$/99-Hotload-Keyboard.rules" afterDir="false" />
</list>
<list default="true" id="2686ebbf-1c6c-4484-bb57-dec59a208d53" name="Changes" comment="" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
@ -102,7 +100,7 @@
<window_info anchor="bottom" id="CMake" weight="0.22384511" />
<window_info anchor="bottom" id="Database Changes" />
<window_info anchor="bottom" id="TypeScript" />
<window_info anchor="bottom" id="Build" weight="0.32982337" />
<window_info anchor="bottom" id="Build" weight="0.26324728" />
<window_info anchor="bottom" id="Python Packages" />
<window_info anchor="bottom" id="TODO" />
<window_info anchor="bottom" id="File Transfer" />
@ -154,6 +152,7 @@
<workItem from="1710410667925" duration="2000" />
<workItem from="1710410734122" duration="3818000" />
<workItem from="1710428742857" duration="5381000" />
<workItem from="1710488169055" duration="12511000" />
</task>
<task id="LOCAL-00001" summary="Removed Rust code, added misc device and irq handle. Began work on correctly formatting print msg and logging files.">
<option name="closed" value="true" />
@ -169,6 +168,9 @@
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="3" />
</component>
<component name="UnknownFeatures">
<option featureType="com.intellij.fileTypeFactory" implementationName="*.rules" />
</component>
<component name="VCPKGProject">
<isAutomaticEditVcpkgJson value="false" />
<isAutomaticCheckingOnLaunch value="false" />

View File

@ -4,9 +4,6 @@
#include "drivers_and_interrupts.h"
// 17:06:43 "d" (0x64) PRESSED
//
size_t calc_node_size(struct linked_list_node *node) {
size_t size = 14;
if (node->key.state == PRESSED) {
@ -24,5 +21,50 @@ size_t calc_node_size(struct linked_list_node *node) {
ssize_t read_keyboard_misc_device(struct file *file, char __user *buf, size_t count, loff_t *ppos) {
return simple_read_from_buffer(buf, count, ppos, "jrathelo", strlen("jrathelo"));
struct linked_list_node *tmp;
loff_t node_offset = *ppos;
mutex_lock(&lock);
list_for_each_entry(tmp, &keyboard_log, list) {
if (node_offset < tmp->size) {
break;
}
node_offset -= tmp->size;
}
if (node_offset > tmp->size) {
printk("early exit\n");
return 0;
}
// if (count > len - *ppos) {
// count = len - *ppos;
// }
size_t user_offset = 0;
for (; !list_entry_is_head(tmp, &keyboard_log, list); tmp = list_next_entry(tmp, list)) {
char sec = (tmp->when.tv_sec - (sys_tz.tz_minuteswest * 60)) % 60;
char min = (tmp->when.tv_sec - (sys_tz.tz_minuteswest * 60)) / 60 % 60;
char hour = (tmp->when.tv_sec - (sys_tz.tz_minuteswest * 60)) / 60 / 60 % 24;
char *buffer = kmalloc(sizeof(char) * tmp->size, GFP_KERNEL);
memset(buffer, 0, tmp->size);
snprintf(buffer, tmp->size, "%02d:%02d:%02d \"%s\"", hour, min, sec, tmp->key.key_name);
if (tmp->key.ascii_value) {
snprintf(buffer + strlen(buffer), tmp->size - strlen(buffer), "(0x%02x) ", tmp->key.ascii_value);
}
if (tmp->key.state == PRESSED) {
snprintf(buffer + strlen(buffer), tmp->size - strlen(buffer), "PRESSED\n");
} else {
snprintf(buffer + strlen(buffer), tmp->size - strlen(buffer), "RELEASED\n");
}
if (copy_to_user(buf + user_offset, buffer + node_offset, tmp->size - node_offset)) {
kfree(buffer);
return -EFAULT;
}
kfree(buffer);
user_offset += tmp->size - node_offset;
node_offset = 0;
}
*ppos += (long long)user_offset;
mutex_unlock(&lock);
return (long long)user_offset;
}