1/* $NetBSD$ */ 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 58static const struct mntopt mopts[] = { 59 MOPT_STDOPTS, 60 MOPT_GETARGS, 61 MOPT_NULL, 62}; 63 64/* --------------------------------------------------------------------- */ 65 66static void usage(void) __dead; 67 68/* --------------------------------------------------------------------- */ 69 70void 71mount_chfs_parseargs(int argc, char *argv[], struct ufs_args *args, 72 int *mntflags, char *canon_dev, char *canon_dir) 73{ 74 int ch; 75 struct stat sb; 76 77 /* Set default values for mount point arguments. */ 78 memset(args, 0, sizeof(*args)); 79 *mntflags = 0; 80 81 optind = optreset = 1; 82 83 while ((ch = getopt(argc, argv, "i:")) != -1) { 84 switch (ch) { 85 case '?': 86 default: 87 usage(); 88 } 89 } 90 argc -= optind; 91 argv += optind; 92 93 if (argc != 2) 94 usage(); 95 96 //strlcpy(canon_dev, argv[0], MAXPATHLEN); 97 pathadj(argv[0], canon_dev); 98 pathadj(argv[1], canon_dir); 99 100 args->fspec = canon_dev; 101 102 if (stat(canon_dir, &sb) == -1) { 103 err(EXIT_FAILURE, "cannot stat `%s'", canon_dir); 104 } 105 106} 107 108/* --------------------------------------------------------------------- */ 109 110static void 111usage(void) 112{ 113 (void)fprintf(stderr, 114 "usage: %s special mountpath\n", 115 getprogname()); 116 exit(1); 117} 118 119/* --------------------------------------------------------------------- */ 120 121int 122mount_chfs(int argc, char *argv[]) 123{ 124 struct ufs_args args; 125 char canon_dev[MAXPATHLEN], fs_name[MAXPATHLEN]; 126 int mntflags; 127 128 129 mount_chfs_parseargs(argc, argv, &args, &mntflags, 130 canon_dev, fs_name); 131 132 if (mount(MOUNT_CHEWIEFS, fs_name, mntflags, &args, sizeof args) == -1) { 133 err(EXIT_FAILURE, "chfs on %s", fs_name); 134 } 135 136 if (mntflags & MNT_GETARGS) { 137 138 //(void)printf("flash index=%d\n", args.fl_index); 139 } 140 141 return EXIT_SUCCESS; 142} 143 144#ifndef MOUNT_NOMAIN 145int 146main(int argc, char *argv[]) 147{ 148 setprogname(argv[0]); 149 return mount_chfs(argc, argv); 150} 151#endif 152