Changeset 58898d1d in mainline for uspace/srv/vfs
- Timestamp:
- 2017-03-24T20:31:54Z (9 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8e9b2534
- Parents:
- c9e3692
- Location:
- uspace/srv/vfs
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/vfs/vfs.h
rc9e3692 r58898d1d 142 142 /** Append on write. */ 143 143 bool append; 144 145 /** Current absolute position in the file. */146 int64_t pos;147 144 } vfs_file_t; 148 145 … … 190 187 extern int64_t vfs_node_get_size(vfs_node_t *node); 191 188 extern bool vfs_node_has_children(vfs_node_t *node); 192 193 #define MAX_OPEN_FILES 128194 189 195 190 extern void *vfs_client_data_create(void); … … 216 211 extern int vfs_op_mtab_get(void); 217 212 extern int vfs_op_open2(int fd, int flags); 218 extern int vfs_op_read(int fd, size_t *out_bytes);213 extern int vfs_op_read(int fd, aoff64_t, size_t *out_bytes); 219 214 extern int vfs_op_rename(int basefd, char *old, char *new); 220 extern int vfs_op_seek(int fd, int64_t offset, int whence, int64_t *out_offset);221 215 extern int vfs_op_statfs(int fd); 222 216 extern int vfs_op_sync(int fd); … … 226 220 extern int vfs_op_wait_handle(bool high_fd); 227 221 extern int vfs_op_walk(int parentfd, int flags, char *path, int *out_fd); 228 extern int vfs_op_write(int fd, size_t *out_bytes);222 extern int vfs_op_write(int fd, aoff64_t, size_t *out_bytes); 229 223 230 224 extern void vfs_register(ipc_callid_t, ipc_call_t *); … … 237 231 } rdwr_io_chunk_t; 238 232 239 extern int vfs_rdwr_internal(int, bool, rdwr_io_chunk_t *);233 extern int vfs_rdwr_internal(int, aoff64_t, bool, rdwr_io_chunk_t *); 240 234 241 235 extern void vfs_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg); -
uspace/srv/vfs/vfs_file.c
rc9e3692 r58898d1d 45 45 #include <adt/list.h> 46 46 #include <task.h> 47 #include <vfs/vfs.h> 47 48 #include "vfs.h" 48 49 -
uspace/srv/vfs/vfs_ipc.c
rc9e3692 r58898d1d 122 122 { 123 123 int fd = IPC_GET_ARG1(*request); 124 aoff64_t pos = MERGE_LOUP32(IPC_GET_ARG2(*request), 125 IPC_GET_ARG3(*request)); 124 126 125 127 size_t bytes = 0; 126 int rc = vfs_op_read(fd, &bytes);128 int rc = vfs_op_read(fd, pos, &bytes); 127 129 async_answer_1(rid, rc, bytes); 128 130 } … … 170 172 if (new) 171 173 free(new); 172 }173 174 static void vfs_in_seek(ipc_callid_t rid, ipc_call_t *request)175 {176 int fd = (int) IPC_GET_ARG1(*request);177 int64_t off = (int64_t) MERGE_LOUP32(IPC_GET_ARG2(*request), IPC_GET_ARG3(*request));178 int whence = (int) IPC_GET_ARG4(*request);179 180 int64_t new_offset = 0;181 int rc = vfs_op_seek(fd, off, whence, &new_offset);182 async_answer_2(rid, rc, LOWER32(new_offset), UPPER32(new_offset));183 174 } 184 175 … … 256 247 { 257 248 int fd = IPC_GET_ARG1(*request); 249 aoff64_t pos = MERGE_LOUP32(IPC_GET_ARG2(*request), 250 IPC_GET_ARG3(*request)); 258 251 259 252 size_t bytes = 0; 260 int rc = vfs_op_write(fd, &bytes);253 int rc = vfs_op_write(fd, pos, &bytes); 261 254 async_answer_1(rid, rc, bytes); 262 255 } … … 308 301 vfs_in_rename(callid, &call); 309 302 break; 310 case VFS_IN_SEEK:311 vfs_in_seek(callid, &call);312 break;313 303 case VFS_IN_STATFS: 314 304 vfs_in_statfs(callid, &call); -
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 -
uspace/srv/vfs/vfs_pager.c
rc9e3692 r58898d1d 50 50 int rc; 51 51 52 vfs_file_t *file = vfs_file_get(fd);53 if (!file) {54 async_answer_0(rid, ENOENT);55 return;56 }57 58 52 page = as_area_create(AS_AREA_ANY, page_size, 59 53 AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE, … … 61 55 62 56 if (page == AS_MAP_FAILED) { 63 vfs_file_put(file);64 57 async_answer_0(rid, ENOMEM); 65 58 return; … … 71 64 }; 72 65 73 file->pos = offset;74 vfs_file_put(file);75 76 66 size_t total = 0; 67 aoff64_t pos = offset; 77 68 do { 78 rc = vfs_rdwr_internal(fd, true, &chunk);69 rc = vfs_rdwr_internal(fd, pos, true, &chunk); 79 70 if (rc != EOK) 80 71 break; … … 82 73 break; 83 74 total += chunk.size; 75 pos += chunk.size; 84 76 chunk.buffer += chunk.size; 85 77 chunk.size = page_size - total;
Note:
See TracChangeset
for help on using the changeset viewer.