DF-3181 / holder.c
/* * DF-3181 helper — holds an open fd on an unlinked tmpfs file and reports * fstat(fd).st_size every second, so we can watch tmpfs_unmount's * pre-vflush truncation destroy the data of a file whose vnode keeps * vflush() busy (EBUSY) and the mount alive. */ #include <sys/stat.h> #include <err.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> int main(int argc, char **argv) { struct stat st; char path[1024]; int fd; int i; if (argc < 2) errx(1, "usage: %s <file-to-open-and-unlink>", argv[0]); snprintf(path, sizeof(path), "%s", argv[1]); fd = open(path, O_RDONLY); if (fd < 0) err(1, "open"); if (unlink(path) < 0) err(1, "unlink"); if (fstat(fd, &st) < 0) err(1, "fstat"); printf("holder: opened+unlinked, initial st_size=%lld\n", (long long)st.st_size); fflush(stdout); for (i = 0; i < 60; i++) { sleep(1); if (fstat(fd, &st) < 0) err(1, "fstat"); printf("holder: t+%d st_size=%lld\n", i + 1, (long long)st.st_size); fflush(stdout); } return 0; } |