Rev 4327 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 4327 | Rev 4581 | ||
|---|---|---|---|
| Line 46... | Line 46... | ||
| 46 | #include <async.h> |
46 | #include <async.h> |
| 47 | #include <atomic.h> |
47 | #include <atomic.h> |
| 48 | #include <futex.h> |
48 | #include <futex.h> |
| 49 | #include <errno.h> |
49 | #include <errno.h> |
| 50 | #include <string.h> |
50 | #include <string.h> |
| - | 51 | #include <devmap.h> |
|
| - | 52 | #include <ipc/vfs.h> |
|
| 51 | #include <ipc/devmap.h> |
53 | #include <ipc/devmap.h> |
| 52 | #include "../../../srv/vfs/vfs.h" |
- | |
| 53 | 54 | ||
| 54 | int vfs_phone = -1; |
55 | static int vfs_phone = -1; |
| 55 | futex_t vfs_phone_futex = FUTEX_INITIALIZER; |
56 | static futex_t vfs_phone_futex = FUTEX_INITIALIZER; |
| - | 57 | static futex_t cwd_futex = FUTEX_INITIALIZER; |
|
| 56 | 58 | ||
| 57 | futex_t cwd_futex = FUTEX_INITIALIZER; |
- | |
| 58 | DIR *cwd_dir = NULL; |
59 | DIR *cwd_dir = NULL; |
| 59 | char *cwd_path = NULL; |
60 | char *cwd_path = NULL; |
| 60 | size_t cwd_size = 0; |
61 | size_t cwd_size = 0; |
| 61 | 62 | ||
| 62 | char *absolutize(const char *path, size_t *retlen) |
63 | char *absolutize(const char *path, size_t *retlen) |
| Line 113... | Line 114... | ||
| 113 | { |
114 | { |
| 114 | while (vfs_phone < 0) |
115 | while (vfs_phone < 0) |
| 115 | vfs_phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_VFS, 0, 0); |
116 | vfs_phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_VFS, 0, 0); |
| 116 | } |
117 | } |
| 117 | 118 | ||
| 118 | static int device_get_handle(const char *name, dev_handle_t *handle, |
- | |
| 119 | const unsigned int flags) |
- | |
| 120 | { |
- | |
| 121 | int phone; |
- | |
| 122 | - | ||
| 123 | if (flags & IPC_FLAG_BLOCKING) |
- | |
| 124 | phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_DEVMAP, DEVMAP_CLIENT, 0); |
- | |
| 125 | else |
- | |
| 126 | phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAP, DEVMAP_CLIENT, 0); |
- | |
| 127 | - | ||
| 128 | if (phone < 0) |
- | |
| 129 | return phone; |
- | |
| 130 | - | ||
| 131 | ipc_call_t answer; |
- | |
| 132 | aid_t req = async_send_2(phone, DEVMAP_DEVICE_GET_HANDLE, flags, 0, |
- | |
| 133 | &answer); |
- | |
| 134 | - | ||
| 135 | ipcarg_t retval = ipc_data_write_start(phone, name, str_size(name) + 1); |
- | |
| 136 | - | ||
| 137 | if (retval != EOK) { |
- | |
| 138 | async_wait_for(req, NULL); |
- | |
| 139 | ipc_hangup(phone); |
- | |
| 140 | return retval; |
- | |
| 141 | } |
- | |
| 142 | - | ||
| 143 | async_wait_for(req, &retval); |
- | |
| 144 | - | ||
| 145 | if (handle != NULL) |
- | |
| 146 | *handle = -1; |
- | |
| 147 | - | ||
| 148 | if (retval == EOK) { |
- | |
| 149 | if (handle != NULL) |
- | |
| 150 | *handle = (dev_handle_t) IPC_GET_ARG1(answer); |
- | |
| 151 | } |
- | |
| 152 | - | ||
| 153 | ipc_hangup(phone); |
- | |
| 154 | return retval; |
- | |
| 155 | } |
- | |
| 156 | - | ||
| 157 | int mount(const char *fs_name, const char *mp, const char *dev, |
119 | int mount(const char *fs_name, const char *mp, const char *dev, |
| 158 | const char *opts, const unsigned int flags) |
120 | const char *opts, unsigned int flags) |
| 159 | { |
121 | { |
| 160 | int res; |
122 | int res; |
| 161 | ipcarg_t rc; |
123 | ipcarg_t rc; |
| 162 | aid_t req; |
124 | aid_t req; |
| 163 | dev_handle_t dev_handle; |
125 | dev_handle_t dev_handle; |
| 164 | 126 | ||
| 165 | res = device_get_handle(dev, &dev_handle, flags); |
127 | res = devmap_device_get_handle(dev, &dev_handle, flags); |
| 166 | if (res != EOK) |
128 | if (res != EOK) |
| 167 | return res; |
129 | return res; |
| 168 | 130 | ||
| 169 | size_t mpa_size; |
131 | size_t mpa_size; |
| 170 | char *mpa = absolutize(mp, &mpa_size); |
132 | char *mpa = absolutize(mp, &mpa_size); |
| Line 247... | Line 209... | ||
| 247 | } |
209 | } |
| 248 | async_wait_for(req, &rc); |
210 | async_wait_for(req, &rc); |
| 249 | async_serialize_end(); |
211 | async_serialize_end(); |
| 250 | futex_up(&vfs_phone_futex); |
212 | futex_up(&vfs_phone_futex); |
| 251 | free(pa); |
213 | free(pa); |
| 252 | 214 | ||
| 253 | if (rc != EOK) |
215 | if (rc != EOK) |
| 254 | return (int) rc; |
216 | return (int) rc; |
| - | 217 | ||
| 255 | return (int) IPC_GET_ARG1(answer); |
218 | return (int) IPC_GET_ARG1(answer); |
| 256 | } |
219 | } |
| 257 | 220 | ||
| 258 | int open(const char *path, int oflag, ...) |
221 | int open(const char *path, int oflag, ...) |
| 259 | { |
222 | { |
| 260 | return _open(path, L_FILE, oflag); |
223 | return _open(path, L_FILE, oflag); |
| 261 | } |
224 | } |
| 262 | 225 | ||
| - | 226 | int open_node(fdi_node_t *node, int oflag) |
|
| - | 227 | { |
|
| - | 228 | futex_down(&vfs_phone_futex); |
|
| - | 229 | async_serialize_start(); |
|
| - | 230 | vfs_connect(); |
|
| - | 231 | ||
| - | 232 | ipc_call_t answer; |
|
| - | 233 | aid_t req = async_send_4(vfs_phone, VFS_OPEN_NODE, node->fs_handle, |
|
| - | 234 | node->dev_handle, node->index, oflag, &answer); |
|
| - | 235 | ||
| - | 236 | ipcarg_t rc; |
|
| - | 237 | async_wait_for(req, &rc); |
|
| - | 238 | async_serialize_end(); |
|
| - | 239 | futex_up(&vfs_phone_futex); |
|
| - | 240 | ||
| - | 241 | if (rc != EOK) |
|
| - | 242 | return (int) rc; |
|
| - | 243 | ||
| - | 244 | return (int) IPC_GET_ARG1(answer); |
|
| - | 245 | } |
|
| - | 246 | ||
| 263 | int close(int fildes) |
247 | int close(int fildes) |
| 264 | { |
248 | { |
| 265 | ipcarg_t rc; |
249 | ipcarg_t rc; |
| 266 | 250 | ||
| 267 | futex_down(&vfs_phone_futex); |
251 | futex_down(&vfs_phone_futex); |
| Line 328... | Line 312... | ||
| 328 | return (ssize_t) IPC_GET_ARG1(answer); |
312 | return (ssize_t) IPC_GET_ARG1(answer); |
| 329 | else |
313 | else |
| 330 | return -1; |
314 | return -1; |
| 331 | } |
315 | } |
| 332 | 316 | ||
| - | 317 | int fd_phone(int fildes) |
|
| - | 318 | { |
|
| - | 319 | futex_down(&vfs_phone_futex); |
|
| - | 320 | async_serialize_start(); |
|
| - | 321 | vfs_connect(); |
|
| - | 322 | ||
| - | 323 | ipcarg_t device; |
|
| - | 324 | ipcarg_t rc = async_req_1_1(vfs_phone, VFS_DEVICE, fildes, &device); |
|
| - | 325 | ||
| - | 326 | async_serialize_end(); |
|
| - | 327 | futex_up(&vfs_phone_futex); |
|
| - | 328 | ||
| - | 329 | if (rc != EOK) |
|
| - | 330 | return -1; |
|
| - | 331 | ||
| - | 332 | return devmap_device_connect((dev_handle_t) device, 0); |
|
| - | 333 | } |
|
| - | 334 | ||
| - | 335 | int fd_node(int fildes, fdi_node_t *node) |
|
| - | 336 | { |
|
| - | 337 | futex_down(&vfs_phone_futex); |
|
| - | 338 | async_serialize_start(); |
|
| - | 339 | vfs_connect(); |
|
| - | 340 | ||
| - | 341 | ipcarg_t fs_handle; |
|
| - | 342 | ipcarg_t dev_handle; |
|
| - | 343 | ipcarg_t index; |
|
| - | 344 | ipcarg_t rc = async_req_1_3(vfs_phone, VFS_NODE, fildes, &fs_handle, |
|
| - | 345 | &dev_handle, &index); |
|
| - | 346 | ||
| - | 347 | async_serialize_end(); |
|
| - | 348 | futex_up(&vfs_phone_futex); |
|
| - | 349 | ||
| - | 350 | if (rc == EOK) { |
|
| - | 351 | node->fs_handle = (fs_handle_t) fs_handle; |
|
| - | 352 | node->dev_handle = (dev_handle_t) dev_handle; |
|
| - | 353 | node->index = (fs_index_t) index; |
|
| - | 354 | } |
|
| - | 355 | ||
| - | 356 | return rc; |
|
| - | 357 | } |
|
| - | 358 | ||
| - | 359 | int fsync(int fildes) |
|
| - | 360 | { |
|
| - | 361 | futex_down(&vfs_phone_futex); |
|
| - | 362 | async_serialize_start(); |
|
| - | 363 | vfs_connect(); |
|
| - | 364 | ||
| - | 365 | ipcarg_t rc = async_req_1_0(vfs_phone, VFS_SYNC, fildes); |
|
| - | 366 | ||
| - | 367 | async_serialize_end(); |
|
| - | 368 | futex_up(&vfs_phone_futex); |
|
| - | 369 | ||
| - | 370 | return (int) rc; |
|
| - | 371 | } |
|
| - | 372 | ||
| 333 | off_t lseek(int fildes, off_t offset, int whence) |
373 | off_t lseek(int fildes, off_t offset, int whence) |
| 334 | { |
374 | { |
| 335 | ipcarg_t rc; |
375 | ipcarg_t rc; |
| 336 | 376 | ||
| 337 | futex_down(&vfs_phone_futex); |
377 | futex_down(&vfs_phone_futex); |
| Line 423... | Line 463... | ||
| 423 | } |
463 | } |
| 424 | async_wait_for(req, &rc); |
464 | async_wait_for(req, &rc); |
| 425 | async_serialize_end(); |
465 | async_serialize_end(); |
| 426 | futex_up(&vfs_phone_futex); |
466 | futex_up(&vfs_phone_futex); |
| 427 | free(pa); |
467 | free(pa); |
| 428 | return rc; |
468 | return rc; |
| 429 | } |
469 | } |
| 430 | 470 | ||
| 431 | static int _unlink(const char *path, int lflag) |
471 | static int _unlink(const char *path, int lflag) |
| 432 | { |
472 | { |
| 433 | ipcarg_t rc; |
473 | ipcarg_t rc; |
| Line 453... | Line 493... | ||
| 453 | } |
493 | } |
| 454 | async_wait_for(req, &rc); |
494 | async_wait_for(req, &rc); |
| 455 | async_serialize_end(); |
495 | async_serialize_end(); |
| 456 | futex_up(&vfs_phone_futex); |
496 | futex_up(&vfs_phone_futex); |
| 457 | free(pa); |
497 | free(pa); |
| 458 | return rc; |
498 | return rc; |
| 459 | } |
499 | } |
| 460 | 500 | ||
| 461 | int unlink(const char *path) |
501 | int unlink(const char *path) |
| 462 | { |
502 | { |
| 463 | return _unlink(path, L_NONE); |
503 | return _unlink(path, L_NONE); |