| From 32eda340b89e49f00e4fcec01c642fc4fdd25c91 Mon Sep 17 00:00:00 2001 |
| From: =?UTF-8?q?Fran=C3=A7ois=20Degros?= <fdegros@chromium.org> |
| Date: Wed, 2 Nov 2022 14:21:04 +1100 |
| Subject: [PATCH] Accept open file descriptor as /dev/fd/nnnn |
| |
| --- |
| libntfs-3g/unix_io.c | 11 ++++++++++- |
| 1 file changed, 10 insertions(+), 1 deletion(-) |
| |
| diff --git a/libntfs-3g/unix_io.c b/libntfs-3g/unix_io.c |
| index 5495a6a4..c7bd4b5f 100644 |
| --- a/libntfs-3g/unix_io.c |
| +++ b/libntfs-3g/unix_io.c |
| @@ -140,7 +140,16 @@ static int ntfs_device_unix_io_open(struct ntfs_device *dev, int flags) |
| */ |
| 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; |
| /* if permission error and rw, retry read-only */ |
| -- |
| 2.38.1.273.g43a17bfeac-goog |
| |