1 /* $NetBSD: mount_chfs.c,v 1.2 2013/09/13 21:03:29 joerg Exp $ */ 2 3 /*- 4 * Copyright (c) 2010 Department of Software Engineering, 5 * University of Szeged, Hungary 6 * All rights reserved. 7 * 8 * This code is derived from software contributed to The NetBSD Foundation 9 * by the Department of Software Engineering, University of Szeged, Hungary 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 25 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 27 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 */ 32 33 #include <sys/cdefs.h> 34 #ifndef lint 35 #endif /* not lint */ 36 37 #include <sys/param.h> 38 #include <sys/mount.h> 39 #include <sys/stat.h> 40 #include <ufs/ufs/ufsmount.h> 41 42 #include <ctype.h> 43 #include <err.h> 44 #include <errno.h> 45 #include <grp.h> 46 #include <mntopts.h> 47 #include <pwd.h> 48 #include <stdio.h> 49 #include <stdlib.h> 50 #include <string.h> 51 #include <unistd.h> 52 53 #include "mountprog.h" 54 #include "mount_chfs.h" 55 56 /* --------------------------------------------------------------------- */ 57 58 static void usage(void) __dead; 59 60 /* --------------------------------------------------------------------- */ 61 62 void 63 mount_chfs_parseargs(int argc, char *argv[], struct ufs_args *args, 64 int *mntflags, char *canon_dev, char *canon_dir) 65 { 66 int ch; 67 struct stat sb; 68 69 /* Set default values for mount point arguments. */ 70 memset(args, 0, sizeof(*args)); 71 *mntflags = 0; 72 73 optind = optreset = 1; 74 75 while ((ch = getopt(argc, argv, "i:")) != -1) { 76 switch (ch) { 77 case '?': 78 default: 79 usage(); 80 } 81 } 82 argc -= optind; 83 argv += optind; 84 85 if (argc != 2) 86 usage(); 87 88 //strlcpy(canon_dev, argv[0], MAXPATHLEN); 89 pathadj(argv[0], canon_dev); 90 pathadj(argv[1], canon_dir); 91 92 args->fspec = canon_dev; 93 94 if (stat(canon_dir, &sb) == -1) { 95 err(EXIT_FAILURE, "cannot stat `%s'", canon_dir); 96 } 97 98 } 99 100 /* --------------------------------------------------------------------- */ 101 102 static void 103 usage(void) 104 { 105 (void)fprintf(stderr, 106 "usage: %s special mountpath\n", 107 getprogname()); 108 exit(1); 109 } 110 111 /* --------------------------------------------------------------------- */ 112 113 int 114 mount_chfs(int argc, char *argv[]) 115 { 116 struct ufs_args args; 117 char canon_dev[MAXPATHLEN], fs_name[MAXPATHLEN]; 118 int mntflags; 119 120 121 mount_chfs_parseargs(argc, argv, &args, &mntflags, 122 canon_dev, fs_name); 123 124 if (mount(MOUNT_CHEWIEFS, fs_name, mntflags, &args, sizeof args) == -1) { 125 err(EXIT_FAILURE, "chfs on %s", fs_name); 126 } 127 128 if (mntflags & MNT_GETARGS) { 129 130 //(void)printf("flash index=%d\n", args.fl_index); 131 } 132 133 return EXIT_SUCCESS; 134 } 135 136 #ifndef MOUNT_NOMAIN 137 int 138 main(int argc, char *argv[]) 139 { 140 setprogname(argv[0]); 141 return mount_chfs(argc, argv); 142 } 143 #endif 144