Changeset 19b28b0 in mainline for uspace/lib/libc/generic/vfs/vfs.c
- Timestamp:
- 2009-03-02T17:31:05Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8026731
- Parents:
- 97c9da8
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/libc/generic/vfs/vfs.c
r97c9da8 r19b28b0 32 32 /** @file 33 33 */ 34 34 35 35 #include <vfs/vfs.h> 36 36 #include <vfs/canonify.h> … … 58 58 DIR *cwd_dir = NULL; 59 59 char *cwd_path = NULL; 60 size_t cwd_len = 0; 60 size_t cwd_len = 0; 61 61 62 62 char *absolutize(const char *path, size_t *retlen) … … 110 110 } 111 111 112 static int vfs_connect(void) 113 { 114 if (vfs_phone < 0) 115 vfs_phone = ipc_connect_me_to(PHONE_NS, SERVICE_VFS, 0, 0); 116 return vfs_phone; 117 } 118 119 static int device_get_handle(const char *name, dev_handle_t *handle) 120 { 121 int phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAP, DEVMAP_CLIENT, 122 0); 112 static void vfs_connect(void) 113 { 114 while (vfs_phone < 0) 115 vfs_phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_VFS, 0, 0); 116 } 117 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 123 128 if (phone < 0) 124 129 return phone; 125 130 126 131 ipc_call_t answer; 127 aid_t req = async_send_2(phone, DEVMAP_DEVICE_GET_HANDLE, 0, 0,132 aid_t req = async_send_2(phone, DEVMAP_DEVICE_GET_HANDLE, flags, 0, 128 133 &answer); 129 134 130 135 ipcarg_t retval = ipc_data_write_start(phone, name, strlen(name) + 1); 131 136 132 137 if (retval != EOK) { 133 138 async_wait_for(req, NULL); … … 135 140 return retval; 136 141 } 137 142 138 143 async_wait_for(req, &retval); 139 144 140 145 if (handle != NULL) 141 146 *handle = -1; … … 150 155 } 151 156 152 int mount(const char *fs_name, const char *mp, const char *dev) 157 int mount(const char *fs_name, const char *mp, const char *dev, 158 const unsigned int flags) 153 159 { 154 160 int res; … … 157 163 dev_handle_t dev_handle; 158 164 159 res = device_get_handle(dev, &dev_handle );165 res = device_get_handle(dev, &dev_handle, flags); 160 166 if (res != EOK) 161 167 return res; … … 165 171 if (!mpa) 166 172 return ENOMEM; 167 168 futex_down(&vfs_phone_futex); 169 async_serialize_start(); 170 if (vfs_phone < 0) { 171 res = vfs_connect(); 172 if (res < 0) { 173 async_serialize_end(); 174 futex_up(&vfs_phone_futex); 175 free(mpa); 176 return res; 177 } 178 } 179 req = async_send_1(vfs_phone, VFS_MOUNT, dev_handle, NULL); 180 rc = ipc_data_write_start(vfs_phone, (void *)fs_name, strlen(fs_name)); 173 174 futex_down(&vfs_phone_futex); 175 async_serialize_start(); 176 vfs_connect(); 177 178 req = async_send_2(vfs_phone, VFS_MOUNT, dev_handle, flags, NULL); 179 rc = ipc_data_write_start(vfs_phone, (void *) mpa, mpa_len); 181 180 if (rc != EOK) { 182 181 async_wait_for(req, NULL); … … 186 185 return (int) rc; 187 186 } 188 /* Ask VFS whether it likes fs_name. */189 rc = async_req_0_0(vfs_phone, IPC_M_PING);187 188 rc = ipc_data_write_start(vfs_phone, (void *) fs_name, strlen(fs_name)); 190 189 if (rc != EOK) { 191 190 async_wait_for(req, NULL); … … 195 194 return (int) rc; 196 195 } 197 rc = ipc_data_write_start(vfs_phone, (void *)mpa, mpa_len); 198 if (rc != EOK) { 199 async_wait_for(req, NULL); 200 async_serialize_end(); 201 futex_up(&vfs_phone_futex); 202 free(mpa); 203 return (int) rc; 204 } 196 205 197 async_wait_for(req, &rc); 206 198 async_serialize_end(); 207 199 futex_up(&vfs_phone_futex); 208 200 free(mpa); 201 209 202 return (int) rc; 210 203 } … … 212 205 static int _open(const char *path, int lflag, int oflag, ...) 213 206 { 214 int res;215 207 ipcarg_t rc; 216 208 ipc_call_t answer; … … 224 216 futex_down(&vfs_phone_futex); 225 217 async_serialize_start(); 226 if (vfs_phone < 0) { 227 res = vfs_connect(); 228 if (res < 0) { 229 async_serialize_end(); 230 futex_up(&vfs_phone_futex); 231 free(pa); 232 return res; 233 } 234 } 218 vfs_connect(); 219 235 220 req = async_send_3(vfs_phone, VFS_OPEN, lflag, oflag, 0, &answer); 236 221 rc = ipc_data_write_start(vfs_phone, pa, pa_len); … … 259 244 int close(int fildes) 260 245 { 261 int res; 262 ipcarg_t rc; 263 264 futex_down(&vfs_phone_futex); 265 async_serialize_start(); 266 if (vfs_phone < 0) { 267 res = vfs_connect(); 268 if (res < 0) { 269 async_serialize_end(); 270 futex_up(&vfs_phone_futex); 271 return res; 272 } 273 } 274 246 ipcarg_t rc; 247 248 futex_down(&vfs_phone_futex); 249 async_serialize_start(); 250 vfs_connect(); 251 275 252 rc = async_req_1_0(vfs_phone, VFS_CLOSE, fildes); 276 253 277 254 async_serialize_end(); 278 255 futex_up(&vfs_phone_futex); … … 283 260 ssize_t read(int fildes, void *buf, size_t nbyte) 284 261 { 285 int res;286 262 ipcarg_t rc; 287 263 ipc_call_t answer; … … 290 266 futex_down(&vfs_phone_futex); 291 267 async_serialize_start(); 292 if (vfs_phone < 0) { 293 res = vfs_connect(); 294 if (res < 0) { 295 async_serialize_end(); 296 futex_up(&vfs_phone_futex); 297 return res; 298 } 299 } 268 vfs_connect(); 269 300 270 req = async_send_1(vfs_phone, VFS_READ, fildes, &answer); 301 271 rc = ipc_data_read_start(vfs_phone, (void *)buf, nbyte); … … 317 287 ssize_t write(int fildes, const void *buf, size_t nbyte) 318 288 { 319 int res;320 289 ipcarg_t rc; 321 290 ipc_call_t answer; … … 324 293 futex_down(&vfs_phone_futex); 325 294 async_serialize_start(); 326 if (vfs_phone < 0) { 327 res = vfs_connect(); 328 if (res < 0) { 329 async_serialize_end(); 330 futex_up(&vfs_phone_futex); 331 return res; 332 } 333 } 295 vfs_connect(); 296 334 297 req = async_send_1(vfs_phone, VFS_WRITE, fildes, &answer); 335 298 rc = ipc_data_write_start(vfs_phone, (void *)buf, nbyte); … … 351 314 off_t lseek(int fildes, off_t offset, int whence) 352 315 { 353 int res; 354 ipcarg_t rc; 355 356 futex_down(&vfs_phone_futex); 357 async_serialize_start(); 358 if (vfs_phone < 0) { 359 res = vfs_connect(); 360 if (res < 0) { 361 async_serialize_end(); 362 futex_up(&vfs_phone_futex); 363 return res; 364 } 365 } 366 316 ipcarg_t rc; 317 318 futex_down(&vfs_phone_futex); 319 async_serialize_start(); 320 vfs_connect(); 321 367 322 ipcarg_t newoffs; 368 323 rc = async_req_3_1(vfs_phone, VFS_SEEK, fildes, offset, whence, … … 380 335 int ftruncate(int fildes, off_t length) 381 336 { 382 int res; 383 ipcarg_t rc; 384 385 futex_down(&vfs_phone_futex); 386 async_serialize_start(); 387 if (vfs_phone < 0) { 388 res = vfs_connect(); 389 if (res < 0) { 390 async_serialize_end(); 391 futex_up(&vfs_phone_futex); 392 return res; 393 } 394 } 337 ipcarg_t rc; 338 339 futex_down(&vfs_phone_futex); 340 async_serialize_start(); 341 vfs_connect(); 342 395 343 rc = async_req_2_0(vfs_phone, VFS_TRUNCATE, fildes, length); 396 344 async_serialize_end(); … … 434 382 int mkdir(const char *path, mode_t mode) 435 383 { 436 int res;437 384 ipcarg_t rc; 438 385 aid_t req; … … 442 389 if (!pa) 443 390 return ENOMEM; 444 445 futex_down(&vfs_phone_futex); 446 async_serialize_start(); 447 if (vfs_phone < 0) { 448 res = vfs_connect(); 449 if (res < 0) { 450 async_serialize_end(); 451 futex_up(&vfs_phone_futex); 452 free(pa); 453 return res; 454 } 455 } 391 392 futex_down(&vfs_phone_futex); 393 async_serialize_start(); 394 vfs_connect(); 395 456 396 req = async_send_1(vfs_phone, VFS_MKDIR, mode, NULL); 457 397 rc = ipc_data_write_start(vfs_phone, pa, pa_len); … … 472 412 static int _unlink(const char *path, int lflag) 473 413 { 474 int res;475 414 ipcarg_t rc; 476 415 aid_t req; … … 483 422 futex_down(&vfs_phone_futex); 484 423 async_serialize_start(); 485 if (vfs_phone < 0) { 486 res = vfs_connect(); 487 if (res < 0) { 488 async_serialize_end(); 489 futex_up(&vfs_phone_futex); 490 free(pa); 491 return res; 492 } 493 } 424 vfs_connect(); 425 494 426 req = async_send_0(vfs_phone, VFS_UNLINK, NULL); 495 427 rc = ipc_data_write_start(vfs_phone, pa, pa_len); … … 520 452 int rename(const char *old, const char *new) 521 453 { 522 int res;523 454 ipcarg_t rc; 524 455 aid_t req; … … 538 469 futex_down(&vfs_phone_futex); 539 470 async_serialize_start(); 540 if (vfs_phone < 0) { 541 res = vfs_connect(); 542 if (res < 0) { 543 async_serialize_end(); 544 futex_up(&vfs_phone_futex); 545 free(olda); 546 free(newa); 547 return res; 548 } 549 } 471 vfs_connect(); 472 550 473 req = async_send_0(vfs_phone, VFS_RENAME, NULL); 551 474 rc = ipc_data_write_start(vfs_phone, olda, olda_len);
Note:
See TracChangeset
for help on using the changeset viewer.