update readme
[lunaix-os.git] / lunaix-os / kernel / demos / iotest.c
1 #include <lunaix/fctrl.h>
2 #include <lunaix/foptions.h>
3 #include <lunaix/proc.h>
4 #include <lunaix/syslog.h>
5
6 LOG_MODULE("IOTEST")
7
8 void
9 _iotest_main()
10 {
11     char test_sequence[] = "Once upon a time, in a magical land of Equestria. "
12                            "There were two regal sisters who ruled together "
13                            "and created harmony for all the land.";
14     int fd = open("/dev/block/bd0", 0);
15
16     if (fd < 0) {
17         kprintf(KERROR "fail to open (%d)\n", geterrno());
18         return;
19     }
20
21     lseek(fd, 1, FSEEK_SET);
22     write(fd, test_sequence, sizeof(test_sequence));
23
24     lseek(fd, -1, FSEEK_CUR);
25     char read_out[256];
26     read(fd, read_out, sizeof(read_out));
27
28     kprintf("%s", read_out);
29 }