1 #include <lunaix/fctrl.h>
2 #include <lunaix/foptions.h>
3 #include <lunaix/lunistd.h>
4 #include <lunaix/proc.h>
5 #include <lunaix/syslog.h>
12 char test_sequence[] = "Once upon a time, in a magical land of Equestria. "
13 "There were two regal sisters who ruled together "
14 "and created harmony for all the land.";
16 int fd = open("/dev/sda", 0); // sda 设备 - 硬盘
18 // tty 设备 - 控制台,使用O_DIRECT打开,即所有IO绕过Lunaix内核的缓存机制
19 int tty = open("/dev/tty", FO_DIRECT);
21 if (fd < 0 || tty < 0) {
22 kprintf(KERROR "fail to open (%d)\n", geterrno());
26 // 移动指针至512字节,在大多数情况下,这是第二个逻辑扇区的起始处
27 lseek(fd, 512, FSEEK_SET);
28 write(fd, test_sequence, sizeof(test_sequence));
29 lseek(fd, 521, FSEEK_SET);
30 write(fd, test_sequence, sizeof(test_sequence));
34 lseek(fd, 512, FSEEK_SET);
35 read(fd, read_out, sizeof(read_out));
38 write(tty, read_out, sizeof(read_out));
44 kprint_hex(read_out, sizeof(read_out));