/**************************************************************/ /* tpax: a topological pax implementation */ /* Copyright (C) 2020--2024 SysDeer Technologies, LLC */ /* Released under GPLv2 and GPLv3; see COPYING.TPAX. */ /**************************************************************/ #include #include #include #include #include #include #include "tpax_driver_impl.h" #include "tpax_errinfo_impl.h" #define TPAX_IO_READ_MAX (2147483647) static int tpax_io_range_read_ahead_fileio( struct tpax_driver_ctx * dctx, void * buf, size_t size) { int fdin; ssize_t nbytes; off_t cpos; fdin = tpax_driver_fdin(dctx); cpos = tpax_get_driver_cpos(dctx); nbytes = pread(fdin,buf,size,cpos); while ((nbytes < 0) && (errno = EINTR)) nbytes = pread(fdin,buf,size,cpos); return nbytes; } static int tpax_io_range_read_ahead_mapped( struct tpax_driver_ctx * dctx, void * buf, size_t size) { struct tpax_driver_ctx_impl * ictx; char * ch; off_t cpos; ictx = tpax_get_driver_ictx(dctx); cpos = tpax_get_driver_cpos(dctx); size = (cpos + size <= ictx->mapsize) ? size : ictx->mapsize - cpos; ch = ictx->mapaddr; ch = &ch[cpos]; memcpy(buf,ch,size); return size; } int tpax_io_range_read_ahead(struct tpax_driver_ctx * dctx, void * buf, size_t size) { size = (size <= TPAX_IO_READ_MAX) ? size : TPAX_IO_READ_MAX; if (dctx->cctx->srcflags & TPAX_SOURCE_DATA_FILEIO) { return tpax_io_range_read_ahead_fileio(dctx,buf,size); } else if (dctx->cctx->srcflags & TPAX_SOURCE_DATA_MAPPED) { return tpax_io_range_read_ahead_mapped(dctx,buf,size); } return TPAX_CUSTOM_ERROR( dctx, TPAX_ERR_FLOW_ERROR); }