From 08dcb612aaa24237db3165f4c67c166de1ad4725 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Mon, 9 Jun 2025 15:49:52 -0400 Subject: [PATCH] misc: teach fuse2fs the inusefile command-line option The inusefile option is useful for scripts that want to know when fuse2fs is done modifying the file system after it is unmounted. Signed-off-by: Theodore Ts'o --- misc/fuse2fs.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c index ad4795a..bc49edf 100644 --- a/misc/fuse2fs.c +++ b/misc/fuse2fs.c @@ -212,6 +212,7 @@ struct fuse2fs { unsigned long offset; unsigned int next_generation; unsigned long long cache_size; + char *inusefile; }; #define FUSE2FS_CHECK_MAGIC(fs, ptr, num) do {if ((ptr)->magic != (num)) \ @@ -4231,6 +4232,7 @@ static struct fuse_opt fuse2fs_opts[] = { FUSE_OPT_KEY("noblock_validity", FUSE2FS_IGNORED), FUSE_OPT_KEY("nodelalloc", FUSE2FS_IGNORED), FUSE_OPT_KEY("cache_size=%s", FUSE2FS_CACHE_SIZE), + FUSE2FS_OPT("inusefile=%s", inusefile, 0), FUSE_OPT_KEY("-V", FUSE2FS_VERSION), FUSE_OPT_KEY("--version", FUSE2FS_VERSION), @@ -4283,6 +4285,7 @@ static int fuse2fs_opt_proc(void *data, const char *arg, " -o offset= similar to mount -o offset=, mount the partition starting at \n" " -o norecovery don't replay the journal\n" " -o fuse2fs_debug enable fuse2fs debugging\n" + " -o inusefile= file to show that fuse is still using the file system image\n" " -o kernel run this as if it were the kernel, which sets:\n" " allow_others,default_permissions,suid,dev\n" " -o directio use O_DIRECT to read and write the disk\n" @@ -4411,6 +4414,24 @@ int main(int argc, char *argv[]) fctx.alloc_all_blocks = 1; } + if(fctx.inusefile) { + FILE* inusefile=fopen(fctx.inusefile, "w"); + if(!inusefile) { + fprintf(stderr, "Requested inusefile=%s but couldn't open the file for writing\n", fctx.inusefile); + exit(1); + } + fclose(inusefile); + char* resolved = realpath(fctx.inusefile, NULL); + if (!resolved) { + perror("realpath"); + fprintf(stderr, "Could not resolve realpath for inusefile=%s\n", fctx.inusefile); + unlink(fctx.inusefile); + exit(1); + } + free(fctx.inusefile); + fctx.inusefile = resolved; + } + /* Start up the fs (while we still can use stdout) */ ret = 2; char options[50]; @@ -4615,6 +4636,14 @@ out: com_err(argv[0], err, "while closing fs"); global_fs = NULL; } + if(fctx.inusefile) { + err = unlink(fctx.inusefile); + if (err) + com_err(argv[0], errno, "while unlinking '%s'", + fctx.inusefile); + } + if (fctx.inusefile) + free(fctx.inusefile); if (fctx.device) free(fctx.device); fuse_opt_free_args(&args); -- 1.8.3.1