src/server/daemon/vfs.c

branch
aio
changeset 172
5580517faafc
parent 165
6942a8c3e737
child 185
b4d7ccf4e06d
equal deleted inserted replaced
170:711d00eeed25 172:5580517faafc
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;
56 58
57 static VFS_IO sys_file_io = { 59 static VFS_IO sys_file_io = {
58 sys_file_read, 60 sys_file_read,
59 sys_file_write, 61 sys_file_write,
60 sys_file_seek, 62 sys_file_seek,
61 sys_file_close 63 sys_file_close,
64 sys_file_aioread,
65 sys_file_aiowrite
62 }; 66 };
63 67
64 static VFS_DIRIO sys_dir_io = { 68 static VFS_DIRIO sys_dir_io = {
65 sys_dir_read, 69 sys_dir_read,
66 sys_dir_close 70 sys_dir_close
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 }

mercurial