Serving a directory, char device, fifo, socket, or other unusual file type is likely to cause unusual problems down the road when trying to use .pread; let's move the failure sooner to .open. Signed-off-by: Eric Blake <eblake@redhat.com> --- plugins/file/file.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/plugins/file/file.c b/plugins/file/file.c index dc99f992..e049864a 100644 --- a/plugins/file/file.c +++ b/plugins/file/file.c @@ -189,7 +189,16 @@ file_open (int readonly) return NULL; } - h->is_block_device = S_ISBLK (statbuf.st_mode); + if (S_ISBLK (statbuf.st_mode)) + h->is_block_device = true; + else if (S_ISREG (statbuf.st_mode)) + h->is_block_device = false; + else { + nbdkit_error ("file is not regular or block device: %s", filename); + close (h->fd); + free (h); + return NULL; + } h->sector_size = 4096; /* Start with safe guess */ #ifdef BLKSSZGET -- 2.28.0