1 /* $NetBSD: v25.c,v 1.1 2022/01/22 08:09:40 pho Exp $ */ 2 3 /* 4 * Copyright (c) 2021 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. The name of the author may not be used to endorse or promote 16 * products derived from this software without specific prior written 17 * permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 20 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 25 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #include <sys/cdefs.h> 33 #if !defined(lint) 34 __RCSID("$NetBSD: v25.c,v 1.1 2022/01/22 08:09:40 pho Exp $"); 35 #endif /* !lint */ 36 37 #include <err.h> 38 #include <fuse_internal.h> 39 #include <stdbool.h> 40 #include <string.h> 41 42 int 43 fuse_mount_v25(const char *mountpoint, struct fuse_args *args) { 44 struct fuse_chan* chan; 45 46 /* Of course we cannot accurately emulate the semantics, so we 47 * save arguments and use them later in fuse_new(). */ 48 chan = fuse_chan_new(mountpoint, args); 49 if (!chan) 50 return -1; 51 52 /* But, the return type of this function is just an int which is 53 * supposed to be a file descriptor. It's too narrow to store a 54 * pointer ofc, so... */ 55 return fuse_chan_stash(chan); 56 } 57 58 int 59 fuse_parse_cmdline_v25(struct fuse_args *args, char **mountpoint, 60 int *multithreaded, int *foreground) { 61 struct fuse_cmdline_opts opts; 62 63 if (fuse_parse_cmdline_v30(args, &opts) != 0) 64 return -1; 65 66 *mountpoint = opts.mountpoint; /* Transfer the ownership of the string. */ 67 *multithreaded = !opts.singlethread; 68 *foreground = opts.foreground; 69 return 0; 70 } 71 72 /* The interface of fuse_mount() and fuse_new() became even stranger 73 * in FUSE 2.5. Now they both take "struct fuse_args" which are 74 * expected to be identical between those two calls (which isn't 75 * explained clearly in the documentation). Our implementation just 76 * assume they are identical, because we can't recover from situations 77 * where they differ, as there is no obvious way to merge them 78 * together. */ 79 struct fuse * 80 fuse_new_v25(int fd, struct fuse_args *args, const void *op, 81 int op_version, void *user_data) { 82 struct fuse_chan* chan; 83 struct fuse_args* mount_args; 84 bool args_differ = false; 85 86 /* But at least we can emit a warning when they differ... */ 87 chan = fuse_chan_peek(fd); 88 if (!chan) { 89 warnx("%s: invalid channel: %d", __func__, fd); 90 return NULL; 91 } 92 93 mount_args = fuse_chan_args(chan); 94 95 if (mount_args->argc != args->argc) { 96 args_differ = true; 97 } 98 else { 99 int i; 100 101 for (i = 0; i < args->argc; i++) { 102 if (strcmp(mount_args->argv[i], args->argv[i]) != 0) { 103 args_differ = true; 104 break; 105 } 106 } 107 } 108 109 if (args_differ) { 110 warnx("%s: the argument vector differs from " 111 "that were passed to fuse_mount()", __func__); 112 } 113 114 return fuse_new_v21(fd, NULL, op, op_version, user_data); 115 } 116