[Bug 270632] [ext2fs] files <4096 bytes are corrupted on ext4 filesystems
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sun, 09 Apr 2023 03:09:14 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=270632 --- Comment #8 from Rajeev Pillai <rajeev_v_pillai@yahoo.com> --- (In reply to Alexey Dokuchaev from comment #7) > Until then, the real bug could be just masked out by other things or e.g. extra > debugging turned on in -CURRENT by default. > Good point. I've cooked up an even simpler test program to help things along. When the program prompts, you can either flip to another terminal and check the file, or Ctrl-C it and unmount/remount before examining the file. ``` #include <err.h> #include <fcntl.h> #include <stdio.h> #include <stdbool.h> #include <string.h> #include <unistd.h> static bool prompt(char* msg) { char line[64] = ""; printf("%s", msg); fflush(stdout); fgets(line, sizeof line, stdin); return (line[0] == 'Y' || line[0] == 'y'); } int main(int argc, char* argv[]) { const char* const S = "hello world\n"; char* fn; size_t n; int fd; if (argc != 2) errx(1, "filename required"); fn = argv[1]; if ((fd = open(fn, O_WRONLY|O_CREAT, 0666)) == -1) err(1, "%s: open failed", fn); n = strlen(S); if (write(fd, S, n) != n) err(1, "%s: write failed", fn); if (close(fd) == -1) err(1, "%s: close failed", fn); prompt("Created file. Enter to continue: "); if ((fd = open(fn, O_WRONLY|O_TRUNC, 0666)) == -1) err(1, "%s: open failed", fn); prompt("Truncated file. Enter to continue: "); if (write(fd, S, n) != n) err(1, "%s: write failed", fn); if (prompt("Re-wrote file. fsync (y/n)? ")) if (fsync(fd)) err(1, "fsync failed"); if (close(fd) == -1) err(1, "%s: close failed", fn); prompt("Done. Enter to exit: "); return 0; } ``` Things to note: * The file is initially created and written OK. * The truncation operation succeeds--new file size is 0 after an unmount/remount. * Doing an fsync() doesn't help. * The _second_ write op. fails. The file-size is updated correctly, but, the contents are all NULs. HTH -- You are receiving this mail because: You are the assignee for the bug.