1 /* $NetBSD: mount_v7fs.c,v 1.2 2025/12/24 15:10:09 nia Exp $ */ 2 3 /*- 4 * Copyright (c) 2011 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by UCHIYAMA Yasushi. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 /*- 32 * Copyright (c) 1993, 1994 33 * The Regents of the University of California. All rights reserved. 34 * 35 * Redistribution and use in source and binary forms, with or without 36 * modification, are permitted provided that the following conditions 37 * are met: 38 * 1. Redistributions of source code must retain the above copyright 39 * notice, this list of conditions and the following disclaimer. 40 * 2. Redistributions in binary form must reproduce the above copyright 41 * notice, this list of conditions and the following disclaimer in the 42 * documentation and/or other materials provided with the distribution. 43 * 3. Neither the name of the University nor the names of its contributors 44 * may be used to endorse or promote products derived from this software 45 * without specific prior written permission. 46 * 47 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 48 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 49 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 50 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 51 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 52 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 53 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 54 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 55 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 56 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 57 * SUCH DAMAGE. 58 */ 59 60 #include <sys/cdefs.h> 61 #ifndef lint 62 __RCSID("$NetBSD: mount_v7fs.c,v 1.2 2025/12/24 15:10:09 nia Exp $"); 63 #endif /* not lint */ 64 65 #include <sys/param.h> 66 #include <sys/mount.h> 67 68 #include <err.h> 69 #include <errno.h> 70 #include <endian.h> 71 #include <stdio.h> 72 #include <stdlib.h> 73 74 #include <string.h> 75 #include <unistd.h> 76 77 #include <mntopts.h> 78 79 #include "mountprog.h" 80 #include "mount_v7fs.h" 81 82 static const struct mntopt mopts[] = { 83 MOPT_STDOPTS, 84 MOPT_UPDATE, 85 MOPT_GETARGS, 86 MOPT_NULL, 87 }; 88 89 static void v7fs_usage(void) __dead; 90 91 #ifndef MOUNT_NOMAIN 92 int 93 main(int argc, char **argv) 94 { 95 96 return mount_v7fs(argc, argv); 97 } 98 #endif 99 100 int 101 mount_v7fs(int argc, char *argv[]) 102 { 103 struct v7fs_args args; 104 char canon_dev[MAXPATHLEN], canon_dir[MAXPATHLEN]; 105 const char *errcause; 106 int mntflags; 107 108 mount_v7fs_parseargs(argc, argv, &args, &mntflags, 109 canon_dev, canon_dir); 110 111 if (mount(MOUNT_V7FS, canon_dir, mntflags, &args, sizeof args) == -1) { 112 switch (errno) { 113 case EMFILE: 114 errcause = "mount table full"; 115 break; 116 case EINVAL: 117 if (mntflags & MNT_UPDATE) 118 errcause = 119 "specified device does not match mounted device"; 120 else 121 errcause = "incorrect super block"; 122 break; 123 default: 124 errcause = strerror(errno); 125 break; 126 } 127 errx(EXIT_FAILURE, "%s on %s: %s", canon_dev, canon_dir, 128 errcause); 129 } 130 131 if (mntflags & MNT_GETARGS) { 132 printf("endian=%d\n", args.endian); 133 } 134 135 return EXIT_SUCCESS; 136 } 137 138 void 139 mount_v7fs_parseargs(int argc, char **argv, struct v7fs_args *args, 140 int *mntflags, char *canon_dev, char *canon_dir) 141 { 142 int ch; 143 mntoptparse_t mp; 144 int endian = BYTE_ORDER; 145 *mntflags = 0; 146 optind = optreset = 1; /* Reset for parse of new argv. */ 147 while ((ch = getopt(argc, argv, "o:B:")) != -1) 148 switch (ch) { 149 case 'o': 150 mp = getmntopts(optarg, mopts, mntflags, 0); 151 if (mp == NULL) 152 err(1, "getmntopts"); 153 freemntopts(mp); 154 break; 155 case 'B': 156 switch (optarg[0]) { 157 case 'l': 158 endian = LITTLE_ENDIAN; 159 break; 160 case 'b': 161 endian = BIG_ENDIAN; 162 break; 163 case 'p': 164 endian = PDP_ENDIAN; 165 break; 166 } 167 break; 168 case '?': 169 170 default: 171 v7fs_usage(); 172 } 173 argc -= optind; 174 argv += optind; 175 176 if (argc != 2) 177 v7fs_usage(); 178 179 pathadj(argv[0], canon_dev); 180 args->endian = endian; 181 args->fspec = canon_dev; 182 pathadj(argv[1], canon_dir); 183 } 184 185 static void 186 v7fs_usage(void) 187 { 188 189 fprintf(stderr, "usage: \n %s [-o options] [-B endian] special node\n", 190 getprogname()); 191 exit(EXIT_FAILURE); 192 } 193