ops_pcfs.c (131709) | ops_pcfs.c (174313) |
---|---|
1/* | 1/* |
2 * Copyright (c) 1997-2004 Erez Zadok | 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. 6 * All rights reserved. 7 * 8 * This code is derived from software contributed to Berkeley by 9 * Jan-Simon Pendry at Imperial College, London. 10 * --- 20 unchanged lines hidden (view full) --- 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 37 * SUCH DAMAGE. 38 * | 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. 6 * All rights reserved. 7 * 8 * This code is derived from software contributed to Berkeley by 9 * Jan-Simon Pendry at Imperial College, London. 10 * --- 20 unchanged lines hidden (view full) --- 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 37 * SUCH DAMAGE. 38 * |
39 * %W% (Berkeley) %G% | |
40 * | 39 * |
41 * $Id: ops_pcfs.c,v 1.3.2.5 2004/01/06 03:15:16 ezk Exp $ 42 * $FreeBSD: head/contrib/amd/amd/ops_pcfs.c 131709 2004-07-06 13:44:14Z mbr $ | 40 * File: am-utils/amd/ops_pcfs.c |
43 * 44 */ 45 46/* 47 * PC (MS-DOS) file system 48 */ 49 50#ifdef HAVE_CONFIG_H 51# include <config.h> 52#endif /* HAVE_CONFIG_H */ 53#include <am_defs.h> 54#include <amd.h> 55 56/* forward definitions */ 57static char *pcfs_match(am_opts *fo); | 41 * 42 */ 43 44/* 45 * PC (MS-DOS) file system 46 */ 47 48#ifdef HAVE_CONFIG_H 49# include <config.h> 50#endif /* HAVE_CONFIG_H */ 51#include <am_defs.h> 52#include <amd.h> 53 54/* forward definitions */ 55static char *pcfs_match(am_opts *fo); |
58static int pcfs_fmount(mntfs *mf); 59static int pcfs_fumount(mntfs *mf); | 56static int pcfs_mount(am_node *am, mntfs *mf); 57static int pcfs_umount(am_node *am, mntfs *mf); |
60 61/* 62 * Ops structure 63 */ 64am_ops pcfs_ops = 65{ 66 "pcfs", 67 pcfs_match, 68 0, /* pcfs_init */ | 58 59/* 60 * Ops structure 61 */ 62am_ops pcfs_ops = 63{ 64 "pcfs", 65 pcfs_match, 66 0, /* pcfs_init */ |
69 amfs_auto_fmount, 70 pcfs_fmount, 71 amfs_auto_fumount, 72 pcfs_fumount, 73 amfs_error_lookuppn, | 67 pcfs_mount, 68 pcfs_umount, 69 amfs_error_lookup_child, 70 amfs_error_mount_child, |
74 amfs_error_readdir, 75 0, /* pcfs_readlink */ 76 0, /* pcfs_mounted */ 77 0, /* pcfs_umounted */ | 71 amfs_error_readdir, 72 0, /* pcfs_readlink */ 73 0, /* pcfs_mounted */ 74 0, /* pcfs_umounted */ |
78 find_amfs_auto_srvr, 79 FS_MKMNT | FS_UBACKGROUND | FS_AMQINFO | 75 amfs_generic_find_srvr, 76 0, /* pcfs_get_wchan */ 77 FS_MKMNT | FS_UBACKGROUND | FS_AMQINFO, /* nfs_fs_flags */ 78#ifdef HAVE_FS_AUTOFS 79 AUTOFS_PCFS_FS_FLAGS, 80#endif /* HAVE_FS_AUTOFS */ |
80}; 81 82 83 84/* 85 * PCFS needs remote filesystem. 86 */ 87static char * 88pcfs_match(am_opts *fo) 89{ 90 if (!fo->opt_dev) { 91 plog(XLOG_USER, "pcfs: no source device specified"); 92 return 0; 93 } | 81}; 82 83 84 85/* 86 * PCFS needs remote filesystem. 87 */ 88static char * 89pcfs_match(am_opts *fo) 90{ 91 if (!fo->opt_dev) { 92 plog(XLOG_USER, "pcfs: no source device specified"); 93 return 0; 94 } |
94#ifdef DEBUG | |
95 dlog("PCFS: mounting device \"%s\" on \"%s\"", fo->opt_dev, fo->opt_fs); | 95 dlog("PCFS: mounting device \"%s\" on \"%s\"", fo->opt_dev, fo->opt_fs); |
96#endif /* DEBUG */ | |
97 98 /* 99 * Determine magic cookie to put in mtab 100 */ 101 return strdup(fo->opt_dev); 102} 103 104 105static int | 96 97 /* 98 * Determine magic cookie to put in mtab 99 */ 100 return strdup(fo->opt_dev); 101} 102 103 104static int |
106mount_pcfs(char *dir, char *fs_name, char *opts) | 105mount_pcfs(char *mntdir, char *fs_name, char *opts, int on_autofs) |
107{ 108 pcfs_args_t pcfs_args; 109 mntent_t mnt; 110 int flags; | 106{ 107 pcfs_args_t pcfs_args; 108 mntent_t mnt; 109 int flags; |
110#if defined(HAVE_PCFS_ARGS_T_MASK) || defined(HAVE_PCFS_ARGS_T_DIRMASK) 111 int mask; 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) 114 char *str; 115#endif /* defined(HAVE_PCFS_ARGS_T_UID) || defined(HAVE_PCFS_ARGS_T_UID) */ |
|
111 112 /* 113 * Figure out the name of the file system type. 114 */ 115 MTYPE_TYPE type = MOUNT_TYPE_PCFS; 116 117 memset((voidp) &pcfs_args, 0, sizeof(pcfs_args)); /* Paranoid */ 118 119 /* 120 * Fill in the mount structure 121 */ 122 memset((voidp) &mnt, 0, sizeof(mnt)); | 116 117 /* 118 * Figure out the name of the file system type. 119 */ 120 MTYPE_TYPE type = MOUNT_TYPE_PCFS; 121 122 memset((voidp) &pcfs_args, 0, sizeof(pcfs_args)); /* Paranoid */ 123 124 /* 125 * Fill in the mount structure 126 */ 127 memset((voidp) &mnt, 0, sizeof(mnt)); |
123 mnt.mnt_dir = dir; | 128 mnt.mnt_dir = mntdir; |
124 mnt.mnt_fsname = fs_name; 125 mnt.mnt_type = MNTTAB_TYPE_PCFS; 126 mnt.mnt_opts = opts; 127 128 flags = compute_mount_flags(&mnt); | 129 mnt.mnt_fsname = fs_name; 130 mnt.mnt_type = MNTTAB_TYPE_PCFS; 131 mnt.mnt_opts = opts; 132 133 flags = compute_mount_flags(&mnt); |
134#ifdef HAVE_FS_AUTOFS 135 if (on_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); |
|
129 130#ifdef HAVE_PCFS_ARGS_T_FSPEC 131 pcfs_args.fspec = fs_name; 132#endif /* HAVE_PCFS_ARGS_T_FSPEC */ 133 134#ifdef HAVE_PCFS_ARGS_T_MASK 135 pcfs_args.mask = 0777; /* this may be the msdos file modes */ | 140 141#ifdef HAVE_PCFS_ARGS_T_FSPEC 142 pcfs_args.fspec = fs_name; 143#endif /* HAVE_PCFS_ARGS_T_FSPEC */ 144 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); |
|
136#endif /* HAVE_PCFS_ARGS_T_MASK */ 137 138#ifdef HAVE_PCFS_ARGS_T_DIRMASK | 151#endif /* HAVE_PCFS_ARGS_T_MASK */ 152 153#ifdef HAVE_PCFS_ARGS_T_DIRMASK |
139 pcfs_args.dirmask = 0777; /* this may be the msdos dir modes */ | 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); |
140#endif /* HAVE_PCFS_ARGS_T_DIRMASK */ 141 142#ifdef HAVE_PCFS_ARGS_T_UID | 159#endif /* HAVE_PCFS_ARGS_T_DIRMASK */ 160 161#ifdef HAVE_PCFS_ARGS_T_UID |
143 pcfs_args.uid = 0; /* root */ | 162 pcfs_args.uid = 0; /* default to root */ 163 if ((str = hasmntstr(&mnt, MNTTAB_OPT_USER)) != NULL) { 164 struct passwd *pw; 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 */ 169 XFREE(str); 170 } 171 if (amuDebug(D_TRACE)) 172 plog(XLOG_DEBUG, "mount_pcfs: uid=%d", (int) pcfs_args.uid); |
144#endif /* HAVE_PCFS_ARGS_T_UID */ 145 146#ifdef HAVE_PCFS_ARGS_T_GID | 173#endif /* HAVE_PCFS_ARGS_T_UID */ 174 175#ifdef HAVE_PCFS_ARGS_T_GID |
147 pcfs_args.gid = 0; /* wheel */ | 176 pcfs_args.gid = 0; /* default to wheel/root group */ 177 if ((str = hasmntstr(&mnt, MNTTAB_OPT_GROUP)) != NULL) { 178 struct group *gr; 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 */ 183 XFREE(str); 184 } 185 if (amuDebug(D_TRACE)) 186 plog(XLOG_DEBUG, "mount_pcfs: gid=%d", (int) pcfs_args.gid); |
148#endif /* HAVE_PCFS_ARGS_T_GID */ 149 150#ifdef HAVE_PCFS_ARGS_T_SECONDSWEST 151 pcfs_args.secondswest = 0; /* XXX: fill in correct values */ 152#endif /* HAVE_PCFS_ARGS_T_SECONDSWEST */ 153#ifdef HAVE_PCFS_ARGS_T_DSTTIME 154 pcfs_args.dsttime = 0; /* XXX: fill in correct values */ 155#endif /* HAVE_PCFS_ARGS_T_DSTTIME */ 156 157 /* 158 * Call generic mount routine 159 */ | 187#endif /* HAVE_PCFS_ARGS_T_GID */ 188 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 */ 195 196 /* 197 * Call generic mount routine 198 */ |
160 return mount_fs(&mnt, flags, (caddr_t) & pcfs_args, 0, type, 0, NULL, mnttab_file_name); | 199 return mount_fs(&mnt, flags, (caddr_t) & pcfs_args, 0, type, 0, NULL, mnttab_file_name, on_autofs); |
161} 162 163 164static int | 200} 201 202 203static int |
165pcfs_fmount(mntfs *mf) | 204pcfs_mount(am_node *am, mntfs *mf) |
166{ | 205{ |
206 int on_autofs = mf->mf_flags & MFF_ON_AUTOFS; |
|
167 int error; 168 | 207 int error; 208 |
169 error = mount_pcfs(mf->mf_mount, mf->mf_info, mf->mf_mopts); | 209 error = mount_pcfs(mf->mf_mount, mf->mf_info, mf->mf_mopts, on_autofs); |
170 if (error) { 171 errno = error; 172 plog(XLOG_ERROR, "mount_pcfs: %m"); 173 return error; 174 } 175 176 return 0; 177} 178 179 180static int | 210 if (error) { 211 errno = error; 212 plog(XLOG_ERROR, "mount_pcfs: %m"); 213 return error; 214 } 215 216 return 0; 217} 218 219 220static int |
181pcfs_fumount(mntfs *mf) | 221pcfs_umount(am_node *am, mntfs *mf) |
182{ | 222{ |
183 return UMOUNT_FS(mf->mf_mount, mnttab_file_name); | 223 int unmount_flags = (mf->mf_flags & MFF_ON_AUTOFS) ? AMU_UMOUNT_AUTOFS : 0; 224 225 return UMOUNT_FS(mf->mf_mount, mnttab_file_name, unmount_flags); |
184} | 226} |