From ad79372024fb7e2a94ea2db515d534143b53ae80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Pierre=20Andr=C3=A9?= Date: Fri, 1 Jun 2018 15:59:09 +0200 Subject: [PATCH] Checked whether the device to mount was forced read-only Force the read-only mount mode when the device was set so through a command "blockdev --setro". --- libntfs-3g/unix_io.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/libntfs-3g/unix_io.c b/libntfs-3g/unix_io.c index 64b41d3e..c88e8f82 100644 --- a/libntfs-3g/unix_io.c +++ b/libntfs-3g/unix_io.c @@ -53,6 +53,9 @@ #ifdef HAVE_LINUX_FD_H #include #endif +#ifdef HAVE_LINUX_FS_H +#include +#endif #include "types.h" #include "mst.h" @@ -142,6 +145,21 @@ static int ntfs_device_unix_io_open(struct ntfs_device *dev, int flags) err = errno; goto err_out; } +#ifdef HAVE_LINUX_FS_H + /* Check whether the device was forced read-only */ + if (NDevBlock(dev) && ((flags & O_RDWR) == O_RDWR)) { + int r; + int state; + + r = ioctl(DEV_FD(dev), BLKROGET, &state); + if (!r && state) { + err = EROFS; + if (close(DEV_FD(dev))) + err = errno; + goto err_out; + } + } +#endif if ((flags & O_RDWR) != O_RDWR) NDevSetReadOnly(dev);