Skip to contentSkip to conversation

Missing O_DIRECT Support Causes Errors in Python and Affects Applications

exFAT In review Noah 4 participants 5 messages Feb 3, 2025 – Feb 12, 2025 3 messages not in the archive

Subsystems (2)
lore
Share & tools
lore

Noah

author
#3 lore raw
In reply to a message not in the archive

    Hello,

    I’ve encountered an issue with the exFAT driver when attempting to create an empty file, resulting in the following error:

    OSError: [Errno 14] Bad address

    Reproduction Steps:

    mkdir /tmp/exfat
    cd /tmp/exfat
    fallocate -l 512M exfat.img
    mkfs.exfat exfat.img
    sudo mkdir -p /fatimagedir/
    sudo mount -o umask=0022,gid=$(id -g),uid=$(id -u) /tmp/exfat/exfat.img /fatimagedir/ cd /fatimagedir
    python3 -c 'open("foo", "wb", buffering=0).write(b"")'

    Observations:

        With the kernel exFAT driver:
            Produces OSError: [Errno 14] Bad address on Linux 6.12.10. Despite the error, the file is created.
            As noted by Artem S. Tashkinov:

                "While this code produces an error under Linux 6.12.10, it still works as intended - the file is created."

        With exFAT-FUSE:
            Works as expected without errors:

        sudo losetup -f exfat.img
        sudo fuse/mount.exfat-fuse -o loop,umask=0022,gid=$(id -g),uid=$(id -u) /dev/loop0 /fatimagedir/ cd /fatimagedir
        python3 -c 'open("foo", "wb", buffering=0).write(b"")'
        ls
        foo

    Impact:

        Affects Python's file handling and popular applications like VSCodium and Zed, which rely on unbuffered I/O. Likely related to the lack of O_DIRECT support in the kernel exFAT driver.

    References:

        https://bugzilla.kernel.org/show_bug.cgi?id=219746
        https://bbs.archlinux.org/viewtopic.php?id=294837
        https://github.com/zed-industries/zed/issues/21595

    Is the lack of O_DIRECT support intentional, or would this be considered for future implementation?

    Best regards,
    Max Grass

#4 lore raw
In reply to a message not in the archive

Hi,

Thanks for reporting this issue, I will check it.

Best Regards,
Yuezhang Mo

Quoted 1 line

-----Original Message-----

Subject: [exFAT] Missing O_DIRECT Support Causes Errors in Python and Affects Applications

Quoted 62 lines

From: Noah <[email protected]>
Sent: Tuesday, February 4, 2025 3:04 AM
To: linux-fsdevel <[email protected]>
Cc: sj1557seo <[email protected]>; Mo, Yuezhang <[email protected]>
Subject: RE: [exFAT] Missing O_DIRECT Support Causes Errors in Python and Affects Applications

Hello,
I’ve encountered an issue with the exFAT driver when attempting to create an empty file, resulting in the following error:
OSError: [Errno 14] Bad address

Reproduction Steps:
mkdir /tmp/exfat
cd /tmp/exfat
fallocate -l 512M exfat.img
mkfs.exfat exfat.img
sudo mkdir -p /fatimagedir/
sudo mount -o umask=0022,gid=$(id -g),uid=$(id -u) /tmp/exfat/exfat.img /fatimagedir/
cd /fatimagedir
python3 -c 'open("foo", "wb", buffering=0).write(b"")'

Observations:
1. With the kernel exFAT driver:
o Produces OSError: [Errno 14] Bad address on Linux 6.12.10.
o Despite the error, the file is created.
o As noted by Artem S. Tashkinov:
"While this code produces an error under Linux 6.12.10, it still works as intended - the file is created."
2. With exFAT-FUSE:
o Works as expected without errors:
3. sudo losetup -f exfat.img
4. sudo fuse/mount.exfat-fuse -o loop,umask=0022,gid=$(id -g),uid=$(id -u) /dev/loop0 /fatimagedir/
5. cd /fatimagedir
6. python3 -c 'open("foo", "wb", buffering=0).write(b"")'
7. ls
8. foo

Impact:
• Affects Python's file handling and popular applications like VSCodium and Zed, which rely on unbuffered I/O.
• Likely related to the lack of O_DIRECT support in the kernel exFAT driver. References:
•
https://urldefense.com/v3/__https://bugzilla.kernel.org/show_bug.cgi?id=219
746__;!!O7_YSHcmd9jp3hj_4dEAcyQ!26DSdhkSOyCin--7nq_pt2Bx4clOcZLGhN qHzpfYvg2X53YdxKXARlbJiw9JWpkiBE9d8MUbZ0lYRrYMV1a2Q99Dait6$
•
https://urldefense.com/v3/__https://bbs.archlinux.org/viewtopic.php?id=2948
37__;!!O7_YSHcmd9jp3hj_4dEAcyQ!26DSdhkSOyCin--7nq_pt2Bx4clOcZLGhNq HzpfYvg2X53YdxKXARlbJiw9JWpkiBE9d8MUbZ0lYRrYMV1a2Q3RhXp3D$
•
https://urldefense.com/v3/__https://github.com/zed-industries/zed/issues/21
595__;!!O7_YSHcmd9jp3hj_4dEAcyQ!26DSdhkSOyCin--7nq_pt2Bx4clOcZLGhN qHzpfYvg2X53YdxKXARlbJiw9JWpkiBE9d8MUbZ0lYRrYMV1a2Q6-685n9$
Is the lack of O_DIRECT support intentional, or would this be considered for future implementation?
Best regards,
Max Grass

#5 lore raw

PATCH 1/1 exfat: short-circuit zero-byte writes in exfat_file_write_iter

When generic_write_checks() returns zero, it means that iov_iter_count() is zero, and there is no work to do.

Simply return success like all other filesystems do, rather than proceeding down the write path, which today yields an -EFAULT in generic_perform_write() via the (fault_in_iov_iter_readable(i, bytes) == bytes) check when bytes == 0.

---

fs/exfat/file.c +1 -1
index 05b51e721783..807349d8ea05 100644
@@ -587,7 +587,7 @@ static ssize_t exfat_file_write_iter(struct kiocb *iocb, struct iov_iter *iter)
 	valid_size = ei->valid_size;
 
 	ret = generic_write_checks(iocb, iter);
-	if (ret < 0)
+	if (ret <= 0)
 		goto unlock;
 
 	if (iocb->ki_flags & IOCB_DIRECT) {
#6 lore raw

RE: [PATCH] exfat: short-circuit zero-byte writes in exfat_file_write_iter

Please add the "Fixes" tag.

Fixes 11a347fb6cef ("exfat: change to get file size from DataLength")
maintainer
#7 lore raw

Re: [PATCH] exfat: short-circuit zero-byte writes in exfat_file_write_iter

Quoted 4 lines · On Wed, Feb 12, 2025 at 3:37 PM [email protected] <[email protected]>…

Please add the "Fixes" tag.

Fixes 11a347fb6cef ("exfat: change to get file size from DataLength")

I have directly added and applied it to #dev.
Thanks!