30 |
30 |
31 #include <stdio.h> |
31 #include <stdio.h> |
32 #include <stdlib.h> |
32 #include <stdlib.h> |
33 #include <unistd.h> |
33 #include <unistd.h> |
34 #include <sys/types.h> |
34 #include <sys/types.h> |
|
35 #include <aio.h> |
35 |
36 |
36 #include <ucx/map.h> |
37 #include <ucx/map.h> |
37 |
38 |
38 #include "../util/pool.h" |
39 #include "../util/pool.h" |
39 #include "acl.h" |
40 #include "acl.h" |
40 #include "vfs.h" |
41 #include "vfs.h" |
|
42 #include "event.h" |
41 |
43 |
42 #define VFS_MALLOC(pool, size) pool ? pool_malloc(pool, size) : malloc(size) |
44 #define VFS_MALLOC(pool, size) pool ? pool_malloc(pool, size) : malloc(size) |
43 #define VFS_FREE(pool, ptr) pool ? pool_free(pool, ptr) : free(ptr) |
45 #define VFS_FREE(pool, ptr) pool ? pool_free(pool, ptr) : free(ptr) |
44 |
46 |
45 static UcxMap *vfs_map; |
47 static UcxMap *vfs_map; |
494 } |
498 } |
495 |
499 |
496 void sys_file_close(SYS_FILE fd) { |
500 void sys_file_close(SYS_FILE fd) { |
497 close(fd->fd); |
501 close(fd->fd); |
498 } |
502 } |
|
503 |
|
504 int sys_file_aioread(aiocb_s *aiocb) { |
|
505 WS_ASSERT(aiocb->buf); |
|
506 WS_ASSERT(aiocb->nbytes > 0); |
|
507 return ev_aioread(aiocb->filedes->fd, aiocb); |
|
508 } |
|
509 |
|
510 int sys_file_aiowrite(aiocb_s *aiocb) { |
|
511 WS_ASSERT(aiocb->buf); |
|
512 WS_ASSERT(aiocb->nbytes > 0); |
|
513 return ev_aiowrite(aiocb->filedes->fd, aiocb); |
|
514 } |
|
515 |
499 |
516 |
500 int sys_dir_read(VFS_DIR dir, VFS_ENTRY *entry, int getstat) { |
517 int sys_dir_read(VFS_DIR dir, VFS_ENTRY *entry, int getstat) { |
501 SysVFSDir *dirdata = dir->data; |
518 SysVFSDir *dirdata = dir->data; |
502 struct dirent *result = NULL; |
519 struct dirent *result = NULL; |
503 int s = readdir_r(dirdata->dir, dirdata->cur, &result); |
520 int s = readdir_r(dirdata->dir, dirdata->cur, &result); |
576 |
593 |
577 NSAPI_PUBLIC int system_fclose(SYS_FILE fd) { |
594 NSAPI_PUBLIC int system_fclose(SYS_FILE fd) { |
578 vfs_close(fd); |
595 vfs_close(fd); |
579 return 0; |
596 return 0; |
580 } |
597 } |
|
598 |
|
599 // AIO API |
|
600 |
|
601 NSAPI_PUBLIC int system_aio_read(aiocb_s *aiocb) { |
|
602 if(!aiocb->event || !aiocb->evhandler) { |
|
603 return -1; |
|
604 } |
|
605 |
|
606 SYS_FILE file = aiocb->filedes; |
|
607 aiocb->event->object = (intptr_t)aiocb; |
|
608 if(file->io->opt_aioread) { |
|
609 return file->io->opt_aioread(aiocb); |
|
610 } else { |
|
611 // TODO: implement |
|
612 return -1; |
|
613 } |
|
614 } |
|
615 |
|
616 NSAPI_PUBLIC int system_aio_write(aiocb_s *aiocb) { |
|
617 if(!aiocb->event || !aiocb->evhandler) { |
|
618 return -1; |
|
619 } |
|
620 |
|
621 SYS_FILE file = aiocb->filedes; |
|
622 aiocb->event->object = (intptr_t)aiocb; |
|
623 if(file->io->opt_aiowrite) { |
|
624 return file->io->opt_aiowrite(aiocb); |
|
625 } else { |
|
626 // TODO: implement |
|
627 return -1; |
|
628 } |
|
629 } |