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
refactor: add user space printf.
[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 5e17b02db766f66f56d4c2ac625c73e1bb47c8ed..643452c81f58b0a145c5457f428311c7d9ae89f6 100644
(file)
--- a/
lunaix-os/kernel/demos/iotest.c
+++ b/
lunaix-os/kernel/demos/iotest.c
@@
-2,12
+2,7
@@
#include <lunaix/foptions.h>
#include <lunaix/lunistd.h>
#include <lunaix/proc.h>
#include <lunaix/foptions.h>
#include <lunaix/lunistd.h>
#include <lunaix/proc.h>
-#include <lunaix/syslog.h>
-
-LOG_MODULE("IOTEST")
-
-#define STDIN 1
-#define STDOUT 0
+#include <ulibc/stdio.h>
void
_iotest_main()
void
_iotest_main()
@@
-15,14
+10,26
@@
_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.";
+ char read_out[256];
+
+ // 切换工作目录至 /dev
+ int errno = chdir("/dev");
+ if (errno) {
+ write(stdout, "fail to chdir", 15);
+ return;
+ }
+
+ if (getcwd(read_out, sizeof(read_out))) {
+ printf("current working dir: %s\n", read_out);
+ }
// sda 设备 - 硬盘
// sda设备属于容积设备(Volumetric Device),
// Lunaix会尽可能缓存任何对此设备的上层读写,并使用延迟写入策略。(FO_DIRECT可用于屏蔽该功能)
// sda 设备 - 硬盘
// sda设备属于容积设备(Volumetric Device),
// Lunaix会尽可能缓存任何对此设备的上层读写,并使用延迟写入策略。(FO_DIRECT可用于屏蔽该功能)
- int fd = open("
/dev
/sda", 0);
+ int fd = open("
.
/sda", 0);
if (fd < 0) {
if (fd < 0) {
-
kprintf(KERROR
"fail to open (%d)\n", geterrno());
+
printf(
"fail to open (%d)\n", geterrno());
return;
}
return;
}
@@
-38,25
+45,21
@@
_iotest_main()
lseek(fd, 4 * 4096, FSEEK_SET);
write(fd, test_sequence, sizeof(test_sequence));
lseek(fd, 4 * 4096, FSEEK_SET);
write(fd, test_sequence, sizeof(test_sequence));
- char read_out[256];
- write(STDOUT, "input: ", 8);
- int size = read(STDIN, read_out, 256);
+ printf("input: ");
+ int size = read(stdin, read_out, 256);
+
+ printf("your said: %s\n", read_out);
- write(STDOUT, "your input: ", 13);
- write(STDOUT, read_out, size);
write(fd, read_out, size);
write(fd, read_out, size);
- write(STDOUT, "\n", 1);
// 读出我们写的内容
lseek(fd, 512, FSEEK_SET);
read(fd, read_out, sizeof(read_out));
// 将读出的内容直接写入tty设备
// 读出我们写的内容
lseek(fd, 512, FSEEK_SET);
read(fd, read_out, sizeof(read_out));
// 将读出的内容直接写入tty设备
- write(
STDOUT
, read_out, sizeof(read_out));
- write(
STDOUT
, "\n", 1);
+ write(
stdout
, read_out, sizeof(read_out));
+ write(
stdout
, "\n", 1);
// 关闭文件,这同时会将页缓存中的数据下发到底层驱动
close(fd);
// 关闭文件,这同时会将页缓存中的数据下发到底层驱动
close(fd);
-
- kprint_hex(read_out, sizeof(read_out));
}
\ No newline at end of file
}
\ No newline at end of file