1 /* $NetBSD: mount_nilfs.c,v 1.12 2008/08/05 20:57:45 pooka Exp $ */
4 * Copyright (c) 2008, 2009 Reinoud Zandijk
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed for the
18 * NetBSD Project. See http://www.NetBSD.org/ for
19 * information about NetBSD.
20 * 4. The name of the author may not be used to endorse or promote products
21 * derived from this software without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 #include <sys/cdefs.h>
39 __RCSID("$NetBSD: mount_nilfs.c,v 1.12 2008/08/05 20:57:45 pooka Exp $");
43 #include <sys/param.h>
44 #include <sys/mount.h>
60 /* mount specific options */
61 #include <fs/nilfs/nilfs_mount.h>
64 #include "mountprog.h"
65 #include "mount_nilfs.h"
67 /* options to pass on to the `mount' call */
68 static const struct mntopt mopts
[] = {
69 MOPT_STDOPTS
, /* `normal' options */
70 MOPT_ASYNC
, /* default */
71 MOPT_NOATIME
, /* dont update access times */
72 MOPT_UPDATE
, /* not yet supported */
73 MOPT_GETARGS
, /* printing */
79 static void usage(void) __dead
;
87 (void)fprintf(stderr
, "Usage: %s [-o options] [-c cpno] "
88 "[-t gmtoff] special node\n", getprogname());
95 main(int argc
, char **argv
)
99 return mount_nilfs(argc
, argv
);
106 mount_nilfs_parseargs(int argc
, char **argv
,
107 struct nilfs_args
*args
, int *mntflags
,
108 char *canon_dev
, char *canon_dir
)
113 uint32_t sector_size
;
117 (void)memset(args
, 0, sizeof(*args
));
119 set_gmtoff
= *mntflags
= 0;
122 while ((ch
= getopt(argc
, argv
, "c:o:t:")) != -1) {
125 /* process generic mount options */
126 mp
= getmntopts(optarg
, mopts
, mntflags
, 0);
128 err(EXIT_FAILURE
, "getmntopts");
132 args
->cpno
= a_num(optarg
, "checkpoint number");
135 args
->gmtoff
= a_num(optarg
, "gmtoff");
144 if (optind
+ 2 != argc
)
148 /* use user's time zone as default */
150 tm
= localtime(&now
);
151 args
->gmtoff
= tm
->tm_gmtoff
;
154 /* get device and directory specifier */
155 pathadj(argv
[optind
], canon_dev
);
156 pathadj(argv
[optind
+1], canon_dir
);
158 args
->version
= NILFSMNT_VERSION
;
159 args
->fspec
= canon_dev
;
163 mount_nilfs(int argc
, char *argv
[])
165 struct nilfs_args args
;
166 char canon_dev
[MAXPATHLEN
], canon_dir
[MAXPATHLEN
];
169 mount_nilfs_parseargs(argc
, argv
, &args
, &mntflags
, canon_dev
, canon_dir
);
172 if (mount(MOUNT_NILFS
, canon_dir
, mntflags
, &args
, sizeof args
) == -1)
173 err(EXIT_FAILURE
, "Cannot mount %s on %s", canon_dev
,canon_dir
);
175 if (mntflags
& MNT_GETARGS
) {
178 (void)snprintb(buf
, sizeof(buf
), NILFSMNT_BITS
,
179 (uint64_t)args
.nilfsmflags
);
180 (void)printf("gmtoffset = %d, cpno = %"PRIu64
", flags = %s\n",
181 args
.gmtoff
, args
.cpno
, buf
);