1 /* $NetBSD: mount_efs.c,v 1.5 2011/08/29 14:35:00 joerg Exp $ */ 2 3 /* 4 * Copyright (c) 2006 Stephen M. Rumble <rumble@ephemeral.org> 5 * 6 * Permission to use, copy, modify, and distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 #include <sys/param.h> 20 #include <sys/mount.h> 21 #include <fs/efs/efs.h> 22 #include <fs/efs/efs_sb.h> 23 #include <fs/efs/efs_mount.h> 24 25 #include <err.h> 26 #include <stdio.h> 27 #include <stdlib.h> 28 29 #include <string.h> 30 #include <unistd.h> 31 32 #include <mntopts.h> 33 34 #include "mountprog.h" 35 #include "mount_efs.h" 36 37 static const struct mntopt mopts[] = { 38 MOPT_STDOPTS, 39 MOPT_GETARGS, 40 MOPT_FORCE, 41 MOPT_NULL 42 }; 43 44 __dead static void usage(void); 45 46 static void 47 usage(void) 48 { 49 50 fprintf(stderr, "usage: %s [-o options] special node\n", getprogname()); 51 exit(1); 52 } 53 54 void 55 mount_efs_parseargs(int argc, char **argv, 56 struct efs_args *args, int *mntflags, 57 char *canon_dev, char *canon_dir) 58 { 59 int ch; 60 extern int optind; 61 extern char *optarg; 62 mntoptparse_t mp; 63 64 memset(args, 0, sizeof(*args)); 65 *mntflags = 0; 66 67 while ((ch = getopt(argc, argv, "o:")) != -1) { 68 switch (ch) { 69 case 'o': 70 mp = getmntopts(optarg, mopts, mntflags, NULL); 71 if (mp == NULL) 72 err(1, "getmntopts"); 73 freemntopts(mp); 74 break; 75 76 default: 77 usage(); 78 } 79 } 80 argc -= optind; 81 argv += optind; 82 83 if (argc != 2) 84 usage(); 85 86 pathadj(argv[0], canon_dev); 87 pathadj(argv[1], canon_dir); 88 89 args->fspec = canon_dev; 90 args->version = EFS_MNT_VERSION; 91 } 92 93 int 94 mount_efs(int argc, char **argv) 95 { 96 char special[MAXPATHLEN], node[MAXPATHLEN]; 97 struct efs_args args; 98 int mntflags; 99 100 mount_efs_parseargs(argc, argv, &args, &mntflags, special, node); 101 102 if (mount(MOUNT_EFS, node, mntflags, &args, sizeof args) == -1) 103 err(EXIT_FAILURE, "%s on %s", special, node); 104 105 return (0); 106 } 107 108 #ifndef MOUNT_NOMAIN 109 int 110 main(int argc, char **argv) 111 { 112 113 setprogname(argv[0]); 114 return (mount_efs(argc, argv)); 115 } 116 #endif 117