This source file includes following definitions.
- unixstrategy
- unixopen
- unixclose
- unixioctl
- ulseek
- unix_probe
- unix_init
- unix_putc
- unix_getc
- getsecs
- time_print
- atexit
- cnspeed
- __main
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 #include <sys/param.h>
31 #include <sys/types.h>
32 #include <sys/time.h>
33 #include <sys/syscall.h>
34 #define open uopen
35 #include <sys/fcntl.h>
36 #include <dev/cons.h>
37 #undef open
38 #include "libsa.h"
39 #include <lib/libsa/unixdev.h>
40
41 int
42 unixstrategy(void *devdata, int rw, daddr_t blk, size_t size, void *buf,
43 size_t *rsize)
44 {
45 int rc = 0;
46
47 #ifdef UNIX_DEBUG
48 printf("unixstrategy: %s %d bytes @ %d\n",
49 (rw==F_READ?"reading":"writing"), size, blk);
50 #endif
51 if ((rc = ulseek((int)devdata, blk * DEV_BSIZE, 0)) >= 0)
52 rc = (rw==F_READ) ? uread((int)devdata, buf, size) :
53 uwrite((int)devdata, buf, size);
54
55 if (rc >= 0) {
56 *rsize = (size_t)rc;
57 rc = 0;
58 } else
59 rc = errno;
60
61 return rc;
62 }
63
64 int
65 unixopen(struct open_file *f, ...)
66 {
67 char **file, *p = NULL;
68 va_list ap;
69 int fd;
70
71 va_start(ap, f);
72 file = va_arg(ap, char **);
73 va_end(ap);
74
75 #ifdef UNIX_DEBUG
76 printf("unixopen: %s\n", *file);
77 #endif
78
79 if (strncmp("/dev/", *file, 5) == 0) {
80
81 for (p = *file + 5; *p != '\0' && *p != '/'; p++)
82 ;
83 if (*p == '/')
84 *p = '\0';
85 }
86
87 f->f_devdata = (void *)(fd = uopen(*file, O_RDWR, 0));
88
89 *file = p;
90 if (p != NULL)
91 *p = '/';
92
93 return fd < 0 ? -1 : 0;
94 }
95
96 int
97 unixclose(struct open_file *f)
98 {
99 return uclose((int)f->f_devdata);
100 }
101
102 int
103 unixioctl(struct open_file *f, u_long cmd, void *data)
104 {
105 return uioctl((int)f->f_devdata, cmd, data);
106 }
107
108 off_t
109 ulseek(int fd, off_t off, int wh)
110 {
111 return __syscall((quad_t)SYS_lseek, fd, 0, off, wh);
112 }
113
114
115 void
116 unix_probe(struct consdev *cn)
117 {
118 cn->cn_pri = CN_INTERNAL;
119 cn->cn_dev = makedev(0,0);
120 printf("ux%d ", minor(cn->cn_dev));
121 }
122
123 void
124 unix_init(struct consdev *cn)
125 {
126 }
127
128 void
129 unix_putc(dev_t dev, int c)
130 {
131 uwrite(1, &c, 1);
132 }
133
134 int
135 unix_getc(dev_t dev)
136 {
137 if (dev & 0x80) {
138 struct timeval tv;
139 fd_set fdset;
140 int rc;
141
142 tv.tv_sec = 0;
143 tv.tv_usec = 100000;
144 FD_ZERO(&fdset);
145 FD_SET(0, &fdset);
146
147 if ((rc = syscall(SYS_select, 1, &fdset, NULL, NULL, &tv)) <= 0)
148 return 0;
149 else
150 return 1;
151 } else {
152 char c;
153
154 return uread(0, &c, 1)<1? -1: c;
155 }
156 }
157
158 time_t
159 getsecs(void)
160 {
161 return 1;
162 }
163
164 void
165 time_print(void)
166 {
167 }
168
169 void
170 atexit(void)
171 {
172 }
173
174 int
175 cnspeed(dev_t dev, int sp)
176 {
177 return 9600;
178 }
179
180 void
181 __main(void)
182 {
183 }