1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
#include "test/kshell/io.h"
#include "util/debug.h"
#include "priv.h"
#ifndef __VFS__
#include "drivers/chardev.h"
#endif
#ifdef __VFS__
#include "fs/vfs_syscall.h"
#endif
#include "util/printf.h"
#include "util/string.h"
/*
* If VFS is enabled, we can just use the syscalls.
*
* If VFS is not enabled, then we need to explicitly call the byte
* device.
*/
#ifdef __VFS__
long kshell_write(kshell_t *ksh, const void *buf, size_t nbytes)
{
long retval = do_write(ksh->ksh_out_fd, buf, nbytes);
KASSERT(retval < 0 || (size_t)retval == nbytes);
return retval;
}
long kshell_read(kshell_t *ksh, void *buf, size_t nbytes)
{
return do_read(ksh->ksh_in_fd, buf, nbytes);
}
long kshell_write_all(kshell_t *ksh, void *buf, size_t nbytes)
{
/* See comment in kshell_write */
return kshell_write(ksh, buf, nbytes);
}
#else
long kshell_read(kshell_t *ksh, void *buf, size_t nbytes)
{
return ksh->ksh_cd->cd_ops->read(ksh->ksh_cd, 0, buf, nbytes);
}
long kshell_write(kshell_t *ksh, const void *buf, size_t nbytes)
{
return ksh->ksh_cd->cd_ops->write(ksh->ksh_cd, 0, buf, nbytes);
}
#endif
void kprint(kshell_t *ksh, const char *fmt, va_list args)
{
char buf[KSH_BUF_SIZE];
size_t count;
vsnprintf(buf, sizeof(buf), fmt, args);
count = strnlen(buf, sizeof(buf));
kshell_write(ksh, buf, count);
}
void kprintf(kshell_t *ksh, const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
kprint(ksh, fmt, args);
va_end(args);
}
|