Changeset 58898d1d in mainline for uspace/srv/vfs/vfs_ops.c
- Timestamp:
- 2017-03-24T20:31:54Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8e9b2534
- Parents:
- c9e3692
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/vfs/vfs_ops.c
rc9e3692 r58898d1d 343 343 } 344 344 345 typedef int (* rdwr_ipc_cb_t)(async_exch_t *, vfs_file_t *, ipc_call_t *,346 bool, void *);347 348 static int rdwr_ipc_client(async_exch_t *exch, vfs_file_t *file, 345 typedef int (* rdwr_ipc_cb_t)(async_exch_t *, vfs_file_t *, aoff64_t, 346 ipc_call_t *, bool, void *); 347 348 static int rdwr_ipc_client(async_exch_t *exch, vfs_file_t *file, aoff64_t pos, 349 349 ipc_call_t *answer, bool read, void *data) 350 350 { … … 363 363 rc = async_data_read_forward_4_1(exch, VFS_OUT_READ, 364 364 file->node->service_id, file->node->index, 365 LOWER32( file->pos), UPPER32(file->pos), answer);365 LOWER32(pos), UPPER32(pos), answer); 366 366 } else { 367 367 rc = async_data_write_forward_4_1(exch, VFS_OUT_WRITE, 368 368 file->node->service_id, file->node->index, 369 LOWER32( file->pos), UPPER32(file->pos), answer);369 LOWER32(pos), UPPER32(pos), answer); 370 370 } 371 371 … … 374 374 } 375 375 376 static int rdwr_ipc_internal(async_exch_t *exch, vfs_file_t *file, 376 static int rdwr_ipc_internal(async_exch_t *exch, vfs_file_t *file, aoff64_t pos, 377 377 ipc_call_t *answer, bool read, void *data) 378 378 { … … 383 383 384 384 aid_t msg = async_send_fast(exch, read ? VFS_OUT_READ : VFS_OUT_WRITE, 385 file->node->service_id, file->node->index, LOWER32( file->pos),386 UPPER32( file->pos), answer);385 file->node->service_id, file->node->index, LOWER32(pos), 386 UPPER32(pos), answer); 387 387 if (msg == 0) 388 388 return EINVAL; … … 402 402 } 403 403 404 static int vfs_rdwr(int fd, bool read, rdwr_ipc_cb_t ipc_cb, void *ipc_cb_data) 404 static int vfs_rdwr(int fd, aoff64_t pos, bool read, rdwr_ipc_cb_t ipc_cb, 405 void *ipc_cb_data) 405 406 { 406 407 /* … … 463 464 async_exch_t *fs_exch = vfs_exchange_grab(file->node->fs_handle); 464 465 465 if (!read && file->append) 466 file->pos = file->node->size; 466 if (!read && file->append) { 467 if (file->node->size == -1) 468 file->node->size = vfs_node_get_size(file->node); 469 pos = file->node->size; 470 } 467 471 468 472 /* … … 470 474 */ 471 475 ipc_call_t answer; 472 int rc = ipc_cb(fs_exch, file, &answer, read, ipc_cb_data);476 int rc = ipc_cb(fs_exch, file, pos, &answer, read, ipc_cb_data); 473 477 474 478 vfs_exchange_release(fs_exch); 475 476 size_t bytes = IPC_GET_ARG1(answer);477 479 478 480 if (file->node->type == VFS_NODE_DIRECTORY) … … 491 493 } 492 494 493 /* Update the position pointer and unlock the open file. */494 if (rc == EOK)495 file->pos += bytes;496 495 vfs_file_put(file); 497 496 … … 499 498 } 500 499 501 int vfs_rdwr_internal(int fd, bool read, rdwr_io_chunk_t *chunk)502 { 503 return vfs_rdwr(fd, read, rdwr_ipc_internal, chunk);504 } 505 506 int vfs_op_read(int fd, size_t *out_bytes)507 { 508 return vfs_rdwr(fd, true, rdwr_ipc_client, out_bytes);500 int vfs_rdwr_internal(int fd, aoff64_t pos, bool read, rdwr_io_chunk_t *chunk) 501 { 502 return vfs_rdwr(fd, pos, read, rdwr_ipc_internal, chunk); 503 } 504 505 int vfs_op_read(int fd, aoff64_t pos, size_t *out_bytes) 506 { 507 return vfs_rdwr(fd, pos, true, rdwr_ipc_client, out_bytes); 509 508 } 510 509 … … 608 607 fibril_rwlock_write_unlock(&namespace_rwlock); 609 608 return EOK; 610 }611 612 int vfs_op_seek(int fd, int64_t offset, int whence, int64_t *out_offset)613 {614 vfs_file_t *file = vfs_file_get(fd);615 if (!file)616 return EBADF;617 618 switch (whence) {619 case SEEK_SET:620 if (offset < 0) {621 vfs_file_put(file);622 return EINVAL;623 }624 file->pos = offset;625 *out_offset = offset;626 vfs_file_put(file);627 return EOK;628 case SEEK_CUR:629 if (offset > 0 && file->pos > (INT64_MAX - offset)) {630 vfs_file_put(file);631 return EOVERFLOW;632 }633 634 if (offset < 0 && -file->pos > offset) {635 vfs_file_put(file);636 return EOVERFLOW;637 }638 639 file->pos += offset;640 *out_offset = file->pos;641 vfs_file_put(file);642 return EOK;643 case SEEK_END:644 fibril_rwlock_read_lock(&file->node->contents_rwlock);645 int64_t size = vfs_node_get_size(file->node);646 fibril_rwlock_read_unlock(&file->node->contents_rwlock);647 648 if (offset > 0 && size > (INT64_MAX - offset)) {649 vfs_file_put(file);650 return EOVERFLOW;651 }652 653 if (offset < 0 && -size > offset) {654 vfs_file_put(file);655 return EOVERFLOW;656 }657 658 file->pos = size + offset;659 *out_offset = file->pos;660 vfs_file_put(file);661 return EOK;662 }663 664 vfs_file_put(file);665 return EINVAL;666 609 } 667 610 … … 953 896 } 954 897 955 int vfs_op_write(int fd, size_t *out_bytes)956 { 957 return vfs_rdwr(fd, false, rdwr_ipc_client, out_bytes);898 int vfs_op_write(int fd, aoff64_t pos, size_t *out_bytes) 899 { 900 return vfs_rdwr(fd, pos, false, rdwr_ipc_client, out_bytes); 958 901 } 959 902
Note:
See TracChangeset
for help on using the changeset viewer.