Skip to content

Ftruncate failed when the original file size = 0 and the extended part is not continuous clusters. #66

Open
@Erichorng

Description

@Erichorng

I built the exfat module with the latest code on mainline.
I encountered a bug during the bellow experiment:

steps to reproduce:

  1. create 4G exfat filesystem.
  2. create a file and truncate to 3G.
  3. delete the file.
  4. repeat step 2 again.
  5. receive EIO, ftruncate failed.

Here is the script I used for testing:

#include <iostream>
#include <fcntl.h>
#include <unistd.h>

int main() {
    const char* filename = "example_file";
    off_t file_size = 3LL * 1024 * 1024 * 1024;

    // Open the file or create it if it doesn't exist
    int fd = open(filename, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
    if (fd == -1) {
        std::cerr << "Error opening/creating the file" << std::endl;
        return 1;
    }

    // Set the file size using ftruncate
    if (ftruncate(fd, file_size) == -1) {
        std::cerr << "Error setting file size using ftruncate" << std::endl;
        close(fd);
        return 1;
    }

    // Cleanup
    close(fd);

    return 0;
}

and this is a patch I wrote to fix the bug:
0001-fix-bug-ftruncate-failed.patch
Please help check if this modification is correct and necessary

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions