Changes in uspace/lib/c/generic/vfs/vfs.c [79ae36dd:27b76ca] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/vfs/vfs.c
r79ae36dd r27b76ca 69 69 * 70 70 */ 71 staticasync_exch_t *vfs_exchange_begin(void)71 async_exch_t *vfs_exchange_begin(void) 72 72 { 73 73 fibril_mutex_lock(&vfs_mutex); … … 87 87 * 88 88 */ 89 staticvoid vfs_exchange_end(async_exch_t *exch)89 void vfs_exchange_end(async_exch_t *exch) 90 90 { 91 91 async_exchange_end(exch); … … 329 329 } 330 330 331 int open_node(fdi_node_t *node, int oflag)332 {333 async_exch_t *exch = vfs_exchange_begin();334 335 ipc_call_t answer;336 aid_t req = async_send_4(exch, VFS_IN_OPEN_NODE, node->fs_handle,337 node->devmap_handle, node->index, oflag, &answer);338 339 vfs_exchange_end(exch);340 341 sysarg_t rc;342 async_wait_for(req, &rc);343 344 if (rc != EOK)345 return (int) rc;346 347 return (int) IPC_GET_ARG1(answer);348 }349 350 331 int close(int fildes) 351 332 { … … 415 396 else 416 397 return -1; 398 } 399 400 /** Read entire buffer. 401 * 402 * In face of short reads this function continues reading until either 403 * the entire buffer is read or no more data is available (at end of file). 404 * 405 * @param fildes File descriptor 406 * @param buf Buffer, @a nbytes bytes long 407 * @param nbytes Number of bytes to read 408 * 409 * @return On success, positive number of bytes read. 410 * On failure, negative error code from read(). 411 */ 412 ssize_t read_all(int fildes, void *buf, size_t nbyte) 413 { 414 ssize_t cnt = 0; 415 size_t nread = 0; 416 uint8_t *bp = (uint8_t *) buf; 417 418 do { 419 bp += cnt; 420 nread += cnt; 421 cnt = read(fildes, bp, nbyte - nread); 422 } while (cnt > 0 && (nbyte - nread - cnt) > 0); 423 424 if (cnt < 0) 425 return cnt; 426 427 return nread + cnt; 428 } 429 430 /** Write entire buffer. 431 * 432 * This function fails if it cannot write exactly @a len bytes to the file. 433 * 434 * @param fildes File descriptor 435 * @param buf Data, @a nbytes bytes long 436 * @param nbytes Number of bytes to write 437 * 438 * @return EOK on error, return value from write() if writing 439 * failed. 440 */ 441 ssize_t write_all(int fildes, const void *buf, size_t nbyte) 442 { 443 ssize_t cnt = 0; 444 ssize_t nwritten = 0; 445 const uint8_t *bp = (uint8_t *) buf; 446 447 do { 448 bp += cnt; 449 nwritten += cnt; 450 cnt = write(fildes, bp, nbyte - nwritten); 451 } while (cnt > 0 && ((ssize_t )nbyte - nwritten - cnt) > 0); 452 453 if (cnt < 0) 454 return cnt; 455 456 if ((ssize_t)nbyte - nwritten - cnt > 0) 457 return EIO; 458 459 return nbyte; 417 460 } 418 461 … … 757 800 } 758 801 759 int fd_node(int fildes, fdi_node_t *node)760 {761 struct stat stat;762 int rc = fstat(fildes, &stat);763 764 if (rc == EOK) {765 node->fs_handle = stat.fs_handle;766 node->devmap_handle = stat.devmap_handle;767 node->index = stat.index;768 }769 770 return rc;771 }772 773 802 int dup2(int oldfd, int newfd) 774 803 { … … 786 815 } 787 816 817 int fd_wait(void) 818 { 819 async_exch_t *exch = vfs_exchange_begin(); 820 821 sysarg_t ret; 822 sysarg_t rc = async_req_0_1(exch, VFS_IN_WAIT_HANDLE, &ret); 823 824 vfs_exchange_end(exch); 825 826 if (rc == EOK) 827 return (int) ret; 828 829 return (int) rc; 830 } 831 788 832 /** @} 789 833 */
Note:
See TracChangeset
for help on using the changeset viewer.