1 /* 2 * $Id: pfs_ops.c,v 5.2.1.1 90/10/21 22:29:36 jsp Exp $ 3 * 4 * Copyright (c) 1989 Jan-Simon Pendry 5 * Copyright (c) 1989 Imperial College of Science, Technology & Medicine 6 * Copyright (c) 1989 The Regents of the University of California. 7 * All rights reserved. 8 * 9 * This code is derived from software contributed to Berkeley by 10 * Jan-Simon Pendry at Imperial College, London. 11 * 12 * %sccs.include.redist.c% 13 * 14 * @(#)pfs_ops.c 5.2 (Berkeley) 03/17/91 15 */ 16 17 #include "am.h" 18 19 #ifdef HAS_PFS 20 21 /* 22 * Program file system 23 */ 24 25 /* 26 * Execute needs a mount and unmount command. 27 */ 28 static char *pfs_match(fo) 29 am_opts *fo; 30 { 31 char *prog; 32 if (!fo->opt_mount || !fo->opt_unmount) { 33 plog(XLOG_USER, "program: no mount/unmount specified"); 34 return 0; 35 } 36 prog = strchr(fo->opt_mount, ' '); 37 return strdup(prog ? prog+1 : fo->opt_mount); 38 } 39 40 static int pfs_init(mf) 41 mntfs *mf; 42 { 43 /* 44 * Save unmount command 45 */ 46 if (mf->mf_refc == 1) { 47 mf->mf_private = (voidp) strdup(mf->mf_fo->opt_unmount); 48 mf->mf_prfree = (void (*) ()) free; 49 } 50 return 0; 51 } 52 53 static int pfs_exec(info) 54 char *info; 55 { 56 char **xivec; 57 int error; 58 /* 59 * Split copy of command info string 60 */ 61 info = strdup(info); 62 if (info == 0) 63 return ENOBUFS; 64 xivec = strsplit(info, ' ', '\''); 65 /* 66 * Put stdout to stderr 67 */ 68 (void) fclose(stdout); 69 (void) dup(fileno(logfp)); 70 if (fileno(logfp) != fileno(stderr)) { 71 (void) fclose(stderr); 72 (void) dup(fileno(logfp)); 73 } 74 /* 75 * Try the exec 76 */ 77 #ifdef DEBUG 78 Debug(D_FULL) { 79 char **cp = xivec; 80 plog(XLOG_DEBUG, "executing (un)mount command..."); 81 while (*cp) { 82 plog(XLOG_DEBUG, "arg[%d] = '%s'", cp-xivec, *cp); 83 cp++; 84 } 85 } 86 #endif /* DEBUG */ 87 if (xivec[0] == 0 || xivec[1] == 0) { 88 errno = EINVAL; 89 plog(XLOG_USER, "1st/2nd args missing to (un)mount program"); 90 } else { 91 (void) execv(xivec[0], xivec+1); 92 } 93 /* 94 * Save error number 95 */ 96 error = errno; 97 plog(XLOG_ERROR, "exec failed: %m"); 98 99 /* 100 * Free allocate memory 101 */ 102 free((voidp) info); 103 free((voidp) xivec); 104 /* 105 * Return error 106 */ 107 return error; 108 } 109 110 static int pfs_fmount(mf) 111 mntfs *mf; 112 { 113 return pfs_exec(mf->mf_fo->opt_mount); 114 } 115 116 static int pfs_fumount(mf) 117 mntfs *mf; 118 { 119 return pfs_exec((char *) mf->mf_private); 120 } 121 122 /* 123 * Ops structure 124 */ 125 am_ops pfs_ops = { 126 "program", 127 pfs_match, 128 pfs_init, 129 auto_fmount, 130 pfs_fmount, 131 auto_fumount, 132 pfs_fumount, 133 efs_lookuppn, 134 efs_readdir, 135 0, /* pfs_readlink */ 136 0, /* pfs_mounted */ 137 0, /* pfs_umounted */ 138 find_afs_srvr, 139 FS_BACKGROUND|FS_AMQINFO 140 }; 141 142 #endif /* HAS_PFS */ 143