Rev 4561 | Rev 4587 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 4561 | Rev 4585 | ||
|---|---|---|---|
| Line 41... | Line 41... | ||
| 41 | #include <malloc.h> |
41 | #include <malloc.h> |
| 42 | #include <string.h> |
42 | #include <string.h> |
| 43 | #include <libfs.h> |
43 | #include <libfs.h> |
| 44 | #include <fibril_sync.h> |
44 | #include <fibril_sync.h> |
| 45 | #include <adt/hash_table.h> |
45 | #include <adt/hash_table.h> |
| - | 46 | #include <sys/stat.h> |
|
| 46 | #include "devfs.h" |
47 | #include "devfs.h" |
| 47 | #include "devfs_ops.h" |
48 | #include "devfs_ops.h" |
| 48 | 49 | ||
| 49 | #define PLB_GET_CHAR(pos) (devfs_reg.plb_ro[pos % PLB_SIZE]) |
50 | #define PLB_GET_CHAR(pos) (devfs_reg.plb_ro[pos % PLB_SIZE]) |
| 50 | 51 | ||
| Line 275... | Line 276... | ||
| 275 | fibril_mutex_unlock(&devices_mutex); |
276 | fibril_mutex_unlock(&devices_mutex); |
| 276 | 277 | ||
| 277 | ipc_answer_3(rid, EOK, 0, 1, L_FILE); |
278 | ipc_answer_3(rid, EOK, 0, 1, L_FILE); |
| 278 | } |
279 | } |
| 279 | 280 | ||
| 280 | void devfs_device(ipc_callid_t rid, ipc_call_t *request) |
281 | void devfs_stat(ipc_callid_t rid, ipc_call_t *request) |
| 281 | { |
282 | { |
| - | 283 | dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request); |
|
| 282 | fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); |
284 | fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); |
| 283 | 285 | ||
| - | 286 | ipc_callid_t callid; |
|
| - | 287 | size_t size; |
|
| - | 288 | if (!ipc_data_read_receive(&callid, &size) || |
|
| - | 289 | size < sizeof(struct stat)) { |
|
| - | 290 | ipc_answer_0(callid, EINVAL); |
|
| - | 291 | ipc_answer_0(rid, EINVAL); |
|
| - | 292 | return; |
|
| - | 293 | } |
|
| - | 294 | ||
| - | 295 | struct stat *stat = malloc(sizeof(struct stat)); |
|
| - | 296 | if (!stat) { |
|
| - | 297 | ipc_answer_0(callid, ENOMEM); |
|
| - | 298 | ipc_answer_0(rid, ENOMEM); |
|
| - | 299 | return; |
|
| - | 300 | } |
|
| - | 301 | memset(stat, 0, sizeof(struct stat)); |
|
| - | 302 | ||
| - | 303 | stat->fs_handle = devfs_reg.fs_handle; |
|
| - | 304 | stat->dev_handle = dev_handle; |
|
| - | 305 | stat->index = index; |
|
| - | 306 | stat->lnkcnt = 1; |
|
| - | 307 | stat->is_file = (index != 0); |
|
| - | 308 | stat->size = 0; |
|
| - | 309 | ||
| 284 | if (index != 0) { |
310 | if (index != 0) { |
| 285 | unsigned long key[] = { |
311 | unsigned long key[] = { |
| 286 | [DEVICES_KEY_HANDLE] = (unsigned long) index |
312 | [DEVICES_KEY_HANDLE] = (unsigned long) index |
| 287 | }; |
313 | }; |
| 288 | 314 | ||
| 289 | fibril_mutex_lock(&devices_mutex); |
315 | fibril_mutex_lock(&devices_mutex); |
| 290 | link_t *lnk = hash_table_find(&devices, key); |
316 | link_t *lnk = hash_table_find(&devices, key); |
| 291 | if (lnk == NULL) { |
317 | if (lnk != NULL) |
| 292 | fibril_mutex_unlock(&devices_mutex); |
318 | stat->devfs_stat.device = (dev_handle_t)index; |
| 293 | ipc_answer_0(rid, ENOENT); |
- | |
| 294 | return; |
- | |
| 295 | } |
- | |
| 296 | fibril_mutex_unlock(&devices_mutex); |
319 | fibril_mutex_unlock(&devices_mutex); |
| 297 | 320 | } |
|
| - | 321 | ||
| 298 | ipc_answer_1(rid, EOK, (ipcarg_t) index); |
322 | ipc_data_read_finalize(callid, stat, sizeof(struct stat)); |
| 299 | } else |
- | |
| 300 | ipc_answer_0(rid, ENOTSUP); |
323 | ipc_answer_0(rid, EOK); |
| - | 324 | ||
| - | 325 | free(stat); |
|
| 301 | } |
326 | } |
| 302 | 327 | ||
| 303 | void devfs_read(ipc_callid_t rid, ipc_call_t *request) |
328 | void devfs_read(ipc_callid_t rid, ipc_call_t *request) |
| 304 | { |
329 | { |
| 305 | fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); |
330 | fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); |