9 static int do_invoke_ds(int type
, const char *ds_name
)
15 if(type
== DS_CHECK
|| type
== DS_RETRIEVE_LABEL
) {
16 len_key
= DS_MAX_KEYLEN
;
19 len_key
= strlen(ds_name
)+1;
24 g_key
= cpf_grant_direct(DS_PROC_NR
, (vir_bytes
) ds_name
,
26 if(!GRANT_VALID(g_key
))
29 m
.DS_KEY_GRANT
= g_key
;
30 m
.DS_KEY_LEN
= len_key
;
32 r
= _taskcall(DS_PROC_NR
, type
, &m
);
38 int ds_publish_label(const char *ds_name
, endpoint_t endpoint
, int flags
)
40 m
.DS_VAL
= (u32_t
) endpoint
;
41 m
.DS_FLAGS
= DSF_TYPE_LABEL
| flags
;
42 return do_invoke_ds(DS_PUBLISH
, ds_name
);
45 int ds_publish_u32(const char *ds_name
, u32_t value
, int flags
)
48 m
.DS_FLAGS
= DSF_TYPE_U32
| flags
;
49 return do_invoke_ds(DS_PUBLISH
, ds_name
);
52 static int ds_publish_raw(const char *ds_name
, void *vaddr
, size_t length
,
58 /* Grant for memory range. */
59 gid
= cpf_grant_direct(DS_PROC_NR
, (vir_bytes
)vaddr
, length
, CPF_READ
);
64 m
.DS_VAL_LEN
= length
;
67 r
= do_invoke_ds(DS_PUBLISH
, ds_name
);
73 int ds_publish_str(const char *ds_name
, char *value
, int flags
)
76 length
= strlen(value
) + 1;
77 value
[length
- 1] = '\0';
78 return ds_publish_raw(ds_name
, value
, length
, flags
| DSF_TYPE_STR
);
81 int ds_publish_mem(const char *ds_name
, void *vaddr
, size_t length
, int flags
)
83 return ds_publish_raw(ds_name
, vaddr
, length
, flags
| DSF_TYPE_MEM
);
86 int ds_publish_map(const char *ds_name
, void *vaddr
, size_t length
, int flags
)
91 if(((vir_bytes
)vaddr
% CLICK_SIZE
!= 0) || (length
% CLICK_SIZE
!= 0))
94 /* Grant for mapped memory range. */
95 gid
= cpf_grant_direct(DS_PROC_NR
, (vir_bytes
)vaddr
, length
,
101 m
.DS_VAL_LEN
= length
;
102 m
.DS_FLAGS
= DSF_TYPE_MAP
| flags
;
104 r
= do_invoke_ds(DS_PUBLISH
, ds_name
);
109 int ds_snapshot_map(const char *ds_name
, int *nr_snapshot
)
112 r
= do_invoke_ds(DS_SNAPSHOT
, ds_name
);
113 *nr_snapshot
= m
.DS_NR_SNAPSHOT
;
117 int ds_retrieve_label_name(char *ds_name
, endpoint_t endpoint
)
120 m
.DS_VAL
= (u32_t
) endpoint
;
121 r
= do_invoke_ds(DS_RETRIEVE_LABEL
, ds_name
);
125 int ds_retrieve_label_endpt(const char *ds_name
, endpoint_t
*endpoint
)
128 m
.DS_FLAGS
= DSF_TYPE_LABEL
;
129 r
= do_invoke_ds(DS_RETRIEVE
, ds_name
);
130 *endpoint
= (endpoint_t
) m
.DS_VAL
;
134 int ds_retrieve_u32(const char *ds_name
, u32_t
*value
)
137 m
.DS_FLAGS
= DSF_TYPE_U32
;
138 r
= do_invoke_ds(DS_RETRIEVE
, ds_name
);
143 static int ds_retrieve_raw(const char *ds_name
, char *vaddr
, size_t *length
,
149 /* Grant for memory range. */
150 gid
= cpf_grant_direct(DS_PROC_NR
, (vir_bytes
)vaddr
, *length
, CPF_WRITE
);
151 if(!GRANT_VALID(gid
))
155 m
.DS_VAL_LEN
= *length
;
157 r
= do_invoke_ds(DS_RETRIEVE
, ds_name
);
158 *length
= m
.DS_VAL_LEN
;
164 int ds_retrieve_str(const char *ds_name
, char *value
, size_t len_str
)
167 size_t length
= len_str
+ 1;
168 r
= ds_retrieve_raw(ds_name
, value
, &length
, DSF_TYPE_STR
);
169 value
[length
- 1] = '\0';
173 int ds_retrieve_mem(const char *ds_name
, char *vaddr
, size_t *length
)
175 return ds_retrieve_raw(ds_name
, vaddr
, length
, DSF_TYPE_MEM
);
178 int ds_retrieve_map(const char *ds_name
, char *vaddr
, size_t *length
,
179 int nr_snapshot
, int flags
)
184 /* Map a mapped memory range. */
185 if(flags
& DSMF_MAP_MAPPED
) {
186 /* Request DS to grant. */
187 m
.DS_FLAGS
= DSF_TYPE_MAP
| DSMF_MAP_MAPPED
;
188 r
= do_invoke_ds(DS_RETRIEVE
, ds_name
);
192 /* Do the safemap. */
193 if(*length
> (size_t) m
.DS_VAL_LEN
)
194 *length
= (size_t) m
.DS_VAL_LEN
;
195 *length
= (size_t) CLICK_FLOOR(*length
);
196 r
= sys_safemap(DS_PROC_NR
, m
.DS_VAL
, 0,
197 (vir_bytes
)vaddr
, *length
, 0);
199 /* Copy mapped memory range or a snapshot. */
200 } else if(flags
& (DSMF_COPY_MAPPED
|DSMF_COPY_SNAPSHOT
)) {
201 /* Grant for memory range first. */
202 gid
= cpf_grant_direct(DS_PROC_NR
, (vir_bytes
)vaddr
,
204 if(!GRANT_VALID(gid
))
208 m
.DS_VAL_LEN
= *length
;
209 if(flags
& DSMF_COPY_MAPPED
) {
210 m
.DS_FLAGS
= DSF_TYPE_MAP
| DSMF_COPY_MAPPED
;
213 m
.DS_NR_SNAPSHOT
= nr_snapshot
;
214 m
.DS_FLAGS
= DSF_TYPE_MAP
| DSMF_COPY_SNAPSHOT
;
216 r
= do_invoke_ds(DS_RETRIEVE
, ds_name
);
217 *length
= m
.DS_VAL_LEN
;
227 int ds_delete_u32(const char *ds_name
)
229 m
.DS_FLAGS
= DSF_TYPE_U32
;
230 return do_invoke_ds(DS_DELETE
, ds_name
);
233 int ds_delete_str(const char *ds_name
)
235 m
.DS_FLAGS
= DSF_TYPE_STR
;
236 return do_invoke_ds(DS_DELETE
, ds_name
);
239 int ds_delete_mem(const char *ds_name
)
241 m
.DS_FLAGS
= DSF_TYPE_MEM
;
242 return do_invoke_ds(DS_DELETE
, ds_name
);
245 int ds_delete_map(const char *ds_name
)
247 m
.DS_FLAGS
= DSF_TYPE_MAP
;
248 return do_invoke_ds(DS_DELETE
, ds_name
);
251 int ds_delete_label(const char *ds_name
)
253 m
.DS_FLAGS
= DSF_TYPE_LABEL
;
254 return do_invoke_ds(DS_DELETE
, ds_name
);
257 int ds_subscribe(const char *regexp
, int flags
)
260 return do_invoke_ds(DS_SUBSCRIBE
, regexp
);
263 int ds_check(char *ds_key
, int *type
, endpoint_t
*owner_e
)
266 r
= do_invoke_ds(DS_CHECK
, ds_key
);
267 if(type
) *type
= m
.DS_FLAGS
;
268 if(owner_e
) *owner_e
= m
.DS_OWNER
;