X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/6fefc6f5af83f316e18b0cb9dbbde1cea0b98add..90129c6876c9bac2e468ab82c8264352d1952b4d:/lunaix-os/kernel/demos/iotest.c diff --git a/lunaix-os/kernel/demos/iotest.c b/lunaix-os/kernel/demos/iotest.c index 3fc8914..2ddeb1a 100644 --- 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."; - 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; } + // 移动指针至第二个逻辑扇区(LBA=1),并写入 lseek(fd, 1, FSEEK_SET); write(fd, test_sequence, sizeof(test_sequence)); - lseek(fd, -1, FSEEK_CUR); + // 读出我们写的内容 char read_out[256]; + lseek(fd, -1, FSEEK_CUR); 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