-
Notifications
You must be signed in to change notification settings - Fork 4
/
posixsrv_private.h
154 lines (91 loc) · 2.69 KB
/
posixsrv_private.h
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
* Phoenix-RTOS
*
* posixsrv_private.h
*
* Copyright 2018 Phoenix Systems
* Author: Jan Sikorski
*
* This file is part of Phoenix-RTOS.
*
* %LICENSE%
*/
#ifndef POSIXSRV_PRIVATE_H
#define POSIXSRV_PRIVATE_H
#include <sys/ioctl.h>
#include <termios.h>
#include <posix/utils.h>
#include <posix/idtree.h>
#include <libtty.h>
#include <syslog.h>
#define PIPE_BUFSZ 0x1000
#define log_sev(sev, fmt, ...) syslog(sev, __FILE__ ":%d %s: " fmt, __LINE__, __func__, ##__VA_ARGS__)
#define log_debug(fmt, ...) log_sev(LOG_DEBUG, fmt, ##__VA_ARGS__)
#define log_info(fmt, ...) log_sev(LOG_INFO, fmt, ##__VA_ARGS__)
#define log_warn(fmt, ...) log_sev(LOG_WARNING, fmt, ##__VA_ARGS__)
#define log_error(fmt, ...) log_sev(LOG_ERR, fmt, ##__VA_ARGS__)
typedef struct request_t {
struct request_t *next, *prev;
rbnode_t linkage;
unsigned port;
struct _object_t *object;
time_t wakeup;
msg_rid_t rid;
msg_t msg;
/* Subsystem specific per-request state */
union {
libtty_read_state_t pts_read;
};
} request_t;
struct _object_t;
typedef request_t *(handler_t)(struct _object_t *, request_t *);
struct _pipe_t;
typedef struct {
union {
struct {
handler_t *open, *close, *read, *write, *truncate, *devctl,
*create, *destroy, *setattr, *getattr, *getattrall,
*lookup, *link, *unlink, *readdir;
void (*release)(struct _object_t *);
void (*timeout)(request_t *);
};
handler_t *handlers[mtCount + 2];
};
} operations_t;
typedef struct _object_t {
idnode_t linkage;
const operations_t *operations;
int refs, destroy;
} object_t;
static inline int rq_sz(request_t *r)
{
return (r->msg.type == mtWrite) ? r->msg.i.size : r->msg.o.size;
}
static inline void *rq_buf(request_t *r)
{
return (r->msg.type == mtWrite) ? (void *)r->msg.i.data : r->msg.o.data;
}
extern void rq_wakeup(request_t *r);
extern void rq_setResponse(request_t *r, int retval);
extern void rq_timeout(request_t *r, int timeout);
extern int rq_id(request_t *r);
extern unsigned posixsrv_port(void);
extern int posixsrv_object_link(object_t *o, const char *path);
static inline int posixsrv_object_id(object_t *o)
{
return o->linkage.id;
}
extern void posixsrv_object_destroy(object_t *o);
extern object_t *posixsrv_object_get(int id);
extern void posixsrv_object_ref(object_t *o);
extern void posixsrv_object_put(object_t *o);
extern int posixsrv_object_create(object_t *o, const operations_t *ops);
extern int pipe_create(int type, int *id, unsigned open);
extern int pipe_init(void);
extern int pipe_free(object_t *o);
extern int pipe_avail(object_t *o);
extern int pty_init(void);
extern int special_init(void);
extern int event_init(unsigned *port);
extern int tmpfile_init(void);
#endif