我想从内核模块中读取设备。输出应该类似于“ls”命令的输出
我的阅读功能是:
static void read_file(char *filename)
{
struct file *fd;
char buf[1];
unsigned long long offset=0;
mm_segment_t old_fs = get_fs();
set_fs(KERNEL_DS);
fd = filp_open(filename, O_RDONLY, 0);
if (fd >= 0) {
printk(KERN_DEBUG);
while (vfs_read(fd, buf, 1,&offset) == 1)
{
if((0 <= buf[0]) && (buf[0] <=255))
printk("%c", buf[0]);
}
printk(KERN_ALERT "Loop Ran\n");
filp_close(fd,NULL);
}
set_fs(old_fs);
}
但它与许多垃圾值一起提供输出。我的挂载目录中有一个名为“file1”的文件。
o/p 是(它有“lost+found”和“file1”,但有这些垃圾值)
[
558.452235]
[ 558.452238] (\x02[& \x01 \x05\x1dQ\x04S\x01,Q\x01
8\x02\x01
-\x06AN\x0ex\x7f
[ 558.452308] 'J6pA{h<;
\x01
,Q\x01*+,'\x1f\x04\x02\x04* + , 4\x07\x05\x04\x03 \x04 \x05 \x06 \x07 \x08
[ 558.455546]
\x0e \x0f \x10 \x11 \x12 \x13 \x14 \x15 \x16 \x17 \x18 \x19 \x1a \x1b \x1c \x1d \x1e \x1f ! " # $ % & ' ( )
\x01\x0f,Q,Q,QA\x04\x1dQCQCQ\x03\x020\x04\x04,Q,Q,Q\x01A0,Q,Q,Q\x02\x18CQCQCQ\x01Z\x02
\x01\x02.\x02
\x02\x02..
\x14
[ 558.525090] \x02lost+found
\x03\x05\x01file1
\x01\x02.\x02\x03\x02\x02..\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\x03\x04\x05\x06\x07\x08
[ 558.529810]
\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !"#$%&'()
[ 561.391843] (\x02[& \x01 \x05,QS\x01,Q\x01
\x018\x02\x01
-\x06AN\x0ex\x7f
[ 561.391914] 'J6pA{h<;
\x01
,Q\x01*+,'\x1f\x04\x02\x04* + , 4\x07\x05\x04\x07
[ 562.125651] Loop Ran
但我希望输出类似于 bash 中“ls”命令的输出。它显示了文件和目录的干净名称。我已经在 Google 上搜索过它,但它没有帮助。请帮忙。