git://scm.lunaixsky.com
/
lunaix-os.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
feat: implement readlink(2) readlinkat(2)
[lunaix-os.git]
/
lunaix-os
/
kernel
/
demos
/
iotest.c
diff --git
a/lunaix-os/kernel/demos/iotest.c
b/lunaix-os/kernel/demos/iotest.c
index 3fc89148e38fd8f996fe29d2027e440aee3034ad..2ddeb1a2f29c0593b54208d7d62785edcf2786ce 100644
(file)
--- a/
lunaix-os/kernel/demos/iotest.c
+++ b/
lunaix-os/kernel/demos/iotest.c
@@
-11,19
+11,28
@@
_iotest_main()
char test_sequence[] = "Once upon a time, in a magical land of Equestria. "
"There were two regal sisters who ruled together "
"and created harmony for all the land.";
char test_sequence[] = "Once upon a time, in a magical land of Equestria. "
"There were two regal sisters who ruled together "
"and created harmony for all the land.";
- int fd = open("/dev/block/bd0", 0);
- if (fd < 0) {
+ int fd = open("/dev/sda", 0); // bd0 设备 - 硬盘
+ int tty = open("/dev/tty", 0); // tty 设备 - 控制台
+
+ if (fd < 0 || tty < 0) {
kprintf(KERROR "fail to open (%d)\n", geterrno());
return;
}
kprintf(KERROR "fail to open (%d)\n", geterrno());
return;
}
+ // 移动指针至第二个逻辑扇区(LBA=1),并写入
lseek(fd, 1, FSEEK_SET);
write(fd, test_sequence, sizeof(test_sequence));
lseek(fd, 1, FSEEK_SET);
write(fd, test_sequence, sizeof(test_sequence));
- lseek(fd, -1, FSEEK_CUR);
+ // 读出我们写的内容
char read_out[256];
char read_out[256];
+ lseek(fd, -1, FSEEK_CUR);
read(fd, read_out, sizeof(read_out));
read(fd, read_out, sizeof(read_out));
- kprintf("%s", read_out);
+ write(tty, read_out, sizeof(read_out));
+
+ close(fd);
+ close(tty);
+
+ kprint_hex(read_out, sizeof(read_out));
}
\ No newline at end of file
}
\ No newline at end of file