Fix fops write buf printk bug, improve fops file name further

This commit is contained in:
Ciro Santilli
2017-05-26 09:09:24 +01:00
parent d38baa2358
commit d424380fe6
3 changed files with 12 additions and 12 deletions

View File

@@ -83,11 +83,11 @@ static ssize_t fop_write(struct file *file, const char __user *buf, size_t len,
ret = -EFAULT;
} else {
ret = len;
printk(KERN_INFO "buf = %.*s\n", (int)len, data + *off);
*off += ret;
}
}
}
printk(KERN_INFO "buf = %.*s\n", (int)len, data + *off);
printk(KERN_INFO "ret = %lld\n", (long long)ret);
return ret;
}
@@ -144,7 +144,7 @@ int init_module(void)
printk(KERN_ALERT "debugfs_create_dir failed");
return -1;
}
file = debugfs_create_file("fops", 0666, dir, NULL, &fops);
file = debugfs_create_file("f", 0666, dir, NULL, &fops);
if (!file) {
printk(KERN_ALERT "debugfs_create_file failed");
return -1;

View File

@@ -5,7 +5,7 @@ insmod /fops.ko
cd /sys/kernel/debug/lkmc_fops
## Basic read.
cat fops
cat f
# => abcd
# dmesg => open
# dmesg => read
@@ -14,14 +14,14 @@ cat fops
## Basic write
printf '01' >fops
printf '01' >f
# dmesg => open
# dmesg => write
# dmesg => len = 1
# dmesg => buf = a
# dmesg => close
cat fops
cat f
# => 01cd
# dmesg => open
# dmesg => read
@@ -29,15 +29,15 @@ cat fops
# dmesg => close
## ENOSPC
printf '1234' >fops
printf '12345' >fops
printf '1234' >f
printf '12345' >f
echo "$?"
# => 8
cat fops
cat f
# => 1234
## seek
printf '1234' >fops
printf 'z' | dd bs=1 of=fops seek=2
cat fops
printf '1234' >f
printf 'z' | dd bs=1 of=f seek=2
cat f
# => 12z4

View File

@@ -3,7 +3,7 @@ insmod /fops.ko
cd /sys/kernel/debug/lkmc_fops
i=0
while true; do
printf "$i" >fops
printf "$i" >f
i=$(($i+1))
done &
/kgdb.sh