From: Pavel Charvat Date: Tue, 29 May 2007 09:52:31 +0000 (+0200) Subject: - renamed fbpar_* functions X-Git-Tag: holmes-import~506^2~13^2~120 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=14bfa6253d2ae653cb92c244ed490295437518ed;p=libucw.git - renamed fbpar_* functions - added lookup table for I/O types --- diff --git a/lib/fastbuf.h b/lib/fastbuf.h index e7d441b5..8d7a164e 100644 --- a/lib/fastbuf.h +++ b/lib/fastbuf.h @@ -104,19 +104,25 @@ struct fastbuf *fbdir_open_tmp(struct asio_queue *io_queue); /* FastIO on files with run-time parametrization */ +enum fb_type { + FB_STD, + FB_DIRECT, + FB_MMAP +}; + struct fb_params { - // FIXME - uns odirect; + enum fb_type type; uns buffer_size; }; struct cf_section; extern struct cf_section fbpar_cf; +extern struct fb_params fbpar_defaults; -struct fastbuf *fbpar_open(byte *name, int mode, struct fb_params *params); -struct fastbuf *fbpar_open_try(byte *name, int mode, struct fb_params *params); -struct fastbuf *fbpar_open_fd(int fd, struct fb_params *params); -struct fastbuf *fbpar_open_tmp(struct fb_params *params); +struct fastbuf *bopen_file(byte *name, int mode, struct fb_params *params); +struct fastbuf *bopen_file_try(byte *name, int mode, struct fb_params *params); +struct fastbuf *bopen_tmp_file(struct fb_params *params); +struct fastbuf *bopen_fd(int fd, struct fb_params *params); /* FastI on file descriptors with limit */ diff --git a/lib/fb-param.c b/lib/fb-param.c index 56f9b3f9..6fc5f27a 100644 --- a/lib/fb-param.c +++ b/lib/fb-param.c @@ -11,7 +11,7 @@ #include "lib/conf.h" #include "lib/fastbuf.h" -static struct fb_params fbpar_defaults = { +struct fb_params fbpar_defaults = { .buffer_size = 65536, }; @@ -20,7 +20,7 @@ struct cf_section fbpar_cf = { CF_TYPE(struct fb_params), CF_ITEMS { // FIXME - CF_UNS("DirectIO", F(odirect)), + CF_LOOKUP("Type", (int *)F(type), ((byte *[]){"std", "direct", "mmap", NULL})), CF_UNS("BufSize", F(buffer_size)), CF_END } @@ -41,41 +41,61 @@ fbpar_global_init(void) } struct fastbuf * -fbpar_open(byte *name, int mode, struct fb_params *params) +bopen_file(byte *name, int mode, struct fb_params *params) { params = params ? : &fbpar_defaults; - if (!params->odirect) - return bopen(name, mode, params->buffer_size); - else - return fbdir_open(name, mode, NULL); + switch (params->type) + { + case FB_STD: + return bopen(name, mode, params->buffer_size); + case FB_DIRECT: + return fbdir_open(name, mode, NULL); + default: + ASSERT(0); + } } struct fastbuf * -fbpar_open_try(byte *name, int mode, struct fb_params *params) +bopen_file_try(byte *name, int mode, struct fb_params *params) { params = params ? : &fbpar_defaults; - if (!params->odirect) - return bopen_try(name, mode, params->buffer_size); - else - return fbdir_open_try(name, mode, NULL); + switch (params->type) + { + case FB_STD: + return bopen_try(name, mode, params->buffer_size); + case FB_DIRECT: + return fbdir_open_try(name, mode, NULL); + default: + ASSERT(0); + } } struct fastbuf * -fbpar_open_fd(int fd, struct fb_params *params) +bopen_fd(int fd, struct fb_params *params) { params = params ? : &fbpar_defaults; - if (!params->odirect) - return bfdopen(fd, params->buffer_size); - else - return fbdir_open_fd(fd, NULL); + switch (params->type) + { + case FB_STD: + return bfdopen(fd, params->buffer_size); + case FB_DIRECT: + return fbdir_open_fd(fd, NULL); + default: + ASSERT(0); + } } struct fastbuf * -fbpar_open_tmp(struct fb_params *params) +bopen_tmp_file(struct fb_params *params) { params = params ? : &fbpar_defaults; - if (!params->odirect) - return bopen_tmp(params->buffer_size); - else - return fbdir_open_tmp(NULL); + switch (params->type) + { + case FB_STD: + return bopen_tmp(params->buffer_size); + case FB_DIRECT: + return fbdir_open_tmp(NULL); + default: + ASSERT(0); + } }