mount_chfs.c revision 1.1
11.1Sahoka/* $NetBSD: mount_chfs.c,v 1.1 2011/11/24 15:54:55 ahoka Exp $ */ 21.1Sahoka 31.1Sahoka/*- 41.1Sahoka * Copyright (c) 2010 Department of Software Engineering, 51.1Sahoka * University of Szeged, Hungary 61.1Sahoka * All rights reserved. 71.1Sahoka * 81.1Sahoka * This code is derived from software contributed to The NetBSD Foundation 91.1Sahoka * by the Department of Software Engineering, University of Szeged, Hungary 101.1Sahoka * 111.1Sahoka * Redistribution and use in source and binary forms, with or without 121.1Sahoka * modification, are permitted provided that the following conditions 131.1Sahoka * are met: 141.1Sahoka * 1. Redistributions of source code must retain the above copyright 151.1Sahoka * notice, this list of conditions and the following disclaimer. 161.1Sahoka * 2. Redistributions in binary form must reproduce the above copyright 171.1Sahoka * notice, this list of conditions and the following disclaimer in the 181.1Sahoka * documentation and/or other materials provided with the distribution. 191.1Sahoka * 201.1Sahoka * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 211.1Sahoka * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 221.1Sahoka * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 231.1Sahoka * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 241.1Sahoka * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 251.1Sahoka * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 261.1Sahoka * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 271.1Sahoka * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 281.1Sahoka * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 291.1Sahoka * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 301.1Sahoka * SUCH DAMAGE. 311.1Sahoka */ 321.1Sahoka 331.1Sahoka#include <sys/cdefs.h> 341.1Sahoka#ifndef lint 351.1Sahoka#endif /* not lint */ 361.1Sahoka 371.1Sahoka#include <sys/param.h> 381.1Sahoka#include <sys/mount.h> 391.1Sahoka#include <sys/stat.h> 401.1Sahoka#include <ufs/ufs/ufsmount.h> 411.1Sahoka 421.1Sahoka#include <ctype.h> 431.1Sahoka#include <err.h> 441.1Sahoka#include <errno.h> 451.1Sahoka#include <grp.h> 461.1Sahoka#include <mntopts.h> 471.1Sahoka#include <pwd.h> 481.1Sahoka#include <stdio.h> 491.1Sahoka#include <stdlib.h> 501.1Sahoka#include <string.h> 511.1Sahoka#include <unistd.h> 521.1Sahoka 531.1Sahoka#include "mountprog.h" 541.1Sahoka#include "mount_chfs.h" 551.1Sahoka 561.1Sahoka/* --------------------------------------------------------------------- */ 571.1Sahoka 581.1Sahokastatic const struct mntopt mopts[] = { 591.1Sahoka MOPT_STDOPTS, 601.1Sahoka MOPT_GETARGS, 611.1Sahoka MOPT_NULL, 621.1Sahoka}; 631.1Sahoka 641.1Sahoka/* --------------------------------------------------------------------- */ 651.1Sahoka 661.1Sahokastatic void usage(void) __dead; 671.1Sahoka 681.1Sahoka/* --------------------------------------------------------------------- */ 691.1Sahoka 701.1Sahokavoid 711.1Sahokamount_chfs_parseargs(int argc, char *argv[], struct ufs_args *args, 721.1Sahoka int *mntflags, char *canon_dev, char *canon_dir) 731.1Sahoka{ 741.1Sahoka int ch; 751.1Sahoka struct stat sb; 761.1Sahoka 771.1Sahoka /* Set default values for mount point arguments. */ 781.1Sahoka memset(args, 0, sizeof(*args)); 791.1Sahoka *mntflags = 0; 801.1Sahoka 811.1Sahoka optind = optreset = 1; 821.1Sahoka 831.1Sahoka while ((ch = getopt(argc, argv, "i:")) != -1) { 841.1Sahoka switch (ch) { 851.1Sahoka case '?': 861.1Sahoka default: 871.1Sahoka usage(); 881.1Sahoka } 891.1Sahoka } 901.1Sahoka argc -= optind; 911.1Sahoka argv += optind; 921.1Sahoka 931.1Sahoka if (argc != 2) 941.1Sahoka usage(); 951.1Sahoka 961.1Sahoka //strlcpy(canon_dev, argv[0], MAXPATHLEN); 971.1Sahoka pathadj(argv[0], canon_dev); 981.1Sahoka pathadj(argv[1], canon_dir); 991.1Sahoka 1001.1Sahoka args->fspec = canon_dev; 1011.1Sahoka 1021.1Sahoka if (stat(canon_dir, &sb) == -1) { 1031.1Sahoka err(EXIT_FAILURE, "cannot stat `%s'", canon_dir); 1041.1Sahoka } 1051.1Sahoka 1061.1Sahoka} 1071.1Sahoka 1081.1Sahoka/* --------------------------------------------------------------------- */ 1091.1Sahoka 1101.1Sahokastatic void 1111.1Sahokausage(void) 1121.1Sahoka{ 1131.1Sahoka (void)fprintf(stderr, 1141.1Sahoka "usage: %s special mountpath\n", 1151.1Sahoka getprogname()); 1161.1Sahoka exit(1); 1171.1Sahoka} 1181.1Sahoka 1191.1Sahoka/* --------------------------------------------------------------------- */ 1201.1Sahoka 1211.1Sahokaint 1221.1Sahokamount_chfs(int argc, char *argv[]) 1231.1Sahoka{ 1241.1Sahoka struct ufs_args args; 1251.1Sahoka char canon_dev[MAXPATHLEN], fs_name[MAXPATHLEN]; 1261.1Sahoka int mntflags; 1271.1Sahoka 1281.1Sahoka 1291.1Sahoka mount_chfs_parseargs(argc, argv, &args, &mntflags, 1301.1Sahoka canon_dev, fs_name); 1311.1Sahoka 1321.1Sahoka if (mount(MOUNT_CHEWIEFS, fs_name, mntflags, &args, sizeof args) == -1) { 1331.1Sahoka err(EXIT_FAILURE, "chfs on %s", fs_name); 1341.1Sahoka } 1351.1Sahoka 1361.1Sahoka if (mntflags & MNT_GETARGS) { 1371.1Sahoka 1381.1Sahoka //(void)printf("flash index=%d\n", args.fl_index); 1391.1Sahoka } 1401.1Sahoka 1411.1Sahoka return EXIT_SUCCESS; 1421.1Sahoka} 1431.1Sahoka 1441.1Sahoka#ifndef MOUNT_NOMAIN 1451.1Sahokaint 1461.1Sahokamain(int argc, char *argv[]) 1471.1Sahoka{ 1481.1Sahoka setprogname(argv[0]); 1491.1Sahoka return mount_chfs(argc, argv); 1501.1Sahoka} 1511.1Sahoka#endif 152