1 /* $NetBSD: mount_ntfs.c,v 1.21 2008/08/05 20:57:45 pooka Exp $ */
4 * Copyright (c) 1994 Christopher G. Demetriou
5 * Copyright (c) 1999 Semen Ustimenko
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by Christopher G. Demetriou.
19 * 4. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 * Id: mount_ntfs.c,v 1.1.1.1 1999/02/03 03:51:19 semenu Exp
36 #include <sys/cdefs.h>
38 __RCSID("$NetBSD: mount_ntfs.c,v 1.21 2008/08/05 20:57:45 pooka Exp $");
41 #include <sys/param.h>
42 #include <sys/mount.h>
44 #include <ntfs/ntfsmount.h>
57 #include "mountprog.h"
58 #include "mount_ntfs.h"
60 static const struct mntopt mopts
[] = {
66 static void usage(void) __dead
;
70 main(int argc
, char **argv
)
74 return mount_ntfs(argc
, argv
);
79 mount_ntfs_parseargs(int argc
, char **argv
,
80 struct ntfs_args
*args
, int *mntflags
,
81 char *canon_dev
, char *canon_dir
)
84 int c
, set_gid
, set_uid
, set_mask
;
88 *mntflags
= set_gid
= set_uid
= set_mask
= 0;
89 (void)memset(args
, '\0', sizeof(*args
));
91 while ((c
= getopt(argc
, argv
, "aiu:g:m:o:")) != -1) {
94 args
->uid
= a_uid(optarg
);
98 args
->gid
= a_gid(optarg
);
102 args
->mode
= a_mask(optarg
);
106 args
->flag
|= NTFS_MFLAG_CASEINS
;
109 args
->flag
|= NTFS_MFLAG_ALLNAMES
;
112 mp
= getmntopts(optarg
, mopts
, mntflags
, 0);
114 err(1, "getmntopts");
124 if (optind
+ 2 != argc
)
128 dir
= argv
[optind
+ 1];
130 pathadj(dev
, canon_dev
);
131 pathadj(dir
, canon_dir
);
133 args
->fspec
= canon_dev
;
134 if (!set_gid
|| !set_uid
|| !set_mask
) {
135 if (stat(dir
, &sb
) == -1)
136 err(EX_OSERR
, "stat %s", dir
);
139 args
->uid
= sb
.st_uid
;
141 args
->gid
= sb
.st_gid
;
143 args
->mode
= sb
.st_mode
& (S_IRWXU
| S_IRWXG
| S_IRWXO
);
148 mount_ntfs(int argc
, char *argv
[])
150 struct ntfs_args args
;
152 char canon_dev
[MAXPATHLEN
], canon_dir
[MAXPATHLEN
];
154 mount_ntfs_parseargs(argc
, argv
, &args
, &mntflags
,
155 canon_dev
, canon_dir
);
157 if (mount(MOUNT_NTFS
, canon_dir
, mntflags
, &args
, sizeof args
) == -1)
158 err(EX_OSERR
, "%s on %s", canon_dev
, canon_dir
);
160 if (mntflags
& MNT_GETARGS
) {
162 (void)snprintb(buf
, sizeof(buf
), NTFS_MFLAG_BITS
, args
.flag
);
163 printf("uid=%d, gid=%d, mode=0%o, flags=%s\n", args
.uid
,
164 args
.gid
, args
.mode
, buf
);
172 fprintf(stderr
, "usage: %s [-a] [-i] [-u user] [-g group] [-m mask] "
173 "bdev dir\n", getprogname());