2 * Copyright (c) 1997-2006 Erez Zadok
3 * Copyright (c) 1990 Jan-Simon Pendry
4 * Copyright (c) 1990 Imperial College of Science, Technology & Medicine
5 * Copyright (c) 1990 The Regents of the University of California.
8 * This code is derived from software contributed to Berkeley by
9 * Jan-Simon Pendry at Imperial College, London.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgment:
21 * This product includes software developed by the University of
22 * California, Berkeley and its contributors.
23 * 4. Neither the name of the University nor the names of its contributors
24 * may be used to endorse or promote products derived from this software
25 * without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 * File: am-utils/amd/ops_pcfs.c
45 * PC (MS-DOS) file system
50 #endif /* HAVE_CONFIG_H */
54 /* forward definitions */
55 static char *pcfs_match(am_opts *fo);
56 static int pcfs_mount(am_node *am, mntfs *mf);
57 static int pcfs_umount(am_node *am, mntfs *mf);
69 amfs_error_lookup_child,
70 amfs_error_mount_child,
72 0, /* pcfs_readlink */
74 0, /* pcfs_umounted */
75 amfs_generic_find_srvr,
76 0, /* pcfs_get_wchan */
77 FS_MKMNT | FS_UBACKGROUND | FS_AMQINFO, /* nfs_fs_flags */
80 #endif /* HAVE_FS_AUTOFS */
86 * PCFS needs remote filesystem.
89 pcfs_match(am_opts *fo)
92 plog(XLOG_USER, "pcfs: no source device specified");
95 dlog("PCFS: mounting device \"%s\" on \"%s\"", fo->opt_dev, fo->opt_fs);
98 * Determine magic cookie to put in mtab
100 return strdup(fo->opt_dev);
105 mount_pcfs(char *mntdir, char *fs_name, char *opts, int on_autofs)
107 pcfs_args_t pcfs_args;
110 #if defined(HAVE_PCFS_ARGS_T_MASK) || defined(HAVE_PCFS_ARGS_T_DIRMASK)
112 #endif /* defined(HAVE_PCFS_ARGS_T_MASK) || defined(HAVE_PCFS_ARGS_T_DIRMASK) */
113 #if defined(HAVE_PCFS_ARGS_T_UID) || defined(HAVE_PCFS_ARGS_T_UID)
115 #endif /* defined(HAVE_PCFS_ARGS_T_UID) || defined(HAVE_PCFS_ARGS_T_UID) */
118 * Figure out the name of the file system type.
120 MTYPE_TYPE type = MOUNT_TYPE_PCFS;
122 memset((voidp) &pcfs_args, 0, sizeof(pcfs_args)); /* Paranoid */
125 * Fill in the mount structure
127 memset((voidp) &mnt, 0, sizeof(mnt));
128 mnt.mnt_dir = mntdir;
129 mnt.mnt_fsname = fs_name;
130 mnt.mnt_type = MNTTAB_TYPE_PCFS;
133 flags = compute_mount_flags(&mnt);
134 #ifdef HAVE_FS_AUTOFS
136 flags |= autofs_compute_mount_flags(&mnt);
137 #endif /* HAVE_FS_AUTOFS */
138 if (amuDebug(D_TRACE))
139 plog(XLOG_DEBUG, "mount_pcfs: flags=0x%x", (u_int) flags);
141 #ifdef HAVE_PCFS_ARGS_T_FSPEC
142 pcfs_args.fspec = fs_name;
143 #endif /* HAVE_PCFS_ARGS_T_FSPEC */
145 #ifdef HAVE_PCFS_ARGS_T_MASK
146 pcfs_args.mask = 0777; /* this may be the msdos file modes */
147 if ((mask = hasmntval(&mnt, MNTTAB_OPT_MASK)) > 0)
148 pcfs_args.mask = mask;
149 if (amuDebug(D_TRACE))
150 plog(XLOG_DEBUG, "mount_pcfs: mask=%o (octal)", (u_int) pcfs_args.mask);
151 #endif /* HAVE_PCFS_ARGS_T_MASK */
153 #ifdef HAVE_PCFS_ARGS_T_DIRMASK
154 pcfs_args.dirmask = 0777; /* this may be the msdos dir modes */
155 if ((mask = hasmntval(&mnt, MNTTAB_OPT_DIRMASK)) > 0)
156 pcfs_args.dirmask = mask;
157 if (amuDebug(D_TRACE))
158 plog(XLOG_DEBUG, "mount_pcfs: dirmask=%o (octal)", (u_int) pcfs_args.dirmask);
159 #endif /* HAVE_PCFS_ARGS_T_DIRMASK */
161 #ifdef HAVE_PCFS_ARGS_T_UID
162 pcfs_args.uid = 0; /* default to root */
163 if ((str = hasmntstr(&mnt, MNTTAB_OPT_USER)) != NULL) {
165 if ((pw = getpwnam(str)) != NULL)
166 pcfs_args.uid = pw->pw_uid;
167 else /* maybe used passed a UID number, not user name */
168 pcfs_args.uid = atoi(str); /* atoi returns '0' if it failed */
171 if (amuDebug(D_TRACE))
172 plog(XLOG_DEBUG, "mount_pcfs: uid=%d", (int) pcfs_args.uid);
173 #endif /* HAVE_PCFS_ARGS_T_UID */
175 #ifdef HAVE_PCFS_ARGS_T_GID
176 pcfs_args.gid = 0; /* default to wheel/root group */
177 if ((str = hasmntstr(&mnt, MNTTAB_OPT_GROUP)) != NULL) {
179 if ((gr = getgrnam(str)) != NULL)
180 pcfs_args.gid = gr->gr_gid;
181 else /* maybe used passed a GID number, not group name */
182 pcfs_args.gid = atoi(str); /* atoi returns '0' if it failed */
185 if (amuDebug(D_TRACE))
186 plog(XLOG_DEBUG, "mount_pcfs: gid=%d", (int) pcfs_args.gid);
187 #endif /* HAVE_PCFS_ARGS_T_GID */
189 #ifdef HAVE_PCFS_ARGS_T_SECONDSWEST
190 pcfs_args.secondswest = 0; /* XXX: fill in correct values */
191 #endif /* HAVE_PCFS_ARGS_T_SECONDSWEST */
192 #ifdef HAVE_PCFS_ARGS_T_DSTTIME
193 pcfs_args.dsttime = 0; /* XXX: fill in correct values */
194 #endif /* HAVE_PCFS_ARGS_T_DSTTIME */
197 * Call generic mount routine
199 return mount_fs(&mnt, flags, (caddr_t) & pcfs_args, 0, type, 0, NULL, mnttab_file_name, on_autofs);
204 pcfs_mount(am_node *am, mntfs *mf)
206 int on_autofs = mf->mf_flags & MFF_ON_AUTOFS;
209 error = mount_pcfs(mf->mf_mount, mf->mf_info, mf->mf_mopts, on_autofs);
212 plog(XLOG_ERROR, "mount_pcfs: %m");
221 pcfs_umount(am_node *am, mntfs *mf)
223 int unmount_flags = (mf->mf_flags & MFF_ON_AUTOFS) ? AMU_UMOUNT_AUTOFS : 0;
225 return UMOUNT_FS(mf->mf_mount, mnttab_file_name, unmount_flags);