1146568Sdumbbell/*- 2222176Suqs * Copyright (c) 2005 Jean-S��bastien P��dron 3146568Sdumbbell * All rights reserved. 4146568Sdumbbell * 5146568Sdumbbell * Redistribution and use in source and binary forms, with or without 6146568Sdumbbell * modification, are permitted provided that the following conditions 7146568Sdumbbell * are met: 8146568Sdumbbell * 1. Redistributions of source code must retain the above copyright 9146568Sdumbbell * notice, this list of conditions and the following disclaimer. 10146568Sdumbbell * 2. Redistributions in binary form must reproduce the above copyright 11146568Sdumbbell * notice, this list of conditions and the following disclaimer in the 12146568Sdumbbell * documentation and/or other materials provided with the distribution. 13146568Sdumbbell * 14146568Sdumbbell * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15146568Sdumbbell * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16146568Sdumbbell * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17146568Sdumbbell * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18146568Sdumbbell * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19146568Sdumbbell * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20146568Sdumbbell * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21146568Sdumbbell * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22146568Sdumbbell * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23146568Sdumbbell * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24146568Sdumbbell * SUCH DAMAGE. 25146568Sdumbbell * 26146568Sdumbbell * $FreeBSD$ 27146568Sdumbbell */ 28146568Sdumbbell 29146568Sdumbbell#include <sys/param.h> 30146568Sdumbbell#include <sys/mount.h> 31146568Sdumbbell#include <sys/uio.h> 32146568Sdumbbell 33146568Sdumbbell#include <err.h> 34146568Sdumbbell#include <stdio.h> 35146568Sdumbbell#include <stdlib.h> 36146568Sdumbbell#include <string.h> 37146568Sdumbbell#include <sysexits.h> 38146568Sdumbbell#include <unistd.h> 39146568Sdumbbell 40146568Sdumbbell#include "mntopts.h" 41146568Sdumbbell 42146568Sdumbbellstruct mntopt mopts[] = { 43146568Sdumbbell MOPT_STDOPTS, 44147242Sdelphij MOPT_END 45146568Sdumbbell}; 46146568Sdumbbell 47146568Sdumbbellvoid usage(void); 48146568Sdumbbell 49146568Sdumbbellint 50146568Sdumbbellmain(int argc, char *argv[]) 51146568Sdumbbell{ 52146568Sdumbbell struct iovec *iov; 53146568Sdumbbell int ch, mntflags, iovlen; 54146568Sdumbbell char *dev, *dir, mntpath[MAXPATHLEN]; 55152357Srodrigc char fstype[] = "reiserfs"; 56146568Sdumbbell 57146568Sdumbbell mntflags = 0; 58146568Sdumbbell while ((ch = getopt(argc, argv, "o:")) != -1) { 59146568Sdumbbell switch(ch) { 60146568Sdumbbell case 'o': 61146568Sdumbbell getmntopts(optarg, mopts, &mntflags, 0); 62146568Sdumbbell break; 63146568Sdumbbell case '?': 64146568Sdumbbell default: 65146568Sdumbbell usage(); 66146568Sdumbbell } 67146568Sdumbbell } 68146568Sdumbbell argc -= optind; 69146568Sdumbbell argv += optind; 70146568Sdumbbell 71146568Sdumbbell if (argc != 2) 72146568Sdumbbell usage(); 73146568Sdumbbell 74146568Sdumbbell dev = argv[0]; 75146568Sdumbbell dir = argv[1]; 76146568Sdumbbell 77146568Sdumbbell /* 78146568Sdumbbell * Resolve the mountpoint with realpath(3) and remove unnecessary 79146568Sdumbbell * slashes from the devicename if there are any. 80146568Sdumbbell */ 81146568Sdumbbell (void)checkpath(dir, mntpath); 82146568Sdumbbell (void)rmslashes(dev, dev); 83146568Sdumbbell 84146568Sdumbbell /* Read-only support for now */ 85146568Sdumbbell mntflags |= MNT_RDONLY; 86146568Sdumbbell 87146568Sdumbbell /* Prepare the options vector for nmount(). build_iovec() is declared 88146568Sdumbbell * in mntopts.h. */ 89146568Sdumbbell iov = NULL; 90146568Sdumbbell iovlen = 0; 91152357Srodrigc build_iovec(&iov, &iovlen, "fstype", fstype, (size_t)-1); 92152357Srodrigc build_iovec(&iov, &iovlen, "fspath", mntpath, (size_t)-1); 93152357Srodrigc build_iovec(&iov, &iovlen, "from", dev, (size_t)-1); 94146568Sdumbbell 95146568Sdumbbell if (nmount(iov, iovlen, mntflags) < 0) 96146568Sdumbbell err(EX_OSERR, "%s", dev); 97146568Sdumbbell 98146568Sdumbbell exit(0); 99146568Sdumbbell} 100146568Sdumbbell 101146568Sdumbbellvoid 102146568Sdumbbellusage(void) 103146568Sdumbbell{ 104146568Sdumbbell fprintf(stderr, 105146568Sdumbbell "usage: mount_reiserfs [-o options] special node\n"); 106146568Sdumbbell exit(EX_USAGE); 107146568Sdumbbell} 108