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