--- tme/host/posix/posix-disk.c 2018/04/24 16:39:15 1.1 +++ tme/host/posix/posix-disk.c 2018/04/24 16:40:38 1.1.1.2 @@ -1,4 +1,4 @@ -/* $Id: posix-disk.c,v 1.1 2018/04/24 16:39:15 root Exp $ */ +/* $Id: posix-disk.c,v 1.1.1.2 2018/04/24 16:40:38 root Exp $ */ /* host/posix/posix-disk.c - implementation of disks on a POSIX system: */ @@ -34,7 +34,7 @@ */ #include -_TME_RCSID("$Id: posix-disk.c,v 1.1 2018/04/24 16:39:15 root Exp $"); +_TME_RCSID("$Id: posix-disk.c,v 1.1.1.2 2018/04/24 16:40:38 root Exp $"); /* includes: */ #include @@ -679,6 +679,9 @@ TME_ELEMENT_SUB_NEW_DECL(tme_host_posix, int buffers; struct stat statbuf; tme_uint8_t *block; +#ifdef HAVE_MMAP + int page_size; +#endif /* HAVE_MMAP */ struct tme_posix_disk *posix_disk; struct tme_posix_disk_buffer *buffer, **_prev; int arg_i; @@ -799,9 +802,11 @@ TME_ELEMENT_SUB_NEW_DECL(tme_host_posix, } /* if this is a character device, determine its block size: */ - statbuf.st_blksize = 1; if (S_ISCHR(statbuf.st_mode)) { + /* the block size must be at least one: */ + statbuf.st_blksize = TME_MAX(statbuf.st_blksize, 1); + /* allocate space for the block: */ block = tme_new(tme_uint8_t, statbuf.st_blksize); @@ -842,6 +847,14 @@ TME_ELEMENT_SUB_NEW_DECL(tme_host_posix, } } +#ifdef HAVE_MMAP + /* if we're mmapping, the block size must be at least the page size: */ + for (page_size = getpagesize(); + page_size < statbuf.st_blksize; + page_size <<= 1); + statbuf.st_blksize = page_size; +#endif /* HAVE_MMAP */ + /* start the disk structure: */ posix_disk = tme_new0(struct tme_posix_disk, 1); posix_disk->tme_posix_disk_element = element;