blob: 47ba8081523d855134d70fd52b8b3c8961b808a7 [file] [log] [blame]
diff --git a/libntfs-3g/unix_io.c b/libntfs-3g/unix_io.c
index 64b41d3..5a29528 100644
--- a/libntfs-3g/unix_io.c
+++ b/libntfs-3g/unix_io.c
@@ -135,9 +135,19 @@ static int ntfs_device_unix_io_open(struct ntfs_device *dev, int flags)
* Open file for exclusive access if mounting r/w.
* Fuseblk takes care about block devices.
*/
+
if (!NDevBlock(dev) && (flags & O_RDWR) == O_RDWR)
flags |= O_EXCL;
- *(int*)dev->d_private = open(dev->d_name, flags);
+ /* skip calling open() if fd path is provided */
+ int fd = -1;
+ int len = 0;
+ if (sscanf(dev->d_name, "/dev/fd/%u%n", &fd, &len) == 1 && len == strlen(dev->d_name)) {
+ printf("skipping open and using provided fd: %d\n", fd);
+ *(int*)dev->d_private = fd;
+ }
+ else {
+ *(int*)dev->d_private = open(dev->d_name, flags);
+ }
if (*(int*)dev->d_private == -1) {
err = errno;
goto err_out;